Class ErrorHandler

  • All Implemented Interfaces:
    IObservable, IObserver
    Direct Known Subclasses:
    ErrorHandler

    public abstract class ErrorHandler
    extends java.lang.Object
    implements IObserver, IObservable
    Top of the error handling hierarchy. Will add errors to a queue which can be sent with sendErrors(). Subclasses will get a chance to handle all ImportEvent instances, but should try not to duplicate handling.
    Since:
    Beta4.1
    • Field Detail

      • log

        protected final org.slf4j.Logger log
      • observers

        protected final java.util.List<IObserver> observers
      • cancelUploads

        protected boolean cancelUploads
      • sendFiles

        protected boolean sendFiles
      • sendLogs

        protected boolean sendLogs
      • fileUploadErrors

        public boolean fileUploadErrors
      • totalErrors

        protected int totalErrors
      • icMap

        protected java.util.Map<java.lang.String,​ImportContainer> icMap
        Host information about the file and its corresponding import candidate.
    • Constructor Detail

      • ErrorHandler

        public ErrorHandler​(ImportConfig config)
        Initialize
        Parameters:
        config - the import configuration
    • Method Detail

      • errorCount

        public int errorCount()
        Returns:
        number of errors in ErrorContainer array
      • onUpdate

        protected abstract void onUpdate​(IObservable importLibrary,
                                         ImportEvent event)
        abstract on update method
        Parameters:
        importLibrary - the import library
        event - - importEvent
      • sendErrors

        protected void sendErrors()
        Send existing errors in ErrorContainer array to server
      • addError

        protected void addError​(java.lang.Throwable error,
                                java.io.File file,
                                java.lang.String[] files,
                                java.lang.String readerType)
        Add detailed error to error container array
        Parameters:
        error - - error thrown
        file - - head file for error
        files - - all files in import collection
        readerType - - reader type supplied from bio-formats
      • clearErrors

        protected void clearErrors​(int index)
      • addObserver

        public final boolean addObserver​(IObserver object)
        Description copied from interface: IObservable
        Add observer for notification
        Specified by:
        addObserver in interface IObservable
        Parameters:
        object - - observer object
        Returns:
        true if added
      • deleteObserver

        public final boolean deleteObserver​(IObserver object)
        Description copied from interface: IObservable
        Delete observer
        Specified by:
        deleteObserver in interface IObservable
        Parameters:
        object - - observer to delete
        Returns:
        true if deleted
      • notifyObservers

        public final void notifyObservers​(ImportEvent event)
        Description copied from interface: IObservable
        Notify observers of event
        Specified by:
        notifyObservers in interface IObservable
        Parameters:
        event - - event that happened
      • onCancel

        protected void onCancel()
        action to take on cancel
      • onAddError

        protected void onAddError​(ErrorContainer errorContainer,
                                  java.lang.String message)
        Action to take on adding an error to container
        Parameters:
        errorContainer - - error container
        message - - message string for action (if needed)
      • isSend

        protected boolean isSend​(int index)
        Check if files need sending at error container index
        Parameters:
        index - - index in error container
        Returns:
        - true if file is to be sent
      • onSending

        protected void onSending​(int index)
        Parameters:
        index - the index in the error container
      • onSent

        protected void onSent​(int index)
        Parameters:
        index - the index in the error container
      • onNotSending

        protected void onNotSending​(int index,
                                    java.lang.String serverReply)
        Parameters:
        index - the index in the error container
        serverReply - the reply from the server
      • onException

        protected void onException​(java.lang.Exception exception)
        Action to take on exception
        Parameters:
        exception - the exception
      • finishCancelled

        protected void finishCancelled()
        Action to take when finish cancelled
      • finishComplete

        protected void finishComplete()
        Action to take when finish completed
      • finishWithErroredFiles

        protected void finishWithErroredFiles()
        Action to take when finish completed but with some errors (For example, missing files)
      • executePost

        public void executePost​(java.lang.String sendUrl,
                                java.util.Map<java.lang.String,​java.lang.String> postList)
                         throws HtmlMessengerException
        Execute a post with the given post list. This can be overwritten in order to test error handling without touching QA. The server reply should be non-null, but is otherwise unimportant.
        Parameters:
        sendUrl - the HTTP POST URL
        postList - the form values
        Throws:
        HtmlMessengerException - if POST fails
      • uploadFile

        public void uploadFile​(ErrorContainer errorContainer)
        Upload a single ErrorContainer. This can be overwritten in order to test error handling without touching QA.
        Parameters:
        errorContainer - the error container
      • getStackTrace

        public static java.lang.String getStackTrace​(java.lang.Throwable throwable)
        Return the stack trace from a Throwable.
        Parameters:
        throwable - the Throwable to inspect
        Returns:
        the stack trace