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