Ejemplo n.º 1
0
 @Override
 public boolean containTag(List<Tag> allTags, Tag tag) {
   for (Tag tagInCol : allTags) {
     if (tagInCol.getId().compareTo(tag.getId()) == 0) return true;
   }
   return false;
 }
Ejemplo n.º 2
0
 @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);
   }
 }
Ejemplo n.º 3
0
 @Override
 @Transactional(readOnly = false)
 public void deleteById(int tagId) {
   LOG.info("Deleting Tag with ID " + tagId);
   Tag tag = loadTag(tagId);
   tag.setActive(false);
   tagDao.saveOrUpdate(tag);
 }
Ejemplo n.º 4
0
  @Override
  public boolean isValidTags(List<Tag> allTags, List<Tag> tags) {
    for (Tag tag : tags) {
      if (!containTag(allTags, tag)) {
        LOG.warn("Tag ID " + tag.getId() + " is invalid.");
        return false;
      }
    }

    return true;
  }
Ejemplo n.º 5
0
 @Override
 public void updateTagTypes() {
   LOG.info("About to update type for all tags.");
   for (Tag tag : tagDao.retrieveAll()) {
     if (!tag.getTagForComment()) { // this is an application tag
       tag.setType(TagType.APPLICATION);
     } else {
       tag.setType(TagType.COMMENT);
     }
     tagDao.saveOrUpdate(tag);
   }
 }
Ejemplo n.º 6
0
  @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;
  }
Ejemplo n.º 7
0
 @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);
   }
 }
Ejemplo n.º 8
0
  @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);
        }
      }
    }
  }