use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class QueryGeneratorReferencesTest method setUp.
@BeforeMethod
public void setUp() {
EntityType refEntityType = entityTypeFactory.create("ref_entity");
String refIdAttributeName = "xid";
refEntityType.addAttribute(attrFactory.create().setName(refIdAttributeName), ROLE_ID);
refEntityType.addAttribute(attrFactory.create().setName(refBoolAttributeName).setDataType(BOOL));
refEntityType.addAttribute(attrFactory.create().setName(refCategoricalAttributeName).setDataType(CATEGORICAL).setRefEntity(refEntityType).setNillable(true));
Attribute attrCompound = attrFactory.create().setName(refCompoundAttributeName).setDataType(COMPOUND);
Attribute compoundPart0Attribute = attrFactory.create().setName(refCompoundPart0AttributeName).setDataType(STRING).setParent(attrCompound);
String refCompoundPart1AttributeName = "xcompoundpart1";
Attribute compoundPart1Attribute = attrFactory.create().setName(refCompoundPart1AttributeName).setDataType(STRING).setParent(attrCompound);
refEntityType.addAttribute(attrCompound);
refEntityType.addAttribute(compoundPart0Attribute);
refEntityType.addAttribute(compoundPart1Attribute);
refEntityType.addAttribute(attrFactory.create().setName(refDateAttributeName).setDataType(DATE));
refEntityType.addAttribute(attrFactory.create().setName(refDateTimeAttributeName).setDataType(DATE_TIME));
refEntityType.addAttribute(attrFactory.create().setName(refDecimalAttributeName).setDataType(DECIMAL));
String refEmailAttributeName = "xemail";
refEntityType.addAttribute(attrFactory.create().setName(refEmailAttributeName).setDataType(EMAIL));
String refEnumAttributeName = "xenum";
refEntityType.addAttribute(attrFactory.create().setName(refEnumAttributeName).setDataType(ENUM).setEnumOptions(Arrays.asList("enum0", "enum1", "enum2")));
String refHtmlAttributeName = "xhtml";
refEntityType.addAttribute(attrFactory.create().setName(refHtmlAttributeName).setDataType(HTML));
String refHyperlinkAttributeName = "xhyperlink";
refEntityType.addAttribute(attrFactory.create().setName(refHyperlinkAttributeName).setDataType(HYPERLINK));
refEntityType.addAttribute(attrFactory.create().setName(refIntAttributeName).setDataType(INT));
refEntityType.addAttribute(attrFactory.create().setName(refLongAttributeName).setDataType(LONG));
String refMrefAttributeName = "xmref";
refEntityType.addAttribute(attrFactory.create().setName(refMrefAttributeName).setDataType(MREF).setRefEntity(refEntityType).setNillable(true));
String refScriptAttributeName = "xscript";
refEntityType.addAttribute(attrFactory.create().setName(refScriptAttributeName).setDataType(SCRIPT));
refEntityType.addAttribute(attrFactory.create().setName(refStringAttributeName).setDataType(STRING));
String refTextAttributeName = "xtext";
refEntityType.addAttribute(attrFactory.create().setName(refTextAttributeName).setDataType(TEXT));
String refXrefAttributeName = "xxref";
refEntityType.addAttribute(attrFactory.create().setName(refXrefAttributeName).setDataType(XREF).setRefEntity(refEntityType).setNillable(true));
EntityType emd = entityTypeFactory.create("entity");
String idAttributeName = "id";
emd.addAttribute(attrFactory.create().setName(idAttributeName), ROLE_ID);
emd.addAttribute(attrFactory.create().setName(stringAttributeName).setUnique(true), ROLE_LABEL);
String mrefAttributeName = "mref";
emd.addAttribute(attrFactory.create().setName(mrefAttributeName).setDataType(MREF).setNillable(true).setRefEntity(refEntityType));
this.entityType = emd;
DocumentIdGenerator documentIdGenerator = mock(DocumentIdGenerator.class);
when(documentIdGenerator.generateId(any(Attribute.class))).thenAnswer(invocation -> ((Attribute) invocation.getArguments()[0]).getName());
queryGenerator = new QueryGenerator(documentIdGenerator);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AnnotatorDependencyOrderResolverTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
Attribute attra = attributeFactory.create().setName("A").setDataType(STRING);
// to check for matching "STRING" attributes to required "TEXT" attributes
Attribute attra2 = attributeFactory.create().setName("A").setDataType(TEXT);
Attribute attrb = attributeFactory.create().setName("B").setDataType(STRING);
Attribute attrc = attributeFactory.create().setName("C").setDataType(STRING);
Attribute attrd = attributeFactory.create().setName("D").setDataType(STRING);
Attribute attre = attributeFactory.create().setName("E").setDataType(STRING);
Attribute attrf = attributeFactory.create().setName("F").setDataType(STRING);
Attribute attrg = attributeFactory.create().setName("G").setDataType(STRING);
Attribute attrh = attributeFactory.create().setName("H").setDataType(STRING);
Attribute attri = attributeFactory.create().setName("I").setDataType(STRING);
Attribute attrj = attributeFactory.create().setName("J").setDataType(STRING);
EntityType emd = entityTypeFactory.create("test");
emd.addAttributes(Arrays.asList(attra, attrb));
when(repo.getEntityType()).thenReturn(emd);
when(annotator1.getInfo()).thenReturn(annotator1info);
when(annotator2.getInfo()).thenReturn(annotator2info);
when(annotator3.getInfo()).thenReturn(annotator3info);
when(annotator4.getInfo()).thenReturn(annotator4info);
when(annotator5.getInfo()).thenReturn(annotator5info);
when(annotator1.getSimpleName()).thenReturn("annotator1");
when(annotator2.getSimpleName()).thenReturn("annotator2");
when(annotator3.getSimpleName()).thenReturn("annotator3");
when(annotator4.getSimpleName()).thenReturn("annotator4");
when(annotator5.getSimpleName()).thenReturn("annotator5");
when(annotator1.getRequiredAttributes()).thenReturn(Arrays.asList(attrd, attrh, attri));
when(annotator1info.getOutputAttributes()).thenReturn(Arrays.asList(attre, attrc));
when(annotator2.getRequiredAttributes()).thenReturn(Arrays.asList(attra2, attrb));
when(annotator2info.getOutputAttributes()).thenReturn(Arrays.asList(attrj));
when(annotator3.getRequiredAttributes()).thenReturn(Arrays.asList(attra2, attrh));
when(annotator3info.getOutputAttributes()).thenReturn(Arrays.asList(attrd, attrj));
when(annotator4.getRequiredAttributes()).thenReturn(Arrays.asList(attra, attrb));
when(annotator4info.getOutputAttributes()).thenReturn(Arrays.asList(attrh));
when(annotator5.getRequiredAttributes()).thenReturn(Arrays.asList(attrb, attrd));
when(annotator5info.getOutputAttributes()).thenReturn(Arrays.asList(attri, attrf));
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class CsvRepository method getEntityType.
public EntityType getEntityType() {
if (entityType == null) {
entityType = entityTypeFactory.create(sheetName);
for (String attrName : new CsvIterator(file, sheetName, null, separator).getColNamesMap().keySet()) {
Attribute attr = attrMetaFactory.create().setName(attrName).setDataType(STRING);
entityType.addAttribute(attr);
}
}
return entityType;
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class CsvWriter method writeAttributes.
/**
* Use attribute labels as column names
*/
public void writeAttributes(Iterable<Attribute> attributes) throws IOException {
List<String> attributeNames = Lists.newArrayList();
List<String> attributeLabels = Lists.newArrayList();
for (Attribute attr : attributes) {
attributeNames.add(attr.getName());
if (attr.getLabel() != null) {
attributeLabels.add(attr.getLabel());
} else {
attributeLabels.add(attr.getName());
}
}
writeAttributes(attributeNames, attributeLabels);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class QueryGenerator method createQueryClauseEqualsNoValue.
private QueryBuilder createQueryClauseEqualsNoValue(QueryRule queryRule, EntityType entityType) {
List<Attribute> attributePath = getAttributePath(queryRule.getField(), entityType);
String fieldName = getQueryFieldName(attributePath);
Attribute attr = attributePath.get(0);
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:
return QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(fieldName));
case CATEGORICAL:
case CATEGORICAL_MREF:
case FILE:
case MREF:
case ONE_TO_MANY:
case XREF:
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);
return QueryBuilders.boolQuery().mustNot(QueryBuilders.nestedQuery(fieldName, QueryBuilders.existsQuery(indexFieldName), ScoreMode.Avg));
case COMPOUND:
throw new MolgenisQueryException(format("Illegal attribute type [%s]", attrType.toString()));
default:
throw new UnexpectedEnumException(attrType);
}
}
Aggregations