diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java index 80da90d5..4cd23c62 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java @@ -23,7 +23,7 @@ public interface IIniClient { IniTraceResponseDTO delete(DeleteRequestDTO iniReq); - IniTraceResponseDTO update(IniMetadataUpdateReqDTO iniReq); + IniTraceResponseDTO update(IniMetadataUpdateReqDTO request,boolean callUpdateV2); IniReferenceResponseDTO reference(IniReferenceRequestDTO iniReferenceRequestDTO); diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java index d9d5bbd9..55eadf40 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java @@ -95,16 +95,23 @@ public IniReferenceResponseDTO reference(IniReferenceRequestDTO request) { } @Override - public IniTraceResponseDTO update(IniMetadataUpdateReqDTO request) { + public IniTraceResponseDTO update(IniMetadataUpdateReqDTO request,boolean callUpdateV2) { - String endpoint = routes.update(); + String endpoint = "";; IniTraceResponseDTO output = null; log.debug("{} - Executing request: {}", routes.identifier(), endpoint); try { - // Execute request - ResponseEntity response = client.exchange(endpoint,PUT,new HttpEntity<>(request),IniTraceResponseDTO.class); + ResponseEntity response = null; + if(callUpdateV2) { + endpoint = routes.update("v2"); + response = client.exchange(endpoint,PUT,new HttpEntity<>(request),IniTraceResponseDTO.class); + } else { + endpoint = routes.update("v1"); + response = client.exchange(endpoint,PUT,new HttpEntity<>(request),IniTraceResponseDTO.class); + } + // Retrieve body output = response.getBody(); } catch (RestClientResponseException ex) { diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/IniClientRoutes.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/IniClientRoutes.java index 4b6433cb..30e2d8a7 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/IniClientRoutes.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/IniClientRoutes.java @@ -40,8 +40,8 @@ public String delete() { return base().pathSegment(API_VERSION, DELETE_PATH).build().toUriString(); } - public String update() { - return base().pathSegment(API_VERSION, UPDATE_PATH).build().toUriString(); + public String update(String apiVersion) { + return base().pathSegment(apiVersion, UPDATE_PATH).build().toUriString(); } public String references(String id) { diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java index 634157d1..3438b942 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java @@ -690,7 +690,7 @@ protected PublicationCreationReqDTO getAndValidateValdaPublicationReq(final Stri return out; } - protected ResponseWifDTO updateAbstract(final String idDoc, final PublicationMetadataReqDTO requestBody, boolean callNewUpdate, + protected ResponseWifDTO updateAbstract(final String idDoc, final PublicationMetadataReqDTO requestBody, boolean callUpdateV2, final HttpServletRequest request) { // Estrazione token JWTPayloadDTO jwtPayloadToken = null; @@ -738,7 +738,7 @@ protected ResponseWifDTO updateAbstract(final String idDoc, final PublicationMet kafkaSRV.sendUpdateStatus(logTraceDTO.getTraceID(), wif, idDoc, SUCCESS, jwtPayloadToken, "Regime di mock", INI_UPDATE); } else { IniTraceResponseDTO res = iniClient.update(new IniMetadataUpdateReqDTO(metadatiToUpdate.getMarshallResponse(), jwtPayloadToken,metadatiToUpdate.getDocumentType(),wif, - metadatiToUpdate.getAdministrativeRequest(), metadatiToUpdate.getAuthorInstitution())); + metadatiToUpdate.getAdministrativeRequest(), metadatiToUpdate.getAuthorInstitution()),callUpdateV2); // Check response errors if(Boolean.FALSE.equals(res.getEsito())) { // Send to indexer diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/IniClientTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/IniClientTest.java index 28ff82ef..bf2bdb76 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/IniClientTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/IniClientTest.java @@ -56,7 +56,7 @@ class IniClientTest { void updateConnectionRefusedErrorTest() { Mockito.doThrow(new ConnectionRefusedException("url", "Error: connection refused")).when(restTemplate) .exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), eq(IniTraceResponseDTO.class)); - assertThrows(ConnectionRefusedException.class, () -> iniClient.update(requestBody)); + assertThrows(ConnectionRefusedException.class, () -> iniClient.update(requestBody,false)); } @Test @@ -66,7 +66,7 @@ void updateRecordGenericErrorTest() { responseMock.setMessage("Failed to update on INI"); Mockito.doReturn(new ResponseEntity<>(responseMock, HttpStatus.OK)) .when(restTemplate).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(IniTraceResponseDTO.class)); - assertEquals("Failed to update on INI", iniClient.update(requestBody).getMessage()); + assertEquals("Failed to update on INI", iniClient.update(requestBody,false).getMessage()); } @Test @@ -76,7 +76,7 @@ void updateRecordGenericExceptionTest() { responseMock.setEsito(false); Mockito.doThrow(new BusinessException("Error")).when(restTemplate) .exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), eq(IniTraceResponseDTO.class)); - assertThrows(BusinessException.class, () -> iniClient.update(requestBody)); + assertThrows(BusinessException.class, () -> iniClient.update(requestBody,false)); } // @Test @@ -101,7 +101,7 @@ void updateRecordSuccessTest() { responseMock.setEsito(true); Mockito.doReturn(new ResponseEntity<>(responseMock, HttpStatus.OK)).when(restTemplate) .exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), eq(IniTraceResponseDTO.class)); - IniTraceResponseDTO responseDTO = iniClient.update(requestBody); + IniTraceResponseDTO responseDTO = iniClient.update(requestBody,false); assertEquals(responseDTO, responseMock); } @@ -112,7 +112,7 @@ void updateRecordHttpErrorTest() { responseMock.setEsito(true); Mockito.doReturn(new ResponseEntity<>(responseMock, HttpStatus.BAD_GATEWAY)).when(restTemplate) .exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), eq(IniTraceResponseDTO.class)); - assertNull(iniClient.update(requestBody).getMessage()); + assertNull(iniClient.update(requestBody,false).getMessage()); } @Test @@ -120,6 +120,6 @@ void updateRecordHttpErrorTest() { void updateRecordHttpBodyNullTest() { Mockito.doReturn(new ResponseEntity<>(null, HttpStatus.BAD_GATEWAY)).when(restTemplate) .exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), eq(IniTraceResponseDTO.class)); - assertNull(iniClient.update(requestBody)); + assertNull(iniClient.update(requestBody,false)); } }