@Test public void should_prepare_Linked_units_files() throws Exception { given(metaDataClient.selectUnits(any(JsonNode.class))).willReturn( JsonHandler.getFromInputStream(getClass().getResourceAsStream("/migration/resultMetadata.json"))); File jsonLineFile = tempFolder.newFile(); given(handlerIO.getNewLocalFile("Units.jsonl")).willReturn(jsonLineFile); File reportFile = tempFolder.newFile(); given(handlerIO.getNewLocalFile(("report.json"))).willReturn(reportFile); MigrationUnitPrepare migrationUnitPrepare = new MigrationUnitPrepare(metaDataClientFactory, 3); File file = tempFolder.newFile(); when(handlerIO.getNewLocalFile("migrationUnitsListIds")).thenReturn(file); ItemStatus execute = migrationUnitPrepare.execute(defaultWorkerParameters, handlerIO); assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.OK); try (InputStream is = new FileInputStream(jsonLineFile)) { JsonLineGenericIterator<JsonLineModel> lineGenericIterator = new JsonLineGenericIterator<>(is, TYPE_REFERENCE); List<String> unitIds = IteratorUtils.toList(lineGenericIterator) .stream() .map(JsonLineModel::getId) .collect(Collectors.toList()); assertThat(unitIds).containsExactly( "aeaqaaaaaadf6mc4aathcak7tmtgdnaaaaba", "aeaqaaaaaadf6mc4aathcak7tmtgdmyaaaba", "aeaqaaaaaadf6mc4aathcak7tmtgdayaaaca", "aeaqaaaaaadf6mc4aathcak7tmtgdniaaaba" ); } }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { ItemStatus itemStatus = new ItemStatus(MIGRATION_UNITS_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery selectMultiQuery = getSelectMultiQuery(); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, selectMultiQuery, bachSize); exportToReportAndDistributionFile(scrollRequest, handler, "Units.jsonl", REPORTS + "/" + MIGRATION_UNITS_LIST_IDS + ".json"); } catch (InvalidParseOperationException | InvalidCreateOperationException | ProcessingException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } itemStatus.increment(StatusCode.OK); return new ItemStatus(MIGRATION_UNITS_LIST).setItemsStatus(MIGRATION_UNITS_LIST, itemStatus); }
MigrationUnitPrepare extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { ItemStatus itemStatus = new ItemStatus(MIGRATION_UNITS_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery selectMultiQuery = getSelectMultiQuery(); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, selectMultiQuery, bachSize); exportToReportAndDistributionFile(scrollRequest, handler, "Units.jsonl", REPORTS + "/" + MIGRATION_UNITS_LIST_IDS + ".json"); } catch (InvalidParseOperationException | InvalidCreateOperationException | ProcessingException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } itemStatus.increment(StatusCode.OK); return new ItemStatus(MIGRATION_UNITS_LIST).setItemsStatus(MIGRATION_UNITS_LIST, itemStatus); } }
MigrationUnitPrepare extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { ItemStatus itemStatus = new ItemStatus(MIGRATION_UNITS_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery selectMultiQuery = getSelectMultiQuery(); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, selectMultiQuery, bachSize); exportToReportAndDistributionFile(scrollRequest, handler, "Units.jsonl", REPORTS + "/" + MIGRATION_UNITS_LIST_IDS + ".json"); } catch (InvalidParseOperationException | InvalidCreateOperationException | ProcessingException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } itemStatus.increment(StatusCode.OK); return new ItemStatus(MIGRATION_UNITS_LIST).setItemsStatus(MIGRATION_UNITS_LIST, itemStatus); } @VisibleForTesting  MigrationUnitPrepare(MetaDataClientFactory metaDataClientFactory, int bachSize);  MigrationUnitPrepare(); }
MigrationUnitPrepare extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { ItemStatus itemStatus = new ItemStatus(MIGRATION_UNITS_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery selectMultiQuery = getSelectMultiQuery(); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, selectMultiQuery, bachSize); exportToReportAndDistributionFile(scrollRequest, handler, "Units.jsonl", REPORTS + "/" + MIGRATION_UNITS_LIST_IDS + ".json"); } catch (InvalidParseOperationException | InvalidCreateOperationException | ProcessingException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } itemStatus.increment(StatusCode.OK); return new ItemStatus(MIGRATION_UNITS_LIST).setItemsStatus(MIGRATION_UNITS_LIST, itemStatus); } @VisibleForTesting  MigrationUnitPrepare(MetaDataClientFactory metaDataClientFactory, int bachSize);  MigrationUnitPrepare(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); }
MigrationUnitPrepare extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { ItemStatus itemStatus = new ItemStatus(MIGRATION_UNITS_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery selectMultiQuery = getSelectMultiQuery(); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, selectMultiQuery, bachSize); exportToReportAndDistributionFile(scrollRequest, handler, "Units.jsonl", REPORTS + "/" + MIGRATION_UNITS_LIST_IDS + ".json"); } catch (InvalidParseOperationException | InvalidCreateOperationException | ProcessingException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } itemStatus.increment(StatusCode.OK); return new ItemStatus(MIGRATION_UNITS_LIST).setItemsStatus(MIGRATION_UNITS_LIST, itemStatus); } @VisibleForTesting  MigrationUnitPrepare(MetaDataClientFactory metaDataClientFactory, int bachSize);  MigrationUnitPrepare(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler);  }