@Test void testQueryValue() { Attribute attribute = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock(); assertEquals("string", queryGenerator.getQueryValue(attribute, "string")); }
Object getQueryValue(Attribute attribute, Object queryRuleValue) { AttributeType attrType = attribute.getDataType(); switch (attrType) { case BOOL: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return queryRuleValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: return queryRuleValue instanceof Entity ? ((Entity) queryRuleValue).getIdValue() : queryRuleValue; case DATE: if (queryRuleValue instanceof LocalDate) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type LocalDate instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case DATE_TIME: if (queryRuleValue instanceof Instant) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type Instant instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } }
BaseQueryClauseGenerator implements QueryClauseGenerator { Object getQueryValue(Attribute attribute, Object queryRuleValue) { AttributeType attrType = attribute.getDataType(); switch (attrType) { case BOOL: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return queryRuleValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: return queryRuleValue instanceof Entity ? ((Entity) queryRuleValue).getIdValue() : queryRuleValue; case DATE: if (queryRuleValue instanceof LocalDate) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type LocalDate instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case DATE_TIME: if (queryRuleValue instanceof Instant) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type Instant instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } } }
BaseQueryClauseGenerator implements QueryClauseGenerator { Object getQueryValue(Attribute attribute, Object queryRuleValue) { AttributeType attrType = attribute.getDataType(); switch (attrType) { case BOOL: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return queryRuleValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: return queryRuleValue instanceof Entity ? ((Entity) queryRuleValue).getIdValue() : queryRuleValue; case DATE: if (queryRuleValue instanceof LocalDate) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type LocalDate instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case DATE_TIME: if (queryRuleValue instanceof Instant) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type Instant instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } } BaseQueryClauseGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); }
BaseQueryClauseGenerator implements QueryClauseGenerator { Object getQueryValue(Attribute attribute, Object queryRuleValue) { AttributeType attrType = attribute.getDataType(); switch (attrType) { case BOOL: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return queryRuleValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: return queryRuleValue instanceof Entity ? ((Entity) queryRuleValue).getIdValue() : queryRuleValue; case DATE: if (queryRuleValue instanceof LocalDate) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type LocalDate instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case DATE_TIME: if (queryRuleValue instanceof Instant) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type Instant instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } } BaseQueryClauseGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); @Override Operator getOperator(); @Override QueryBuilder createQueryClause(QueryRule queryRule, EntityType entityType); }
BaseQueryClauseGenerator implements QueryClauseGenerator { Object getQueryValue(Attribute attribute, Object queryRuleValue) { AttributeType attrType = attribute.getDataType(); switch (attrType) { case BOOL: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return queryRuleValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case ONE_TO_MANY: case XREF: return queryRuleValue instanceof Entity ? ((Entity) queryRuleValue).getIdValue() : queryRuleValue; case DATE: if (queryRuleValue instanceof LocalDate) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type LocalDate instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case DATE_TIME: if (queryRuleValue instanceof Instant) { return queryRuleValue.toString(); } else if (queryRuleValue instanceof String) { return queryRuleValue; } else { throw new MolgenisQueryException( format( "Query value must be of type Instant instead of [%s]", queryRuleValue.getClass().getSimpleName())); } case COMPOUND: throw new MolgenisQueryException(new IllegalAttributeTypeException(attrType)); default: throw new UnexpectedEnumException(attrType); } } BaseQueryClauseGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); @Override Operator getOperator(); @Override QueryBuilder createQueryClause(QueryRule queryRule, EntityType entityType);  }