Search in sources :

Example 26 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelNullValuePlusHyperlink.

@Test
public void testCreateRfdModelNullValuePlusHyperlink() {
    // public Model createRdfModel(String subjectIRI, Entity objectEntity)
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute1 = mock(Attribute.class);
    Attribute attribute2 = mock(Attribute.class);
    List<Attribute> attributeList = Arrays.asList(attribute1, attribute2);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    when(objectEntity.get("attribute1Name")).thenReturn(null);
    String value = "http://molgenis.org/index.html";
    doReturn(value).when(objectEntity).get("attribute2Name");
    when(objectEntity.getString("attribute2Name")).thenReturn(value);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute1.getName()).thenReturn("attribute1Name");
    when(attribute2.getName()).thenReturn("attribute2Name");
    when(attribute2.getDataType()).thenReturn(AttributeType.HYPERLINK);
    LabeledResource tag2 = new LabeledResource("http://IRI1.nl", "tag1 label");
    Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2);
    doReturn(tags2).when(tagService).getTagsForAttribute(entityType, attribute2);
    Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity);
    assertEquals(result.size(), 1);
    Iterator results = result.iterator();
    assertEquals(results.next().toString(), "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI1.nl, http://molgenis.org/index.html) [null]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) LabeledResource(org.molgenis.data.semantic.LabeledResource) Attribute(org.molgenis.data.meta.model.Attribute) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Iterator(java.util.Iterator) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 27 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class DataExplorerDownloadHandler method filterAttributes.

private List<Attribute> filterAttributes(DataRequest dataRequest) {
    EntityType entityType = dataService.getEntityType(dataRequest.getEntityName());
    final Set<String> attributeNames = newHashSet(dataRequest.getAttributeNames());
    return Streams.stream(entityType.getAtomicAttributes()).filter(attribute -> attributeNames.contains(attribute.getName())).collect(toList());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) OutputStream(java.io.OutputStream) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) EntityWriteMode(org.molgenis.data.support.AbstractWritable.EntityWriteMode) Set(java.util.Set) AttributeWriteMode(org.molgenis.data.support.AbstractWritable.AttributeWriteMode) IOException(java.io.IOException) Streams(com.google.common.collect.Streams) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) FileFormat(org.molgenis.data.excel.ExcelWriter.FileFormat) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Objects.requireNonNull(java.util.Objects.requireNonNull) DataService(org.molgenis.data.DataService) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) ExcelWriter(org.molgenis.data.excel.ExcelWriter) ExcelSheetWriter(org.molgenis.data.excel.ExcelSheetWriter) MolgenisDataException(org.molgenis.data.MolgenisDataException) DataRequest(org.molgenis.dataexplorer.controller.DataRequest) CsvWriter(org.molgenis.data.csv.CsvWriter)

Example 28 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class DataExplorerDownloadHandler method writeToExcel.

public void writeToExcel(DataRequest dataRequest, OutputStream outputStream) throws IOException {
    String entityTypeId = dataRequest.getEntityName();
    List<Attribute> attributes = filterAttributes(dataRequest);
    checkNumberOfCells(dataRequest, entityTypeId, attributes.size());
    AttributeWriteMode attributeWriteMode = getAttributeWriteMode(dataRequest.getColNames());
    try (ExcelWriter excelWriter = new ExcelWriter(outputStream, attrMetaFactory, FileFormat.XLSX);
        ExcelSheetWriter excelSheetWriter = excelWriter.createWritable(entityTypeId, attributes, attributeWriteMode)) {
        excelSheetWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues()));
        excelSheetWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery()));
    }
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) ExcelWriter(org.molgenis.data.excel.ExcelWriter) AttributeWriteMode(org.molgenis.data.support.AbstractWritable.AttributeWriteMode) ExcelSheetWriter(org.molgenis.data.excel.ExcelSheetWriter)

Example 29 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class PersonMetaData3 method init.

@Override
public void init() {
    setLabel("Person");
    addAttribute(ID, ROLE_ID).setLabel("Identifier");
    addAttribute(LABEL, ROLE_LABEL).setNillable(false).setLabel("Label");
    Attribute parentAttr = addAttribute(ATTR_PARENT).setDataType(XREF).setRefEntity(this);
    addAttribute(ATTR_CHILDREN).setDataType(ONE_TO_MANY).setRefEntity(this).setMappedBy(parentAttr).setOrderBy(new Sort(ID, ASC));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) Sort(org.molgenis.data.Sort)

Example 30 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class PersonMetaData4 method init.

@Override
public void init() {
    setLabel("Person");
    addAttribute(ID, ROLE_ID).setLabel("Identifier");
    addAttribute(LABEL, ROLE_LABEL).setNillable(false).setLabel("Label");
    Attribute parentAttr = addAttribute(ATTR_PARENT).setDataType(XREF).setRefEntity(this);
    addAttribute(ATTR_CHILDREN).setDataType(ONE_TO_MANY).setRefEntity(this).setMappedBy(parentAttr).setOrderBy(new Sort(ID, DESC));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) Sort(org.molgenis.data.Sort)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16