private boolean checkChanged(GovernanceArtifact fa, String attrName, String attrValue) {
   boolean isChanged = true;
   try {
     String curval = fa.getAttribute(attrName);
     if ((curval == null || curval.isEmpty()) && (attrValue == null || attrValue.isEmpty())) {
       isChanged = false;
     } else if (attrValue != null && curval != null && curval.equals(attrValue)) {
       isChanged = false;
     } else {
       fa.setAttribute(attrName, attrValue);
     }
   } catch (GovernanceException e) {
     log.error("updateAttributes " + e.getMessage());
   }
   return isChanged;
 }
コード例 #2
0
  private void validateArtifact(GovernanceArtifact artifact) throws GovernanceException {
    if (validationAttributes == null) {
      return;
    }
    Map<String, Object> map;
    for (int i = 0; i < validationAttributes.size(); ++i) {
      map = validationAttributes.get(i);
      String value = "";
      String prop = (String) map.get("properties");
      List<String> keys = (List<String>) map.get("keys");

      if (prop != null && "unbounded".equals(prop)) {
        // assume there are only 1 key
        String[] values = artifact.getAttributes((String) keys.get(0));
        if (values != null) {
          for (int j = 0; j < values.length; ++j) {
            if (!values[j].matches((String) map.get("regexp"))) {
              // return an exception to stop adding artifact
              throw new GovernanceException(
                  (String) map.get("name") + " doesn't match regex: " + (String) map.get("Regexp"));
            }
          }
        }
      } else {
        for (int j = 0; j < keys.size(); ++j) {
          String v = artifact.getAttribute(keys.get(j));
          if (j != 0) value += ":";
          value += (v == null ? "" : v);
        }
        if (!value.matches((String) map.get("regexp"))) {
          // return an exception to stop adding artifact
          throw new GovernanceException(
              (String) map.get("name") + " doesn't match regex: " + (String) map.get("Regexp"));
        }
      }
    }
  }