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 59dc741..1cd66e9 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 @@ -26,9 +26,9 @@ public interface IIniClient { IniTraceResponseDTO update(IniMetadataUpdateReqDTO iniReq); - IniReferenceResponseDTO reference(IniReferenceRequestDTO iniReferenceRequestDTO); + IniReferenceResponseDTO reference(IniReferenceRequestDTO iniReferenceRequestDTO, String workflowInstanceId); - GetMergedMetadatiDTO metadata(MergedMetadatiRequestDTO iniReq); + GetMergedMetadatiDTO metadata(MergedMetadatiRequestDTO iniReq, String workflowInstanceId); IniAuditDto callSearchEventByWorkflowInstanceId(String workflowInstanceId); 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 4e2e737..6678688 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 @@ -80,7 +80,7 @@ public IniTraceResponseDTO delete(final DeleteRequestDTO request) { } @Override - public IniReferenceResponseDTO reference(IniReferenceRequestDTO request) { + public IniReferenceResponseDTO reference(IniReferenceRequestDTO request, String workflowInstanceId) { String endpoint = routes.references(request.getIdDoc()); IniReferenceResponseDTO output = null; @@ -88,11 +88,9 @@ public IniReferenceResponseDTO reference(IniReferenceRequestDTO request) { log.debug("{} - Executing request: {}", routes.identifier(), endpoint); try { - - Map requestBody = new HashMap<>(); - requestBody.put("token", request.getToken()); - requestBody.put("workflowInstanceId", "test"); - + Map requestBody = new HashMap<>(); + requestBody.put("token", request); + requestBody.put("workflowInstanceId", workflowInstanceId); // Execute request ResponseEntity response = restTemplateIni.exchange(endpoint,POST,new HttpEntity<>(requestBody),IniReferenceResponseDTO.class); // Retrieve body @@ -126,7 +124,7 @@ public IniTraceResponseDTO update(IniMetadataUpdateReqDTO request) { @Override - public GetMergedMetadatiDTO metadata(final MergedMetadatiRequestDTO request) { + public GetMergedMetadatiDTO metadata(final MergedMetadatiRequestDTO request, String workflowInstanceId) { String endpoint = routes.metadata(); GetMergedMetadatiDTO output = null; @@ -134,7 +132,11 @@ public GetMergedMetadatiDTO metadata(final MergedMetadatiRequestDTO request) { log.debug("{} - Executing request: {}", routes.identifier(), endpoint); try { - ResponseEntity response = restTemplateIni.exchange(endpoint,PUT,new HttpEntity<>(request),GetMergedMetadatiDTO.class); + Map requestBody = new HashMap<>(); + requestBody.put("token", request); + requestBody.put("workflowInstanceId", workflowInstanceId); + + ResponseEntity response = restTemplateIni.exchange(endpoint,PUT,new HttpEntity<>(requestBody),GetMergedMetadatiDTO.class); output = response.getBody(); } catch (ResourceAccessException ex) { throw new BusinessException("Timeout error while call merge metadati"); diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java index eedc948..30cffb0 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java @@ -240,7 +240,8 @@ public ResponseEntity replace(final String idDoc, final Publi log.info("[START] {}() with arguments {}={}, {}={}, {}={}","replace","traceId", traceInfoDTO.getTraceID(),"wif", validationInfo.getValidationData().getWorkflowInstanceId(),"idDoc", idDoc); IniReferenceRequestDTO iniReq = new IniReferenceRequestDTO(idDoc, validationInfo.getJwtPayloadToken()); - IniReferenceResponseDTO response = iniClient.reference(iniReq); + //TODO: verify wii + IniReferenceResponseDTO response = iniClient.reference(iniReq, null); if(!isNullOrEmpty(response.getErrorMessage())) { log.error("Errore. Nessun riferimento trovato."); @@ -300,7 +301,7 @@ public ResponseWifDTO updateMetadata(final String idDoc, final PublicationMetada validateUpdateMetadataReq(requestBody); wif = createWorkflowInstanceId(idDoc); - final GetMergedMetadatiDTO metadatiToUpdate = iniClient.metadata(new MergedMetadatiRequestDTO(idDoc,jwtPayloadToken, requestBody)); + final GetMergedMetadatiDTO metadatiToUpdate = iniClient.metadata(new MergedMetadatiRequestDTO(idDoc,jwtPayloadToken, requestBody), wif); if(!StringUtility.isNullOrEmpty(metadatiToUpdate.getErrorMessage()) && !metadatiToUpdate.getErrorMessage().contains("Invalid region ip")) { kafkaSRV.sendUpdateStatus(logTraceDTO.getTraceID(), wif, idDoc, BLOCKING_ERROR, jwtPayloadToken, metadatiToUpdate.getErrorMessage(), RIFERIMENTI_INI); throw new IniException(metadatiToUpdate.getErrorMessage()); @@ -515,7 +516,7 @@ public ResponseWifDTO delete(String idDoc, HttpServletRequest request) { // ============================== // [1] Retrieve reference from INI // ============================== - IniReferenceResponseDTO iniReference = iniClient.reference(new IniReferenceRequestDTO(idDoc, jwtPayloadToken)); + IniReferenceResponseDTO iniReference = iniClient.reference(new IniReferenceRequestDTO(idDoc, jwtPayloadToken), workflowInstanceId); // Exit if necessary if(!isNullOrEmpty(iniReference.getErrorMessage())) { kafkaSRV.sendDeleteStatus(info.getTraceID(), workflowInstanceId, idDoc, iniReference.getErrorMessage(), BLOCKING_ERROR, jwtPayloadToken, RIFERIMENTI_INI); @@ -725,7 +726,8 @@ public ResponseEntity validateAndReplace( log.info("[START] {}() with arguments {}={}, {}={}, {}={}","replace","traceId", traceInfoDTO.getTraceID(),"wif", validationResult.getValidationData().getWorkflowInstanceId(),"idDoc", idDoc); IniReferenceRequestDTO iniReq = new IniReferenceRequestDTO(idDoc, validationResult.getJwtPayloadToken()); - IniReferenceResponseDTO response = iniClient.reference(iniReq); + //TODO: verify wii + IniReferenceResponseDTO response = iniClient.reference(iniReq, null); if(!isNullOrEmpty(response.getErrorMessage())) { log.error("Errore. Nessun riferimento trovato."); diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java index 5c17085..e5aad5c 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java @@ -111,7 +111,7 @@ void givenACorrectCDA_shouldInsertInInvocations(final String filename) { mockFhirMapping(); mockIniClient(HttpStatus.OK, true); mockGetReference(new IniReferenceResponseDTO(idDocument, null, "DocumentType", null, null)); - Mockito.doReturn(new IniReferenceResponseDTO(idDocument, "DocumentType", "", null, null)).when(iniClient).reference(any(it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO.class)); + Mockito.doReturn(new IniReferenceResponseDTO(idDocument, "DocumentType", "", null, null)).when(iniClient).reference(any(it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO.class), anyString()); final byte[] pdfAttachment = FileUtility.getFileFromInternalResources("Files" + File.separator + "accreditamento" + File.separator + filename); @@ -172,7 +172,7 @@ void givenInvalidRequest_shouldReturnError(final String filename) { mockFhirMapping(); mockGetReference(new IniReferenceResponseDTO(idDocument, null,"DocumentType", null, null)); //when(iniClient.reference(any(it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO.class))).thenReturn(true); - Mockito.doReturn(new IniReferenceResponseDTO("uuid", "DocumentType", "", null, null)).when(iniClient).reference(any(it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO.class)); + Mockito.doReturn(new IniReferenceResponseDTO("uuid", "DocumentType", "", null, null)).when(iniClient).reference(any(it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO.class), anyString()); final byte[] notPdfFile = FileUtility.getFileFromInternalResources("Files/Test.docx"); assertThrows(HttpClientErrorException.BadRequest.class,