use of org.molgenis.data.semantic.SemanticTag in project molgenis by molgenis.
the class UntypedTagService method addEntityTag.
@Override
public void addEntityTag(SemanticTag<EntityType, LabeledResource, LabeledResource> tag) {
Entity entity = findEntity(tag.getSubject());
if (entity == null) {
throw new UnknownEntityException("Unknown entity [" + tag.getSubject().getId() + "]");
}
ImmutableList<SemanticTag<EntityType, LabeledResource, LabeledResource>> existingTags = ImmutableList.copyOf(getTagsForEntity(tag.getSubject()));
if (existingTags.contains(tag)) {
LOG.debug("Tag already present");
return;
}
ImmutableList.Builder<Entity> builder = ImmutableList.builder();
builder.addAll(entity.getEntities(EntityTypeMetadata.TAGS));
builder.add(getTagEntity(tag));
entity.set(EntityTypeMetadata.TAGS, builder.build());
dataService.update(ENTITY_TYPE_META_DATA, entity);
}
use of org.molgenis.data.semantic.SemanticTag in project molgenis by molgenis.
the class OntologyTagServiceTest method testGetTagEntity.
@Test
public void testGetTagEntity() {
Tag expected = tagFactory.create();
expected.set(TagMetadata.ID, "1233");
expected.set(TagMetadata.OBJECT_IRI, "http://edamontology.org/data_3031");
expected.set(TagMetadata.LABEL, "Core data");
expected.set(TagMetadata.RELATION_IRI, "http://molgenis.org/biobankconnect/instanceOf");
expected.set(TagMetadata.RELATION_LABEL, "instanceOf");
expected.set(TagMetadata.CODE_SYSTEM, "http://edamontology.org");
OntologyTerm coreData = mock(OntologyTerm.class);
when(coreData.getIRI()).thenReturn("http://edamontology.org/data_3031");
when(coreData.getLabel()).thenReturn("Core data");
Ontology edamOntology = mock(Ontology.class);
when(edamOntology.getIRI()).thenReturn("http://edamontology.org");
SemanticTag<Object, OntologyTerm, Ontology> tag = new SemanticTag<>("1233", null, Relation.instanceOf, coreData, edamOntology);
when(tagRepository.getTagEntity("http://edamontology.org/data_3031", "Core data", Relation.instanceOf, "http://edamontology.org")).thenReturn(expected);
assertEquals(ontologyTagService.getTagEntity(tag), expected);
}
use of org.molgenis.data.semantic.SemanticTag in project molgenis by molgenis.
the class OntologyTagServiceTest method testGetTagsForPackage.
@Test
public void testGetTagsForPackage() {
Package p = packageFactory.create("test", "desc");
Package pack = packageFactory.create();
pack.setTags(singletonList(chromosomeNameTagEntity));
when(ontologyService.getOntology("http://edamontology.org")).thenReturn(EDAM_ONTOLOGY);
when(ontologyService.getOntologyTerm("http://edamontology.org/data_0987")).thenReturn(CHROMOSOME_NAME_ONTOLOGY_TERM);
when(dataService.findOneById(PACKAGE, "test")).thenReturn(pack);
assertEquals(ontologyTagService.getTagsForPackage(p), singletonList(new SemanticTag<>("1234", p, Relation.forIRI("http://molgenis.org/biobankconnect/instanceOf"), OntologyTerm.create("http://edamontology.org/data_0987", "Chromosome name", "Name of a chromosome."), Ontology.create("EDAM", "http://edamontology.org", "The EDAM ontology."))));
}
Aggregations