Search in sources :

Example 1 with Tag

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

the class TagClient method makeTag.

private Tag makeTag(TagDto tagDto) {
    if (tagDto == null)
        return null;
    List<Tag> parentTags = new ArrayList<>();
    if (tagDto.getTagIds() != null) {
        for (Long tagId : tagDto.getTagIds()) {
            Tag tag = getTag(tagId);
            if (tag == null) {
                throw new IllegalArgumentException("Tag with id " + tagId + " does not exist.");
            }
            parentTags.add(tag);
        }
    }
    Tag tag = new Tag();
    tag.setId(tagDto.getId());
    tag.setName(tagDto.getName());
    tag.setDescription(tagDto.getDescription());
    tag.setTimestamp(tagDto.getTimestamp());
    tag.setTags(parentTags);
    return tag;
}
Also used : ArrayList(java.util.ArrayList) Tag(com.hortonworks.registries.tag.Tag)

Example 2 with Tag

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

the class CatalogTagService method getTag.

@Override
public Tag getTag(Long tagId) {
    Tag tag = new Tag();
    tag.setId(tagId);
    Tag result = this.dao.get(new StorableKey(TAG_NAMESPACE, tag.getPrimaryKey()));
    if (result != null) {
        result.setTags(getTags(getTaggedEntity(result)));
    }
    return result;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Tag(com.hortonworks.registries.tag.Tag)

Example 3 with Tag

use of com.hortonworks.registries.tag.Tag in project registry 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.registries.tag.Tag)

Example 4 with Tag

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

the class CatalogTagService method removeTagsFromStorable.

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

Example 5 with Tag

use of com.hortonworks.registries.tag.Tag in project registry 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.registries.tag.Tag)

Aggregations

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