@Override public void validate(Tag tag, BindingResult result) { Tag databaseTag; if (tag.getName().trim().equals("")) { result.rejectValue("name", null, null, "This field cannot be blank"); } if (containsHTML(tag.getName())) { LOG.error(HTML_ERROR); result.rejectValue("name", null, null, HTML_ERROR); } if (tag.getType() == null) { result.rejectValue("type", null, null, "This field cannot be blank"); } else { // Checking if type is valid TagType type = TagType.getTagType(tag.getType().toString()); databaseTag = loadTagWithType(tag.getName().trim(), type); if (databaseTag != null && (tag.getId() == null || !databaseTag.getId().equals(tag.getId()))) { result.rejectValue("name", MessageConstants.ERROR_NAMETAKEN); } // Check if updating tag is enterprise tag if (tag.getId() != null) { databaseTag = loadTag(tag.getId()); if (databaseTag == null || (databaseTag.getEnterpriseTag() != null && databaseTag.getEnterpriseTag())) { result.rejectValue("name", MessageConstants.ERROR_INVALID, new String[] {"Tag Id"}, null); } } } }
@Override public List<Tag> setEnterpriseTag(List<Tag> tags) { for (Tag tag : listFrom(tags)) { Tag databaseTag = tagDao.retrieveById(tag.getId()); if (databaseTag == null) { tags.remove(tag); } else { tag.setEnterpriseTag(databaseTag.getEnterpriseTag()); } } return tags; }
@Override public void copyAppTagsToCommentTags() { List<Tag> appTags = loadAllApplicationTags(); if (appTags == null) { LOG.info("There is no tags in system."); return; } LOG.info("About to copy " + appTags.size() + " application tags to comment tags."); for (Tag appTag : appTags) { if (loadCommentTag(appTag.getName()) == null) { LOG.info("Copying " + appTag.getName()); Tag newCommentTag = new Tag(); newCommentTag.setName(appTag.getName()); newCommentTag.setEnterpriseTag(appTag.getEnterpriseTag()); newCommentTag.setDefaultJsonFilter(appTag.getDefaultJsonFilter()); newCommentTag.setType(TagType.COMMENT); tagDao.saveOrUpdate(newCommentTag); } appTag.setType(TagType.APPLICATION); tagDao.saveOrUpdate(appTag); } }