@Test void mapQueryRuleNonNullIntValues() { QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn("attr"); when(queryRule.getValue()).thenReturn(0); 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); QueryBuilder queryBuilder = queryClauseEqualsGenerator.mapQueryRule(queryRule, entityType); QueryBuilder expectedQueryBuilder = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("attr", 0)); assertQueryBuilderEquals(expectedQueryBuilder, queryBuilder); }
QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); QueryBuilder queryBuilder; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: String fieldName = getQueryFieldName(attributePath); if (queryRule.getValue() != null) { Object queryValue = getQueryValue(attr, queryRule.getValue()); if (useNotAnalyzedField(attr)) { fieldName = fieldName + '.' + FIELD_NOT_ANALYZED; } queryBuilder = nestedQueryBuilder( entityType, attributePath, QueryBuilders.termQuery(fieldName, queryValue)); } else { queryBuilder = QueryBuilders.boolQuery() .mustNot( nestedQueryBuilder( entityType, attributePath, QueryBuilders.existsQuery(fieldName))); } break; case CATEGORICAL: case CATEGORICAL_MREF: case XREF: case MREF: case FILE: case ONE_TO_MANY: case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } return QueryBuilders.constantScoreQuery(queryBuilder); }
QueryClauseEqualsGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); QueryBuilder queryBuilder; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: String fieldName = getQueryFieldName(attributePath); if (queryRule.getValue() != null) { Object queryValue = getQueryValue(attr, queryRule.getValue()); if (useNotAnalyzedField(attr)) { fieldName = fieldName + '.' + FIELD_NOT_ANALYZED; } queryBuilder = nestedQueryBuilder( entityType, attributePath, QueryBuilders.termQuery(fieldName, queryValue)); } else { queryBuilder = QueryBuilders.boolQuery() .mustNot( nestedQueryBuilder( entityType, attributePath, QueryBuilders.existsQuery(fieldName))); } break; case CATEGORICAL: case CATEGORICAL_MREF: case XREF: case MREF: case FILE: case ONE_TO_MANY: case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } return QueryBuilders.constantScoreQuery(queryBuilder); } }
QueryClauseEqualsGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); QueryBuilder queryBuilder; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: String fieldName = getQueryFieldName(attributePath); if (queryRule.getValue() != null) { Object queryValue = getQueryValue(attr, queryRule.getValue()); if (useNotAnalyzedField(attr)) { fieldName = fieldName + '.' + FIELD_NOT_ANALYZED; } queryBuilder = nestedQueryBuilder( entityType, attributePath, QueryBuilders.termQuery(fieldName, queryValue)); } else { queryBuilder = QueryBuilders.boolQuery() .mustNot( nestedQueryBuilder( entityType, attributePath, QueryBuilders.existsQuery(fieldName))); } break; case CATEGORICAL: case CATEGORICAL_MREF: case XREF: case MREF: case FILE: case ONE_TO_MANY: case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } return QueryBuilders.constantScoreQuery(queryBuilder); } QueryClauseEqualsGenerator(DocumentIdGenerator documentIdGenerator); }
QueryClauseEqualsGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); QueryBuilder queryBuilder; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: String fieldName = getQueryFieldName(attributePath); if (queryRule.getValue() != null) { Object queryValue = getQueryValue(attr, queryRule.getValue()); if (useNotAnalyzedField(attr)) { fieldName = fieldName + '.' + FIELD_NOT_ANALYZED; } queryBuilder = nestedQueryBuilder( entityType, attributePath, QueryBuilders.termQuery(fieldName, queryValue)); } else { queryBuilder = QueryBuilders.boolQuery() .mustNot( nestedQueryBuilder( entityType, attributePath, QueryBuilders.existsQuery(fieldName))); } break; case CATEGORICAL: case CATEGORICAL_MREF: case XREF: case MREF: case FILE: case ONE_TO_MANY: case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } return QueryBuilders.constantScoreQuery(queryBuilder); } QueryClauseEqualsGenerator(DocumentIdGenerator documentIdGenerator);  }
QueryClauseEqualsGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); QueryBuilder queryBuilder; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: String fieldName = getQueryFieldName(attributePath); if (queryRule.getValue() != null) { Object queryValue = getQueryValue(attr, queryRule.getValue()); if (useNotAnalyzedField(attr)) { fieldName = fieldName + '.' + FIELD_NOT_ANALYZED; } queryBuilder = nestedQueryBuilder( entityType, attributePath, QueryBuilders.termQuery(fieldName, queryValue)); } else { queryBuilder = QueryBuilders.boolQuery() .mustNot( nestedQueryBuilder( entityType, attributePath, QueryBuilders.existsQuery(fieldName))); } break; case CATEGORICAL: case CATEGORICAL_MREF: case XREF: case MREF: case FILE: case ONE_TO_MANY: case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } return QueryBuilders.constantScoreQuery(queryBuilder); } QueryClauseEqualsGenerator(DocumentIdGenerator documentIdGenerator);   }