Search in sources :

Example 61 with Tags

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

the class TagsDirectorTest method testGetTagIdAndChildrenIdsNotExists.

@Test
public void testGetTagIdAndChildrenIdsNotExists() {
    Tags tag = createTag("tag1", "desc1");
    String idsStr = tagsDirector.getTagIdAndChildrenIds(tag.getTagId());
    assertEquals(StringUtils.EMPTY, idsStr);
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 62 with Tags

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

the class UpdateTagCommand method validate.

@Override
protected boolean validate() {
    // we fetch by new name to see if it is in use
    Tags tag = tagDao.getByName(getParameters().getTag().getTagName());
    if (tag != null && !tag.getTagId().equals(getParameters().getTag().getTagId())) {
        addValidationMessage(EngineMessage.TAGS_SPECIFY_TAG_IS_IN_USE);
        return false;
    }
    // we fetch by id to see if the tag is realy read-only
    tag = tagDao.get(getParameters().getTag().getTagId());
    if (tag.getIsReadonly() != null && tag.getIsReadonly()) {
        addValidationMessage(EngineMessage.TAGS_CANNOT_EDIT_READONLY_TAG);
        return false;
    }
    return true;
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 63 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 tagName
 *            the name of the 'root' tag.
 * @return a comma separated list of IDs.
 */
public String getTagIdAndChildrenIds(String tagName) {
    Tags tag = getTagByTagName(tagName);
    StringBuilder sb = tag.getTagIdAndChildrenIds();
    return sb.toString();
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 64 with Tags

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

the class TagsDirector method addTagToHash.

private void addTagToHash(Tags tag) {
    tagsMapByID.put(tag.getTagId(), tag);
    tagsMapByName.put(tag.getTagName(), tag);
    if (tag.getParentId() != null) {
        // If the tag has a parent, the parent should have in its children the added tag instead
        // of the old version of the tag , if exists
        Tags parentTag = tagsMapByID.get(tag.getParentId());
        if (parentTag == null) {
            log.error("Could not obtain tag for guid '{}'", tag.getParentId());
            return;
        }
        List<Tags> parentChildren = parentTag.getChildren();
        replaceTagInChildren(tag, parentChildren);
        // replace the parent tag after the modification
        addTagToHash(parentTag);
    }
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 65 with Tags

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

the class TagsDirector method addTag.

public void addTag(Tags tag) {
    if (tagsMapByID.containsKey(tag.getParentId())) {
        Tags parent = tagsMapByID.get(tag.getParentId());
        parent.getChildren().add(tag);
        addTagToHash(tag);
        addTagToHash(parent);
    } else {
        log.error("Trying to add tag '{}', parent doesn't exist in Data Structure - '{}'", tag.getTagName(), tag.getParentId());
    }
}
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