Exemplo n.º 1
0
  /** Computes operation result status based on subtask status. */
  public void computeStatus() {
    if (getSubresults().isEmpty()) {
      if (status == OperationResultStatus.UNKNOWN) {
        status = OperationResultStatus.SUCCESS;
      }
      return;
    }
    if (status == OperationResultStatus.FATAL_ERROR) {
      return;
    }
    OperationResultStatus newStatus = OperationResultStatus.UNKNOWN;
    boolean allSuccess = true;
    boolean allNotApplicable = true;
    String newMessage = null;
    for (OperationResult sub : getSubresults()) {
      if (sub.getStatus() != OperationResultStatus.NOT_APPLICABLE) {
        allNotApplicable = false;
      }
      if (sub.getStatus() == OperationResultStatus.FATAL_ERROR) {
        status = OperationResultStatus.FATAL_ERROR;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ": " + sub.getMessage();
        }
        return;
      }
      if (sub.getStatus() == OperationResultStatus.IN_PROGRESS) {
        status = OperationResultStatus.IN_PROGRESS;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ": " + sub.getMessage();
        }
        return;
      }
      if (sub.getStatus() == OperationResultStatus.PARTIAL_ERROR) {
        newStatus = OperationResultStatus.PARTIAL_ERROR;
        newMessage = sub.getMessage();
      }
      if (newStatus != OperationResultStatus.PARTIAL_ERROR) {
        if (sub.getStatus() == OperationResultStatus.HANDLED_ERROR) {
          newStatus = OperationResultStatus.HANDLED_ERROR;
          newMessage = sub.getMessage();
        }
      }
      if (sub.getStatus() != OperationResultStatus.SUCCESS
          && sub.getStatus() != OperationResultStatus.NOT_APPLICABLE) {
        allSuccess = false;
      }
      if (newStatus != OperationResultStatus.HANDLED_ERROR) {
        if (sub.getStatus() == OperationResultStatus.WARNING) {
          newStatus = OperationResultStatus.WARNING;
          newMessage = sub.getMessage();
        }
      }
    }

    if (allNotApplicable && !getSubresults().isEmpty()) {
      status = OperationResultStatus.NOT_APPLICABLE;
    }
    if (allSuccess && !getSubresults().isEmpty()) {
      status = OperationResultStatus.SUCCESS;
    } else {
      status = newStatus;
      if (message == null) {
        message = newMessage;
      } else {
        message = message + ": " + newMessage;
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Used when the result contains several composite sub-result that are of equivalent meaning. If
   * all of them fail the result will be fatal error as well. If only some of them fail the result
   * will be partial error. Handled error is considered a success.
   */
  public void computeStatusComposite() {
    if (getSubresults().isEmpty()) {
      if (status == OperationResultStatus.UNKNOWN) {
        status = OperationResultStatus.NOT_APPLICABLE;
      }
      return;
    }

    boolean allFatalError = true;
    boolean allNotApplicable = true;
    boolean hasInProgress = false;
    boolean hasHandledError = false;
    boolean hasError = false;
    boolean hasWarning = false;
    for (OperationResult sub : getSubresults()) {
      if (sub.getStatus() != OperationResultStatus.NOT_APPLICABLE) {
        allNotApplicable = false;
      }
      if (sub.getStatus() != OperationResultStatus.FATAL_ERROR) {
        allFatalError = false;
      }
      if (sub.getStatus() == OperationResultStatus.FATAL_ERROR) {
        hasError = true;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ", " + sub.getMessage();
        }
      }
      if (sub.getStatus() == OperationResultStatus.PARTIAL_ERROR) {
        hasError = true;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ", " + sub.getMessage();
        }
      }
      if (sub.getStatus() == OperationResultStatus.HANDLED_ERROR) {
        hasHandledError = true;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ", " + sub.getMessage();
        }
      }
      if (sub.getStatus() == OperationResultStatus.IN_PROGRESS) {
        hasInProgress = true;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ", " + sub.getMessage();
        }
      }
      if (sub.getStatus() == OperationResultStatus.WARNING) {
        hasWarning = true;
        if (message == null) {
          message = sub.getMessage();
        } else {
          message = message + ", " + sub.getMessage();
        }
      }
    }

    if (allNotApplicable) {
      status = OperationResultStatus.NOT_APPLICABLE;
    } else if (allFatalError) {
      status = OperationResultStatus.FATAL_ERROR;
    } else if (hasInProgress) {
      status = OperationResultStatus.IN_PROGRESS;
    } else if (hasError) {
      status = OperationResultStatus.PARTIAL_ERROR;
    } else if (hasWarning) {
      status = OperationResultStatus.WARNING;
    } else if (hasHandledError) {
      status = OperationResultStatus.HANDLED_ERROR;
    } else {
      status = OperationResultStatus.SUCCESS;
    }
  }
Exemplo n.º 3
0
  private OperationResultType createOperationResultType(OperationResult opResult) {
    OperationResultType result = new OperationResultType();
    result.setToken(opResult.getToken());
    result.setStatus(OperationResultStatus.createStatusType(opResult.getStatus()));
    if (opResult.getCount() != 1) {
      result.setCount(opResult.getCount());
    }
    result.setOperation(opResult.getOperation());
    result.setMessage(opResult.getMessage());
    result.setMessageCode(opResult.getMessageCode());

    if (opResult.getCause() != null || !opResult.details.isEmpty()) {
      StringBuilder detailsb = new StringBuilder();

      // Record text messages in details (if present)
      if (!opResult.details.isEmpty()) {
        for (String line : opResult.details) {
          detailsb.append(line);
          detailsb.append("\n");
        }
      }

      // Record stack trace in details if a cause is present
      if (opResult.getCause() != null) {
        Throwable ex = opResult.getCause();
        detailsb.append(ex.getClass().getName());
        detailsb.append(": ");
        detailsb.append(ex.getMessage());
        detailsb.append("\n");
        StackTraceElement[] stackTrace = ex.getStackTrace();
        for (int i = 0; i < stackTrace.length; i++) {
          detailsb.append(stackTrace[i].toString());
          detailsb.append("\n");
        }
      }

      result.setDetails(detailsb.toString());
    }

    if (StringUtils.isNotEmpty(opResult.getLocalizationMessage())) {
      LocalizedMessageType message = new LocalizedMessageType();
      message.setKey(opResult.getLocalizationMessage());
      if (opResult.getLocalizationArguments() != null) {
        message.getArgument().addAll(opResult.getLocalizationArguments());
      }
      result.setLocalizedMessage(message);
    }

    //		Set<Entry<String, Serializable>> params = opResult.getParams();
    //		if (!params.isEmpty()) {
    ParamsType paramsType = ParamsTypeUtil.toParamsType(opResult.getParams());
    result.setParams(paramsType);

    //			for (Entry<String, Serializable> entry : params) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    //		Set<Entry<String, Serializable>> context = opResult.getContext().entrySet();
    //		if (!context.isEmpty()) {
    paramsType = ParamsTypeUtil.toParamsType(opResult.getContext());
    result.setContext(paramsType);

    //			for (Entry<String, Serializable> entry : context) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    //		Set<Entry<String, Serializable>> returns = opResult.getReturns().entrySet();
    //		if (!returns.isEmpty()) {
    paramsType = ParamsTypeUtil.toParamsType(opResult.getReturns());
    result.setReturns(paramsType);

    //			for (Entry<String, Serializable> entry : returns) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    for (OperationResult subResult : opResult.getSubresults()) {
      result.getPartialResults().add(opResult.createOperationResultType(subResult));
    }

    return result;
  }