Ejemplo n.º 1
0
  /**
   * Validates a collection of anything splitable. This implies that it contains <code>
   * {@link CreditSplit}</code> instances.
   *
   * @param splitable_it
   * @param creditType
   * @param greaterCummulative
   * @return boolean is valid?
   */
  public boolean validateCreditSplitable(
      Iterator<? extends CreditSplitable> splitable_it,
      InvestigatorCreditType creditType,
      DecimalHolder greaterCummulative) {
    if (!splitable_it.hasNext()) {
      return isCreditSplitTotalValid(greaterCummulative.getValue());
    }
    boolean retval = true;

    CreditSplitable splitable = splitable_it.next();
    info(VALIDATING_MESSAGE, getCreditSplitableName(splitable));

    DecimalHolder lesserCummulative = new DecimalHolder(KualiDecimal.ZERO);
    retval &=
        validateCreditSplit(splitable.getCreditSplits().iterator(), creditType, lesserCummulative);

    greaterCummulative.add(lesserCummulative);

    return retval & validateCreditSplitable(splitable_it, creditType, greaterCummulative);
  }
Ejemplo n.º 2
0
  /**
   * Discover the name of a {@link CreditSplitable}. Not all {@link CreditSplitable} instances will
   * have a <code>name</code> property. Even if they did, it's not likely for all the properties to
   * be called <code>name</code>. {@link CreditSplitable} relies on a property to be annotated as
   * being the name of the {@link CreditSplitable}. This checks for that annotation and returns the
   * name.
   *
   * @param splitable
   * @return <code>null</code> if the name could not be found or if the value of the name is also
   *     <code>null</code>; otherwise, the name is returned.
   */
  private String getCreditSplitableName(CreditSplitable splitable) {

    for (Method method : splitable.getClass().getMethods()) {
      if (method.isAnnotationPresent(CreditSplitNameInfo.class)) {
        LOG.info("Found method name " + method.getName());
        try {
          return (String) method.invoke(splitable, null);
        } catch (Exception e) {
          LOG.warn(
              "Could not find the name property for the credit splitable object of class "
                  + splitable.getClass().getName()
                  + ". Make sure the "
                  + CreditSplitNameInfo.class.getSimpleName()
                  + " annotation is declared on the name property of "
                  + splitable.getClass().getSimpleName());
        }
      }
    }

    return null;
  }