@Test @RunWithCustomExecutor public void fail_when_a_related_server_is_unavailable() throws Exception { Select select = new Select(); select.setQuery(QueryHelper.eq("name", "dd")); ProbativeValueRequest probativeValueRequest = new ProbativeValueRequest(select.getFinalSelect(), "BinaryMaster", "1"); willThrow(ContentAddressableStorageServerException.class).given(workspaceClient).putObject(anyString(), any(), any()); Response probativeValue = probativeValueResource.exportProbativeValue(probativeValueRequest); assertThat(probativeValue.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); willThrow(LogbookClientAlreadyExistsException.class).given(logbookOperationsClient).create(any()); probativeValue = probativeValueResource.exportProbativeValue(probativeValueRequest); assertThat(probativeValue.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); }
@POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response exportProbativeValue(ProbativeValueRequest probativeValueRequest) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", probativeValueRequest.getDslQuery()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try { checkEmptyQuery(probativeValueRequest.getDslQuery()); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AdminManagementClient adminManagementClient = AdminManagementClientFactory.getInstance().getClient()) { Select select = new Select(); Query query = QueryHelper.eq(AccessContract.IDENTIFIER, VitamThreadUtils.getVitamSession().getContractId()); select.setQuery(query); AccessContractModel accessContractModel = ((RequestResponseOK<AccessContractModel>) adminManagementClient .findAccessContracts(select.getFinalSelect())).getResults().get(0); workspaceClient.createContainer(operationId); createProbativeOperation(operationId); workspaceClient .putObject(operationId, OperationContextMonitor.OperationContextFileName, writeToInpustream( OperationContextModel.get(probativeValueRequest))); JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(probativeValueRequest.getDslQuery(), accessContractModel); workspaceClient.putObject(operationId, "request", JsonHandler.writeToInpustream(probativeValueRequest)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); OperationContextMonitor .compressInWorkspace(workspaceClientFactory, operationId, Contexts.EXPORT_PROBATIVE_VALUE.getLogbookTypeProcess(), OperationContextMonitor.OperationContextFileName); processingClient.initVitamProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | OperationContextException | VitamClientException | LogbookClientServerException | InternalServerException | InvalidGuidOperationException e) { LOGGER.error("Error while exporting probative value", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientBadRequestException | LogbookClientAlreadyExistsException | AdminManagementClientServerException 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(VitamCode.GLOBAL_EMPTY_QUERY); } }
ProbativeValueResource { @POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response exportProbativeValue(ProbativeValueRequest probativeValueRequest) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", probativeValueRequest.getDslQuery()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try { checkEmptyQuery(probativeValueRequest.getDslQuery()); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AdminManagementClient adminManagementClient = AdminManagementClientFactory.getInstance().getClient()) { Select select = new Select(); Query query = QueryHelper.eq(AccessContract.IDENTIFIER, VitamThreadUtils.getVitamSession().getContractId()); select.setQuery(query); AccessContractModel accessContractModel = ((RequestResponseOK<AccessContractModel>) adminManagementClient .findAccessContracts(select.getFinalSelect())).getResults().get(0); workspaceClient.createContainer(operationId); createProbativeOperation(operationId); workspaceClient .putObject(operationId, OperationContextMonitor.OperationContextFileName, writeToInpustream( OperationContextModel.get(probativeValueRequest))); JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(probativeValueRequest.getDslQuery(), accessContractModel); workspaceClient.putObject(operationId, "request", JsonHandler.writeToInpustream(probativeValueRequest)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); OperationContextMonitor .compressInWorkspace(workspaceClientFactory, operationId, Contexts.EXPORT_PROBATIVE_VALUE.getLogbookTypeProcess(), OperationContextMonitor.OperationContextFileName); processingClient.initVitamProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | OperationContextException | VitamClientException | LogbookClientServerException | InternalServerException | InvalidGuidOperationException e) { LOGGER.error("Error while exporting probative value", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientBadRequestException | LogbookClientAlreadyExistsException | AdminManagementClientServerException 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(VitamCode.GLOBAL_EMPTY_QUERY); } } }
ProbativeValueResource { @POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response exportProbativeValue(ProbativeValueRequest probativeValueRequest) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", probativeValueRequest.getDslQuery()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try { checkEmptyQuery(probativeValueRequest.getDslQuery()); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AdminManagementClient adminManagementClient = AdminManagementClientFactory.getInstance().getClient()) { Select select = new Select(); Query query = QueryHelper.eq(AccessContract.IDENTIFIER, VitamThreadUtils.getVitamSession().getContractId()); select.setQuery(query); AccessContractModel accessContractModel = ((RequestResponseOK<AccessContractModel>) adminManagementClient .findAccessContracts(select.getFinalSelect())).getResults().get(0); workspaceClient.createContainer(operationId); createProbativeOperation(operationId); workspaceClient .putObject(operationId, OperationContextMonitor.OperationContextFileName, writeToInpustream( OperationContextModel.get(probativeValueRequest))); JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(probativeValueRequest.getDslQuery(), accessContractModel); workspaceClient.putObject(operationId, "request", JsonHandler.writeToInpustream(probativeValueRequest)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); OperationContextMonitor .compressInWorkspace(workspaceClientFactory, operationId, Contexts.EXPORT_PROBATIVE_VALUE.getLogbookTypeProcess(), OperationContextMonitor.OperationContextFileName); processingClient.initVitamProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | OperationContextException | VitamClientException | LogbookClientServerException | InternalServerException | InvalidGuidOperationException e) { LOGGER.error("Error while exporting probative value", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientBadRequestException | LogbookClientAlreadyExistsException | AdminManagementClientServerException 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(VitamCode.GLOBAL_EMPTY_QUERY); } } @VisibleForTesting  ProbativeValueResource(
        ProcessingManagementClientFactory processingManagementClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory);   ProbativeValueResource(); }
ProbativeValueResource { @POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response exportProbativeValue(ProbativeValueRequest probativeValueRequest) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", probativeValueRequest.getDslQuery()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try { checkEmptyQuery(probativeValueRequest.getDslQuery()); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AdminManagementClient adminManagementClient = AdminManagementClientFactory.getInstance().getClient()) { Select select = new Select(); Query query = QueryHelper.eq(AccessContract.IDENTIFIER, VitamThreadUtils.getVitamSession().getContractId()); select.setQuery(query); AccessContractModel accessContractModel = ((RequestResponseOK<AccessContractModel>) adminManagementClient .findAccessContracts(select.getFinalSelect())).getResults().get(0); workspaceClient.createContainer(operationId); createProbativeOperation(operationId); workspaceClient .putObject(operationId, OperationContextMonitor.OperationContextFileName, writeToInpustream( OperationContextModel.get(probativeValueRequest))); JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(probativeValueRequest.getDslQuery(), accessContractModel); workspaceClient.putObject(operationId, "request", JsonHandler.writeToInpustream(probativeValueRequest)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); OperationContextMonitor .compressInWorkspace(workspaceClientFactory, operationId, Contexts.EXPORT_PROBATIVE_VALUE.getLogbookTypeProcess(), OperationContextMonitor.OperationContextFileName); processingClient.initVitamProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | OperationContextException | VitamClientException | LogbookClientServerException | InternalServerException | InvalidGuidOperationException e) { LOGGER.error("Error while exporting probative value", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientBadRequestException | LogbookClientAlreadyExistsException | AdminManagementClientServerException 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(VitamCode.GLOBAL_EMPTY_QUERY); } } @VisibleForTesting  ProbativeValueResource(
        ProcessingManagementClientFactory processingManagementClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory);   ProbativeValueResource(); @POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response exportProbativeValue(ProbativeValueRequest probativeValueRequest); }
ProbativeValueResource { @POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response exportProbativeValue(ProbativeValueRequest probativeValueRequest) { Response.Status status; LOGGER.debug("DEBUG: start selectUnits {}", probativeValueRequest.getDslQuery()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); try { checkEmptyQuery(probativeValueRequest.getDslQuery()); try (ProcessingManagementClient processingClient = processingManagementClientFactory.getClient(); WorkspaceClient workspaceClient = workspaceClientFactory.getClient(); AdminManagementClient adminManagementClient = AdminManagementClientFactory.getInstance().getClient()) { Select select = new Select(); Query query = QueryHelper.eq(AccessContract.IDENTIFIER, VitamThreadUtils.getVitamSession().getContractId()); select.setQuery(query); AccessContractModel accessContractModel = ((RequestResponseOK<AccessContractModel>) adminManagementClient .findAccessContracts(select.getFinalSelect())).getResults().get(0); workspaceClient.createContainer(operationId); createProbativeOperation(operationId); workspaceClient .putObject(operationId, OperationContextMonitor.OperationContextFileName, writeToInpustream( OperationContextModel.get(probativeValueRequest))); JsonNode finalQuery = AccessContractRestrictionHelper. applyAccessContractRestrictionForUnitForSelect(probativeValueRequest.getDslQuery(), accessContractModel); workspaceClient.putObject(operationId, "request", JsonHandler.writeToInpustream(probativeValueRequest)); workspaceClient.putObject(operationId, "query.json", JsonHandler.writeToInpustream(finalQuery)); OperationContextMonitor .compressInWorkspace(workspaceClientFactory, operationId, Contexts.EXPORT_PROBATIVE_VALUE.getLogbookTypeProcess(), OperationContextMonitor.OperationContextFileName); processingClient.initVitamProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name()); RequestResponse<ItemStatus> jsonNodeRequestResponse = processingClient.executeOperationProcess(operationId, Contexts.EXPORT_PROBATIVE_VALUE.name(), ProcessAction.RESUME.getValue()); return jsonNodeRequestResponse.toResponse(); } catch (ContentAddressableStorageServerException | OperationContextException | VitamClientException | LogbookClientServerException | InternalServerException | InvalidGuidOperationException e) { LOGGER.error("Error while exporting probative value", e); return Response.status(INTERNAL_SERVER_ERROR) .entity(getErrorEntity(INTERNAL_SERVER_ERROR, e.getMessage())).build(); } catch (LogbookClientBadRequestException | LogbookClientAlreadyExistsException | AdminManagementClientServerException 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(VitamCode.GLOBAL_EMPTY_QUERY); } } @VisibleForTesting  ProbativeValueResource(
        ProcessingManagementClientFactory processingManagementClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory);   ProbativeValueResource(); @POST @Path("/probativevalueexport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response exportProbativeValue(ProbativeValueRequest probativeValueRequest);  }