-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
43 additions
and
60 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,18 +66,18 @@ | |
@Service | ||
public class ColecticaServiceImpl implements ColecticaService { | ||
|
||
private final static String CONTENT_TYPE = "Content-Type"; | ||
private final static String APPLICATION_XML = "application/xml"; | ||
private final static String APPLICATION_JSON = "application/json"; | ||
private final static String AUTHORIZATION = "Authorization"; | ||
private final static String BEARER = "Bearer "; | ||
private final static String HTTP = "http://"; | ||
private final static String VERSION = "version"; | ||
private final static String SEARCH = "/_search"; | ||
private final static String BASIC = "Basic "; | ||
private final static String ERREUR_COLECTICA = "Une erreur s'est produite lors de la requête vers Colectica."; | ||
private final static String ERREUR_ELASTICSEARCH = "Une erreur s'est produite lors de la requête Elasticsearch."; | ||
private final static String TRANSACTIONID = "{\"TransactionId\":"; | ||
private static final String CONTENT_TYPE = "Content-Type"; | ||
private static final String APPLICATION_XML = "application/xml"; | ||
private static final String APPLICATION_JSON = "application/json"; | ||
private static final String AUTHORIZATION = "Authorization"; | ||
private static final String BEARER = "Bearer "; | ||
private static final String HTTP = "http://"; | ||
private static final String VERSION = "version"; | ||
private static final String SEARCH = "/_search"; | ||
private static final String BASIC = "Basic "; | ||
private static final String ERREUR_COLECTICA = "Une erreur s'est produite lors de la requête vers Colectica."; | ||
private static final String ERREUR_ELASTICSEARCH = "Une erreur s'est produite lors de la requête Elasticsearch."; | ||
private static final String TRANSACTIONID = "{\"TransactionId\":"; | ||
|
||
|
||
|
||
|
@@ -167,9 +167,7 @@ private ResponseEntity<String> searchColecticaFragmentByUuid(String uuid) { | |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(ERREUR_COLECTICA); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} catch (ExceptionColecticaUnreachable e) { | ||
} catch (IOException|ExceptionColecticaUnreachable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
@@ -212,9 +210,7 @@ private ResponseEntity<String> searchColecticaInstanceByUuid(String uuid) { | |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(ERREUR_COLECTICA); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} catch (ExceptionColecticaUnreachable e) { | ||
} catch (IOException|ExceptionColecticaUnreachable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
@@ -232,7 +228,7 @@ public ResponseEntity<String> filteredSearchText(String index, String texte) { | |
} | ||
|
||
@Override | ||
public ResponseEntity<String> SearchByType(String index, DDIItemType type) { | ||
public ResponseEntity<String> searchByType(String index, DDIItemType type) { | ||
ResponseEntity<String> responseEntity = searchType(index, String.valueOf(type.getUUID()).toLowerCase()); | ||
if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
String responseBody = (String) responseEntity.getBody(); | ||
|
@@ -244,10 +240,10 @@ public ResponseEntity<String> SearchByType(String index, DDIItemType type) { | |
} | ||
|
||
@Override | ||
public ResponseEntity<String> SearchTexteByType(String index,String texte, DDIItemType type) { | ||
public ResponseEntity<String> searchTexteByType(String index, String texte, DDIItemType type) { | ||
ResponseEntity<String> responseEntity = searchTextByType(index, texte, String.valueOf(type.getUUID()).toLowerCase()); | ||
if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
String responseBody = (String) responseEntity.getBody(); | ||
String responseBody = (String) responseEntity.getBody(); | ||
String filteredResponse = filterAndTransformResponse(responseBody); | ||
return ResponseEntity.ok(filteredResponse); | ||
} else { | ||
|
@@ -269,8 +265,8 @@ private ResponseEntity<String> searchType(String index,String type) { | |
} | ||
else { | ||
httpPost = new HttpPost(HTTP + elasticHost + ":" + elasticHostPort + "/" + index + SEARCH); | ||
String token = Base64.getEncoder().encodeToString((apiId + ":" + apiKey).getBytes(StandardCharsets.UTF_8)); | ||
httpPost.setHeader(AUTHORIZATION, BASIC + token); | ||
String tokenElastic = Base64.getEncoder().encodeToString((apiId + ":" + apiKey).getBytes(StandardCharsets.UTF_8)); | ||
httpPost.setHeader(AUTHORIZATION, BASIC + tokenElastic); | ||
Check failure Code scanning / SonarCloud Basic authentication should not be used High
Use a more secure method than basic authentication. See more on SonarCloud
|
||
httpPost.setHeader(CONTENT_TYPE, APPLICATION_JSON); | ||
httpPost.setEntity(entity); | ||
} | ||
|
@@ -297,8 +293,8 @@ private ResponseEntity<String> searchText(String index, String texte) { | |
httpGet = new HttpGet("https://" + elasticHost + ":" + elasticHostPort + "/" + index + "/_search?q=" + encodedTexte); | ||
} else { | ||
httpGet = new HttpGet(HTTP + elasticHost + ":" + elasticHostPort + "/" + index + "/_search?q=*" + encodedTexte + "*"); | ||
String token = Base64.getEncoder().encodeToString((apiId + ":" + apiKey).getBytes(StandardCharsets.UTF_8)); | ||
httpGet.addHeader(AUTHORIZATION, BASIC + token); | ||
String tokenElastic = Base64.getEncoder().encodeToString((apiId + ":" + apiKey).getBytes(StandardCharsets.UTF_8)); | ||
httpGet.addHeader(AUTHORIZATION, BASIC + tokenElastic); | ||
Check failure Code scanning / SonarCloud Basic authentication should not be used High
Use a more secure method than basic authentication. See more on SonarCloud
|
||
} | ||
|
||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) { | ||
|
@@ -317,8 +313,8 @@ private ResponseEntity<String> searchTextByType(String index, String texte, Stri | |
|
||
// Ajouter l'en-tête pour l'authentification et le type de contenu si nécessaire | ||
if (!elasticHost.contains("kube")) { | ||
String token = Base64.getEncoder().encodeToString((apiId + ":" + apiKey).getBytes(StandardCharsets.UTF_8)); | ||
httpPost.setHeader(AUTHORIZATION, BASIC + token); | ||
String tokenElastic = Base64.getEncoder().encodeToString((apiId + ":" + apiKey).getBytes(StandardCharsets.UTF_8)); | ||
httpPost.setHeader(AUTHORIZATION, BASIC + tokenElastic); | ||
Check failure Code scanning / SonarCloud Basic authentication should not be used High
Use a more secure method than basic authentication. See more on SonarCloud
|
||
httpPost.setHeader(CONTENT_TYPE, APPLICATION_JSON); | ||
} | ||
|
||
|
@@ -423,9 +419,7 @@ public ResponseEntity<List<Map<String,String>>> getJsonWithChild(String identifi | |
} else { | ||
return ResponseEntity.status(response.getStatusCode()).body(null); | ||
} | ||
} catch (HttpClientErrorException e) { | ||
return ResponseEntity.status(e.getStatusCode()).body(null); | ||
} catch (HttpServerErrorException e) { | ||
} catch (HttpClientErrorException|HttpServerErrorException e) { | ||
return ResponseEntity.status(e.getStatusCode()).body(null); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); | ||
|
@@ -524,8 +518,7 @@ public String replaceXmlParameters(@RequestBody String inputXml, | |
StringWriter writer = new StringWriter(); | ||
transformer.transform(new DOMSource(document2), new StreamResult(writer)); | ||
InputStream xsltStream2 = getClass().getResourceAsStream("/DDIxmltojsonForOneObject.xsl"); | ||
String jsonContent = transformToJson(new ByteArrayResource(writer.toString().getBytes(StandardCharsets.UTF_8)), xsltStream2, idepUtilisateur,version); | ||
return jsonContent; | ||
return transformToJson(new ByteArrayResource(writer.toString().getBytes(StandardCharsets.UTF_8)), xsltStream2, idepUtilisateur,version); | ||
|
||
|
||
} catch (Exception e) { | ||
|
@@ -548,8 +541,7 @@ private String transformToJson(Resource resultResource, InputStream xsltFileJson | |
StringWriter xmlWriter = new StringWriter(); | ||
StreamResult xmlResult = new StreamResult(xmlWriter); | ||
transformer.transform(text, xmlResult); | ||
String jsonContent = xmlWriter.toString(); | ||
return jsonContent; | ||
return xmlWriter.toString(); | ||
} | ||
|
||
@Override | ||
|
@@ -586,7 +578,7 @@ public ResponseEntity<?> getByType(DDIItemType type) throws IOException, Excepti | |
} | ||
|
||
@Override | ||
public ResponseEntity<String> sendUpdateColectica(String DdiUpdatingInJson, TransactionType transactionType) { | ||
public ResponseEntity<String> sendUpdateColectica(String ddiUpdatingInJson, TransactionType transactionType) { | ||
try { | ||
// Étape 1: Initialiser la transaction | ||
String initTransactionUrl = serviceUrl + "/api/v1/transaction"; | ||
|
@@ -618,7 +610,7 @@ public ResponseEntity<String> sendUpdateColectica(String DdiUpdatingInJson, Tran | |
populateTransactionHeaders.setContentType(MediaType.APPLICATION_JSON); | ||
populateTransactionHeaders.setBearerAuth(authentToken); | ||
// Créez un objet de demande pour peupler la transaction ici avec transactionId et DdiUpdatingInJson | ||
String updatedJson = DdiUpdatingInJson.replaceFirst("\\{", TRANSACTIONID + transactionId + ","); | ||
String updatedJson = ddiUpdatingInJson.replaceFirst("\\{", TRANSACTIONID + transactionId + ","); | ||
HttpEntity<String> populateTransactionRequest = new HttpEntity<>(updatedJson, populateTransactionHeaders); | ||
ResponseEntity<String> populateTransactionResponse = restTemplate.exchange( | ||
populateTransactionUrl, | ||
|
@@ -669,8 +661,7 @@ private int extractTransactionId(String responseBody) { | |
try { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JsonNode jsonNode = objectMapper.readTree(responseBody); | ||
int transactionId = jsonNode.get("TransactionId").asInt(); | ||
return transactionId; | ||
return jsonNode.get("TransactionId").asInt(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return -1; | ||
|
@@ -851,8 +842,7 @@ private String transformToXml(MultipartFile file, InputStream xsltFile, String i | |
StringWriter xmlWriter = new StringWriter(); | ||
StreamResult xmlResult = new StreamResult(xmlWriter); | ||
transformer.transform(text, xmlResult); | ||
String xmlContent = xmlWriter.toString(); | ||
return xmlContent; | ||
return xmlWriter.toString(); | ||
} | ||
|
||
private String transformToXmlForComplexList(MultipartFile file, InputStream xsltFile, String idValue, String nomenclatureName, | ||
|
@@ -890,8 +880,7 @@ private String transformToXmlForComplexList(MultipartFile file, InputStream xslt | |
StringWriter xmlWriter = new StringWriter(); | ||
StreamResult xmlResult = new StreamResult(xmlWriter); | ||
transformer.transform(text, xmlResult); | ||
String xmlContent = xmlWriter.toString(); | ||
return xmlContent; | ||
return xmlWriter.toString(); | ||
} | ||
|
||
private String transformToJson(Resource resultResource, InputStream xsltFileJson, String idepUtilisateur) throws IOException, TransformerException { | ||
|
@@ -907,8 +896,7 @@ private String transformToJson(Resource resultResource, InputStream xsltFileJson | |
StringWriter xmlWriter = new StringWriter(); | ||
StreamResult xmlResult = new StreamResult(xmlWriter); | ||
transformer.transform(text, xmlResult); | ||
String jsonContent = xmlWriter.toString(); | ||
return jsonContent; | ||
return xmlWriter.toString(); | ||
} | ||
|
||
@Override | ||
|
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