Skip to content

Commit

Permalink
refactoring: Remove usage of generic wildcard type
Browse files Browse the repository at this point in the history
ResponseEntity<?> replaced par a more specific type :
ResponseEntity<String> for end-points "/ddiFragment/uuid, /filtered-search/texte, /filtered-search/texteByType, /filtered-search/type/
 ResponseEntity<List<Map<String,String>>> for end-point /suggesters/jsonWithChild
  • Loading branch information
GtanSndil committed Dec 13, 2023
1 parent fd4a1e2 commit f26fbf3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ResponseEntity<String> FindInstanceByUuidColectica (
@GetMapping("ddiFragment/uuid")
@Operation(summary = "Get Fragment by uuid", description = "Get an XML document for a ddi:Fragment from Colectica repository.")
@Produces(MediaType.APPLICATION_XML)
public ResponseEntity<?> FindFragmentByUuidColectica (
public ResponseEntity<String> FindFragmentByUuidColectica (
@Parameter(
description = "id de l'objet colectica",
required = true,
Expand All @@ -64,7 +64,7 @@ public ResponseEntity<?> FindFragmentByUuidColectica (

@GetMapping("/filtered-search/texte")
@Operation(summary = "Get list of match in elasticsearch database", description = "Get a JSON ")
public ResponseEntity<?> filteredSearchText(
public ResponseEntity<String> filteredSearchText(
@Parameter(
description = "nom par défaut de l'index colectica",
required = true,
Expand All @@ -81,7 +81,7 @@ public ResponseEntity<?> filteredSearchText(

@GetMapping("/filtered-search/texteByType")
@Operation(summary = "Get list of match in elasticsearch database", description = "Get a JSON ")
public ResponseEntity<?> filteredSearchTextByType(
public ResponseEntity<String> filteredSearchTextByType(
@Parameter(
description = "nom par défaut de l'index colectica",
required = true,
Expand All @@ -103,7 +103,7 @@ public ResponseEntity<?> filteredSearchTextByType(

@GetMapping("/filtered-search/type/")
@Operation(summary = "Get list of match by type in elasticsearch database", description = "Get a JSON ")
public ResponseEntity<?> SearchByType(
public ResponseEntity<String> SearchByType(
@Parameter(
description = "nom par défaut de l'index colectica",
required = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface ColecticaService {
ResponseEntity<?> findFragmentByUuid(String uuid);
ResponseEntity<String> findFragmentByUuid(String uuid);

ResponseEntity<String> findInstanceByUuid(String uuid);

ResponseEntity<?> filteredSearchText(String index, String texte);
ResponseEntity<String> filteredSearchText(String index, String texte);

ResponseEntity<?> SearchTexteByType(String index, String texte, DDIItemType type);
ResponseEntity<?> SearchByType(String index, DDIItemType type);
ResponseEntity<?> getJsonWithChild(String identifier, String outputField, String fieldLabelName) throws Exception;
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;

String convertXmlToJson(String uuid) throws ExceptionColecticaUnreachable, JsonProcessingException;
String replaceXmlParameters(String inputXml, DDIItemType type, String label, int version, String name, String idepUtilisateur);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public ColecticaServiceImpl(ElasticsearchClient elasticsearchClient,RestTemplate
}

@Override
public ResponseEntity<?> findFragmentByUuid(String uuid) {
ResponseEntity<?> responseEntity = searchColecticaFragmentByUuid(uuid);
public ResponseEntity<String> findFragmentByUuid(String uuid) {
ResponseEntity<String> responseEntity = searchColecticaFragmentByUuid(uuid);
if (responseEntity.getStatusCode().is2xxSuccessful()) {
String responseBody = (String) responseEntity.getBody();
return ResponseEntity.ok(responseBody);
Expand All @@ -134,7 +134,7 @@ public ResponseEntity<?> findFragmentByUuid(String uuid) {
}
}

private ResponseEntity<?> searchColecticaFragmentByUuid(String uuid) {
private ResponseEntity<String> searchColecticaFragmentByUuid(String uuid) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String url = String.format("%s/api/v1/item/%s/%s", serviceUrl, agency, uuid);
HttpGet httpGet = new HttpGet(url);
Expand Down Expand Up @@ -220,8 +220,8 @@ private ResponseEntity<String> searchColecticaInstanceByUuid(String uuid) {
}

@Override
public ResponseEntity<?> filteredSearchText(String index, String texte) {
ResponseEntity<?> responseEntity = searchText(index, texte);
public ResponseEntity<String> filteredSearchText(String index, String texte) {
ResponseEntity<String> responseEntity = searchText(index, texte);
if (responseEntity.getStatusCode().is2xxSuccessful()) {
String responseBody = (String) responseEntity.getBody();
String filteredResponse = filterAndTransformResponse(responseBody);
Expand All @@ -232,8 +232,8 @@ public ResponseEntity<?> filteredSearchText(String index, String texte) {
}

@Override
public ResponseEntity<?> SearchByType(String index, DDIItemType type) {
ResponseEntity<?> responseEntity = searchType(index, String.valueOf(type.getUUID()).toLowerCase());
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();
String filteredResponse = filterAndTransformResponse(responseBody);
Expand All @@ -244,8 +244,8 @@ public ResponseEntity<?> SearchByType(String index, DDIItemType type) {
}

@Override
public ResponseEntity<?> SearchTexteByType(String index,String texte, DDIItemType type) {
ResponseEntity<?> responseEntity = searchTextByType(index, texte, String.valueOf(type.getUUID()).toLowerCase());
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 filteredResponse = filterAndTransformResponse(responseBody);
Expand All @@ -256,7 +256,7 @@ public ResponseEntity<?> SearchTexteByType(String index,String texte, DDIItemTyp
}


private ResponseEntity<?> searchType(String index,String type) {
private ResponseEntity<String> searchType(String index,String type) {

try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost;
Expand Down Expand Up @@ -288,7 +288,7 @@ private ResponseEntity<?> searchType(String index,String type) {
}


private ResponseEntity<?> searchText(String index, String texte) {
private ResponseEntity<String> searchText(String index, String texte) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String encodedTexte = URLEncoder.encode(texte, StandardCharsets.UTF_8.toString());
HttpGet httpGet;
Expand All @@ -311,7 +311,7 @@ private ResponseEntity<?> searchText(String index, String texte) {
}
}

private ResponseEntity<?> searchTextByType(String index, String texte, String type) {
private ResponseEntity<String> searchTextByType(String index, String texte, String type) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(HTTP + elasticHost + ":" + elasticHostPort + "/" + index + SEARCH);

Expand Down Expand Up @@ -387,7 +387,7 @@ private String filterAndTransformResponse(String responseBody) {
}

@Override
public ResponseEntity<?> getJsonWithChild(String identifier, String outputField, String fieldLabelName) throws Exception {
public ResponseEntity<List<Map<String,String>>> getJsonWithChild(String identifier, String outputField, String fieldLabelName) throws Exception {
String apiUrl = serviceUrl+"/api/v1/jsonset/fr.insee/" + identifier;

if (!serviceUrl.contains("kube")){
Expand Down

0 comments on commit f26fbf3

Please sign in to comment.