@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 void changeTagInVulnComments() { LOG.info( "About to update all tags in Vulnerability Comments from Application Tag to Comment Tag."); List<VulnerabilityComment> vulnerabilityComments = vulnerabilityCommentDao.retrieveAllActive(); if (vulnerabilityComments == null) { LOG.info("There is no vulnerability comments in the system."); return; } LOG.info( "Looking for tags in " + vulnerabilityComments.size() + " vulnerability comments, and change them if found."); for (VulnerabilityComment comment : vulnerabilityComments) { List<Tag> newTags = CollectionUtils.list(); for (Tag tag : comment.getTags()) { if (tag.getType() == TagType.APPLICATION) { Tag sameTagInComment = loadCommentTag(tag.getName()); if (sameTagInComment != null) newTags.add(sameTagInComment); else LOG.warn( "Can't find comment tag " + tag.getName() + " to change for comment in vulnerability ID " + comment.getVulnerability().getId()); } else newTags.add(tag); } comment.setTags(newTags); vulnerabilityCommentDao.saveOrUpdate(comment); } }