@Test public void testUpdateUnitById() throws Exception { when(accessInternalClient.updateUnitbyId(any(), any())) .thenReturn(new RequestResponseOK<JsonNode>().addResult( JsonHandler.getFromString("{'#id': '1', 'Title': 'Archive 1', 'DescriptionLevel': 'Archive Mock'}"))); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, TENANT_ID) .body(UPDATE_QUERY_VALID) .when() .put("/units/" + ID) .then() .statusCode(Status.OK.getStatusCode()); Update query = new Update(); query.addActions(UpdateActionHelper.set("Title", "new title")); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, TENANT_ID) .body(query.getFinalUpdateById()) .when() .put("/units/" + ID) .then() .statusCode(Status.OK.getStatusCode()); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, TENANT_ID) .body(query.getFinalUpdate()) .when() .put("/units/" + ID) .then() .statusCode(Status.BAD_REQUEST.getStatusCode()); UpdateMultiQuery emptyUpdateMultiQuery = new UpdateMultiQuery(); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, TENANT_ID) .body(emptyUpdateMultiQuery.getFinalUpdate()) .when() .put("/units/" + ID) .then() .statusCode(Status.BAD_REQUEST.getStatusCode()); UpdateMultiQuery queryUpdateMultiQuery = new UpdateMultiQuery(); queryUpdateMultiQuery.setQuery(eq("#id", "1")); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, TENANT_ID) .body(query.getFinalUpdate()) .when() .put("/units/" + ID) .then() .statusCode(Status.BAD_REQUEST.getStatusCode()); SelectMultiQuery selectMultiQuery = new SelectMultiQuery(); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, TENANT_ID) .body(selectMultiQuery.getFinalSelect()) .when() .put("/units/" + ID) .then() .statusCode(Status.BAD_REQUEST.getStatusCode()); given() .contentType(ContentType.JSON) .header(GlobalDataRest.X_TENANT_ID, UNEXTISTING_TENANT_ID) .body(buildDSLWithOptions(QUERY_SIMPLE_TEST, DATA)) .when() .put("/units/" + ID) .then() .statusCode(Status.UNAUTHORIZED.getStatusCode()); given() .contentType(ContentType.JSON) .body(buildDSLWithOptions(QUERY_SIMPLE_TEST, DATA)) .when() .put("/units/" + ID) .then() .statusCode(Status.PRECONDITION_FAILED.getStatusCode()); }
@PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") public Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit) { Status status; try (AccessInternalClient client = accessInternalClientFactory.getClient()) { UpdateParserMultiple updateParserMultiple = new UpdateParserMultiple(); updateParserMultiple.parse(queryJson); UpdateMultiQuery updateMultiQuery = updateParserMultiple.getRequest(); updateMultiQuery.addRoots(idUnit); RequestResponse<JsonNode> response = client.updateUnitbyId(updateMultiQuery.getFinalUpdate(), idUnit); if (!response.isOk() && response instanceof VitamError) { VitamError error = (VitamError) response; return buildErrorFromError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, error.getMessage(), error); } return Response.status(Status.OK).entity(response).build(); } catch (final InvalidParseOperationException e) { LOGGER.debug(PREDICATES_FAILED_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientServerException e) { LOGGER.debug(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), e); status = Status.INTERNAL_SERVER_ERROR; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientNotFoundException e) { LOGGER.debug(REQUEST_RESOURCES_DOES_NOT_EXISTS, e); status = Status.NOT_FOUND; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UNIT_NOT_FOUND, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (NoWritingPermissionException e) { LOGGER.debug(WRITING_PERMISSIONS_INVALID, e); status = Status.METHOD_NOT_ALLOWED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (AccessUnauthorizedException e) { LOGGER.debug(CONTRACT_ACCESS_NOT_ALLOW, e); status = Status.UNAUTHORIZED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } }
AccessExternalResource extends ApplicationStatusResource { @PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") public Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit) { Status status; try (AccessInternalClient client = accessInternalClientFactory.getClient()) { UpdateParserMultiple updateParserMultiple = new UpdateParserMultiple(); updateParserMultiple.parse(queryJson); UpdateMultiQuery updateMultiQuery = updateParserMultiple.getRequest(); updateMultiQuery.addRoots(idUnit); RequestResponse<JsonNode> response = client.updateUnitbyId(updateMultiQuery.getFinalUpdate(), idUnit); if (!response.isOk() && response instanceof VitamError) { VitamError error = (VitamError) response; return buildErrorFromError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, error.getMessage(), error); } return Response.status(Status.OK).entity(response).build(); } catch (final InvalidParseOperationException e) { LOGGER.debug(PREDICATES_FAILED_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientServerException e) { LOGGER.debug(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), e); status = Status.INTERNAL_SERVER_ERROR; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientNotFoundException e) { LOGGER.debug(REQUEST_RESOURCES_DOES_NOT_EXISTS, e); status = Status.NOT_FOUND; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UNIT_NOT_FOUND, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (NoWritingPermissionException e) { LOGGER.debug(WRITING_PERMISSIONS_INVALID, e); status = Status.METHOD_NOT_ALLOWED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (AccessUnauthorizedException e) { LOGGER.debug(CONTRACT_ACCESS_NOT_ALLOW, e); status = Status.UNAUTHORIZED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } } }
AccessExternalResource extends ApplicationStatusResource { @PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") public Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit) { Status status; try (AccessInternalClient client = accessInternalClientFactory.getClient()) { UpdateParserMultiple updateParserMultiple = new UpdateParserMultiple(); updateParserMultiple.parse(queryJson); UpdateMultiQuery updateMultiQuery = updateParserMultiple.getRequest(); updateMultiQuery.addRoots(idUnit); RequestResponse<JsonNode> response = client.updateUnitbyId(updateMultiQuery.getFinalUpdate(), idUnit); if (!response.isOk() && response instanceof VitamError) { VitamError error = (VitamError) response; return buildErrorFromError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, error.getMessage(), error); } return Response.status(Status.OK).entity(response).build(); } catch (final InvalidParseOperationException e) { LOGGER.debug(PREDICATES_FAILED_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientServerException e) { LOGGER.debug(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), e); status = Status.INTERNAL_SERVER_ERROR; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientNotFoundException e) { LOGGER.debug(REQUEST_RESOURCES_DOES_NOT_EXISTS, e); status = Status.NOT_FOUND; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UNIT_NOT_FOUND, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (NoWritingPermissionException e) { LOGGER.debug(WRITING_PERMISSIONS_INVALID, e); status = Status.METHOD_NOT_ALLOWED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (AccessUnauthorizedException e) { LOGGER.debug(CONTRACT_ACCESS_NOT_ALLOW, e); status = Status.UNAUTHORIZED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } } AccessExternalResource(SecureEndpointRegistry secureEndpointRegistry); @VisibleForTesting  AccessExternalResource(SecureEndpointRegistry secureEndpointRegistry,
        AccessInternalClientFactory accessInternalClientFactory); }
AccessExternalResource extends ApplicationStatusResource { @PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") public Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit) { Status status; try (AccessInternalClient client = accessInternalClientFactory.getClient()) { UpdateParserMultiple updateParserMultiple = new UpdateParserMultiple(); updateParserMultiple.parse(queryJson); UpdateMultiQuery updateMultiQuery = updateParserMultiple.getRequest(); updateMultiQuery.addRoots(idUnit); RequestResponse<JsonNode> response = client.updateUnitbyId(updateMultiQuery.getFinalUpdate(), idUnit); if (!response.isOk() && response instanceof VitamError) { VitamError error = (VitamError) response; return buildErrorFromError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, error.getMessage(), error); } return Response.status(Status.OK).entity(response).build(); } catch (final InvalidParseOperationException e) { LOGGER.debug(PREDICATES_FAILED_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientServerException e) { LOGGER.debug(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), e); status = Status.INTERNAL_SERVER_ERROR; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientNotFoundException e) { LOGGER.debug(REQUEST_RESOURCES_DOES_NOT_EXISTS, e); status = Status.NOT_FOUND; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UNIT_NOT_FOUND, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (NoWritingPermissionException e) { LOGGER.debug(WRITING_PERMISSIONS_INVALID, e); status = Status.METHOD_NOT_ALLOWED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (AccessUnauthorizedException e) { LOGGER.debug(CONTRACT_ACCESS_NOT_ALLOW, e); status = Status.UNAUTHORIZED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } } AccessExternalResource(SecureEndpointRegistry secureEndpointRegistry); @VisibleForTesting  AccessExternalResource(SecureEndpointRegistry secureEndpointRegistry,
        AccessInternalClientFactory accessInternalClientFactory); @Path("/") @OPTIONS @Produces(MediaType.APPLICATION_JSON) @Unsecured() Response listResourceEndpoints(); @GET @Path("/units") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:read", description = "Récupérer la liste des unités archivistiques") Response getUnits(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @POST @Path("/dipexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "dipexport:create", description = "Générer le DIP à partir d'un DSL") Response exportDIP(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @POST @Path("/transfers") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "transfers:create", description = "Générer le SIP pour transfer à partir d'un DSL") Response transfer(TransferRequest transferRequest); @POST @Path("/transfers/reply") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "transfers:reply", description = "Start transfer reply workflow.") Response transferReply(InputStream transferReply); @GET @Path("/transfers/{id}/sip") @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "transfers:id:sip:read", description = "Récupérer le SIP du transfer") Response findTransferByID(@PathParam("id") String id); @POST @Path("/reclassification") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "reclassification:update", description = "Mise à jour d'arborescence des unités archivistiques") Response reclassification(@Dsl(DslSchema.RECLASSIFICATION_QUERY) JsonNode queryJson); @POST @Path("/elimination/analysis") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "elimination:analysis", description = "Analyse de l'élimination d'unités archivistiques") Response startEliminationAnalysis(EliminationRequestBody eliminationRequestBody); @POST @Path("/elimination/action") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "elimination:action", description = "Elimination définitive d'unités archivistiques") Response startEliminationAction(EliminationRequestBody eliminationRequestBody); @GET @Path("/dipexport/{id}/dip") @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "dipexport:id:dip:read", description = "Récupérer le DIP") Response findExportByID(@PathParam("id") String id); @GET @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:read:json", description = "Obtenir le détail d'une unité archivistique au format json") Response getUnitById(@Dsl(value = DslSchema.GET_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit); @PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit); @GET @Path("/units/{idu}/objects") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:objects:read:json", description = "Télécharger le groupe d'objet technique de l'unité archivistique donnée") Response getObjectGroupMetadataByUnitId(@Context HttpHeaders headers, @PathParam("idu") String unitId,
        @Dsl(value = DslSchema.GET_BY_ID) JsonNode queryJson); @GET @Path("/units/{idu}/objects") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "units:id:objects:read:binary", description = "Télecharger un objet") Response getDataObjectByUnitId(@Context HttpHeaders headers, @PathParam("idu") String unitId); @POST @Path("/units") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:update", description = "Mise à jour en masse des unités archivistiques") Response massUpdateUnits(@Dsl(DslSchema.MASS_UPDATE) JsonNode queryJson); @POST @Path("/units/rules") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:rules:update", description = "Mise à jour en masse des règles de gestion") Response massUpdateUnitsRules(MassUpdateUnitRuleRequest massUpdateUnitRuleRequest); @Path("/units/computedInheritedRules") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "computeInheritedRules:action", description = "Lancer le processus de calcul des règles hérité pour la recherche") Response startComputeInheritedRules(@Dsl(value = DslSchema.BATCH_PROCESSING) JsonNode dslQuery); @Path("/units/computedInheritedRules") @DELETE @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "computeInheritedRules:delete", description = "Lancer le processus de Suppression calcul des règles hérité pour la recherche") Response deleteComputeInheritedRules(@Dsl(value = DslSchema.BATCH_PROCESSING) JsonNode dslQuery); @GET @Path("/unitsWithInheritedRules") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "unitsWithInheritedRules:read", description = "Récupérer la liste des unités archivistiques avec leurs règles de gestion héritées") Response selectUnitsWithInheritedRules(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @GET @Path("/objects") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "objects:read", description = "Récupérer la liste des groupes d'objets") Response getObjects(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @Path("/storageaccesslog") @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "storageaccesslog:read:binary", description = "Télécharger les journaux d'accès") Response getAccessLog(JsonNode params); @Path("/preservation") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "preservation:update", description = "Lancer le processus de préservation") Response startPreservation(PreservationRequest preservationRequest); }
AccessExternalResource extends ApplicationStatusResource { @PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") public Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit) { Status status; try (AccessInternalClient client = accessInternalClientFactory.getClient()) { UpdateParserMultiple updateParserMultiple = new UpdateParserMultiple(); updateParserMultiple.parse(queryJson); UpdateMultiQuery updateMultiQuery = updateParserMultiple.getRequest(); updateMultiQuery.addRoots(idUnit); RequestResponse<JsonNode> response = client.updateUnitbyId(updateMultiQuery.getFinalUpdate(), idUnit); if (!response.isOk() && response instanceof VitamError) { VitamError error = (VitamError) response; return buildErrorFromError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, error.getMessage(), error); } return Response.status(Status.OK).entity(response).build(); } catch (final InvalidParseOperationException e) { LOGGER.debug(PREDICATES_FAILED_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientServerException e) { LOGGER.debug(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), e); status = Status.INTERNAL_SERVER_ERROR; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (final AccessInternalClientNotFoundException e) { LOGGER.debug(REQUEST_RESOURCES_DOES_NOT_EXISTS, e); status = Status.NOT_FOUND; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UNIT_NOT_FOUND, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (NoWritingPermissionException e) { LOGGER.debug(WRITING_PERMISSIONS_INVALID, e); status = Status.METHOD_NOT_ALLOWED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } catch (AccessUnauthorizedException e) { LOGGER.debug(CONTRACT_ACCESS_NOT_ALLOW, e); status = Status.UNAUTHORIZED; return Response.status(status) .entity(VitamCodeHelper.toVitamError(VitamCode.ACCESS_EXTERNAL_UPDATE_UNIT_BY_ID_ERROR, e.getLocalizedMessage()).setHttpCode(status.getStatusCode())) .build(); } } AccessExternalResource(SecureEndpointRegistry secureEndpointRegistry); @VisibleForTesting  AccessExternalResource(SecureEndpointRegistry secureEndpointRegistry,
        AccessInternalClientFactory accessInternalClientFactory); @Path("/") @OPTIONS @Produces(MediaType.APPLICATION_JSON) @Unsecured() Response listResourceEndpoints(); @GET @Path("/units") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:read", description = "Récupérer la liste des unités archivistiques") Response getUnits(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @POST @Path("/dipexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "dipexport:create", description = "Générer le DIP à partir d'un DSL") Response exportDIP(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @POST @Path("/transfers") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "transfers:create", description = "Générer le SIP pour transfer à partir d'un DSL") Response transfer(TransferRequest transferRequest); @POST @Path("/transfers/reply") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "transfers:reply", description = "Start transfer reply workflow.") Response transferReply(InputStream transferReply); @GET @Path("/transfers/{id}/sip") @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "transfers:id:sip:read", description = "Récupérer le SIP du transfer") Response findTransferByID(@PathParam("id") String id); @POST @Path("/reclassification") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "reclassification:update", description = "Mise à jour d'arborescence des unités archivistiques") Response reclassification(@Dsl(DslSchema.RECLASSIFICATION_QUERY) JsonNode queryJson); @POST @Path("/elimination/analysis") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "elimination:analysis", description = "Analyse de l'élimination d'unités archivistiques") Response startEliminationAnalysis(EliminationRequestBody eliminationRequestBody); @POST @Path("/elimination/action") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "elimination:action", description = "Elimination définitive d'unités archivistiques") Response startEliminationAction(EliminationRequestBody eliminationRequestBody); @GET @Path("/dipexport/{id}/dip") @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "dipexport:id:dip:read", description = "Récupérer le DIP") Response findExportByID(@PathParam("id") String id); @GET @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:read:json", description = "Obtenir le détail d'une unité archivistique au format json") Response getUnitById(@Dsl(value = DslSchema.GET_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit); @PUT @Path("/units/{idu}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:update", description = "Réaliser la mise à jour d'une unité archivistique") Response updateUnitById(@Dsl(DslSchema.UPDATE_BY_ID) JsonNode queryJson, @PathParam("idu") String idUnit); @GET @Path("/units/{idu}/objects") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:id:objects:read:json", description = "Télécharger le groupe d'objet technique de l'unité archivistique donnée") Response getObjectGroupMetadataByUnitId(@Context HttpHeaders headers, @PathParam("idu") String unitId,
        @Dsl(value = DslSchema.GET_BY_ID) JsonNode queryJson); @GET @Path("/units/{idu}/objects") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "units:id:objects:read:binary", description = "Télecharger un objet") Response getDataObjectByUnitId(@Context HttpHeaders headers, @PathParam("idu") String unitId); @POST @Path("/units") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:update", description = "Mise à jour en masse des unités archivistiques") Response massUpdateUnits(@Dsl(DslSchema.MASS_UPDATE) JsonNode queryJson); @POST @Path("/units/rules") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "units:rules:update", description = "Mise à jour en masse des règles de gestion") Response massUpdateUnitsRules(MassUpdateUnitRuleRequest massUpdateUnitRuleRequest); @Path("/units/computedInheritedRules") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "computeInheritedRules:action", description = "Lancer le processus de calcul des règles hérité pour la recherche") Response startComputeInheritedRules(@Dsl(value = DslSchema.BATCH_PROCESSING) JsonNode dslQuery); @Path("/units/computedInheritedRules") @DELETE @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "computeInheritedRules:delete", description = "Lancer le processus de Suppression calcul des règles hérité pour la recherche") Response deleteComputeInheritedRules(@Dsl(value = DslSchema.BATCH_PROCESSING) JsonNode dslQuery); @GET @Path("/unitsWithInheritedRules") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "unitsWithInheritedRules:read", description = "Récupérer la liste des unités archivistiques avec leurs règles de gestion héritées") Response selectUnitsWithInheritedRules(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @GET @Path("/objects") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "objects:read", description = "Récupérer la liste des groupes d'objets") Response getObjects(@Dsl(value = DslSchema.SELECT_MULTIPLE) JsonNode queryJson); @Path("/storageaccesslog") @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) @Secured(permission = "storageaccesslog:read:binary", description = "Télécharger les journaux d'accès") Response getAccessLog(JsonNode params); @Path("/preservation") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Secured(permission = "preservation:update", description = "Lancer le processus de préservation") Response startPreservation(PreservationRequest preservationRequest);  }