Skip to content

Commit

Permalink
feat: Call update v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Oct 4, 2024
1 parent b681d9f commit cf8acf7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IniTraceResponseDTO> response = client.exchange(endpoint,PUT,new HttpEntity<>(request),IniTraceResponseDTO.class);
ResponseEntity<IniTraceResponseDTO> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}

Expand All @@ -112,14 +112,14 @@ 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
@DisplayName("Update - updateRecordHttpBodyNullTest")
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));
}
}

0 comments on commit cf8acf7

Please sign in to comment.