Search in sources :

Example 26 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class FairController method getDataset.

@GetMapping(produces = TEXT_TURTLE_VALUE, value = "/{catalogID}/{datasetID}")
@ResponseBody
@RunAsSystem
public Model getDataset(@PathVariable("catalogID") String catalogID, @PathVariable("datasetID") String datasetID) {
    String subjectIRI = getBaseUri().pathSegment(catalogID, datasetID).toUriString();
    Entity subjectEntity = dataService.findOneById("fdp_Dataset", datasetID);
    return entityModelWriter.createRdfModel(subjectIRI, subjectEntity);
}
Also used : Entity(org.molgenis.data.Entity) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 27 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class FairController method getMetadata.

@GetMapping(produces = TEXT_TURTLE_VALUE)
@ResponseBody
@RunAsSystem
public Model getMetadata() {
    String subjectIRI = getBaseUri().toUriString();
    Entity subjectEntity = dataService.findOne("fdp_Metadata", new QueryImpl<>());
    return entityModelWriter.createRdfModel(subjectIRI, subjectEntity);
}
Also used : Entity(org.molgenis.data.Entity) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 28 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelDECIMAL.

@Test
public void testCreateRfdModelDECIMAL() {
    // public Model createRdfModel(String subjectIRI, Entity objectEntity)
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute = mock(Attribute.class);
    List<Attribute> attributeList = singletonList(attribute);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    double value = 10.0;
    when(objectEntity.get("attributeName")).thenReturn(value);
    when(objectEntity.getDouble("attributeName")).thenReturn(value);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute.getName()).thenReturn("attributeName");
    when(attribute.getDataType()).thenReturn(AttributeType.DECIMAL);
    LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label");
    Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag);
    when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags);
    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://IRI.nl, \"10.0\"^^<http://www.w3.org/2001/XMLSchema#double>) [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 29 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class EntityModelWriterTest method testCreateRfdModelLONG.

@Test
public void testCreateRfdModelLONG() {
    // public Model createRdfModel(String subjectIRI, Entity objectEntity)
    Entity objectEntity = mock(Entity.class);
    EntityType entityType = mock(EntityType.class);
    Attribute attribute = mock(Attribute.class);
    List<Attribute> attributeList = singletonList(attribute);
    when(objectEntity.getEntityType()).thenReturn(entityType);
    long value = 987654321L;
    when(objectEntity.get("attributeName")).thenReturn(value);
    when(objectEntity.getLong("attributeName")).thenReturn(value);
    when(entityType.getAtomicAttributes()).thenReturn(attributeList);
    when(attribute.getName()).thenReturn("attributeName");
    when(attribute.getDataType()).thenReturn(AttributeType.LONG);
    LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label");
    Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag);
    when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags);
    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://IRI.nl, \"987654321\"^^<http://www.w3.org/2001/XMLSchema#long>) [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 30 with Entity

use of org.molgenis.data.Entity 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)

Aggregations

Entity (org.molgenis.data.Entity)448 Test (org.testng.annotations.Test)295 DynamicEntity (org.molgenis.data.support.DynamicEntity)192 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)120 Attribute (org.molgenis.data.meta.model.Attribute)111 EntityType (org.molgenis.data.meta.model.EntityType)110 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)37 MolgenisDataException (org.molgenis.data.MolgenisDataException)20 QueryImpl (org.molgenis.data.support.QueryImpl)20 AttributeType (org.molgenis.data.meta.AttributeType)18 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)18 Stream (java.util.stream.Stream)17 QueryRule (org.molgenis.data.QueryRule)16 MultiAllelicResultFilter (org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter)16 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)16 Objects.requireNonNull (java.util.Objects.requireNonNull)15 DataService (org.molgenis.data.DataService)15 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 Instant (java.time.Instant)13