More On Validations

Two of the Evidence Interface functions which form part of the infrastructure support for evidence validation are selectForValidations and validate.

The selectForValidations function will typically be used to select all evidences which are related to or are dependant on the piece of evidence being validated. An example of this would be the modification of an amount on a parent evidence record. As part of the validation of the parent evidence, a check might need to be performed to ensure the sum of the child evidence records does not exceed the modified parent amount.

When a user applies changes to evidence records, the Evidence Controller calls out to the selectForValidations interface function on the entities for each evidence record. The logic within this method retrieves all related 'Active' and 'In Edit' evidences within the hierarchy for validation. For instance, if we are validating a child evidence record within a parent-child-grandchild relationship structure, both parent evidence and grandchild evidence are retrieved for the validation processing.

Once processing returns to the Evidence Controller, a filter is applied to the list of evidence. This filters the input list and leaves only 'Active' records, or 'In Edit' records as appropriate depending on whether the function must validate against work-in-progress or active only evidence. This filtered list is then passed to the validate function where custom validation is applied.

The program listing below shows a selectForValidations implementation used in the Asset demo.

// __________________________________________________________
  /**
   * Selects all the records for validations
   *
   * @param evKey Contains an evidenceID / evidenceType pairing
   *
   * @return List of evidenceID / evidenceType pairings
   */
  public EIEvidenceKeyList selectForValidation(
    EIEvidenceKey evKey) 
    throws AppException, InformationalException {

    // Return object
    EIEvidenceKey eiEvidenceKey = new EIEvidenceKey();

    // Casting to impl due to calling non-modeled interface
    curam.seg.evidence.entity.intf.AssetOwnership 
      assetOwnershipObj =
        (curam.seg.evidence.entity.impl.AssetOwnership)
           AssetOwnershipFactory.newInstance();

    eiEvidenceKey.evidenceID = evKey.evidenceID;
    eiEvidenceKey.evidenceType = 
      CASEEVIDENCE.ASSET;

    EIEvidenceKeyList eiEvidenceKeyList =
      assetOwnershipObj.readAllByParentID(eiEvidenceKey);

    eiEvidenceKeyList.dtls.add(0, evKey);

    return eiEvidenceKeyList;
  }

The code here, on the Asset parent entity, makes a call to the readAllByParentID interface method implementation on the child entity, Asset Ownership. The implementation of the readAllByParentID function on the Asset Ownership is shown in the program listing below.

// __________________________________________________________
/**
 * Read all Asset Ownership records
 *
 * @param key Contains the evidenceID and evidenceType
 *
 * @return A list of evidenceID and evidenceType pairs
 */
public EIEvidenceKeyList readAllByParentID(EIEvidenceKey key)
  throws AppException, InformationalException {

  // Return object
  EIEvidenceKeyList eiEvidenceKeyList = new EIEvidenceKeyList();

  // Create the link entity object
  EvidenceRelationship evidenceRelationshipObj =
    EvidenceRelationshipFactory.newInstance();

  // parent entity key
  ParentKey parentKey = new ParentKey();
  parentKey.parentID = key.evidenceID;
  parentKey.parentType = key.evidenceType;

  // Reads all relationship details for the specified parent
  ChildKeyList childKeyList =
    evidenceRelationshipObj.searchByParent(parentKey);

  // Iterate through the link details list
  for (int i = 0; i < childKeyList.dtls.size(); i++) {

    if (childKeyList.dtls.item(i).childType.equals(
      CASEEVIDENCE.ASSETOWNERSHIP)) {

      EIEvidenceKey listEvidenceKey = new EIEvidenceKey();

      listEvidenceKey.evidenceID =
        childKeyList.dtls.item(i).childID;
      listEvidenceKey.evidenceType =
        childKeyList.dtls.item(i).childType;

      eiEvidenceKeyList.dtls.addRef(listEvidenceKey);
    }
  }

  return eiEvidenceKeyList;

}

The function above retrieves all child evidence keys for the specified parent. The childID and childType pairings are returned to the calling mechanism.