Search in sources :

Example 26 with Tags

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

the class BaseConditionFieldAutoCompleter method formatValue.

@Override
public void formatValue(String fieldName, Pair<String, String> pair, boolean caseSensitive) {
    if (fieldName == null) {
        return;
    }
    if ("TIME".equals(fieldName) || "CREATIONDATE".equals(fieldName)) {
        Date temp = DateUtils.parse(StringHelper.trim(pair.getSecond(), '\''));
        DateTime result;
        if (temp == null) {
            result = dealWithDateEnum(pair.getSecond());
        } else {
            result = new DateTime(temp);
        }
        if (pair.getFirst() != null && pair.getFirst().equals("=")) {
            pair.setFirst("between");
            DateTime nextDay = result.addDays(1);
            pair.setSecond(StringFormat.format("'%1$s' and '%2$s'", result.toString(DateUtils.getFormat(DateFormat.DEFAULT, DateFormat.SHORT)), nextDay.toString(DateUtils.getFormat(DateFormat.DEFAULT, DateFormat.SHORT))));
        } else {
            // ">" or "<"
            // value.argvalue = String.format("'%1$s'", result);
            pair.setSecond(StringFormat.format("'%1$s'", result.toString(DateUtils.getFormat(DateFormat.DEFAULT, DateFormat.SHORT))));
        }
    } else if ("TAG".equals(fieldName)) {
        pair.setSecond(pair.getSecond().startsWith("N'") ? pair.getSecond().substring(2) : pair.getSecond());
        if (pair.getFirst() != null && pair.getFirst().equals("=")) {
            pair.setFirst("IN");
            pair.setSecond(StringHelper.trim(pair.getSecond(), '\''));
            Tags tag = tagsHandler.getTagByTagName(pair.getSecond());
            if (tag != null) {
                pair.setSecond(StringFormat.format("(%1$s)", tagsHandler.getTagNameAndChildrenNames(tag.getTagId())));
            } else {
                pair.setSecond(StringFormat.format("('%1$s')", Guid.Empty));
            }
        } else if (pair.getFirst() != null && (pair.getFirst().equals("LIKE") || pair.getFirst().equals("ILIKE"))) {
            pair.setFirst("IN");
            pair.setSecond(StringHelper.trim(pair.getSecond(), '\'').replace("%", "*"));
            String IDs = tagsHandler.getTagNamesAndChildrenNamesByRegExp(pair.getSecond());
            if (StringHelper.isNullOrEmpty(IDs)) {
                pair.setSecond(StringFormat.format("('%1$s')", Guid.Empty));
            } else {
                pair.setSecond(StringFormat.format("(%1$s)", IDs));
            }
        }
    }
}
Also used : Date(java.util.Date) DateTime(org.ovirt.engine.core.compat.DateTime) Tags(org.ovirt.engine.core.common.businessentities.Tags)

Example 27 with Tags

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

the class TagDaoImpl method getTagTemplateByTagIdAndByTemplateId.

/**
 * In the database both Template and Vm Tags share the same tables and functions
 */
@Override
public TagsTemplateMap getTagTemplateByTagIdAndByTemplateId(Guid tagId, Guid vmId) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("tag_id", tagId).addValue("vm_id", vmId);
    RowMapper<TagsTemplateMap> mapper = (rs, rowNum) -> {
        TagsTemplateMap entity = new TagsTemplateMap();
        entity.setTagId(getGuidDefaultEmpty(rs, "tag_id"));
        entity.setTemplateId(getGuidDefaultEmpty(rs, "vm_id"));
        entity.setDefaultDisplayType((Integer) rs.getObject("DefaultDisplayType"));
        return entity;
    };
    return getCallsHandler().executeRead("GetTagVmByTagIdAndByvmId", mapper, parameterSource);
}
Also used : TagsVdsMap(org.ovirt.engine.core.common.businessentities.TagsVdsMap) Guid(org.ovirt.engine.core.compat.Guid) TagsUserGroupMap(org.ovirt.engine.core.common.businessentities.TagsUserGroupMap) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Singleton(javax.inject.Singleton) TagsTemplateMap(org.ovirt.engine.core.common.businessentities.TagsTemplateMap) TagsType(org.ovirt.engine.core.common.businessentities.TagsType) SQLException(java.sql.SQLException) List(java.util.List) TagsUserMap(org.ovirt.engine.core.common.businessentities.TagsUserMap) ResultSet(java.sql.ResultSet) Tags(org.ovirt.engine.core.common.businessentities.Tags) TagsVmMap(org.ovirt.engine.core.common.businessentities.TagsVmMap) RowMapper(org.springframework.jdbc.core.RowMapper) Named(javax.inject.Named) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) TagsTemplateMap(org.ovirt.engine.core.common.businessentities.TagsTemplateMap)

Example 28 with Tags

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

the class TagDaoTest method testRemove.

/**
 * Ensures that removing a tag works as expected.
 */
@Test
public void testRemove() {
    dao.remove(existingTag.getTagId());
    Tags result = dao.get(existingTag.getTagId());
    assertNull(result);
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 29 with Tags

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

the class TagDaoTest method testUpdate.

/**
 * Ensures that updating a tag in the database works as expected.
 */
@Test
public void testUpdate() {
    existingTag.setDescription("this is the updated description!");
    dao.update(existingTag);
    Tags result = dao.get(existingTag.getTagId());
    assertEquals(existingTag, result);
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 30 with Tags

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

the class TagDaoTest method testGetWithInvalidId.

/**
 * Ensures that using an invalid id returns no tag.
 */
@Test
public void testGetWithInvalidId() {
    Tags result = dao.get(Guid.newGuid());
    assertNull(result);
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

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