Skip to content

Commit

Permalink
Merge branch 'dev-postElasticSearch' into refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeMBourgeois authored Feb 20, 2024
2 parents cb8b584 + 77f620e commit 5885ade
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ RUN mvn -B -f /DDI-Access-Services/pom.xml package
MAINTAINER hugobouttes

FROM openjdk:17-alpine
COPY --from=mvn DDI-Access-Services/target/rmes-0.0.10-BetaElastic.jar app.jar
COPY --from=mvn DDI-Access-Services/target/rmes-0.1.10-BetaElastic.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
11 changes: 11 additions & 0 deletions src/main/java/fr/insee/rmes/ToColecticaApi/controller/GetItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ public ResponseEntity<String> findFragmentByUuidColectica(

}

@GetMapping("ddiFragment/uuid/withChildren")
@Operation(summary = "Get Fragment by uuid", description = "Get an XML document for a ddi:Fragment from Colectica repository.")
@Produces(MediaType.APPLICATION_XML)
public String FindFragmentByUuidWithChildrenColectica (
@Parameter(
description = "id de l'objet colectica",
required = true,
schema = @Schema(
type = "string", example="d6c08ec1-c4d2-4b9a-b358-b23aa4e0af93")) String uuid) throws Exception {
return colecticaService.findFragmentByUuidWithChildren(uuid);

}

@GetMapping("/filtered-search/texte")
@Operation(summary = "Get list of match in elasticsearch database", description = "Get a JSON ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
public interface ColecticaService {
ResponseEntity<String> findFragmentByUuid(String uuid);


ResponseEntity<String> findInstanceByUuid(String uuid);
String findFragmentByUuidWithChildren(String uuid) throws Exception;
ResponseEntity<String> filteredSearchText(String index, String texte);


ResponseEntity<String> searchTexteByType(String index, String texte, DDIItemType type);
ResponseEntity<String> searchByType(String index, DDIItemType type);
ResponseEntity<List<Map<String,String>>> getJsonWithChild(String identifier, String outputField, String fieldLabelName) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.sf.saxon.s9api.Processor;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
Expand All @@ -36,8 +38,6 @@
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -105,7 +105,7 @@ public class ColecticaServiceImpl implements ColecticaService {
@Value("${fr.insee.rmes.api.remote.metadata.agency}")
private String agency;

@Value("${fr.insee.rmes.elasticsearch.host}")
@Value("${fr.insee.rmes.elasticsearch.host}")
private String elasticHost;

@Value("${fr.insee.rmes.elasticsearch.port}")
Expand Down Expand Up @@ -271,8 +271,18 @@ private JSONObject extractDataFromFragment(String fragmentXml) {
return new JSONObject();
}
}
private ResponseEntity<String> searchColecticaInstanceByUuid(String uuid) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {


private ResponseEntity<?> searchColecticaInstanceByUuid(String uuid) {
// Configuration pour ignorer les cookies invalides
RequestConfig globalConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.build();

try (CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(globalConfig)
.build()) {

HttpGet httpGet;
String authentToken;
String url = String.format("%s/api/v1/ddiset/%s/%s", serviceUrl, agency, uuid);
Expand All @@ -286,6 +296,7 @@ private ResponseEntity<String> searchColecticaInstanceByUuid(String uuid) {
authentToken = extractAccessToken(token2);
httpGet.setHeader(AUTHORIZATION, BEARER + authentToken);
}

try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
String preresponseBody = EntityUtils.toString(response.getEntity());
String responseBody = preresponseBody.replace("","");
Expand Down Expand Up @@ -550,12 +561,9 @@ public String convertXmlToJson(String uuid) throws ExceptionColecticaUnreachable
}

@Override
public String replaceXmlParameters(@RequestBody String inputXml,
@RequestParam("Type") DDIItemType type,
@RequestParam ("Label") String label,
@RequestParam (VERSION) int version,
@RequestParam ("Name") String name,
@RequestParam ("VersionResponsibility") String idepUtilisateur) {

public String replaceXmlParameters(String inputXml, DDIItemType type, String label, int version,String name,
String idepUtilisateur) {
try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Expand Down

0 comments on commit 5885ade

Please sign in to comment.