use of org.molgenis.data.meta.AttributeType in project molgenis by molgenis.
the class EntityTypeUtilsTest method isReferenceTypeAttrTypeProvider.
@DataProvider(name = "isReferenceTypeAttrTypeProvider")
public static Iterator<Object[]> isReferenceTypeAttrTypeProvider() {
List<Object[]> dataList = Lists.newArrayList();
for (AttributeType attrType : AttributeType.values()) {
boolean isRefAttr = attrType == CATEGORICAL || attrType == CATEGORICAL_MREF || attrType == FILE || attrType == MREF || attrType == ONE_TO_MANY || attrType == XREF;
dataList.add(new Object[] { attrType, isRefAttr });
}
return dataList.iterator();
}
use of org.molgenis.data.meta.AttributeType in project molgenis by molgenis.
the class EntityTypeUtilsTest method isReferenceTypeAttrProvider.
@DataProvider(name = "isReferenceTypeAttrProvider")
public static Iterator<Object[]> isReferenceTypeAttrProvider() {
List<Object[]> dataList = Lists.newArrayList();
for (AttributeType attrType : AttributeType.values()) {
Attribute attr = mock(Attribute.class);
when(attr.getDataType()).thenReturn(attrType);
when(attr.toString()).thenReturn("attr_" + attrType.toString());
boolean isRefAttr = attrType == CATEGORICAL || attrType == CATEGORICAL_MREF || attrType == FILE || attrType == MREF || attrType == ONE_TO_MANY || attrType == XREF;
dataList.add(new Object[] { attr, isRefAttr });
}
return dataList.iterator();
}
use of org.molgenis.data.meta.AttributeType in project molgenis by molgenis.
the class QueryGenerator method createQueryClauseFuzzyMatchNgram.
private QueryBuilder createQueryClauseFuzzyMatchNgram(QueryRule queryRule, EntityType entityType) {
String queryField = queryRule.getField();
Object queryValue = queryRule.getValue();
QueryBuilder queryBuilder;
if (queryValue == null)
throw new MolgenisQueryException("Query value cannot be null");
if (queryField == null) {
queryBuilder = QueryBuilders.matchQuery("_all", queryValue);
} else {
Attribute attr = entityType.getAttribute(queryField);
if (attr == null) {
throw new UnknownAttributeException(entityType, queryField);
}
// construct query part
AttributeType dataType = attr.getDataType();
switch(dataType) {
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:
queryField = getQueryFieldName(attr) + ".ngram";
queryBuilder = QueryBuilders.queryStringQuery(queryField + ":(" + queryValue + ")");
break;
case MREF:
case XREF:
queryField = getQueryFieldName(attr) + "." + getQueryFieldName(attr.getRefEntity().getLabelAttribute()) + ".ngram";
queryBuilder = QueryBuilders.nestedQuery(getQueryFieldName(attr), QueryBuilders.queryStringQuery(queryField + ":(" + queryValue + ")"), ScoreMode.Max);
break;
default:
throw new UnexpectedEnumException(dataType);
}
}
return queryBuilder;
}
use of org.molgenis.data.meta.AttributeType in project molgenis by molgenis.
the class QueryGenerator method createQueryClauseEqualsValue.
private QueryBuilder createQueryClauseEqualsValue(QueryRule queryRule, EntityType entityType) {
List<Attribute> attributePath = getAttributePath(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 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:
if (useNotAnalyzedField(attr)) {
fieldName = fieldName + '.' + FIELD_NOT_ANALYZED;
}
return nestedQueryBuilder(attributePath, QueryBuilders.termQuery(fieldName, queryValue));
case CATEGORICAL:
case CATEGORICAL_MREF:
case XREF:
case MREF:
case FILE:
case ONE_TO_MANY:
if (attributePath.size() > 1) {
throw new MolgenisQueryException("Can not filter on references deeper than 1.");
}
Attribute refIdAttr = attr.getRefEntity().getIdAttribute();
List<Attribute> refAttributePath = concat(attributePath.stream(), of(refIdAttr)).collect(toList());
String indexFieldName = getQueryFieldName(refAttributePath);
if (useNotAnalyzedField(refIdAttr)) {
indexFieldName = indexFieldName + '.' + FIELD_NOT_ANALYZED;
}
return QueryBuilders.nestedQuery(fieldName, QueryBuilders.termQuery(indexFieldName, queryValue), ScoreMode.Avg);
case COMPOUND:
throw new MolgenisQueryException(format("Illegal attribute type [%s]", attrType.toString()));
default:
throw new UnexpectedEnumException(attrType);
}
}
use of org.molgenis.data.meta.AttributeType in project molgenis by molgenis.
the class QueryGenerator method createQueryClauseFuzzyMatch.
private QueryBuilder createQueryClauseFuzzyMatch(QueryRule queryRule, EntityType entityType) {
String queryField = queryRule.getField();
Object queryValue = queryRule.getValue();
QueryBuilder queryBuilder;
if (queryValue == null)
throw new MolgenisQueryException("Query value cannot be null");
if (queryField == null) {
queryBuilder = QueryBuilders.matchQuery("_all", queryValue);
} else {
Attribute attr = entityType.getAttribute(queryField);
if (attr == null) {
throw new UnknownAttributeException(entityType, queryField);
}
// construct query part
AttributeType dataType = attr.getDataType();
switch(dataType) {
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:
queryBuilder = QueryBuilders.queryStringQuery(getQueryFieldName(attr) + ":(" + queryValue + ")");
break;
case MREF:
case XREF:
case CATEGORICAL:
case CATEGORICAL_MREF:
case ONE_TO_MANY:
case FILE:
queryField = getQueryFieldName(attr) + "." + getQueryFieldName(attr.getRefEntity().getLabelAttribute());
queryBuilder = QueryBuilders.nestedQuery(getQueryFieldName(attr), QueryBuilders.queryStringQuery(queryField + ":(" + queryValue + ")"), ScoreMode.Max);
break;
case BOOL:
case COMPOUND:
throw new MolgenisQueryException("Illegal data type [" + dataType + "] for operator [" + QueryRule.Operator.FUZZY_MATCH + "]");
default:
throw new UnexpectedEnumException(dataType);
}
}
return queryBuilder;
}
Aggregations