@SuppressWarnings("deprecation") @Test void mapQueryRuleNullValue() { QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn("attr"); Attribute attribute = mock(Attribute.class); when(attribute.getDataType()).thenReturn(AttributeType.INT); when(documentIdGenerator.generateId(attribute)).thenReturn("attr"); EntityType entityType = mock(EntityType.class); when(entityType.getAttributeByName("attr")).thenReturn(attribute); assertThrows( MolgenisQueryException.class, () -> baseQueryClauseRangeGenerator.mapQueryRule(queryRule, entityType)); }
QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); validateNumericalQueryField(attr); String fieldName = getQueryFieldName(attributePath); Object queryValue = getQueryValue(attr, queryRule.getValue()); if (queryValue == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(fieldName); switch (getOperator()) { case GREATER: rangeQueryBuilder.gt(queryValue); break; case GREATER_EQUAL: rangeQueryBuilder.gte(queryValue); break; case LESS: rangeQueryBuilder.lt(queryValue); break; case LESS_EQUAL: rangeQueryBuilder.lte(queryValue); break; default: throw new UnexpectedEnumException(getOperator()); } return QueryBuilders.constantScoreQuery( nestedQueryBuilder(entityType, attributePath, rangeQueryBuilder)); }
BaseQueryClauseRangeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); validateNumericalQueryField(attr); String fieldName = getQueryFieldName(attributePath); Object queryValue = getQueryValue(attr, queryRule.getValue()); if (queryValue == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(fieldName); switch (getOperator()) { case GREATER: rangeQueryBuilder.gt(queryValue); break; case GREATER_EQUAL: rangeQueryBuilder.gte(queryValue); break; case LESS: rangeQueryBuilder.lt(queryValue); break; case LESS_EQUAL: rangeQueryBuilder.lte(queryValue); break; default: throw new UnexpectedEnumException(getOperator()); } return QueryBuilders.constantScoreQuery( nestedQueryBuilder(entityType, attributePath, rangeQueryBuilder)); } }
BaseQueryClauseRangeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); validateNumericalQueryField(attr); String fieldName = getQueryFieldName(attributePath); Object queryValue = getQueryValue(attr, queryRule.getValue()); if (queryValue == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(fieldName); switch (getOperator()) { case GREATER: rangeQueryBuilder.gt(queryValue); break; case GREATER_EQUAL: rangeQueryBuilder.gte(queryValue); break; case LESS: rangeQueryBuilder.lt(queryValue); break; case LESS_EQUAL: rangeQueryBuilder.lte(queryValue); break; default: throw new UnexpectedEnumException(getOperator()); } return QueryBuilders.constantScoreQuery( nestedQueryBuilder(entityType, attributePath, rangeQueryBuilder)); } BaseQueryClauseRangeGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); }
BaseQueryClauseRangeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); validateNumericalQueryField(attr); String fieldName = getQueryFieldName(attributePath); Object queryValue = getQueryValue(attr, queryRule.getValue()); if (queryValue == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(fieldName); switch (getOperator()) { case GREATER: rangeQueryBuilder.gt(queryValue); break; case GREATER_EQUAL: rangeQueryBuilder.gte(queryValue); break; case LESS: rangeQueryBuilder.lt(queryValue); break; case LESS_EQUAL: rangeQueryBuilder.lte(queryValue); break; default: throw new UnexpectedEnumException(getOperator()); } return QueryBuilders.constantScoreQuery( nestedQueryBuilder(entityType, attributePath, rangeQueryBuilder)); } BaseQueryClauseRangeGenerator(DocumentIdGenerator documentIdGenerator, Operator operator);  }
BaseQueryClauseRangeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); validateNumericalQueryField(attr); String fieldName = getQueryFieldName(attributePath); Object queryValue = getQueryValue(attr, queryRule.getValue()); if (queryValue == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(fieldName); switch (getOperator()) { case GREATER: rangeQueryBuilder.gt(queryValue); break; case GREATER_EQUAL: rangeQueryBuilder.gte(queryValue); break; case LESS: rangeQueryBuilder.lt(queryValue); break; case LESS_EQUAL: rangeQueryBuilder.lte(queryValue); break; default: throw new UnexpectedEnumException(getOperator()); } return QueryBuilders.constantScoreQuery( nestedQueryBuilder(entityType, attributePath, rangeQueryBuilder)); } BaseQueryClauseRangeGenerator(DocumentIdGenerator documentIdGenerator, Operator operator);   }