Search in sources :

Example 16 with Tag

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

the class TagRepository method getTagEntity.

/**
 * Fetches a tag from the repository. Creates a new one if it does not yet exist.
 *
 * @param objectIRI     IRI of the object
 * @param label         label of the object
 * @param relation      {@link Relation} of the tag
 * @param codeSystemIRI the IRI of the code system of the tag
 * @return {@link Tag} of type {@link TagMetadata}
 */
public Tag getTagEntity(String objectIRI, String label, Relation relation, String codeSystemIRI) {
    Tag tag = dataService.query(TAG, Tag.class).eq(OBJECT_IRI, objectIRI).and().eq(RELATION_IRI, relation.getIRI()).and().eq(CODE_SYSTEM, codeSystemIRI).findOne();
    if (tag == null) {
        tag = tagFactory.create();
        tag.setId(idGenerator.generateId());
        tag.setObjectIri(objectIRI);
        tag.setLabel(label);
        tag.setRelationIri(relation.getIRI());
        tag.setRelationLabel(relation.getLabel());
        tag.setCodeSystem(codeSystemIRI);
        dataService.add(TAG, tag);
    }
    return tag;
}
Also used : Tag(org.molgenis.data.meta.model.Tag)

Example 17 with Tag

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

the class TagRepositoryTest method testGetTagEntityNew.

@Test
public void testGetTagEntityNew() {
    Tag tag = tagFactory.create();
    tag.setId(uuid.toString());
    tag.setObjectIri("http://edamontology.org/data_3031");
    tag.setLabel("Core data");
    tag.setRelationIri("http://molgenis.org/biobankconnect/instanceOf");
    tag.setRelationLabel("instanceOf");
    tag.setCodeSystem("http://edamontology.org");
    @SuppressWarnings("unchecked") Query<Tag> q = mock(Query.class);
    when(q.eq(anyString(), any())).thenReturn(q);
    when(q.and()).thenReturn(q);
    when(q.findOne()).thenReturn(null);
    when(dataService.query(TAG, Tag.class)).thenReturn(q);
    assertTrue(EntityUtils.equals(tagRepository.getTagEntity("http://edamontology.org/data_3031", "Core data", Relation.instanceOf, "http://edamontology.org"), tag));
    verify(dataService, times(1)).add(eq(TAG), any(Tag.class));
}
Also used : Tag(org.molgenis.data.meta.model.Tag) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 18 with Tag

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

the class TagRepositoryTest method testGetTagEntityExisting.

@Test
public void testGetTagEntityExisting() {
    Tag tag = tagFactory.create();
    tag.setId(uuid.toString());
    tag.setObjectIri("http://edamontology.org/data_3031");
    tag.setLabel("Core data");
    tag.setRelationIri("http://molgenis.org/biobankconnect/instanceOf");
    tag.setRelationLabel("instanceOf");
    tag.setCodeSystem("http://edamontology.org");
    @SuppressWarnings("unchecked") Query<Tag> q = mock(Query.class);
    when(q.eq(OBJECT_IRI, "http://edamontology.org/data_3031")).thenReturn(q);
    when(q.and()).thenReturn(q);
    when(q.eq(RELATION_IRI, "http://molgenis.org/biobankconnect/instanceOf")).thenReturn(q);
    when(q.and()).thenReturn(q);
    when(q.eq(CODE_SYSTEM, "http://edamontology.org")).thenReturn(q);
    when(q.findOne()).thenReturn(tag);
    when(dataService.query(TAG, Tag.class)).thenReturn(q);
    assertTrue(EntityUtils.equals(tagRepository.getTagEntity("http://edamontology.org/data_3031", "Core data", Relation.instanceOf, "http://edamontology.org"), tag));
}
Also used : Tag(org.molgenis.data.meta.model.Tag) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Tag (org.molgenis.data.meta.model.Tag)18 Test (org.testng.annotations.Test)14 Stream (java.util.stream.Stream)4 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)4 EntityType (org.molgenis.data.meta.model.EntityType)3 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)2 Package (org.molgenis.data.meta.model.Package)2 EditorTagIdentifier (org.molgenis.metadata.manager.model.EditorTagIdentifier)2 Attribute (org.molgenis.data.meta.model.Attribute)1