Exemplo 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;
 }
Exemplo n.º 2
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);
        }
      }
    }
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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;
  }