@Test void mapQueryRule() { QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn("attr"); when(queryRule.getValue()).thenReturn("val"); Attribute attribute = mock(Attribute.class); when(attribute.getDataType()).thenReturn(AttributeType.STRING); when(documentIdGenerator.generateId(attribute)).thenReturn("attr"); EntityType entityType = mock(EntityType.class); when(entityType.getAttributeByName("attr")).thenReturn(attribute); QueryBuilder queryBuilder = queryClauseLikeGenerator.mapQueryRule(queryRule, entityType); QueryBuilder expectedQueryBuilder = QueryBuilders.matchPhrasePrefixQuery("attr", "val") .maxExpansions(50) .slop(10) .analyzer("default"); assertQueryBuilderEquals(expectedQueryBuilder, queryBuilder); }
QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case EMAIL: case ENUM: case HYPERLINK: case STRING: return nestedQueryBuilder( entityType, attributePath, getQueryBuilder(attr, fieldName, queryValue)); case BOOL: case COMPOUND: case DATE: case DATE_TIME: case DECIMAL: case INT: case LONG: case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: throw new MolgenisQueryException( format("Illegal data type [%s] for operator [%s]", attrType, LIKE)); case HTML: case SCRIPT: case TEXT: throw new UnsupportedOperationException( format("Unsupported data type [%s] for operator [%s]", attrType, LIKE)); default: throw new UnexpectedEnumException(attrType); } }
QueryClauseLikeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case EMAIL: case ENUM: case HYPERLINK: case STRING: return nestedQueryBuilder( entityType, attributePath, getQueryBuilder(attr, fieldName, queryValue)); case BOOL: case COMPOUND: case DATE: case DATE_TIME: case DECIMAL: case INT: case LONG: case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: throw new MolgenisQueryException( format("Illegal data type [%s] for operator [%s]", attrType, LIKE)); case HTML: case SCRIPT: case TEXT: throw new UnsupportedOperationException( format("Unsupported data type [%s] for operator [%s]", attrType, LIKE)); default: throw new UnexpectedEnumException(attrType); } } }
QueryClauseLikeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case EMAIL: case ENUM: case HYPERLINK: case STRING: return nestedQueryBuilder( entityType, attributePath, getQueryBuilder(attr, fieldName, queryValue)); case BOOL: case COMPOUND: case DATE: case DATE_TIME: case DECIMAL: case INT: case LONG: case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: throw new MolgenisQueryException( format("Illegal data type [%s] for operator [%s]", attrType, LIKE)); case HTML: case SCRIPT: case TEXT: throw new UnsupportedOperationException( format("Unsupported data type [%s] for operator [%s]", attrType, LIKE)); default: throw new UnexpectedEnumException(attrType); } } QueryClauseLikeGenerator(DocumentIdGenerator documentIdGenerator); }
QueryClauseLikeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case EMAIL: case ENUM: case HYPERLINK: case STRING: return nestedQueryBuilder( entityType, attributePath, getQueryBuilder(attr, fieldName, queryValue)); case BOOL: case COMPOUND: case DATE: case DATE_TIME: case DECIMAL: case INT: case LONG: case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: throw new MolgenisQueryException( format("Illegal data type [%s] for operator [%s]", attrType, LIKE)); case HTML: case SCRIPT: case TEXT: throw new UnsupportedOperationException( format("Unsupported data type [%s] for operator [%s]", attrType, LIKE)); default: throw new UnexpectedEnumException(attrType); } } QueryClauseLikeGenerator(DocumentIdGenerator documentIdGenerator);  }
QueryClauseLikeGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case EMAIL: case ENUM: case HYPERLINK: case STRING: return nestedQueryBuilder( entityType, attributePath, getQueryBuilder(attr, fieldName, queryValue)); case BOOL: case COMPOUND: case DATE: case DATE_TIME: case DECIMAL: case INT: case LONG: case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: throw new MolgenisQueryException( format("Illegal data type [%s] for operator [%s]", attrType, LIKE)); case HTML: case SCRIPT: case TEXT: throw new UnsupportedOperationException( format("Unsupported data type [%s] for operator [%s]", attrType, LIKE)); default: throw new UnexpectedEnumException(attrType); } } QueryClauseLikeGenerator(DocumentIdGenerator documentIdGenerator);   }