Package ome.formats.importer.util
Class ErrorHandler
- java.lang.Object
-
- ome.formats.importer.util.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 withsendErrors()
. Subclasses will get a chance to handle allImportEvent
instances, but should try not to duplicate handling.- Since:
- Beta4.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ErrorHandler.EXCEPTION_EVENT
static class
ErrorHandler.FILE_EXCEPTION
ErrorHandler.FILE_EXCEPTION
s are thrown any time in the context of a particular file and otherwise unspecified exception takes place.static class
ErrorHandler.INTERNAL_EXCEPTION
static class
ErrorHandler.MISSING_LIBRARY
AErrorHandler.FILE_EXCEPTION
caused specifically by some library (native or otherwise) not being installed locally.static class
ErrorHandler.UNKNOWN_FORMAT
UnlikeErrorHandler.FILE_EXCEPTION
, UNKNOWN_FORMAT does not have a reader since bio-formats is telling us that it does not know how to handle the given file.static class
ErrorHandler.UNREADABLE_FILE
Similar toErrorHandler.UNKNOWN_FORMAT
UNREADABLE_FILE specifies that the file which is being accessed is unreadable (does not exist or canRead is false), so if the user is specifically saying that the file should be imported, there may be some underlying issue.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
cancelUploads
protected ImportConfig
config
protected java.util.List<ErrorContainer>
errors
boolean
fileUploadErrors
protected java.util.Map<java.lang.String,ImportContainer>
icMap
Host information about the file and its corresponding import candidate.protected org.slf4j.Logger
log
protected java.util.List<IObserver>
observers
protected boolean
sendFiles
protected boolean
sendLogs
protected int
totalErrors
-
Constructor Summary
Constructors Constructor Description ErrorHandler(ImportConfig config)
Initialize
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 arrayboolean
addObserver(IObserver object)
Add observer for notificationprotected void
clearErrors(int index)
boolean
deleteObserver(IObserver object)
Delete observerint
errorCount()
void
executePost(java.lang.String sendUrl, java.util.Map<java.lang.String,java.lang.String> postList)
Execute a post with the given post list.protected void
finishCancelled()
Action to take when finish cancelledprotected void
finishComplete()
Action to take when finish completedprotected void
finishWithErroredFiles()
Action to take when finish completed but with some errors (For example, missing files)static java.lang.String
getStackTrace(java.lang.Throwable throwable)
Return the stack trace from aThrowable
.protected boolean
isSend(int index)
Check if files need sending at error container indexvoid
notifyObservers(ImportEvent event)
Notify observers of eventprotected void
onAddError(ErrorContainer errorContainer, java.lang.String message)
Action to take on adding an error to containerprotected void
onCancel()
action to take on cancelprotected void
onException(java.lang.Exception exception)
Action to take on exceptionprotected void
onNotSending(int index, java.lang.String serverReply)
protected void
onSending(int index)
protected void
onSent(int index)
protected abstract void
onUpdate(IObservable importLibrary, ImportEvent event)
abstract on update methodprotected void
sendErrors()
Send existing errors in ErrorContainer array to servervoid
update(IObservable observable, ImportEvent event)
Update observable on eventvoid
uploadFile(ErrorContainer errorContainer)
Upload a singleErrorContainer
.
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
observers
protected final java.util.List<IObserver> observers
-
errors
protected final java.util.List<ErrorContainer> errors
-
config
protected final ImportConfig config
-
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
-
update
public final void update(IObservable observable, ImportEvent event)
Description copied from interface:IObserver
Update observable on event
-
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 libraryevent
- - 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 thrownfile
- - head file for errorfiles
- - all files in import collectionreaderType
- - 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 interfaceIObservable
- 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 interfaceIObservable
- 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 interfaceIObservable
- 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 containermessage
- - 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 containerserverReply
- 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 URLpostList
- the form values- Throws:
HtmlMessengerException
- if POST fails
-
uploadFile
public void uploadFile(ErrorContainer errorContainer)
Upload a singleErrorContainer
. 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 aThrowable
.- Parameters:
throwable
- theThrowable
to inspect- Returns:
- the stack trace
-
-