@Override public void update(Tags tag) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("description", tag.getDescription()) .addValue("tag_id", tag.getTagId()) .addValue("tag_name", tag.getTagName()) .addValue("parent_id", tag.getParentId()) .addValue("readonly", tag.getIsReadonly()) .addValue("type", tag.getType()); getCallsHandler() .executeModification("Updatetags", parameterSource); }
public void getRootTag(AsyncQuery<Tags> aQuery) { aQuery.converterCallback = source -> { if (source != null) { Tags tag = (Tags) source; Tags root = new Tags(tag.getDescription(), tag.getParentId(), tag.getIsReadonly(), tag.getTagId(), tag.getTagName()); if (tag.getChildren() != null) { fillTagsRecursive(root, tag.getChildren()); } return root; } return new Tags(); }; Frontend.getInstance().runQuery(QueryType.GetRootTag, new QueryParametersBase(), aQuery); }
@Mapping(from = Tag.class, to = Tags.class) public static Tags map(Tag model, Tags template) { Tags entity = template != null ? template : new Tags(); entity.setParentId(parent(model, entity.getParentId())); if (model.isSetId()) { entity.setTagId(GuidUtils.asGuid(model.getId())); } if (model.isSetName()) { entity.setTagName(model.getName()); } if (model.isSetDescription()) { entity.setDescription(model.getDescription()); } return entity; }
public void fillTagsRecursive(Tags tagToFill, List<Tags> children) { ArrayList<Tags> list = new ArrayList<>(); for (Tags tag : children) { // tags child = new tags(tag.description, tag.parent_id, tag.IsReadonly, tag.tag_id, tag.tag_name); if (tag.getType() == TagsType.GeneralTag) { list.add(tag); if (tag.getChildren() != null) { fillTagsRecursive(tag, tag.getChildren()); } } } tagToFill.setChildren(list); }
private Tags createTag(String name, String desc) { Tags tag = new Tags(); tag.setChildren(new ArrayList<>()); tag.setDescription(desc); tag.setTagName(name); tag.setIsReadonly(true); tag.setParentId(Guid.Empty); tag.setType(TagsType.GeneralTag); return tag; }
public TagsOperationParameters(Tags tag) { super(tag.getTagId()); _tag = tag; }
private Tags setUpTagExpectations(Guid tagId) { Tags tags = mock(Tags.class); when(tags.getTagId()).thenReturn(tagId); when(tags.getParentId()).thenReturn(VM_ID); return tags; } }
@Mapping(from = Tags.class, to = Tag.class) public static Tag map(Tags entity, Tag template) { Tag model = template != null ? template : new Tag(); model.setId(entity.getTagId().toString()); model.setName(entity.getTagName()); model.setDescription(entity.getDescription()); model.setParent(parent(entity)); return model; }
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); existingTag = dao.get(EXISTING_TAG_ID); existingTag = dao.get(new Guid("d3ec3e01-ca89-48e1-8b43-a9b38f873b0c")); parent = FixturesTool.DATA_CENTER; user = new Guid("9bf7c640-b620-456f-a550-0348f366544a"); vm = EXISTING_VM_ID; template = new Guid("77296e00-0cad-4e5a-9299-008a7b6f4355"); vmPool = new Guid("103cfd1d-18b1-4790-8a0c-1e52621b0076"); newTag = new Tags(); newTag.setTagName("newtagname"); newTag.setIsReadonly(true); newTag.setDescription("newtagdescription"); newTag.setParentId(parent); existingUserGroupTag = dao.getTagUserGroupByGroupIdAndByTagId(EXISTING_TAG_ID, EXISTING_GROUP_ID); existingUserTag = dao.getTagUserByTagIdAndByuserId(EXISTING_TAG_ID, EXISTING_USER_ID); existingVdsTag = dao.getTagVdsByTagIdAndByVdsId(EXISTING_TAG_ID, FixturesTool.VDS_RHEL6_NFS_SPM); newVdsTag = new TagsVdsMap(EXISTING_TAG_ID, FixturesTool.HOST_ID); existingVmTag = dao.getTagVmByTagIdAndByVmId(EXISTING_TAG_ID, EXISTING_VM_ID); existingTemplateTag = dao.getTagTemplateByTagIdAndByTemplateId(EXISTING_TAG_ID, EXISTING_TEMPLATE_ID); newVmTag = new TagsVmMap(EXISTING_TAG_ID, FREE_VM_ID); newTemplateTag = new TagsTemplateMap(EXISTING_TAG_ID, FREE_TEMPLATE_ID); }
@Test public void testBatch() { List<Tags> tags = dao.getAll(); for (Tags tag : tags) { dao.remove(tag.getTagId()); } List<Tags> data = new ArrayList<>(); data.add(new Tags("a", Guid.Empty, true, Guid.newGuid(), "a")); data.add(new Tags("b", Guid.Empty, true, Guid.newGuid(), "b")); List<MapSqlParameterSource> executions = data.stream().map(this::getParamsSource).collect(Collectors.toList()); jdbcCallsHandler.executeStoredProcAsBatch("Inserttags", executions); List<Tags> tagsAfterInsert = dao.getAll(); assertNotNull(tagsAfterInsert); assertEquals(data.size(), tagsAfterInsert.size()); assertTrue(data.containsAll(tagsAfterInsert)); } }
/** * 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); }
@Override protected Tags getEntity(int index) { return new Tags(DESCRIPTIONS[index], null, false, GUIDS[index], NAMES[index]); }
@BeforeEach public void setup() { BaseConditionFieldAutoCompleter.tagsHandler = mock(ITagsHandler.class); Tags tags = new Tags(); tags.setTagName(TAG_NAME); when(BaseConditionFieldAutoCompleter.tagsHandler.getTagByTagName(any())).thenReturn(tags); when(BaseConditionFieldAutoCompleter.tagsHandler.getTagNamesAndChildrenNamesByRegExp(any())) .thenReturn(TAG_NAME_WITH_CHILDREN); }
protected Tag lookupTagByName(String name) { for (Tags tag : getBackendCollection(Tags.class, QueryType.GetAllTags, new QueryParametersBase())) { if (tag.getTagName().equals(name)) { return map(tag); } } return handleError(new EntityNotFoundException(name), false); }
private static Tag parent(Tags entity) { if (entity.getParentId() != null) { Tag parent = new Tag(); parent.setId(entity.getParentId().toString()); return parent; } else { return null; } } }
@Test public void testAddTagNoParent() { setUriInfo(setUpBasicUriExpectations()); Tags entity = getEntity(0); entity.setParentId(Guid.Empty); setUpCreationExpectations(ActionType.AddTag, TagsOperationParameters.class, new String[] { "Tag.TagName", "Tag.ParentId" }, new Object[] { NAMES[0], Guid.Empty }, true, true, null, QueryType.GetTagByTagName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[0] }, entity); Tag model = getModel(0); model.setParent(null); Response response = collection.add(model); assertEquals(201, response.getStatus()); assertTrue(response.getEntity() instanceof Tag); verifyModel((Tag)response.getEntity(), 0, Guid.Empty.toString()); }
private void setAttachedTagsConverter(AsyncQuery<List<Tags>> aQuery) { aQuery.converterCallback = source -> { if (source != null) { ArrayList<Tags> ret = new ArrayList<>(); for (Tags tags : (ArrayList<Tags>) source) { if (tags.getType() == TagsType.GeneralTag) { ret.add(tags); } } return ret; } return new ArrayList<>(); }; }
String getParentId(Tag tag) { return lookupTagByName(tag.getParent().getName()).getTagId().toString(); }
private Tags setUpTagExpectations(Guid tagId) { Tags tags = mock(Tags.class); when(tags.getTagId()).thenReturn(tagId); when(tags.getParentId()).thenReturn(USER_ID); return tags; } }
@Override protected Tags getEntity(int index) { return new Tags(DESCRIPTIONS[index], PARENT_GUID, false, GUIDS[index], NAMES[index]); }