@Test public void should_not_include_duplicate_object_group_response() throws Exception { File newLocalFile = tempFolder.newFile(); TestHandlerIO handlerIO = new TestHandlerIO(); handlerIO.setNewLocalFile(newLocalFile); ProbativeValueRequest probativeValueRequest = new ProbativeValueRequest(JsonHandler.createObjectNode(), "BinaryMaster", "1"); handlerIO.setInputStreamFromWorkspace(new ByteArrayInputStream(JsonHandler.fromPojoToBytes(probativeValueRequest))); ObjectNode selectedUnitGOT = JsonHandler.createObjectNode(); selectedUnitGOT.put("#id", "BATMAN_ID"); selectedUnitGOT.put("#object", "ROBIN_ID"); ObjectNode selectedUnitGOT2 = JsonHandler.createObjectNode(); selectedUnitGOT2.put("#id", "JOKER_ID"); selectedUnitGOT2.put("#object", "ROBIN_ID"); RequestResponseOK requestResponseOK = new RequestResponseOK(); requestResponseOK.addResult(selectedUnitGOT); requestResponseOK.addResult(selectedUnitGOT2); given(metaDataClient.selectUnits(any())).willReturn(JsonHandler.toJsonNode(requestResponseOK)); probativeCreateDistribution.execute(null, handlerIO); assertThat(handlerIO.getTransferedFileToWorkspace("distributionFile.jsonl")).isEqualTo(newLocalFile); assertThat(Files.readAllLines(handlerIO.getTransferedFileToWorkspace("distributionFile.jsonl").toPath())) .contains("{\"id\":\"ROBIN_ID\",\"params\":{\"unitIds\":[\"BATMAN_ID\",\"JOKER_ID\"],\"usageVersion\":\"BinaryMaster_1\"}}"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { File objectGroupsToCheck = handler.getNewLocalFile("OBJECT_GROUP_TO_CHECK.jsonL"); try (MetaDataClient metadataClient = metaDataClientFactory.getClient(); FileOutputStream outputStream = new FileOutputStream(objectGroupsToCheck); JsonLineWriter writer = new JsonLineWriter(outputStream); InputStream request = handler.getInputStreamFromWorkspace("request")) { ProbativeValueRequest probativeValueRequest = JsonHandler.getFromInputStream(request, ProbativeValueRequest.class); String usageVersion = String.format("%s_%s", probativeValueRequest.getUsage(), probativeValueRequest.getVersion()); SelectMultiQuery select = constructSelectMultiQuery(probativeValueRequest); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper.createUnitScrollSplitIterator(metadataClient, select); SpliteratorIterator<JsonNode> iterator = new SpliteratorIterator<>(scrollRequest); JsonNode previousElement = null; List<String> elementIds = new ArrayList<>(); while (iterator.hasNext()) { JsonNode element = iterator.next(); JsonNode objectValue = element.path(VitamFieldsHelper.object()); if (objectValue.isMissingNode() || objectValue.isNull() || StringUtils.isBlank(objectValue.asText())) { continue; } elementIds.add(element.get(VitamFieldsHelper.id()).asText()); if (iterator.hasNext() && (previousElement == null || objectValue.equals(previousElement.get(VitamFieldsHelper.object())))) { previousElement = element; continue; } JsonLineModel jsonLine = toJsonLineDistribution(element, usageVersion, elementIds); writeLines(jsonLine, writer); elementIds.clear(); } } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, KO, EventDetails.of("Creation of distribution file error.")); } handler.transferFileToWorkspace("distributionFile.jsonl", objectGroupsToCheck, false, false); return buildItemStatus(HANDLER_ID, OK, EventDetails.of("Creation of distribution file succeed.")); }
ProbativeCreateDistributionFile extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { File objectGroupsToCheck = handler.getNewLocalFile("OBJECT_GROUP_TO_CHECK.jsonL"); try (MetaDataClient metadataClient = metaDataClientFactory.getClient(); FileOutputStream outputStream = new FileOutputStream(objectGroupsToCheck); JsonLineWriter writer = new JsonLineWriter(outputStream); InputStream request = handler.getInputStreamFromWorkspace("request")) { ProbativeValueRequest probativeValueRequest = JsonHandler.getFromInputStream(request, ProbativeValueRequest.class); String usageVersion = String.format("%s_%s", probativeValueRequest.getUsage(), probativeValueRequest.getVersion()); SelectMultiQuery select = constructSelectMultiQuery(probativeValueRequest); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper.createUnitScrollSplitIterator(metadataClient, select); SpliteratorIterator<JsonNode> iterator = new SpliteratorIterator<>(scrollRequest); JsonNode previousElement = null; List<String> elementIds = new ArrayList<>(); while (iterator.hasNext()) { JsonNode element = iterator.next(); JsonNode objectValue = element.path(VitamFieldsHelper.object()); if (objectValue.isMissingNode() || objectValue.isNull() || StringUtils.isBlank(objectValue.asText())) { continue; } elementIds.add(element.get(VitamFieldsHelper.id()).asText()); if (iterator.hasNext() && (previousElement == null || objectValue.equals(previousElement.get(VitamFieldsHelper.object())))) { previousElement = element; continue; } JsonLineModel jsonLine = toJsonLineDistribution(element, usageVersion, elementIds); writeLines(jsonLine, writer); elementIds.clear(); } } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, KO, EventDetails.of("Creation of distribution file error.")); } handler.transferFileToWorkspace("distributionFile.jsonl", objectGroupsToCheck, false, false); return buildItemStatus(HANDLER_ID, OK, EventDetails.of("Creation of distribution file succeed.")); } }
ProbativeCreateDistributionFile extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { File objectGroupsToCheck = handler.getNewLocalFile("OBJECT_GROUP_TO_CHECK.jsonL"); try (MetaDataClient metadataClient = metaDataClientFactory.getClient(); FileOutputStream outputStream = new FileOutputStream(objectGroupsToCheck); JsonLineWriter writer = new JsonLineWriter(outputStream); InputStream request = handler.getInputStreamFromWorkspace("request")) { ProbativeValueRequest probativeValueRequest = JsonHandler.getFromInputStream(request, ProbativeValueRequest.class); String usageVersion = String.format("%s_%s", probativeValueRequest.getUsage(), probativeValueRequest.getVersion()); SelectMultiQuery select = constructSelectMultiQuery(probativeValueRequest); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper.createUnitScrollSplitIterator(metadataClient, select); SpliteratorIterator<JsonNode> iterator = new SpliteratorIterator<>(scrollRequest); JsonNode previousElement = null; List<String> elementIds = new ArrayList<>(); while (iterator.hasNext()) { JsonNode element = iterator.next(); JsonNode objectValue = element.path(VitamFieldsHelper.object()); if (objectValue.isMissingNode() || objectValue.isNull() || StringUtils.isBlank(objectValue.asText())) { continue; } elementIds.add(element.get(VitamFieldsHelper.id()).asText()); if (iterator.hasNext() && (previousElement == null || objectValue.equals(previousElement.get(VitamFieldsHelper.object())))) { previousElement = element; continue; } JsonLineModel jsonLine = toJsonLineDistribution(element, usageVersion, elementIds); writeLines(jsonLine, writer); elementIds.clear(); } } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, KO, EventDetails.of("Creation of distribution file error.")); } handler.transferFileToWorkspace("distributionFile.jsonl", objectGroupsToCheck, false, false); return buildItemStatus(HANDLER_ID, OK, EventDetails.of("Creation of distribution file succeed.")); } @VisibleForTesting  ProbativeCreateDistributionFile(MetaDataClientFactory metaDataClientFactory);  ProbativeCreateDistributionFile(); }
ProbativeCreateDistributionFile extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { File objectGroupsToCheck = handler.getNewLocalFile("OBJECT_GROUP_TO_CHECK.jsonL"); try (MetaDataClient metadataClient = metaDataClientFactory.getClient(); FileOutputStream outputStream = new FileOutputStream(objectGroupsToCheck); JsonLineWriter writer = new JsonLineWriter(outputStream); InputStream request = handler.getInputStreamFromWorkspace("request")) { ProbativeValueRequest probativeValueRequest = JsonHandler.getFromInputStream(request, ProbativeValueRequest.class); String usageVersion = String.format("%s_%s", probativeValueRequest.getUsage(), probativeValueRequest.getVersion()); SelectMultiQuery select = constructSelectMultiQuery(probativeValueRequest); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper.createUnitScrollSplitIterator(metadataClient, select); SpliteratorIterator<JsonNode> iterator = new SpliteratorIterator<>(scrollRequest); JsonNode previousElement = null; List<String> elementIds = new ArrayList<>(); while (iterator.hasNext()) { JsonNode element = iterator.next(); JsonNode objectValue = element.path(VitamFieldsHelper.object()); if (objectValue.isMissingNode() || objectValue.isNull() || StringUtils.isBlank(objectValue.asText())) { continue; } elementIds.add(element.get(VitamFieldsHelper.id()).asText()); if (iterator.hasNext() && (previousElement == null || objectValue.equals(previousElement.get(VitamFieldsHelper.object())))) { previousElement = element; continue; } JsonLineModel jsonLine = toJsonLineDistribution(element, usageVersion, elementIds); writeLines(jsonLine, writer); elementIds.clear(); } } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, KO, EventDetails.of("Creation of distribution file error.")); } handler.transferFileToWorkspace("distributionFile.jsonl", objectGroupsToCheck, false, false); return buildItemStatus(HANDLER_ID, OK, EventDetails.of("Creation of distribution file succeed.")); } @VisibleForTesting  ProbativeCreateDistributionFile(MetaDataClientFactory metaDataClientFactory);  ProbativeCreateDistributionFile(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
ProbativeCreateDistributionFile extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { File objectGroupsToCheck = handler.getNewLocalFile("OBJECT_GROUP_TO_CHECK.jsonL"); try (MetaDataClient metadataClient = metaDataClientFactory.getClient(); FileOutputStream outputStream = new FileOutputStream(objectGroupsToCheck); JsonLineWriter writer = new JsonLineWriter(outputStream); InputStream request = handler.getInputStreamFromWorkspace("request")) { ProbativeValueRequest probativeValueRequest = JsonHandler.getFromInputStream(request, ProbativeValueRequest.class); String usageVersion = String.format("%s_%s", probativeValueRequest.getUsage(), probativeValueRequest.getVersion()); SelectMultiQuery select = constructSelectMultiQuery(probativeValueRequest); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper.createUnitScrollSplitIterator(metadataClient, select); SpliteratorIterator<JsonNode> iterator = new SpliteratorIterator<>(scrollRequest); JsonNode previousElement = null; List<String> elementIds = new ArrayList<>(); while (iterator.hasNext()) { JsonNode element = iterator.next(); JsonNode objectValue = element.path(VitamFieldsHelper.object()); if (objectValue.isMissingNode() || objectValue.isNull() || StringUtils.isBlank(objectValue.asText())) { continue; } elementIds.add(element.get(VitamFieldsHelper.id()).asText()); if (iterator.hasNext() && (previousElement == null || objectValue.equals(previousElement.get(VitamFieldsHelper.object())))) { previousElement = element; continue; } JsonLineModel jsonLine = toJsonLineDistribution(element, usageVersion, elementIds); writeLines(jsonLine, writer); elementIds.clear(); } } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, KO, EventDetails.of("Creation of distribution file error.")); } handler.transferFileToWorkspace("distributionFile.jsonl", objectGroupsToCheck, false, false); return buildItemStatus(HANDLER_ID, OK, EventDetails.of("Creation of distribution file succeed.")); } @VisibleForTesting  ProbativeCreateDistributionFile(MetaDataClientFactory metaDataClientFactory);  ProbativeCreateDistributionFile(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }