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;
}
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));
}
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));
}
Aggregations