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;
}
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);
}
}
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);
}
}
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());
}
}
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();
}
Aggregations