@Test public void should_write_query_dsl_in_logbook() throws Exception { HandlerIO handler = mock(HandlerIO.class); WorkerParameters workerParameters = mock(WorkerParameters.class); ObjectNode finalSelect = new Select().getFinalSelect(); PreservationRequest preservationRequest = new PreservationRequest(finalSelect, "id", "BinaryMaster", LAST, "BinaryMaster"); when(handler.getJsonFromWorkspace("preservationRequest")).thenReturn(toJsonNode(preservationRequest)); Map<String, File> files = new HashMap<>(); doAnswer((args) -> { File file = temporaryFolder.newFile(); files.put(args.getArgument(0), file); return file; }).when(handler).getNewLocalFile(anyString()); ItemStatus itemStatus = preservationPreparationPlugin.execute(workerParameters, handler); StatusCode globalStatus = itemStatus.getGlobalStatus(); assertThat(globalStatus).isEqualTo(StatusCode.OK); assertThat(itemStatus.getEvDetailData()) .isEqualTo(JsonHandler.unprettyPrint(createObjectNode().put("query", JsonHandler.unprettyPrint(finalSelect)))); List<String> lines = IOUtils.readLines(new FileInputStream(files.get(OBJECT_GROUPS_TO_PRESERVE_JSONL)), "UTF-8"); assertThat(lines.size()).isEqualTo(5); JsonLineModel firstLine = JsonHandler.getFromString(lines.get(0), JsonLineModel.class); assertThat(firstLine.getParams().get("sourceStrategy").asText()).isEqualTo("default-fake"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { PreservationRequest preservationRequest = loadPreservationRequest(handler); computePreparation(handler, metaDataClient, preservationRequest, param.getRequestId()); return buildItemStatus(PRESERVATION_PREPARATION, StatusCode.OK, createObjectNode().put("query", preservationRequest.getDslQuery().toString())); } catch (Exception e) { LOGGER.error(String.format("Preservation action failed with status [%s]", KO), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PRESERVATION_PREPARATION, KO, error); } }
PreservationPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { PreservationRequest preservationRequest = loadPreservationRequest(handler); computePreparation(handler, metaDataClient, preservationRequest, param.getRequestId()); return buildItemStatus(PRESERVATION_PREPARATION, StatusCode.OK, createObjectNode().put("query", preservationRequest.getDslQuery().toString())); } catch (Exception e) { LOGGER.error(String.format("Preservation action failed with status [%s]", KO), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PRESERVATION_PREPARATION, KO, error); } } }
PreservationPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { PreservationRequest preservationRequest = loadPreservationRequest(handler); computePreparation(handler, metaDataClient, preservationRequest, param.getRequestId()); return buildItemStatus(PRESERVATION_PREPARATION, StatusCode.OK, createObjectNode().put("query", preservationRequest.getDslQuery().toString())); } catch (Exception e) { LOGGER.error(String.format("Preservation action failed with status [%s]", KO), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PRESERVATION_PREPARATION, KO, error); } } PreservationPreparationPlugin(); @VisibleForTesting  PreservationPreparationPlugin(AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory, WorkspaceClientFactory workspaceClientFactory); }
PreservationPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { PreservationRequest preservationRequest = loadPreservationRequest(handler); computePreparation(handler, metaDataClient, preservationRequest, param.getRequestId()); return buildItemStatus(PRESERVATION_PREPARATION, StatusCode.OK, createObjectNode().put("query", preservationRequest.getDslQuery().toString())); } catch (Exception e) { LOGGER.error(String.format("Preservation action failed with status [%s]", KO), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PRESERVATION_PREPARATION, KO, error); } } PreservationPreparationPlugin(); @VisibleForTesting  PreservationPreparationPlugin(AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory, WorkspaceClientFactory workspaceClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
PreservationPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { PreservationRequest preservationRequest = loadPreservationRequest(handler); computePreparation(handler, metaDataClient, preservationRequest, param.getRequestId()); return buildItemStatus(PRESERVATION_PREPARATION, StatusCode.OK, createObjectNode().put("query", preservationRequest.getDslQuery().toString())); } catch (Exception e) { LOGGER.error(String.format("Preservation action failed with status [%s]", KO), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PRESERVATION_PREPARATION, KO, error); } } PreservationPreparationPlugin(); @VisibleForTesting  PreservationPreparationPlugin(AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory, WorkspaceClientFactory workspaceClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }