Skip to content
Snippets Groups Projects
Commit cffcccf1 authored by ludovic Blanchet's avatar ludovic Blanchet Committed by Gaëlle FOURNIER
Browse files

19009 - Agencies - Fix delete error message


Co-authored-by: default avatarbenemart <benedicte.martinez@cea.fr>
parent 64f6e679
No related branches found
No related tags found
No related merge requests found
Showing
with 37 additions and 20 deletions
......@@ -142,16 +142,18 @@ public class VitamAgencyService {
return importAgencies(vitamContext, actualAgencies);
}
public RequestResponse<?> deleteAgency(final VitamContext vitamContext, final String id)
public boolean deleteAgency(final VitamContext vitamContext, final String id)
throws InvalidParseOperationException, AccessExternalClientException, VitamClientException, IOException {
RequestResponse<AgenciesModel> requestResponse = agencyService.findAgencies(vitamContext, new Select().getFinalSelect());
final List<AgencyModelDto> actualAgencies = objectMapper
.treeToValue(requestResponse.toJsonNode(), AgencyResponseDto.class).getResults();
return importAgencies(vitamContext, actualAgencies.stream()
RequestResponse r = importAgencies(vitamContext, actualAgencies.stream()
.filter( agency -> !id.equals(agency.getId()) )
.collect(Collectors.toList()));
LOGGER.error("is ok ? {}", r.isOk());
return r.isOk();
}
public RequestResponse<?> create(final VitamContext vitamContext, AgencyModelDto newAgency)
......
......@@ -91,4 +91,9 @@ public class AgencyExternalRestClient extends BasePaginatingAndSortingRestClient
final HttpEntity<AgencyDto> request = new HttpEntity<>(null, buildHeaders(context));
return restTemplate.exchange(uriBuilder.toUriString(), HttpMethod.GET, request, Resource.class);
}
public ResponseEntity<Boolean> deleteWithResponse(ExternalHttpContext context, final String id) {
final HttpEntity<Void> request = new HttpEntity<>(buildHeaders(context));
return restTemplate.exchange(getUrl() + CommonConstants.PATH_ID, HttpMethod.DELETE, request, Boolean.class, id);
}
}
......@@ -144,9 +144,9 @@ public class AgencyExternalController {
@Secured(ServicesData.ROLE_DELETE_AGENCIES)
@DeleteMapping(CommonConstants.PATH_ID)
public void delete(final @PathVariable("id") String id) {
public ResponseEntity<Boolean> delete(final @PathVariable("id") String id) {
LOGGER.debug("Delete agency with id :{}", id);
agencyExternalService.delete(id);
return agencyExternalService.deleteWithResponse(id);
}
@Secured(ServicesData.ROLE_EXPORT_AGENCIES)
......
......@@ -118,8 +118,8 @@ public class AgencyExternalService extends AbstractResourceClientService<AgencyD
return agencyInternalRestClient.check(getInternalHttpContext(), accessContractDto);
}
public void delete(final String id) {
agencyInternalRestClient.delete(getInternalHttpContext(), id);
public ResponseEntity<Boolean> deleteWithResponse(final String id) {
return agencyInternalRestClient.deleteWithResponse(getInternalHttpContext(), id);
}
public ResponseEntity<Resource> export() {
......
......@@ -92,4 +92,8 @@ public class AgencyInternalRestClient extends BasePaginatingAndSortingRestClient
return restTemplate.exchange(uriBuilder.toUriString(), HttpMethod.GET, request, Resource.class);
}
public ResponseEntity<Boolean> deleteWithResponse(final InternalHttpContext context, final String id) {
final HttpEntity<Void> request = new HttpEntity<>(buildHeaders(context));
return restTemplate.exchange(getUrl() + CommonConstants.PATH_ID, HttpMethod.DELETE, request, Boolean.class, id);
}
}
......@@ -214,8 +214,7 @@ public class AgencyInternalService {
public boolean delete(VitamContext context, String id) {
try {
RequestResponse<?> requestResponse = vitamAgencyService.deleteAgency(context, id);
return requestResponse.isOk();
return vitamAgencyService.deleteAgency(context, id);
} catch (InvalidParseOperationException | AccessExternalClientException | VitamClientException | IOException e) {
throw new InternalServerException("Unable to delete agency", e);
}
......
......@@ -146,10 +146,10 @@ public class AgencyInternalController {
}
@DeleteMapping(CommonConstants.PATH_ID)
public void delete(final @PathVariable("id") String id) {
public ResponseEntity<Boolean> delete(final @PathVariable("id") String id) {
LOGGER.debug("Delete {}", id);
final VitamContext vitamContext = securityService.buildVitamContext(securityService.getTenantIdentifier());
agencyInternalService.delete(vitamContext, id);
return new ResponseEntity<>(agencyInternalService.delete(vitamContext, id), HttpStatus.OK);
}
@GetMapping("/export")
......
......@@ -125,12 +125,19 @@ export class AgencyService extends SearchService<Agency> {
delete(agency: Agency): Observable<any> {
return this.agencyApiService.delete(agency.id).pipe(
tap(() => {
this.snackBar.openFromComponent(VitamUISnackBarComponent, {
panelClass: 'vitamui-snack-bar',
duration: 10000,
data: {type: 'agencyDelete', name: agency.identifier}
});
tap((response) => {
if (response === false) {
this.snackBar.open('Erreur lors de la suppression du Service Agent ' + agency.id, null, {
panelClass: 'vitamui-snack-bar',
duration: 10000
});
} else {
this.snackBar.openFromComponent(VitamUISnackBarComponent, {
panelClass: 'vitamui-snack-bar',
duration: 10000,
data: {type: 'agencyDelete', name: agency.identifier}
});
}
},
(error) => {
this.snackBar.open(error.error.message, null, {
......
......@@ -162,9 +162,9 @@ public class AgencyController extends AbstractUiRestController {
@ApiOperation(value = "delete agency")
@DeleteMapping(CommonConstants.PATH_ID)
public void delete(final @PathVariable String id) {
public ResponseEntity<Boolean> delete(final @PathVariable String id) {
LOGGER.debug("delete agency with id :{}", id);
service.delete(buildUiHttpContext(), id);
return service.deleteWithResponse(buildUiHttpContext(), id);
}
@ApiOperation(value = "get exported csv for agencies")
......
......@@ -92,8 +92,8 @@ public class AgencyService extends AbstractPaginateService<AgencyDto> {
return client.check(context,accessContractDto);
}
public void delete(ExternalHttpContext context, String id) {
client.delete(context, id);
public ResponseEntity<Boolean> deleteWithResponse(ExternalHttpContext context, String id) {
return client.deleteWithResponse(context, id);
}
public ResponseEntity<Resource> export(ExternalHttpContext context) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment