/**
   * Return the set of Obligations associated with the current result indexed by ObligationId.
   *
   * @return a Map of String, Obligation pairs
   * @throws PepException
   */
  public Map<String, Obligation> getObligations() throws PepException {

    assertValidResult();
    HashMap<String, Obligation> obligations = new HashMap<String, Obligation>();

    if (!(this.currentResult instanceof AzResult)) {
      this.log.warn("getObligations() method not supported on " + "PepRequest.OPERATION.QUERY");
      return obligations;
    }

    AzResult azResult = (AzResult) this.currentResult;
    AzObligations azObligations = azResult.getAzObligations();

    if (azObligations != null) {
      if (log.isTraceEnabled()) log.trace("process azObligations");
      Iterator<AzEntity<AzCategoryIdObligation>> obligationsIt = azObligations.iterator();
      while (obligationsIt.hasNext()) {
        AzEntity<AzCategoryIdObligation> azObligation = obligationsIt.next();
        if (log.isTraceEnabled()) log.trace("read and wrap next azObligation");
        Obligation obligation =
            this.getResponseFactory().getObligationFactory().createObject(azObligation);
        String name = obligation.getAzEntity().getAzEntityId();
        if (log.isTraceEnabled()) log.trace("\n\tput wrapped Obligation: ObligationId = " + name);
        obligations.put(name, obligation);
      }
    } else {
      if (log.isTraceEnabled()) log.trace("No Obligations returned in PepResponse");
    }
    return obligations;
  }
  /**
   * Returns the decision associated with the current result.
   *
   * @return true if the user was granted access to the resource, otherwise false
   * @throws PepException if the <code>Behavior</code> configured in the <code>PepResponseFactory
   *     </code> indicates that for the specific AzDecision and AzStatus that an exception should be
   *     thrown
   */
  public boolean allowed() throws PepException {

    if (!(this.currentResult instanceof AzResult)) {
      return this.queryAllowed;
    }

    AzResult azResult = (AzResult) this.currentResult;

    switch (azResult.getAzDecision()) {
      case AZ_PERMIT:
        return true;
      case AZ_DENY:
        return false;
      case AZ_NOTAPPLICABLE:
        return enforceBehavior(this.getResponseFactory().getNotApplicableBehavior());
      case AZ_INDETERMINATE:
        switch (azResult.getAzStatusCode()) {
          case AZ_SYNTAX_ERROR:
            return enforceBehavior(this.getResponseFactory().getSyntaxErrorBehavior());
          case AZ_PROCESSING_ERROR:
            return enforceBehavior(this.getResponseFactory().getProcessingErrorBehavior());
          case AZ_MISSING_ATTRIBUTE:
            return enforceBehavior(this.getResponseFactory().getMissingAttributeBehavior());
        }
    } // end switch

    throw new PepException("AzResult.getAzDecision did not match any of the known values");
  }
 static void printResultData(AzResult azResult, Log log) {
   log.debug(
       "\nTestAzAPI: "
           + "\n\t azResult.getAzResourceActionAssociation.getCorrelationId: "
           + azResult.getAzResourceActionAssociation().getCorrelationId()
           + "\n\t azResult.getAzResourceActionAssociationId: "
           + "\n\t\t "
           + azResult.getAzResourceActionAssociation()
           + "\n\t azResult.getAzDecision: "
           + azResult.getAzDecision()
           + "\n\t azResult.getAzStatusCode: "
           + azResult.getAzStatusCode()
           + "\n\t azResult.getStatusMessage: "
           + "\n\t\t "
           + azResult.getStatusMessage());
 }
 static void printMissingAttributes(AzResult azResult, Log log) {
   Iterator<AzAttribute<?>> itMAD =
       azResult.getAzStatusDetail().getAzAttributeMixedSet().iterator();
   log.debug("  TestAzAPI: itMAD.hasNext() = " + itMAD.hasNext());
   while (itMAD.hasNext()) {
     AzAttribute<?> azMissingAttributeDetail = itMAD.next();
     printAttributeData(azMissingAttributeDetail, "MissingAttributeDetail attribute: ", log);
   }
 }
 /**
  * TBD: Some old helper methods below: probably should be removed and replaced by clean logging
  * capabilities.
  *
  * @param azResult
  * @param log
  */
 static void printObligations(AzResult azResult, Log log) {
   Iterator<AzEntity<AzCategoryIdObligation>> itOb = azResult.getAzObligations().iterator();
   log.debug("  TestAzAPI: itOb.hasNext() = " + itOb.hasNext());
   while (itOb.hasNext()) {
     AzEntity<AzCategoryIdObligation> azObligation = itOb.next();
     Iterator<AzAttribute<?>> itAttr = azObligation.getAzAttributeMixedSet().iterator();
     log.debug("  TestAzAPI: itAttr.hasNext() = " + itAttr.hasNext());
     while (itAttr.hasNext()) {
       printAttributeData(itAttr.next(), "Obligation attribute: ", log);
     }
   }
 }