Search in sources :

Example 16 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class EventSubscriptionCommandBase method validateTag.

/**
 * Validates the tag.
 *
 * @param tagName
 *            Name of the tag.
 */
protected boolean validateTag(String tagName) {
    boolean retValue = true;
    Tags tag = tagDao.getByName(tagName);
    if (tag == null) {
        addValidationMessage(EngineMessage.EN_UNKNOWN_TAG_NAME);
        retValue = false;
    }
    return retValue;
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 17 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirector method moveTag.

public void moveTag(Guid tagId, Guid newParent) {
    if (tagsMapByID.containsKey(tagId)) {
        Tags tag = tagsMapByID.get(tagId);
        if (tagsMapByID.containsKey(newParent)) {
            if (tagsMapByID.containsKey(tag.getParentId())) {
                Tags parentTag = tagsMapByID.get(tag.getParentId());
                parentTag.getChildren().remove(tag);
                addTagToHash(parentTag);
            } else {
                log.warn("Trying to move tag from parent that doesn't exist in Data Structure - '{}'", tag.getParentId());
            }
            Tags newParentTag = tagsMapByID.get(newParent);
            newParentTag.getChildren().add(tag);
            tag.setParentId(newParent);
            // Parent got changed, modify it.
            addTagToHash(newParentTag);
            updateTagInBackend(tag);
        } else {
            log.error("Trying to move tag, to parent not exists in Data Structure - '{}'", newParent);
        }
    } else {
        log.error("Trying to move tag, not exists in Data Structure - '{}'", tagId);
    }
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 18 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirector method removeTag.

/**
 * Remove tag operation. For tag with children all tag's children will be removed as well
 *
 * @param tagId
 *            tag to remove
 */
public void removeTag(Guid tagId) {
    if (tagsMapByID.containsKey(tagId)) {
        Tags tag = tagsMapByID.get(tagId);
        removeTagAndChildren(tag);
        Tags parent = tagsMapByID.get(tag.getParentId());
        parent.getChildren().remove(tag);
        addTagToHash(parent);
    } else {
        log.warn("Trying to remove tag, not exists in Data Structure - '{}'", tagId);
    }
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 19 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirector method updateTag.

/**
 * Update tag. We assume that the id doesn't change.
 */
public void updateTag(Tags tag) {
    if (tagsMapByID.containsKey(tag.getTagId())) {
        Tags tagFromCache = tagsMapByID.get(tag.getTagId());
        String oldName = tagFromCache.getTagName();
        // accordingly:
        if (!tag.getTagName().equals(oldName)) {
            tagsMapByName.remove(oldName);
        }
        // Copy the children of the cached tag to keep the object hierarchy consistent.
        tag.setChildren(tagFromCache.getChildren());
        addTagToHash(tag);
    } else {
        log.warn("Trying to update tag, not exists in Data Structure - '{}'", tag.getTagName());
    }
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 20 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirector method getTagIdAndChildrenIds.

/**
 * This function will return the tag's ID and its children IDs. Its used to determine if a tag is assigned to an
 * entity. Tag is determined as assigned to an entity if the entity is assigned to the tag or to one of its
 * children.
 *
 * @param tagId
 *            the ID of the 'root' tag.
 * @return a comma separated list of IDs.
 */
@Override
public String getTagIdAndChildrenIds(Guid tagId) {
    Tags tag = getTagById(tagId);
    if (tag == null) {
        return StringUtils.EMPTY;
    }
    StringBuilder sb = tag.getTagIdAndChildrenIds();
    return sb.toString();
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Aggregations

Tags (org.ovirt.engine.core.common.businessentities.Tags)68 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)8 Guid (org.ovirt.engine.core.compat.Guid)5 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Before (org.junit.Before)2 TagsTemplateMap (org.ovirt.engine.core.common.businessentities.TagsTemplateMap)2 TagsVdsMap (org.ovirt.engine.core.common.businessentities.TagsVdsMap)2 TagsVmMap (org.ovirt.engine.core.common.businessentities.TagsVmMap)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 Named (javax.inject.Named)1 Singleton (javax.inject.Singleton)1 Response (javax.ws.rs.core.Response)1 Tag (org.ovirt.engine.api.model.Tag)1