@Test public void selectUnitsWithInheritedRules_invalidProjectionV1() throws Exception { ComputeInheritedRuleService computeInheritedRuleService = mock(ComputeInheritedRuleService.class); MetaDataImpl metadata = mock(MetaDataImpl.class); MetadataRuleService instance = new MetadataRuleService(computeInheritedRuleService, metadata); SelectMultiQuery select = new SelectMultiQuery(); select.addQueries(exists("Title")); select.addUsedProjection("Title", BuilderToken.GLOBAL.RULES.exactToken()); assertThatThrownBy(() -> instance.selectUnitsWithInheritedRules(select.getFinalSelect())) .isInstanceOf(InvalidParseOperationException.class) .hasMessage("Invalid $rules projection"); }
public RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery) throws InvalidParseOperationException, MetaDataExecutionException, BadRequestException, VitamDBException, MetaDataNotFoundException, MetaDataDocumentSizeException { LOGGER.debug("selectUnitsWithInheritedRules / selectQuery: " + selectQuery); RequestParserMultiple parser = RequestParserHelper.getParser(selectQuery); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException("Expected a select query"); } final SelectMultiQuery request = (SelectMultiQuery) parser.getRequest(); ObjectNode fieldsProjection = (ObjectNode) request.getProjection().get(BuilderToken.PROJECTION.FIELDS.exactToken()); if (fieldsProjection != null && fieldsProjection.size() > 0) { if (fieldsProjection.has(BuilderToken.GLOBAL.RULES.exactToken())) { throw new InvalidParseOperationException( "Invalid " + BuilderToken.GLOBAL.RULES.exactToken() + " projection"); } fieldsProjection.put(VitamFieldsHelper.id(), 1); } RequestResponseOK<JsonNode> unitsRequestResponseOK = (RequestResponseOK<JsonNode>) metaData.selectUnitsByQuery(request.getFinalSelect()); computeInheritedRulesForUnits(unitsRequestResponseOK.getResults()); return unitsRequestResponseOK; }
MetadataRuleService { public RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery) throws InvalidParseOperationException, MetaDataExecutionException, BadRequestException, VitamDBException, MetaDataNotFoundException, MetaDataDocumentSizeException { LOGGER.debug("selectUnitsWithInheritedRules / selectQuery: " + selectQuery); RequestParserMultiple parser = RequestParserHelper.getParser(selectQuery); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException("Expected a select query"); } final SelectMultiQuery request = (SelectMultiQuery) parser.getRequest(); ObjectNode fieldsProjection = (ObjectNode) request.getProjection().get(BuilderToken.PROJECTION.FIELDS.exactToken()); if (fieldsProjection != null && fieldsProjection.size() > 0) { if (fieldsProjection.has(BuilderToken.GLOBAL.RULES.exactToken())) { throw new InvalidParseOperationException( "Invalid " + BuilderToken.GLOBAL.RULES.exactToken() + " projection"); } fieldsProjection.put(VitamFieldsHelper.id(), 1); } RequestResponseOK<JsonNode> unitsRequestResponseOK = (RequestResponseOK<JsonNode>) metaData.selectUnitsByQuery(request.getFinalSelect()); computeInheritedRulesForUnits(unitsRequestResponseOK.getResults()); return unitsRequestResponseOK; } }
MetadataRuleService { public RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery) throws InvalidParseOperationException, MetaDataExecutionException, BadRequestException, VitamDBException, MetaDataNotFoundException, MetaDataDocumentSizeException { LOGGER.debug("selectUnitsWithInheritedRules / selectQuery: " + selectQuery); RequestParserMultiple parser = RequestParserHelper.getParser(selectQuery); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException("Expected a select query"); } final SelectMultiQuery request = (SelectMultiQuery) parser.getRequest(); ObjectNode fieldsProjection = (ObjectNode) request.getProjection().get(BuilderToken.PROJECTION.FIELDS.exactToken()); if (fieldsProjection != null && fieldsProjection.size() > 0) { if (fieldsProjection.has(BuilderToken.GLOBAL.RULES.exactToken())) { throw new InvalidParseOperationException( "Invalid " + BuilderToken.GLOBAL.RULES.exactToken() + " projection"); } fieldsProjection.put(VitamFieldsHelper.id(), 1); } RequestResponseOK<JsonNode> unitsRequestResponseOK = (RequestResponseOK<JsonNode>) metaData.selectUnitsByQuery(request.getFinalSelect()); computeInheritedRulesForUnits(unitsRequestResponseOK.getResults()); return unitsRequestResponseOK; } MetadataRuleService(MetaDataImpl metaData); @VisibleForTesting  MetadataRuleService(ComputeInheritedRuleService computeInheritedRuleService, MetaDataImpl metaData); }
MetadataRuleService { public RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery) throws InvalidParseOperationException, MetaDataExecutionException, BadRequestException, VitamDBException, MetaDataNotFoundException, MetaDataDocumentSizeException { LOGGER.debug("selectUnitsWithInheritedRules / selectQuery: " + selectQuery); RequestParserMultiple parser = RequestParserHelper.getParser(selectQuery); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException("Expected a select query"); } final SelectMultiQuery request = (SelectMultiQuery) parser.getRequest(); ObjectNode fieldsProjection = (ObjectNode) request.getProjection().get(BuilderToken.PROJECTION.FIELDS.exactToken()); if (fieldsProjection != null && fieldsProjection.size() > 0) { if (fieldsProjection.has(BuilderToken.GLOBAL.RULES.exactToken())) { throw new InvalidParseOperationException( "Invalid " + BuilderToken.GLOBAL.RULES.exactToken() + " projection"); } fieldsProjection.put(VitamFieldsHelper.id(), 1); } RequestResponseOK<JsonNode> unitsRequestResponseOK = (RequestResponseOK<JsonNode>) metaData.selectUnitsByQuery(request.getFinalSelect()); computeInheritedRulesForUnits(unitsRequestResponseOK.getResults()); return unitsRequestResponseOK; } MetadataRuleService(MetaDataImpl metaData); @VisibleForTesting  MetadataRuleService(ComputeInheritedRuleService computeInheritedRuleService, MetaDataImpl metaData); RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery); }
MetadataRuleService { public RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery) throws InvalidParseOperationException, MetaDataExecutionException, BadRequestException, VitamDBException, MetaDataNotFoundException, MetaDataDocumentSizeException { LOGGER.debug("selectUnitsWithInheritedRules / selectQuery: " + selectQuery); RequestParserMultiple parser = RequestParserHelper.getParser(selectQuery); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException("Expected a select query"); } final SelectMultiQuery request = (SelectMultiQuery) parser.getRequest(); ObjectNode fieldsProjection = (ObjectNode) request.getProjection().get(BuilderToken.PROJECTION.FIELDS.exactToken()); if (fieldsProjection != null && fieldsProjection.size() > 0) { if (fieldsProjection.has(BuilderToken.GLOBAL.RULES.exactToken())) { throw new InvalidParseOperationException( "Invalid " + BuilderToken.GLOBAL.RULES.exactToken() + " projection"); } fieldsProjection.put(VitamFieldsHelper.id(), 1); } RequestResponseOK<JsonNode> unitsRequestResponseOK = (RequestResponseOK<JsonNode>) metaData.selectUnitsByQuery(request.getFinalSelect()); computeInheritedRulesForUnits(unitsRequestResponseOK.getResults()); return unitsRequestResponseOK; } MetadataRuleService(MetaDataImpl metaData); @VisibleForTesting  MetadataRuleService(ComputeInheritedRuleService computeInheritedRuleService, MetaDataImpl metaData); RequestResponse<JsonNode> selectUnitsWithInheritedRules(JsonNode selectQuery); static final String INHERITED_RULES; }