@Test public void testSelectUnitsByQueryDslAndAccessContract() throws Exception { AccessContractModel accessContractModel = createAccessContractWithRestrictions(); SelectMultiQuery selectMultiQuery = new SelectMultiQuery(); selectMultiQuery.addQueries(QueryHelper.in(VitamFieldsHelper.id(), "MyId1", "MyId2", "MyId3")); doReturn(buildResponseJsonNode("MyId1", "MyId3")) .when(metaDataClient).selectUnits((any())); Set<String> ids = unitGraphInfoLoader .selectUnitsByQueryDslAndAccessContract(metaDataClient, selectMultiQuery, accessContractModel); assertThat(ids).containsExactlyInAnyOrder("MyId1", "MyId3"); ArgumentCaptor<JsonNode> queryArgumentCaptor = ArgumentCaptor.forClass(JsonNode.class); verify(metaDataClient).selectUnits((queryArgumentCaptor.capture())); String query = JsonHandler.unprettyPrint(queryArgumentCaptor.getValue()); assertThat(query).contains(originatingAgency); assertThat(query).contains(includedRootId); assertThat(query).contains(excludedRootId); assertThat(query).contains("MyId1"); }
public Set<String> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient, SelectMultiQuery select, AccessContractModel accessContractModel) throws InvalidParseOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException, InvalidCreateOperationException { select.addUsedProjection(VitamFieldsHelper.id()); JsonNode selectWithAccessContractFilter = AccessContractRestrictionHelper .applyAccessContractRestrictionForUnitForSelect(select.getFinalSelect(), accessContractModel); JsonNode resultJson = metaDataClient.selectUnits(selectWithAccessContractFilter); Set<String> foundUnitIds = new HashSet<>(); for (JsonNode node : resultJson.get(RESULTS)) { String id = node.get(VitamFieldsHelper.id()).asText(); foundUnitIds.add(id); } return foundUnitIds; }
UnitGraphInfoLoader { public Set<String> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient, SelectMultiQuery select, AccessContractModel accessContractModel) throws InvalidParseOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException, InvalidCreateOperationException { select.addUsedProjection(VitamFieldsHelper.id()); JsonNode selectWithAccessContractFilter = AccessContractRestrictionHelper .applyAccessContractRestrictionForUnitForSelect(select.getFinalSelect(), accessContractModel); JsonNode resultJson = metaDataClient.selectUnits(selectWithAccessContractFilter); Set<String> foundUnitIds = new HashSet<>(); for (JsonNode node : resultJson.get(RESULTS)) { String id = node.get(VitamFieldsHelper.id()).asText(); foundUnitIds.add(id); } return foundUnitIds; } }
UnitGraphInfoLoader { public Set<String> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient, SelectMultiQuery select, AccessContractModel accessContractModel) throws InvalidParseOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException, InvalidCreateOperationException { select.addUsedProjection(VitamFieldsHelper.id()); JsonNode selectWithAccessContractFilter = AccessContractRestrictionHelper .applyAccessContractRestrictionForUnitForSelect(select.getFinalSelect(), accessContractModel); JsonNode resultJson = metaDataClient.selectUnits(selectWithAccessContractFilter); Set<String> foundUnitIds = new HashSet<>(); for (JsonNode node : resultJson.get(RESULTS)) { String id = node.get(VitamFieldsHelper.id()).asText(); foundUnitIds.add(id); } return foundUnitIds; }  }
UnitGraphInfoLoader { public Set<String> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient, SelectMultiQuery select, AccessContractModel accessContractModel) throws InvalidParseOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException, InvalidCreateOperationException { select.addUsedProjection(VitamFieldsHelper.id()); JsonNode selectWithAccessContractFilter = AccessContractRestrictionHelper .applyAccessContractRestrictionForUnitForSelect(select.getFinalSelect(), accessContractModel); JsonNode resultJson = metaDataClient.selectUnits(selectWithAccessContractFilter); Set<String> foundUnitIds = new HashSet<>(); for (JsonNode node : resultJson.get(RESULTS)) { String id = node.get(VitamFieldsHelper.id()).asText(); foundUnitIds.add(id); } 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> selectUnitsByQueryDslAndAccessContract(MetaDataClient metaDataClient, SelectMultiQuery select, AccessContractModel accessContractModel) throws InvalidParseOperationException, VitamDBException, MetaDataDocumentSizeException, MetaDataExecutionException, MetaDataClientServerException, InvalidCreateOperationException { select.addUsedProjection(VitamFieldsHelper.id()); JsonNode selectWithAccessContractFilter = AccessContractRestrictionHelper .applyAccessContractRestrictionForUnitForSelect(select.getFinalSelect(), accessContractModel); JsonNode resultJson = metaDataClient.selectUnits(selectWithAccessContractFilter); Set<String> foundUnitIds = new HashSet<>(); for (JsonNode node : resultJson.get(RESULTS)) { String id = node.get(VitamFieldsHelper.id()).asText(); foundUnitIds.add(id); } 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);  }