@Test public void selectAllUnitGraphByIds() throws Exception { Map<String, List<String>> unitsWithParents = new HashMap<>(); unitsWithParents.put("1", Arrays.asList()); unitsWithParents.put("2", Arrays.asList("1", "4", "6")); unitsWithParents.put("3", Arrays.asList("2")); unitsWithParents.put("4", Arrays.asList()); unitsWithParents.put("5", Arrays.asList()); unitsWithParents.put("6", Arrays.asList("5")); unitsWithParents.put("7", Arrays.asList("6")); unitsWithParents.put("8", Arrays.asList("3")); unitsWithParents.put("9", Arrays.asList("5")); unitsWithParents.put("10", Arrays.asList("9")); unitsWithParents.put("11", Arrays.asList("10")); when(metaDataClient.selectUnits(any())).then(args -> { JsonNode dsl = args.getArgument(0); SelectParserMultiple parserMultiple = new SelectParserMultiple(); parserMultiple.parse(dsl); ArrayNode jsonIds = (ArrayNode) parserMultiple.getRequest().getQueries().get(0).getNode("$in").get(VitamFieldsHelper.id()); Set<String> ids = new HashSet<>(); jsonIds.elements().forEachRemaining(e -> ids.add(e.asText())); ArrayNode results = JsonHandler.createArrayNode(); for (String id : ids) { results.add(JsonHandler.createObjectNode() .put(VitamFieldsHelper.id(), id) .put(VitamFieldsHelper.unitType(), UnitType.INGEST.name()) .set(VitamFieldsHelper.unitups(), JsonHandler.toJsonNode(unitsWithParents.get(id)))); } return JsonHandler.createObjectNode().set("$results", results); }); Map<String, UnitGraphInfo> unitGraphInfoMap = unitGraphInfoLoader.selectAllUnitGraphByIds(metaDataClient, new HashSet<>(Arrays.asList("8", "10"))); assertThat(unitGraphInfoMap).hasSize(9); assertThat(unitGraphInfoMap.keySet()).containsExactlyInAnyOrder("1", "2", "3", "4", "5", "6", "8", "9", "10"); verify(metaDataClient, times(4)).selectUnits(any()); }
public Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds) throws VitamDBException, InvalidParseOperationException, MetaDataExecutionException, MetaDataDocumentSizeException, MetaDataClientServerException, InvalidCreateOperationException { Map<String, UnitGraphInfo> unitGraphById = new HashMap<>(); Set<String> unitsToLoad = new HashSet<>(unitIds); while (!unitsToLoad.isEmpty()) { Set<String> bulkIds = unitsToLoad.stream() .limit(MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE) .collect(Collectors.toSet()); for (String bulkId : bulkIds) { unitGraphById.put(bulkId, null); } List<UnitGraphInfo> loadedUnits = loadBulkUnitGraph(metaDataClient, bulkIds); for (UnitGraphInfo loadedUnit : loadedUnits) { unitGraphById.put(loadedUnit.getId(), loadedUnit); for (String up : loadedUnit.getUp()) { if (!unitGraphById.containsKey(up)) { unitsToLoad.add(up); } } } unitsToLoad.removeAll(bulkIds); } return unitGraphById; }
UnitGraphInfoLoader { public Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds) throws VitamDBException, InvalidParseOperationException, MetaDataExecutionException, MetaDataDocumentSizeException, MetaDataClientServerException, InvalidCreateOperationException { Map<String, UnitGraphInfo> unitGraphById = new HashMap<>(); Set<String> unitsToLoad = new HashSet<>(unitIds); while (!unitsToLoad.isEmpty()) { Set<String> bulkIds = unitsToLoad.stream() .limit(MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE) .collect(Collectors.toSet()); for (String bulkId : bulkIds) { unitGraphById.put(bulkId, null); } List<UnitGraphInfo> loadedUnits = loadBulkUnitGraph(metaDataClient, bulkIds); for (UnitGraphInfo loadedUnit : loadedUnits) { unitGraphById.put(loadedUnit.getId(), loadedUnit); for (String up : loadedUnit.getUp()) { if (!unitGraphById.containsKey(up)) { unitsToLoad.add(up); } } } unitsToLoad.removeAll(bulkIds); } return unitGraphById; } }
UnitGraphInfoLoader { public Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds) throws VitamDBException, InvalidParseOperationException, MetaDataExecutionException, MetaDataDocumentSizeException, MetaDataClientServerException, InvalidCreateOperationException { Map<String, UnitGraphInfo> unitGraphById = new HashMap<>(); Set<String> unitsToLoad = new HashSet<>(unitIds); while (!unitsToLoad.isEmpty()) { Set<String> bulkIds = unitsToLoad.stream() .limit(MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE) .collect(Collectors.toSet()); for (String bulkId : bulkIds) { unitGraphById.put(bulkId, null); } List<UnitGraphInfo> loadedUnits = loadBulkUnitGraph(metaDataClient, bulkIds); for (UnitGraphInfo loadedUnit : loadedUnits) { unitGraphById.put(loadedUnit.getId(), loadedUnit); for (String up : loadedUnit.getUp()) { if (!unitGraphById.containsKey(up)) { unitsToLoad.add(up); } } } unitsToLoad.removeAll(bulkIds); } return unitGraphById; }  }
UnitGraphInfoLoader { public Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds) throws VitamDBException, InvalidParseOperationException, MetaDataExecutionException, MetaDataDocumentSizeException, MetaDataClientServerException, InvalidCreateOperationException { Map<String, UnitGraphInfo> unitGraphById = new HashMap<>(); Set<String> unitsToLoad = new HashSet<>(unitIds); while (!unitsToLoad.isEmpty()) { Set<String> bulkIds = unitsToLoad.stream() .limit(MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE) .collect(Collectors.toSet()); for (String bulkId : bulkIds) { unitGraphById.put(bulkId, null); } List<UnitGraphInfo> loadedUnits = loadBulkUnitGraph(metaDataClient, bulkIds); for (UnitGraphInfo loadedUnit : loadedUnits) { unitGraphById.put(loadedUnit.getId(), loadedUnit); for (String up : loadedUnit.getUp()) { if (!unitGraphById.containsKey(up)) { unitsToLoad.add(up); } } } unitsToLoad.removeAll(bulkIds); } return unitGraphById; }  Set<String> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient,
        SelectMultiQuery select, AccessContractModel accessContractModel); Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds,
        AccessContractModel accessContractModel); Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds); }
UnitGraphInfoLoader { public Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds) throws VitamDBException, InvalidParseOperationException, MetaDataExecutionException, MetaDataDocumentSizeException, MetaDataClientServerException, InvalidCreateOperationException { Map<String, UnitGraphInfo> unitGraphById = new HashMap<>(); Set<String> unitsToLoad = new HashSet<>(unitIds); while (!unitsToLoad.isEmpty()) { Set<String> bulkIds = unitsToLoad.stream() .limit(MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE) .collect(Collectors.toSet()); for (String bulkId : bulkIds) { unitGraphById.put(bulkId, null); } List<UnitGraphInfo> loadedUnits = loadBulkUnitGraph(metaDataClient, bulkIds); for (UnitGraphInfo loadedUnit : loadedUnits) { unitGraphById.put(loadedUnit.getId(), loadedUnit); for (String up : loadedUnit.getUp()) { if (!unitGraphById.containsKey(up)) { unitsToLoad.add(up); } } } unitsToLoad.removeAll(bulkIds); } return unitGraphById; }  Set<String> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient,
        SelectMultiQuery select, AccessContractModel accessContractModel); Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds,
        AccessContractModel accessContractModel); Map<String, UnitGraphInfo> selectAllUnitGraphByIds(MetaDataClient metaDataClient, Set<String> unitIds);  }