@Test public void testGetTagEntityNew() { Tag tag = tagFactory.create(); tag.setId(uuid.toString()); tag.setObjectIri("http: tag.setLabel("Core data"); tag.setRelationIri("http: tag.setRelationLabel("instanceOf"); tag.setCodeSystem("http: @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: "Core data", Relation.instanceOf, "http: tag)); verify(dataService, times(1)).add(eq(TAG), any(Tag.class)); }
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; }
TagRepository { 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; } }
TagRepository { 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; } TagRepository(DataService dataService, IdGenerator idGenerator, TagFactory tagFactory); }
TagRepository { 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; } TagRepository(DataService dataService, IdGenerator idGenerator, TagFactory tagFactory); Tag getTagEntity(String objectIRI, String label, Relation relation, String codeSystemIRI); }
TagRepository { 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; } TagRepository(DataService dataService, IdGenerator idGenerator, TagFactory tagFactory); Tag getTagEntity(String objectIRI, String label, Relation relation, String codeSystemIRI);  }