Search in sources :

Example 1 with Tag

use of com.hortonworks.streamline.registries.tag.Tag in project streamline by hortonworks.

the class CatalogTagService method flatten.

private List<Tag> flatten(List<Tag> tags) {
    List<Tag> res = new ArrayList<>();
    for (Tag tag : tags) {
        res.add(tag);
        res.addAll(flatten(tag.getTags()));
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) Tag(com.hortonworks.streamline.registries.tag.Tag)

Example 2 with Tag

use of com.hortonworks.streamline.registries.tag.Tag in project streamline by hortonworks.

the class CatalogTagService method getTags.

@Override
public List<Tag> getTags(TaggedEntity taggedEntity) {
    List<Tag> tags = new ArrayList<>();
    QueryParam qp1 = new QueryParam(TagStorableMap.FIELD_STORABLE_ID, String.valueOf(taggedEntity.getId()));
    QueryParam qp2 = new QueryParam(TagStorableMap.FIELD_STORABLE_NAMESPACE, String.valueOf(taggedEntity.getNamespace()));
    for (TagStorableMap mapping : listTagStorableMapping(ImmutableList.of(qp1, qp2))) {
        tags.add(getTag(mapping.getTagId()));
    }
    return tags;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) TagStorableMap(com.hortonworks.streamline.registries.tag.TagStorableMap) Tag(com.hortonworks.streamline.registries.tag.Tag)

Example 3 with Tag

use of com.hortonworks.streamline.registries.tag.Tag in project streamline by hortonworks.

the class CatalogTagService method removeTagsFromStorable.

@Override
public void removeTagsFromStorable(TaggedEntity taggedEntity, List<Tag> tags) {
    if (tags != null) {
        for (Tag tag : tags) {
            TagStorableMap tagStorable = new TagStorableMap();
            tagStorable.setTagId(tag.getId());
            tagStorable.setStorableId(taggedEntity.getId());
            tagStorable.setStorableNamespace(taggedEntity.getNamespace());
            this.dao.remove(tagStorable.getStorableKey());
        }
    }
}
Also used : TagStorableMap(com.hortonworks.streamline.registries.tag.TagStorableMap) Tag(com.hortonworks.streamline.registries.tag.Tag)

Example 4 with Tag

use of com.hortonworks.streamline.registries.tag.Tag in project streamline by hortonworks.

the class CatalogTagService method addTagsForStorable.

@Override
public void addTagsForStorable(TaggedEntity taggedEntity, List<Tag> tags) {
    if (tags != null) {
        for (Tag tag : tags) {
            TagStorableMap tagStorable = new TagStorableMap();
            tagStorable.setTagId(tag.getId());
            tagStorable.setStorableNamespace(taggedEntity.getNamespace());
            tagStorable.setStorableId(taggedEntity.getId());
            this.dao.add(tagStorable);
        }
    }
}
Also used : TagStorableMap(com.hortonworks.streamline.registries.tag.TagStorableMap) Tag(com.hortonworks.streamline.registries.tag.Tag)

Example 5 with Tag

use of com.hortonworks.streamline.registries.tag.Tag in project streamline by hortonworks.

the class CatalogTagService method removeTag.

@Override
public Tag removeTag(Long tagId) {
    Tag tag = getTag(tagId);
    if (tag != null) {
        if (!getEntities(tagId, false).isEmpty()) {
            throw new TagNotEmptyException("Tag not empty, has child entities.");
        }
        removeTagsFromStorable(getTaggedEntity(tag), tag.getTags());
        dao.<Tag>remove(new StorableKey(TAG_NAMESPACE, tag.getPrimaryKey()));
    }
    return tag;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Tag(com.hortonworks.streamline.registries.tag.Tag)

Aggregations

Tag (com.hortonworks.streamline.registries.tag.Tag)10 ArrayList (java.util.ArrayList)4 TagStorableMap (com.hortonworks.streamline.registries.tag.TagStorableMap)3 StorableKey (com.hortonworks.registries.storage.StorableKey)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)1 TaggedEntity (com.hortonworks.streamline.registries.tag.TaggedEntity)1 TagClient (com.hortonworks.streamline.registries.tag.client.TagClient)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1