@Test public void testExportReclassificationChildNodes() throws Exception { String unitsToUpdateJsonLineFileName = "UnitsToUpdate.jsonl"; String objectGroupsToUpdateJsonLineFileName = "ObjectGroupsToUpdate.jsonl"; RequestResponseOK<JsonNode> results = new RequestResponseOK<JsonNode>() .addAllResults(Arrays.asList( JsonHandler.createObjectNode().put("#id", "id1").put("#object", "og1"), JsonHandler.createObjectNode().put("#id", "id2"), JsonHandler.createObjectNode().put("#id", "id3-1").put("#object", "og3"), JsonHandler.createObjectNode().put("#id", "id3-2").put("#object", "og3"), JsonHandler.createObjectNode().put("#id", "id4").put("#object", "og4") )); doReturn(results).when(metaData).selectUnitsByQuery(any()); Map<String, File> savedFiles = new HashMap<>(); doAnswer((args) -> { File file = this.folder.newFile(); FileUtils.copyInputStreamToFile(args.getArgument(2), file); savedFiles.put(args.getArgument(1), file); return null; }).when(workspaceClient).putObject(eq(operationId), anyString(), any(InputStream.class)); Set<String> ids = new HashSet<>(Arrays.asList("id1", "id2", "id3")); instance .exportReclassificationChildNodes(ids, unitsToUpdateJsonLineFileName, objectGroupsToUpdateJsonLineFileName); verify(workspaceClient).putObject(eq(operationId), eq(unitsToUpdateJsonLineFileName), any(InputStream.class)); verify(workspaceClient) .putObject(eq(operationId), eq(objectGroupsToUpdateJsonLineFileName), any(InputStream.class)); List<String> unitIds = readDistributionFile(savedFiles.get(unitsToUpdateJsonLineFileName)); List<String> objectGroupIds = readDistributionFile(savedFiles.get(objectGroupsToUpdateJsonLineFileName)); assertThat(unitIds).containsExactly("id1", "id2", "id3-1", "id3-2", "id4"); assertThat(objectGroupIds).containsExactly("og1", "og3", "og4"); }
public void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName, String objectGroupsToUpdateJsonLineFileName) throws IOException, InvalidParseOperationException, InvalidCreateOperationException { SelectMultiQuery select = createSelectRequest(unitIds); Iterator<JsonNode> iterator = executeSelectAsIterator(select); File tempUnitReportFile = null; File tempObjectGroupReportFile = null; try { tempUnitReportFile = File.createTempFile(UNIT_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); tempObjectGroupReportFile = File.createTempFile(OBJECT_GROUP_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); try (JsonLineWriter unitReportWriter = new JsonLineWriter(new FileOutputStream(tempUnitReportFile)); JsonLineWriter objectGroupReportWriter = new JsonLineWriter( new FileOutputStream(tempObjectGroupReportFile))) { appendEntries(iterator, unitReportWriter, objectGroupReportWriter); } storeIntoWorkspace(unitsToUpdateJsonLineFileName, tempUnitReportFile); storeIntoWorkspace(objectGroupsToUpdateJsonLineFileName, tempObjectGroupReportFile); } finally { FileUtils.deleteQuietly(tempUnitReportFile); FileUtils.deleteQuietly(tempObjectGroupReportFile); } }
ReclassificationDistributionService { public void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName, String objectGroupsToUpdateJsonLineFileName) throws IOException, InvalidParseOperationException, InvalidCreateOperationException { SelectMultiQuery select = createSelectRequest(unitIds); Iterator<JsonNode> iterator = executeSelectAsIterator(select); File tempUnitReportFile = null; File tempObjectGroupReportFile = null; try { tempUnitReportFile = File.createTempFile(UNIT_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); tempObjectGroupReportFile = File.createTempFile(OBJECT_GROUP_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); try (JsonLineWriter unitReportWriter = new JsonLineWriter(new FileOutputStream(tempUnitReportFile)); JsonLineWriter objectGroupReportWriter = new JsonLineWriter( new FileOutputStream(tempObjectGroupReportFile))) { appendEntries(iterator, unitReportWriter, objectGroupReportWriter); } storeIntoWorkspace(unitsToUpdateJsonLineFileName, tempUnitReportFile); storeIntoWorkspace(objectGroupsToUpdateJsonLineFileName, tempObjectGroupReportFile); } finally { FileUtils.deleteQuietly(tempUnitReportFile); FileUtils.deleteQuietly(tempObjectGroupReportFile); } } }
ReclassificationDistributionService { public void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName, String objectGroupsToUpdateJsonLineFileName) throws IOException, InvalidParseOperationException, InvalidCreateOperationException { SelectMultiQuery select = createSelectRequest(unitIds); Iterator<JsonNode> iterator = executeSelectAsIterator(select); File tempUnitReportFile = null; File tempObjectGroupReportFile = null; try { tempUnitReportFile = File.createTempFile(UNIT_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); tempObjectGroupReportFile = File.createTempFile(OBJECT_GROUP_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); try (JsonLineWriter unitReportWriter = new JsonLineWriter(new FileOutputStream(tempUnitReportFile)); JsonLineWriter objectGroupReportWriter = new JsonLineWriter( new FileOutputStream(tempObjectGroupReportFile))) { appendEntries(iterator, unitReportWriter, objectGroupReportWriter); } storeIntoWorkspace(unitsToUpdateJsonLineFileName, tempUnitReportFile); storeIntoWorkspace(objectGroupsToUpdateJsonLineFileName, tempObjectGroupReportFile); } finally { FileUtils.deleteQuietly(tempUnitReportFile); FileUtils.deleteQuietly(tempObjectGroupReportFile); } } ReclassificationDistributionService(MetaDataImpl metaData); @VisibleForTesting  ReclassificationDistributionService(
        WorkspaceClientFactory workspaceClientFactory,
        MetaDataImpl metaData); }
ReclassificationDistributionService { public void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName, String objectGroupsToUpdateJsonLineFileName) throws IOException, InvalidParseOperationException, InvalidCreateOperationException { SelectMultiQuery select = createSelectRequest(unitIds); Iterator<JsonNode> iterator = executeSelectAsIterator(select); File tempUnitReportFile = null; File tempObjectGroupReportFile = null; try { tempUnitReportFile = File.createTempFile(UNIT_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); tempObjectGroupReportFile = File.createTempFile(OBJECT_GROUP_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); try (JsonLineWriter unitReportWriter = new JsonLineWriter(new FileOutputStream(tempUnitReportFile)); JsonLineWriter objectGroupReportWriter = new JsonLineWriter( new FileOutputStream(tempObjectGroupReportFile))) { appendEntries(iterator, unitReportWriter, objectGroupReportWriter); } storeIntoWorkspace(unitsToUpdateJsonLineFileName, tempUnitReportFile); storeIntoWorkspace(objectGroupsToUpdateJsonLineFileName, tempObjectGroupReportFile); } finally { FileUtils.deleteQuietly(tempUnitReportFile); FileUtils.deleteQuietly(tempObjectGroupReportFile); } } ReclassificationDistributionService(MetaDataImpl metaData); @VisibleForTesting  ReclassificationDistributionService(
        WorkspaceClientFactory workspaceClientFactory,
        MetaDataImpl metaData); void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName,
        String objectGroupsToUpdateJsonLineFileName); }
ReclassificationDistributionService { public void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName, String objectGroupsToUpdateJsonLineFileName) throws IOException, InvalidParseOperationException, InvalidCreateOperationException { SelectMultiQuery select = createSelectRequest(unitIds); Iterator<JsonNode> iterator = executeSelectAsIterator(select); File tempUnitReportFile = null; File tempObjectGroupReportFile = null; try { tempUnitReportFile = File.createTempFile(UNIT_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); tempObjectGroupReportFile = File.createTempFile(OBJECT_GROUP_LIST_TMP_FILE_PREFIX, JSONL_EXTENSION, new File(VitamConfiguration.getVitamTmpFolder())); try (JsonLineWriter unitReportWriter = new JsonLineWriter(new FileOutputStream(tempUnitReportFile)); JsonLineWriter objectGroupReportWriter = new JsonLineWriter( new FileOutputStream(tempObjectGroupReportFile))) { appendEntries(iterator, unitReportWriter, objectGroupReportWriter); } storeIntoWorkspace(unitsToUpdateJsonLineFileName, tempUnitReportFile); storeIntoWorkspace(objectGroupsToUpdateJsonLineFileName, tempObjectGroupReportFile); } finally { FileUtils.deleteQuietly(tempUnitReportFile); FileUtils.deleteQuietly(tempObjectGroupReportFile); } } ReclassificationDistributionService(MetaDataImpl metaData); @VisibleForTesting  ReclassificationDistributionService(
        WorkspaceClientFactory workspaceClientFactory,
        MetaDataImpl metaData); void exportReclassificationChildNodes(Set<String> unitIds, String unitsToUpdateJsonLineFileName,
        String objectGroupsToUpdateJsonLineFileName);  }