Class GenericProcess

java.lang.Object
co.ecg.alpaca.toolkit.task.GenericProcess
All Implemented Interfaces:
Loggable
Direct Known Subclasses:
IterableProcess

public class GenericProcess extends Object implements Loggable
An abstract process that is error-able and tracks its state.
Author:
Matthew Keathley on 5/10/16.
  • Field Details

    • log

      public transient org.slf4j.Logger log
  • Constructor Details

    • GenericProcess

      public GenericProcess()
    • GenericProcess

      public GenericProcess(String processId)
    • GenericProcess

      public GenericProcess(GenericProcess parentProcess)
  • Method Details

    • getProcessContext

      public ProcessContext getProcessContext()
    • getLogIdentifier

      public String getLogIdentifier()
    • getParentProcess

      public GenericProcess getParentProcess()
    • setProcessId

      public void setProcessId(String processId)
    • setExceptionOnErrors

      public void setExceptionOnErrors(boolean exceptionOnErrors)
      Determines whether to throw an exception on errors or just log.
      Parameters:
      exceptionOnErrors - a boolean
    • hasErrors

      public boolean hasErrors()
      Reports if the process contains errors
      Returns:
      True IFF there was 0+ errors reported.
    • errorCount

      public int errorCount()
    • hasWarnings

      public boolean hasWarnings()
      Reports if the process contains warnings
      Returns:
      True IFF there was 0+ warnings reported.
    • getErrors

      public Set<String> getErrors()
    • fail

      public void fail(Throwable throwable) throws ProcessTerminatingException
      Process is failing due to provided exception. Errors will be added to parent if provided.
      Parameters:
      throwable - The throwable reason that the process is failing.
      Throws:
      ProcessTerminatingException
    • getWarnings

      public Set<String> getWarnings()
    • checkValidity

      public void checkValidity() throws ProcessTerminatingException
      Checks the validity of the process
      Throws:
      ProcessTerminatingException - Thrown if the process has errors.
    • printReport

      public void printReport(PrintStream out)
      Prints a report of errors and warnings to the provided printstream.
      Parameters:
      out - The printstream to write the report
    • getReportList

      public List<String> getReportList()
    • getReportList

      public List<String> getReportList(String taskInfo)
    • getReport

      public String getReport()
    • exception

      public String exception(String message, Throwable throwable)
      Adds an exception error to the errors to report.
      Parameters:
      throwable - The throwable to process.
    • exception

      public String exception(Throwable throwable)
      Adds an exception error to the errors to report.
      Parameters:
      throwable - The throwable to process.
    • isError

      public boolean isError(Response response)
      Checks if a response is an error -- If so add the response message to the list of errors
      Parameters:
      response - The response to check
      Returns:
      true IFF the response is an error
    • isError

      public boolean isError(Response response, String... expectedErrorCodes)
      Checks if a Response is an error with optional expected error codes
      Parameters:
      response - The response to check
      expectedErrorCodes - The array of expected error codes
      Returns:
      true IFF the response is an error
    • isError

      public boolean isError(Response response, boolean markErrorCodesAsWarnings, String... expectedErrorCodes)
      Checks if a Response is an error with optional expected error codes
      Parameters:
      response - The response to check
      markErrorCodesAsWarnings - Flag to add expected error codes as warning messages.
      expectedErrorCodes - The array of expected error codes
      Returns:
      true IFF the response is an error
    • isErrorsAsWarnings

      public boolean isErrorsAsWarnings()
    • setErrorsAsWarnings

      public void setErrorsAsWarnings(boolean errorsAsWarnings)
    • addWarning

      public void addWarning(Map<String,String> warnings)
    • addWarning

      public void addWarning(String message)
    • addError

      public void addError(Map<String,String> errors)
    • addError

      public void addError(String message)
    • getProcessId

      public String getProcessId()
    • setParentProcess

      public void setParentProcess(GenericProcess process)
    • isDescendantOf

      public boolean isDescendantOf(Class... clazz)