@SuppressWarnings("deprecation") @Test void mapQueryRuleNonRangeValue() { QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn("attr"); when(queryRule.getValue()).thenReturn(2); 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, () -> queryClauseRangeGenerator.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); } if (!(queryValue instanceof Iterable<?>)) { throw new MolgenisQueryException( format( "Query value must be a Iterable instead of [%s]", queryValue.getClass().getSimpleName())); } Iterator<?> queryValuesIterator = ((Iterable<?>) queryValue).iterator(); Object queryValueFrom = getQueryValue(attr, queryValuesIterator.next()); Object queryValueTo = getQueryValue(attr, queryValuesIterator.next()); return QueryBuilders.constantScoreQuery( nestedQueryBuilder( entityType, attributePath, QueryBuilders.rangeQuery(fieldName).gte(queryValueFrom).lte(queryValueTo))); }
QueryClauseRangeGenerator 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); } if (!(queryValue instanceof Iterable<?>)) { throw new MolgenisQueryException( format( "Query value must be a Iterable instead of [%s]", queryValue.getClass().getSimpleName())); } Iterator<?> queryValuesIterator = ((Iterable<?>) queryValue).iterator(); Object queryValueFrom = getQueryValue(attr, queryValuesIterator.next()); Object queryValueTo = getQueryValue(attr, queryValuesIterator.next()); return QueryBuilders.constantScoreQuery( nestedQueryBuilder( entityType, attributePath, QueryBuilders.rangeQuery(fieldName).gte(queryValueFrom).lte(queryValueTo))); } }
QueryClauseRangeGenerator 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); } if (!(queryValue instanceof Iterable<?>)) { throw new MolgenisQueryException( format( "Query value must be a Iterable instead of [%s]", queryValue.getClass().getSimpleName())); } Iterator<?> queryValuesIterator = ((Iterable<?>) queryValue).iterator(); Object queryValueFrom = getQueryValue(attr, queryValuesIterator.next()); Object queryValueTo = getQueryValue(attr, queryValuesIterator.next()); return QueryBuilders.constantScoreQuery( nestedQueryBuilder( entityType, attributePath, QueryBuilders.rangeQuery(fieldName).gte(queryValueFrom).lte(queryValueTo))); } QueryClauseRangeGenerator(DocumentIdGenerator documentIdGenerator); }
QueryClauseRangeGenerator 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); } if (!(queryValue instanceof Iterable<?>)) { throw new MolgenisQueryException( format( "Query value must be a Iterable instead of [%s]", queryValue.getClass().getSimpleName())); } Iterator<?> queryValuesIterator = ((Iterable<?>) queryValue).iterator(); Object queryValueFrom = getQueryValue(attr, queryValuesIterator.next()); Object queryValueTo = getQueryValue(attr, queryValuesIterator.next()); return QueryBuilders.constantScoreQuery( nestedQueryBuilder( entityType, attributePath, QueryBuilders.rangeQuery(fieldName).gte(queryValueFrom).lte(queryValueTo))); } QueryClauseRangeGenerator(DocumentIdGenerator documentIdGenerator);  }
QueryClauseRangeGenerator 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); } if (!(queryValue instanceof Iterable<?>)) { throw new MolgenisQueryException( format( "Query value must be a Iterable instead of [%s]", queryValue.getClass().getSimpleName())); } Iterator<?> queryValuesIterator = ((Iterable<?>) queryValue).iterator(); Object queryValueFrom = getQueryValue(attr, queryValuesIterator.next()); Object queryValueTo = getQueryValue(attr, queryValuesIterator.next()); return QueryBuilders.constantScoreQuery( nestedQueryBuilder( entityType, attributePath, QueryBuilders.rangeQuery(fieldName).gte(queryValueFrom).lte(queryValueTo))); } QueryClauseRangeGenerator(DocumentIdGenerator documentIdGenerator);   }