Skip to content

Commit

Permalink
feat(draft): pass wii for delete & update
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDel03 committed Oct 2, 2024
1 parent fbd7f15 commit e317176
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,17 @@ 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;

log.debug("{} - Executing request: {}", routes.identifier(), endpoint);

try {

Map<String,Object> requestBody = new HashMap<>();
requestBody.put("token", request.getToken());
requestBody.put("workflowInstanceId", "test");

Map<String, Object> requestBody = new HashMap<>();
requestBody.put("token", request);
requestBody.put("workflowInstanceId", workflowInstanceId);
// Execute request
ResponseEntity<IniReferenceResponseDTO> response = restTemplateIni.exchange(endpoint,POST,new HttpEntity<>(requestBody),IniReferenceResponseDTO.class);
// Retrieve body
Expand Down Expand Up @@ -126,15 +124,19 @@ 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;

log.debug("{} - Executing request: {}", routes.identifier(), endpoint);

try {
ResponseEntity<GetMergedMetadatiDTO> response = restTemplateIni.exchange(endpoint,PUT,new HttpEntity<>(request),GetMergedMetadatiDTO.class);
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("token", request);
requestBody.put("workflowInstanceId", workflowInstanceId);

ResponseEntity<GetMergedMetadatiDTO> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ public ResponseEntity<PublicationResDTO> 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.");
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -725,7 +726,8 @@ public ResponseEntity<PublicationResDTO> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e317176

Please sign in to comment.