-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Zenika/zenika-dev
027b WIP
- Loading branch information
Showing
40 changed files
with
727 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=auto | ||
*.sh text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM vimagick/json-server |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 20 additions & 2 deletions
22
src/main/java/fr/insee/pogues/config/ApplicationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
package fr.insee.pogues.config; | ||
|
||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.ssl.SSLContexts; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import java.security.KeyManagementException; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
@Configuration | ||
@PropertySource("classpath:env/${fr.insee.pogues.env:dv}/pogues-bo.properties") | ||
public class ApplicationContext { | ||
|
||
@Bean | ||
public HttpClient httpClient(){ | ||
return HttpClients.createDefault(); | ||
public HttpClient httpClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { | ||
SSLContext sslContext = SSLContexts.custom() | ||
.loadTrustMaterial(null, new TrustSelfSignedStrategy()) | ||
.build(); | ||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( | ||
sslContext, | ||
NoopHostnameVerifier.INSTANCE); | ||
return HttpClients.custom() | ||
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) | ||
.setSSLSocketFactory(sslsf) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/fr/insee/pogues/metadata/client/MetadataClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fr.insee.pogues.metadata.client; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
public interface MetadataClient { | ||
|
||
JSONObject getItem(String id) throws Exception; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/fr/insee/pogues/metadata/client/MetadataClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fr.insee.pogues.metadata.client; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.util.EntityUtils; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MetadataClientImpl implements MetadataClient { | ||
|
||
@Autowired | ||
HttpClient httpClient; | ||
|
||
@Value("${fr.insee.pogues.api.remote.metadata.url}") | ||
String serviceUrl; | ||
|
||
@Override | ||
public JSONObject getItem(String id) throws Exception{ | ||
try { | ||
HttpGet get = new HttpGet(String.format("%s/items/%s", serviceUrl, id)); | ||
// HttpGet get = new HttpGet(String.format("https://dvrmesgopswas01.ad.insee.intra/api/v1/item/fr.insee/%s/1?api_key=ADMINKEY", id)); | ||
get.addHeader("accept", "application/json"); | ||
HttpResponse response = httpClient.execute(get); | ||
if (response.getStatusLine().getStatusCode() != 200) { | ||
throw new RuntimeException("Failed : HTTP error code : " | ||
+ response.getStatusLine().getStatusCode()); | ||
} | ||
String body = EntityUtils.toString(response.getEntity()); | ||
return (JSONObject) | ||
new JSONParser().parse(body); | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/fr/insee/pogues/metadata/model/MetadataResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fr.insee.pogues.metadata.model; | ||
|
||
public class MetadataResponse { | ||
|
||
String version; | ||
String Identifier; | ||
String Item; | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/fr/insee/pogues/metadata/repository/MetadataRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fr.insee.pogues.metadata.repository; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
public interface MetadataRepository { | ||
|
||
JSONObject findById(String id) throws Exception; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/fr/insee/pogues/metadata/repository/MetadataRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.insee.pogues.metadata.repository; | ||
|
||
import fr.insee.pogues.metadata.client.MetadataClient; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MetadataRepositoryImpl implements MetadataRepository { | ||
|
||
@Autowired | ||
MetadataClient metadataClient; | ||
|
||
@Override | ||
public JSONObject findById(String id) throws Exception{ | ||
try { | ||
return metadataClient.getItem(id); | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/fr/insee/pogues/metadata/service/MetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package fr.insee.pogues.metadata.service; | ||
|
||
import fr.insee.pogues.search.model.Family; | ||
import org.json.simple.JSONObject; | ||
|
||
public interface MetadataService { | ||
|
||
JSONObject getItem(String id) throws Exception; | ||
Family getFamily(String id) throws Exception; | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/fr/insee/pogues/metadata/service/MetadataServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package fr.insee.pogues.metadata.service; | ||
|
||
import fr.insee.pogues.metadata.repository.MetadataRepository; | ||
import fr.insee.pogues.metadata.utils.XpathProcessor; | ||
import fr.insee.pogues.search.model.Family; | ||
import fr.insee.pogues.search.model.Operation; | ||
import fr.insee.pogues.search.model.Questionnaire; | ||
import fr.insee.pogues.search.model.Series; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class MetadataServiceImpl implements MetadataService { | ||
|
||
@Autowired | ||
MetadataRepository metadataRepository; | ||
|
||
@Autowired | ||
XpathProcessor xpathProcessor; | ||
|
||
@Override | ||
public JSONObject getItem(String id) throws Exception{ | ||
try { | ||
return metadataRepository.findById(id); | ||
} catch(Exception e) { | ||
e.printStackTrace(); | ||
throw e; | ||
} | ||
} | ||
|
||
public Family getFamily(String id) throws Exception { | ||
Family family = new Family(); | ||
String fragment = getItem(id).get("Item").toString(); | ||
String groupExp = "//*[local-name()='Group']"; | ||
String labelExp = "//*[local-name()='Citation']/*[local-name()='Title']/*[local-name()='String']/text()"; | ||
Node rootNode = xpathProcessor.queryList(fragment, groupExp).item(0); | ||
family.setId(id); | ||
family.setLabel(xpathProcessor.queryText(rootNode, labelExp)); | ||
family.setSeries(getSeries(rootNode, family)); | ||
return family; | ||
} | ||
|
||
public List<Series> getSeries(Node node, Family family) throws Exception { | ||
List<Series> seriesList = new ArrayList<>(); | ||
String childExp = ".//*[local-name()='SubGroupReference']"; | ||
NodeList children = xpathProcessor.queryList(node, childExp); | ||
for(int i = 0; i < children.getLength(); i++) { | ||
String id = xpathProcessor.queryText(children.item(i),".//*[local-name()='ID']/text()"); | ||
String fragment = getItem(id).get("Item").toString(); | ||
System.out.println("fragment " + fragment); | ||
Node child = xpathProcessor.toDocument(fragment); | ||
Series series = new Series(); | ||
series.setId(id); | ||
series.setParent(family.getId()); | ||
series.setLabel(xpathProcessor.queryText(child, ".//*[local-name()='SubGroup']/*[local-name()='Citation']/*[local-name()='Title']/*[local-name()='String']/text()")); | ||
series.setOperations(getOperations(child, series)); | ||
seriesList.add(series); | ||
} | ||
return seriesList; | ||
} | ||
|
||
public List<Operation> getOperations(Node node, Series series) throws Exception { | ||
List<Operation> operations = new ArrayList<>(); | ||
System.out.println(node.getLocalName()); | ||
String childExp = ".//*[local-name()='StudyUnitReference']"; | ||
NodeList children = xpathProcessor.queryList(node, childExp); | ||
for(int i = 0; i < children.getLength(); i++) { | ||
String id = xpathProcessor.queryText(children.item(i),".//*[local-name()='ID']/text()"); | ||
String fragment = getItem(id).get("Item").toString(); | ||
System.out.println("id: " + id); | ||
System.out.println("frg : " + fragment); | ||
Node child = xpathProcessor.toDocument(fragment); | ||
Operation operation = new Operation(); | ||
operation.setId(id); | ||
operation.setParent(series.getId()); | ||
operation.setLabel(xpathProcessor.queryText(child, ".//*[local-name()='StudyUnit']/*[local-name()='Citation']/*[local-name()='Title']/*[local-name()='String']/text()")); | ||
operation.setQuestionnaires(getQuestionnaires(child, operation)); | ||
operations.add(operation); | ||
} | ||
return operations; | ||
} | ||
|
||
public List<Questionnaire> getQuestionnaires(Node node, Operation operation) throws Exception { | ||
List<Questionnaire> questionnaires = new ArrayList<>(); | ||
String childExp = ".//*[local-name()='DataCollectionReference']"; | ||
NodeList children = xpathProcessor.queryList(node, childExp); | ||
for(int i = 0; i < children.getLength(); i++) { | ||
String id = xpathProcessor.queryText(children.item(i),".//*[local-name()='ID']/text()"); | ||
String fragment = getItem(id).get("Item").toString(); | ||
Node child = xpathProcessor.toDocument(fragment); | ||
Questionnaire questionnaire = new Questionnaire(); | ||
questionnaire.setId(id); | ||
questionnaire.setParent(operation.getId()); | ||
questionnaire.setLabel(xpathProcessor.queryText(child, ".//*[local-name()='DataCollection']/*[local-name()='Label']/*[local-name()='Content']/text()")); | ||
questionnaires.add(questionnaire); | ||
} | ||
return questionnaires; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/fr/insee/pogues/metadata/utils/XpathProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fr.insee.pogues.metadata.utils; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public interface XpathProcessor { | ||
|
||
NodeList queryList(String fragment, String xpathExpression) throws Exception; | ||
NodeList queryList(Node node, String xpathExpression) throws Exception; | ||
String queryText(String fragment, String xpathExpression) throws Exception; | ||
String queryText(Node node, String xpathExpression) throws Exception; | ||
Document toDocument(String xml) throws Exception; | ||
} |
Oops, something went wrong.