コード例 #1
0
 /**
  * When a correction criterion is about to be added to a group, this will check if it is valid,
  * meaning that the field name is not blank
  *
  * @param correctionCriteria validated correction criteria
  * @return true if correction criteria is valid for adding
  */
 public static boolean validCorrectionCriteriaForAdding(CorrectionCriteria correctionCriteria) {
   String fieldName = correctionCriteria.getCorrectionFieldName();
   if (StringUtils.isBlank(fieldName)) {
     return false;
   }
   return true;
 }
コード例 #2
0
  /**
   * Returns whether an origin entry matches the passed in criteria. If both the criteria and actual
   * value are both String types and are empty, null, or whitespace only, then they will match.
   *
   * @param cc correction criteria to test against origin entry
   * @param oe origin entry to test
   * @return true if origin entry matches the passed in criteria
   */
  public static boolean entryMatchesCriteria(CorrectionCriteria cc, OriginEntryFull oe) {
    OriginEntryFieldFinder oeff = new OriginEntryFieldFinder();
    Object fieldActualValue = oe.getFieldValue(cc.getCorrectionFieldName());
    String fieldTestValue =
        StringUtils.isBlank(cc.getCorrectionFieldValue()) ? "" : cc.getCorrectionFieldValue();
    String fieldType = oeff.getFieldType(cc.getCorrectionFieldName());

    String fieldActualValueString = convertToString(fieldActualValue, fieldType);

    if ("String".equals(fieldType)
        || "sw".equals(cc.getCorrectionOperatorCode())
        || "ew".equals(cc.getCorrectionOperatorCode())
        || "ct".equals(cc.getCorrectionOperatorCode())) {
      return compareStringData(cc, fieldTestValue, fieldActualValueString);
    }
    int compareTo = 0;
    try {
      if (fieldActualValue == null) {
        return false;
      }
      if ("Integer".equals(fieldType)) {
        compareTo = ((Integer) fieldActualValue).compareTo(Integer.parseInt(fieldTestValue));
      }
      if ("KualiDecimal".equals(fieldType)) {
        compareTo =
            ((KualiDecimal) fieldActualValue)
                .compareTo(new KualiDecimal(Double.parseDouble(fieldTestValue)));
      }
      if ("BigDecimal".equals(fieldType)) {
        compareTo =
            ((BigDecimal) fieldActualValue)
                .compareTo(new BigDecimal(Double.parseDouble(fieldTestValue)));
      }
      if ("Date".equals(fieldType)) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        compareTo = ((Date) fieldActualValue).compareTo(df.parse(fieldTestValue));
      }
    } catch (Exception e) {
      // any exception while parsing data return false
      return false;
    }
    return compareTo(compareTo, cc.getCorrectionOperatorCode());
  }
コード例 #3
0
 /**
  * When a document is about to be saved, this will check if it is valid, meaning that the field
  * name and value are both blank
  *
  * @param correctionCriteria validated correction criteria
  * @return true if correction criteria is valid for saving
  */
 public static boolean validCorrectionCriteriaForSaving(CorrectionCriteria correctionCriteria) {
   return correctionCriteria == null
       || (StringUtils.isBlank(correctionCriteria.getCorrectionFieldName())
           && StringUtils.isBlank(correctionCriteria.getCorrectionFieldValue()));
 }