@Test public void testSelectUnitsByIdsAndAccessContract_LotsOfUnitIds() throws Exception { AccessContractModel accessContractModel = createAccessContractWithRestrictions(); SelectMultiQuery selectMultiQuery = new SelectMultiQuery(); selectMultiQuery.addQueries(QueryHelper.in(VitamFieldsHelper.id(), "MyId1", "MyId2", "MyId3")); Set<String> ids = IntStream.rangeClosed(1, UnitGraphInfoLoader.MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE + 1) .mapToObj(i -> "MyId" + i) .collect(Collectors.toSet()); when(metaDataClient.selectUnits(any())).thenReturn( buildResponseJsonNode("MyId1", "MyId2"), buildResponseJsonNode("MyId1001")); Set<String> foundIds = unitGraphInfoLoader .selectUnitsByIdsAndAccessContract(metaDataClient, ids, accessContractModel); assertThat(foundIds).containsExactlyInAnyOrder("MyId1", "MyId2", "MyId1001"); ArgumentCaptor<JsonNode> queryArgumentCaptor = ArgumentCaptor.forClass(JsonNode.class); verify(metaDataClient, times(2)).selectUnits((queryArgumentCaptor.capture())); String query = JsonHandler.unprettyPrint(queryArgumentCaptor.getValue()); assertThat(query).contains(originatingAgency); assertThat(query).contains(includedRootId); assertThat(query).contains(excludedRootId); }
public Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds, AccessContractModel accessContractModel) throws InvalidParseOperationException, InvalidCreateOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException { Set<String> foundUnitIds = new HashSet<>(); for (List<String> ids : ListUtils.partition(new ArrayList<>(unitIds), MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE)) { SelectMultiQuery select = new SelectMultiQuery(); select.setQuery(QueryHelper.in(VitamFieldsHelper.id(), ids.toArray(new String[0]))); foundUnitIds.addAll(selectUnitsByQueryDslAndAccessContract(metaDataClient, select, accessContractModel)); } return foundUnitIds; }
UnitGraphInfoLoader { public Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds, AccessContractModel accessContractModel) throws InvalidParseOperationException, InvalidCreateOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException { Set<String> foundUnitIds = new HashSet<>(); for (List<String> ids : ListUtils.partition(new ArrayList<>(unitIds), MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE)) { SelectMultiQuery select = new SelectMultiQuery(); select.setQuery(QueryHelper.in(VitamFieldsHelper.id(), ids.toArray(new String[0]))); foundUnitIds.addAll(selectUnitsByQueryDslAndAccessContract(metaDataClient, select, accessContractModel)); } return foundUnitIds; } }
UnitGraphInfoLoader { public Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds, AccessContractModel accessContractModel) throws InvalidParseOperationException, InvalidCreateOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException { Set<String> foundUnitIds = new HashSet<>(); for (List<String> ids : ListUtils.partition(new ArrayList<>(unitIds), MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE)) { SelectMultiQuery select = new SelectMultiQuery(); select.setQuery(QueryHelper.in(VitamFieldsHelper.id(), ids.toArray(new String[0]))); foundUnitIds.addAll(selectUnitsByQueryDslAndAccessContract(metaDataClient, select, accessContractModel)); } return foundUnitIds; }  }
UnitGraphInfoLoader { public Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds, AccessContractModel accessContractModel) throws InvalidParseOperationException, InvalidCreateOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException { Set<String> foundUnitIds = new HashSet<>(); for (List<String> ids : ListUtils.partition(new ArrayList<>(unitIds), MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE)) { SelectMultiQuery select = new SelectMultiQuery(); select.setQuery(QueryHelper.in(VitamFieldsHelper.id(), ids.toArray(new String[0]))); foundUnitIds.addAll(selectUnitsByQueryDslAndAccessContract(metaDataClient, select, accessContractModel)); } return foundUnitIds; }  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 Set<String> selectUnitsByIdsAndAccessContract(MetaDataClient metaDataClient, Set<String> unitIds, AccessContractModel accessContractModel) throws InvalidParseOperationException, InvalidCreateOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException { Set<String> foundUnitIds = new HashSet<>(); for (List<String> ids : ListUtils.partition(new ArrayList<>(unitIds), MAX_ELASTIC_SEARCH_IN_REQUEST_SIZE)) { SelectMultiQuery select = new SelectMultiQuery(); select.setQuery(QueryHelper.in(VitamFieldsHelper.id(), ids.toArray(new String[0]))); foundUnitIds.addAll(selectUnitsByQueryDslAndAccessContract(metaDataClient, select, accessContractModel)); } return foundUnitIds; }  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);  }