@Test @RunWithCustomExecutor public void given_empty_query_when_audit_then_return_forbidden_request() throws Exception { Response audit = evidenceResource.audit(new Select().getFinalSelect()); assertThat(audit.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode()); }
@POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response audit(JsonNode queryDsl) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", queryDsl); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AccessContractImpl accessContractService = new AccessContractImpl(mongoDbAccess, vitamCounterService)) { checkEmptyQuery(queryDsl); AccessContractModel contract = accessContractService .findByIdentifier(VitamThreadUtils.getVitamSession().getContractId()); if (contract == null) { throw new AccessUnauthorizedException("Contract Not Found"); } JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(queryDsl, contract); workspaceClient.createContainer(operationId); createEvidenceAuditOperation(operationId, contract); ObjectNode options = JsonHandler.createObjectNode().put("correctiveOption", false); workspaceClient.putObject(operationId, "evidenceOptions", JsonHandler.writeToInpustream(options)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); processingClient.initVitamProcess(operationId, Contexts.EVIDENCE_AUDIT.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EVIDENCE_AUDIT.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | VitamClientException | InternalServerException | InvalidGuidOperationException | ReferentialException e) { LOGGER.error("Error while auditing", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientServerException | LogbookClientBadRequestException | LogbookClientAlreadyExistsException e) { return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (final InvalidParseOperationException | InvalidCreateOperationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(getErrorEntity(status, e.getMessage())).build(); } catch (BadRequestException e) { LOGGER.error("Empty query is impossible", e); return buildErrorResponse(); } }
EvidenceResource { @POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response audit(JsonNode queryDsl) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", queryDsl); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AccessContractImpl accessContractService = new AccessContractImpl(mongoDbAccess, vitamCounterService)) { checkEmptyQuery(queryDsl); AccessContractModel contract = accessContractService .findByIdentifier(VitamThreadUtils.getVitamSession().getContractId()); if (contract == null) { throw new AccessUnauthorizedException("Contract Not Found"); } JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(queryDsl, contract); workspaceClient.createContainer(operationId); createEvidenceAuditOperation(operationId, contract); ObjectNode options = JsonHandler.createObjectNode().put("correctiveOption", false); workspaceClient.putObject(operationId, "evidenceOptions", JsonHandler.writeToInpustream(options)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); processingClient.initVitamProcess(operationId, Contexts.EVIDENCE_AUDIT.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EVIDENCE_AUDIT.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | VitamClientException | InternalServerException | InvalidGuidOperationException | ReferentialException e) { LOGGER.error("Error while auditing", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientServerException | LogbookClientBadRequestException | LogbookClientAlreadyExistsException e) { return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (final InvalidParseOperationException | InvalidCreateOperationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(getErrorEntity(status, e.getMessage())).build(); } catch (BadRequestException e) { LOGGER.error("Empty query is impossible", e); return buildErrorResponse(); } } }
EvidenceResource { @POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response audit(JsonNode queryDsl) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", queryDsl); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AccessContractImpl accessContractService = new AccessContractImpl(mongoDbAccess, vitamCounterService)) { checkEmptyQuery(queryDsl); AccessContractModel contract = accessContractService .findByIdentifier(VitamThreadUtils.getVitamSession().getContractId()); if (contract == null) { throw new AccessUnauthorizedException("Contract Not Found"); } JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(queryDsl, contract); workspaceClient.createContainer(operationId); createEvidenceAuditOperation(operationId, contract); ObjectNode options = JsonHandler.createObjectNode().put("correctiveOption", false); workspaceClient.putObject(operationId, "evidenceOptions", JsonHandler.writeToInpustream(options)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); processingClient.initVitamProcess(operationId, Contexts.EVIDENCE_AUDIT.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EVIDENCE_AUDIT.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | VitamClientException | InternalServerException | InvalidGuidOperationException | ReferentialException e) { LOGGER.error("Error while auditing", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientServerException | LogbookClientBadRequestException | LogbookClientAlreadyExistsException e) { return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (final InvalidParseOperationException | InvalidCreateOperationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(getErrorEntity(status, e.getMessage())).build(); } catch (BadRequestException e) { LOGGER.error("Empty query is impossible", e); return buildErrorResponse(); } } @VisibleForTesting  EvidenceResource(
        ProcessingManagementClientFactory processingManagementClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory,
        MongoDbAccessAdminImpl mongoDbAccess,
        VitamCounterService vitamCounterService);   EvidenceResource(MongoDbAccessAdminImpl mongoDbAccess, VitamCounterService vitamCounterService); }
EvidenceResource { @POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response audit(JsonNode queryDsl) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", queryDsl); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AccessContractImpl accessContractService = new AccessContractImpl(mongoDbAccess, vitamCounterService)) { checkEmptyQuery(queryDsl); AccessContractModel contract = accessContractService .findByIdentifier(VitamThreadUtils.getVitamSession().getContractId()); if (contract == null) { throw new AccessUnauthorizedException("Contract Not Found"); } JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(queryDsl, contract); workspaceClient.createContainer(operationId); createEvidenceAuditOperation(operationId, contract); ObjectNode options = JsonHandler.createObjectNode().put("correctiveOption", false); workspaceClient.putObject(operationId, "evidenceOptions", JsonHandler.writeToInpustream(options)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); processingClient.initVitamProcess(operationId, Contexts.EVIDENCE_AUDIT.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EVIDENCE_AUDIT.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | VitamClientException | InternalServerException | InvalidGuidOperationException | ReferentialException e) { LOGGER.error("Error while auditing", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientServerException | LogbookClientBadRequestException | LogbookClientAlreadyExistsException e) { return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (final InvalidParseOperationException | InvalidCreateOperationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(getErrorEntity(status, e.getMessage())).build(); } catch (BadRequestException e) { LOGGER.error("Empty query is impossible", e); return buildErrorResponse(); } } @VisibleForTesting  EvidenceResource(
        ProcessingManagementClientFactory processingManagementClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory,
        MongoDbAccessAdminImpl mongoDbAccess,
        VitamCounterService vitamCounterService);   EvidenceResource(MongoDbAccessAdminImpl mongoDbAccess, VitamCounterService vitamCounterService); @POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response audit(JsonNode queryDsl); @POST @Path("rectificationaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response rectificationAudit(String operation); }
EvidenceResource { @POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response audit(JsonNode queryDsl) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", queryDsl); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AccessContractImpl accessContractService = new AccessContractImpl(mongoDbAccess, vitamCounterService)) { checkEmptyQuery(queryDsl); AccessContractModel contract = accessContractService .findByIdentifier(VitamThreadUtils.getVitamSession().getContractId()); if (contract == null) { throw new AccessUnauthorizedException("Contract Not Found"); } JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(queryDsl, contract); workspaceClient.createContainer(operationId); createEvidenceAuditOperation(operationId, contract); ObjectNode options = JsonHandler.createObjectNode().put("correctiveOption", false); workspaceClient.putObject(operationId, "evidenceOptions", JsonHandler.writeToInpustream(options)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); processingClient.initVitamProcess(operationId, Contexts.EVIDENCE_AUDIT.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EVIDENCE_AUDIT.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | VitamClientException | InternalServerException | InvalidGuidOperationException | ReferentialException e) { LOGGER.error("Error while auditing", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientServerException | LogbookClientBadRequestException | LogbookClientAlreadyExistsException e) { return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (final InvalidParseOperationException | InvalidCreateOperationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(getErrorEntity(status, e.getMessage())).build(); } catch (BadRequestException e) { LOGGER.error("Empty query is impossible", e); return buildErrorResponse(); } } @VisibleForTesting  EvidenceResource(
        ProcessingManagementClientFactory processingManagementClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory,
        MongoDbAccessAdminImpl mongoDbAccess,
        VitamCounterService vitamCounterService);   EvidenceResource(MongoDbAccessAdminImpl mongoDbAccess, VitamCounterService vitamCounterService); @POST @Path("/evidenceaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response audit(JsonNode queryDsl); @POST @Path("rectificationaudit") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response rectificationAudit(String operation);  }