use of com.hortonworks.streamline.registries.tag.TaggedEntity in project streamline by hortonworks.
the class CatalogTagService method getTaggedEntities.
private List<TaggedEntity> getTaggedEntities(Long tagId) {
List<TaggedEntity> taggedEntities = new ArrayList<>();
QueryParam qp1 = new QueryParam(TagStorableMap.FIELD_TAG_ID, String.valueOf(tagId));
for (TagStorableMap mapping : listTagStorableMapping(ImmutableList.of(qp1))) {
taggedEntities.add(new TaggedEntity(mapping.getStorableNamespace(), mapping.getStorableId()));
}
return taggedEntities;
}
use of com.hortonworks.streamline.registries.tag.TaggedEntity in project streamline by hortonworks.
the class TagRestServiceTest method testTagResource.
@Test
public void testTagResource() throws Exception {
TagClient tagClient = new TagClient(catalogRootUrl);
long parentTagId = 10L;
long childTagId = 11L;
// create a "parent-tag"
Tag parent = createTag(parentTagId, "parent-tag");
Assert.assertTrue(tagClient.addTag(parent).getId() == parentTagId);
// create a "child-tag" which is tagged under "parent-tag"
Tag child = createTag(childTagId, "child-tag", ImmutableList.<Tag>of(parent));
Assert.assertTrue(tagClient.addTag(child).getId() == childTagId);
// update parent-tag
parent = createTag(parentTagId, "parent-update-tag");
Assert.assertTrue(tagClient.addOrUpdateTag(parent).getId() == parentTagId);
// get a Tag by Id
Tag tag = tagClient.getTag(parentTagId);
Assert.assertTrue("Tag Id is different", tag.getId() == parentTagId);
// get a unkonwn tag by Id
tag = tagClient.getTag(100L);
// add another tag
Tag testTag = createTag(12L, "to-delete-tag");
Assert.assertTrue(tagClient.addTag(testTag).getId() == 12L);
// list all tags
List<Tag> allTags = tagClient.listTags();
Assert.assertTrue("tag count mismatch", allTags.size() == 3);
// list tags with queryParams
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("name", "child-tag");
queryParams.put("description", "child-tag");
allTags = tagClient.listTags(queryParams);
Assert.assertTrue("tag count mismatch", allTags.size() == 1);
// delete a tag
tagClient.removeTag(12L);
allTags = tagClient.listTags();
Assert.assertTrue("count mismatch", allTags.size() == 2);
// add Tag for Entity
tagClient.addTagForEntity(new TaggedEntity("Device", 1L), parentTagId);
tagClient.addTagForEntity(new TaggedEntity("Device", 2L), parentTagId);
tagClient.addTagForEntity(new TaggedEntity("Device", 3L), parentTagId);
// get All Entities For Tag
List<TaggedEntity> allEntities = tagClient.getTaggedEntities(parentTagId);
Assert.assertTrue("entity count mismatch", allEntities.size() == 3);
// remove Tag for Entity
tagClient.removeTagForEntity(new TaggedEntity("Device", 1L), parentTagId);
allEntities = tagClient.getTaggedEntities(parentTagId);
Assert.assertTrue("entity count mismatch", allEntities.size() == 2);
// add new Tag to existing entity
Tag newTag = createTag(13L, "new-tag");
Assert.assertTrue(tagClient.addTag(newTag).getId() == 13L);
tagClient.addTagForEntity(new TaggedEntity("Device", 2L), 13L);
// get All Tags For a given Entity
allTags = tagClient.getTags(new TaggedEntity("Device", 2L));
Assert.assertTrue("tag count mismatch", allTags.size() == 2);
// try adding unknown tag for a Entity
try {
tagClient.addTagForEntity(new TaggedEntity("Device", 1L), 100L);
Assert.fail("should have thrown error");
} catch (RuntimeException e) {
}
// try removing unknown tag for a Entity
try {
tagClient.removeTagForEntity(new TaggedEntity("Device", 1L), 100L);
Assert.fail("should have thrown error");
} catch (RuntimeException e) {
}
}
Aggregations