@Test @RunWithCustomExecutor public void testExecute_OK() throws Exception { doReturn(CloseableIteratorUtils .toCloseableIterator(asList("id_got_1", "id_got_2", "id_got_3", "id_got_4", "id_got_5").iterator())) .when(purgeReportService).exportDistinctObjectGroups(any()); JsonNode objectGroups = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream( "EliminationAction/EliminationActionObjectGroupPreparationHandler/objectGroups.json")); doReturn(objectGroups).when(metaDataClient).selectObjectGroups(any()); JsonNode existingUnits = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream( "EliminationAction/EliminationActionObjectGroupPreparationHandler/existingUnits.json")); doReturn(existingUnits).when(metaDataClient).selectUnits(any()); PurgeObjectGroupPreparationHandler instance = new PurgeObjectGroupPreparationHandler( "PLUGIN_NAME", metaDataClientFactory, purgeReportService, 10); ItemStatus itemStatus = instance.execute(params, handler); assertThat(itemStatus.getGlobalStatus()).isEqualTo(StatusCode.OK); assertThat(reportEntries).hasSize(4); checkReportEntry(reportEntries, "id_got_1", "sp_1", "opi1", Arrays.asList("id_got_1_object_1", "id_got_1_object_2"), null, PurgeObjectGroupStatus.DELETED); checkReportEntry(reportEntries, "id_got_2", "sp_2", "opi2", null, Arrays.asList("id_unit_20"), PurgeObjectGroupStatus.PARTIAL_DETACHMENT); checkReportEntry(reportEntries, "id_got_3", "sp_3", "opi3", Arrays.asList("id_got_3_object_1"), null, PurgeObjectGroupStatus.DELETED); checkReportEntry(reportEntries, "id_got_5", "sp_5", "opi5", null, Arrays.asList("id_unit_50", "id_unit_51"), PurgeObjectGroupStatus.PARTIAL_DETACHMENT); ArgumentCaptor<File> objectGroupsToDeleteFileArgCaptor = ArgumentCaptor.forClass(File.class); ArgumentCaptor<File> objectGroupsToDetachFileArgCaptor = ArgumentCaptor.forClass(File.class); verify(handler).transferFileToWorkspace(eq(PurgeObjectGroupPreparationHandler.OBJECT_GROUPS_TO_DELETE_FILE), objectGroupsToDeleteFileArgCaptor.capture(), eq(true), eq(false)); verify(handler).transferFileToWorkspace(eq(PurgeObjectGroupPreparationHandler.OBJECT_GROUPS_TO_DETACH_FILE), objectGroupsToDetachFileArgCaptor.capture(), eq(true), eq(false)); List<JsonLineModel> objectGroupsToDelete = FileUtils.readLines(objectGroupsToDeleteFileArgCaptor.getValue(), StandardCharsets.UTF_8) .stream().map(PurgeObjectGroupPreparationHandlerTest::parse).collect(toList()); assertThat(objectGroupsToDelete).hasSize(2); checkObjectGroupToDelete(objectGroupsToDelete, "id_got_1", "id_got_1_object_1", "id_got_1_object_2"); checkObjectGroupToDelete(objectGroupsToDelete, "id_got_3", "id_got_3_object_1"); List<JsonLineModel> objectGroupsToDetach = FileUtils.readLines(objectGroupsToDetachFileArgCaptor.getValue(), StandardCharsets.UTF_8) .stream().map(PurgeObjectGroupPreparationHandlerTest::parse).collect(toList()); assertThat(objectGroupsToDetach).hasSize(2); checkObjectGroupToDetach(objectGroupsToDetach, "id_got_2", "id_unit_20"); checkObjectGroupToDetach(objectGroupsToDetach, "id_got_5", "id_unit_50", "id_unit_51"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { File objectGroupsToDeleteFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DELETE_FILE); File objectGroupsToDetachFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DETACH_FILE); try ( OutputStream objectGroupsToDeleteStream = new FileOutputStream(objectGroupsToDeleteFile); OutputStream objectGroupsToDetachStream = new FileOutputStream(objectGroupsToDetachFile); JsonLineWriter objectGroupsToDeleteWriter = new JsonLineWriter(objectGroupsToDeleteStream); JsonLineWriter objectGroupsToDetachWriter = new JsonLineWriter(objectGroupsToDetachStream); CloseableIterator<String> iterator = purgeReportService.exportDistinctObjectGroups(param.getContainerName())) { Iterator<List<String>> bulkIterator = Iterators.partition(iterator, objectGroupBulkSize); while (bulkIterator.hasNext()) { List<String> objectGroupIds = bulkIterator.next(); process(new HashSet<>(objectGroupIds), objectGroupsToDeleteWriter, objectGroupsToDetachWriter, param.getContainerName()); } } catch (IOException | InvalidParseOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not generate object group distribution", e); } handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DELETE_FILE, objectGroupsToDeleteFile, true, false); handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DETACH_FILE, objectGroupsToDetachFile, true, false); LOGGER.info("Purge of object group preparation succeeded"); return buildItemStatus(actionId, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error( String.format("Purge of object group preparation failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(actionId, e.getStatusCode(), e.getEventDetails()); } }
PurgeObjectGroupPreparationHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { File objectGroupsToDeleteFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DELETE_FILE); File objectGroupsToDetachFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DETACH_FILE); try ( OutputStream objectGroupsToDeleteStream = new FileOutputStream(objectGroupsToDeleteFile); OutputStream objectGroupsToDetachStream = new FileOutputStream(objectGroupsToDetachFile); JsonLineWriter objectGroupsToDeleteWriter = new JsonLineWriter(objectGroupsToDeleteStream); JsonLineWriter objectGroupsToDetachWriter = new JsonLineWriter(objectGroupsToDetachStream); CloseableIterator<String> iterator = purgeReportService.exportDistinctObjectGroups(param.getContainerName())) { Iterator<List<String>> bulkIterator = Iterators.partition(iterator, objectGroupBulkSize); while (bulkIterator.hasNext()) { List<String> objectGroupIds = bulkIterator.next(); process(new HashSet<>(objectGroupIds), objectGroupsToDeleteWriter, objectGroupsToDetachWriter, param.getContainerName()); } } catch (IOException | InvalidParseOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not generate object group distribution", e); } handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DELETE_FILE, objectGroupsToDeleteFile, true, false); handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DETACH_FILE, objectGroupsToDetachFile, true, false); LOGGER.info("Purge of object group preparation succeeded"); return buildItemStatus(actionId, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error( String.format("Purge of object group preparation failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(actionId, e.getStatusCode(), e.getEventDetails()); } } }
PurgeObjectGroupPreparationHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { File objectGroupsToDeleteFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DELETE_FILE); File objectGroupsToDetachFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DETACH_FILE); try ( OutputStream objectGroupsToDeleteStream = new FileOutputStream(objectGroupsToDeleteFile); OutputStream objectGroupsToDetachStream = new FileOutputStream(objectGroupsToDetachFile); JsonLineWriter objectGroupsToDeleteWriter = new JsonLineWriter(objectGroupsToDeleteStream); JsonLineWriter objectGroupsToDetachWriter = new JsonLineWriter(objectGroupsToDetachStream); CloseableIterator<String> iterator = purgeReportService.exportDistinctObjectGroups(param.getContainerName())) { Iterator<List<String>> bulkIterator = Iterators.partition(iterator, objectGroupBulkSize); while (bulkIterator.hasNext()) { List<String> objectGroupIds = bulkIterator.next(); process(new HashSet<>(objectGroupIds), objectGroupsToDeleteWriter, objectGroupsToDetachWriter, param.getContainerName()); } } catch (IOException | InvalidParseOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not generate object group distribution", e); } handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DELETE_FILE, objectGroupsToDeleteFile, true, false); handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DETACH_FILE, objectGroupsToDetachFile, true, false); LOGGER.info("Purge of object group preparation succeeded"); return buildItemStatus(actionId, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error( String.format("Purge of object group preparation failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(actionId, e.getStatusCode(), e.getEventDetails()); } } PurgeObjectGroupPreparationHandler(String actionId); @VisibleForTesting protected  PurgeObjectGroupPreparationHandler(
        String actionId, MetaDataClientFactory metaDataClientFactory,
        PurgeReportService purgeReportService,
        int objectGroupBulkSize); }
PurgeObjectGroupPreparationHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { File objectGroupsToDeleteFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DELETE_FILE); File objectGroupsToDetachFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DETACH_FILE); try ( OutputStream objectGroupsToDeleteStream = new FileOutputStream(objectGroupsToDeleteFile); OutputStream objectGroupsToDetachStream = new FileOutputStream(objectGroupsToDetachFile); JsonLineWriter objectGroupsToDeleteWriter = new JsonLineWriter(objectGroupsToDeleteStream); JsonLineWriter objectGroupsToDetachWriter = new JsonLineWriter(objectGroupsToDetachStream); CloseableIterator<String> iterator = purgeReportService.exportDistinctObjectGroups(param.getContainerName())) { Iterator<List<String>> bulkIterator = Iterators.partition(iterator, objectGroupBulkSize); while (bulkIterator.hasNext()) { List<String> objectGroupIds = bulkIterator.next(); process(new HashSet<>(objectGroupIds), objectGroupsToDeleteWriter, objectGroupsToDetachWriter, param.getContainerName()); } } catch (IOException | InvalidParseOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not generate object group distribution", e); } handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DELETE_FILE, objectGroupsToDeleteFile, true, false); handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DETACH_FILE, objectGroupsToDetachFile, true, false); LOGGER.info("Purge of object group preparation succeeded"); return buildItemStatus(actionId, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error( String.format("Purge of object group preparation failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(actionId, e.getStatusCode(), e.getEventDetails()); } } PurgeObjectGroupPreparationHandler(String actionId); @VisibleForTesting protected  PurgeObjectGroupPreparationHandler(
        String actionId, MetaDataClientFactory metaDataClientFactory,
        PurgeReportService purgeReportService,
        int objectGroupBulkSize); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); }
PurgeObjectGroupPreparationHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { File objectGroupsToDeleteFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DELETE_FILE); File objectGroupsToDetachFile = handler.getNewLocalFile(OBJECT_GROUPS_TO_DETACH_FILE); try ( OutputStream objectGroupsToDeleteStream = new FileOutputStream(objectGroupsToDeleteFile); OutputStream objectGroupsToDetachStream = new FileOutputStream(objectGroupsToDetachFile); JsonLineWriter objectGroupsToDeleteWriter = new JsonLineWriter(objectGroupsToDeleteStream); JsonLineWriter objectGroupsToDetachWriter = new JsonLineWriter(objectGroupsToDetachStream); CloseableIterator<String> iterator = purgeReportService.exportDistinctObjectGroups(param.getContainerName())) { Iterator<List<String>> bulkIterator = Iterators.partition(iterator, objectGroupBulkSize); while (bulkIterator.hasNext()) { List<String> objectGroupIds = bulkIterator.next(); process(new HashSet<>(objectGroupIds), objectGroupsToDeleteWriter, objectGroupsToDetachWriter, param.getContainerName()); } } catch (IOException | InvalidParseOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not generate object group distribution", e); } handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DELETE_FILE, objectGroupsToDeleteFile, true, false); handler.transferFileToWorkspace(OBJECT_GROUPS_TO_DETACH_FILE, objectGroupsToDetachFile, true, false); LOGGER.info("Purge of object group preparation succeeded"); return buildItemStatus(actionId, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error( String.format("Purge of object group preparation failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(actionId, e.getStatusCode(), e.getEventDetails()); } } PurgeObjectGroupPreparationHandler(String actionId); @VisibleForTesting protected  PurgeObjectGroupPreparationHandler(
        String actionId, MetaDataClientFactory metaDataClientFactory,
        PurgeReportService purgeReportService,
        int objectGroupBulkSize); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler);  }