Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import notification #1876

Merged
merged 6 commits into from Dec 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/blitz/src/ome/formats/importer/ImportEvent.java
Expand Up @@ -206,6 +206,15 @@ public FILE_UPLOAD_ERROR(String filename, int fileIndex, int fileTotal,
}
}

public static class FILESET_UPLOAD_PREPARATION extends FILE_UPLOAD_EVENT {
public FILESET_UPLOAD_PREPARATION(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}

public static class FILESET_UPLOAD_START extends FILE_UPLOAD_EVENT {
public FILESET_UPLOAD_START(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Expand Down
3 changes: 3 additions & 0 deletions components/blitz/src/ome/formats/importer/ImportLibrary.java
Expand Up @@ -248,6 +248,9 @@ public ImportProcessPrx createImport(final ImportContainer container)
}
}

notifyObservers(new ImportEvent.FILESET_UPLOAD_PREPARATION(
null, 0, usedFiles.length, null, null, null));

// TODO: allow looser sanitization according to server configuration
final FilePathRestrictions portableRequiredRules =
FilePathRestrictionInstance.getFilePathRestrictions(FilePathRestrictionInstance.WINDOWS_REQUIRED,
Expand Down
Expand Up @@ -36,6 +36,8 @@ public void update(IObservable importLibrary, ImportEvent event)
// send the import results to stdout
// to enable external tools integration
outputGreppableResults(ev);
} else if (event instanceof FILESET_UPLOAD_PREPARATION) {
log.info(event.toLog());
} else if (event instanceof FILESET_UPLOAD_START) {
log.info(event.toLog());
} else if (event instanceof FILESET_UPLOAD_END) {
Expand Down
Expand Up @@ -656,7 +656,7 @@ public void actionPerformed(ActionEvent ev) {
namePane.add(fileNameLabel);
namePane.add(Box.createHorizontalStrut(10));
resultLabel = new JLabel();
statusLabel = new StatusLabel();
statusLabel = new StatusLabel(importable.getFile());
statusLabel.addPropertyChangeListener(this);
image = null;
refButton = cancelButton;
Expand Down
Expand Up @@ -41,7 +41,7 @@
/**
* Reports an error occurred while importing an image.
*
* @author Jean-Marie Burel     
* @author Jean-Marie Burel     
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp;
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
Expand All @@ -50,167 +50,167 @@
* @since 3.0-Beta4
*/
public class ImportException
extends Exception
extends Exception
{

/** Text to indicate that the file, after scanning is not valid. */
public static final String FILE_NOT_VALID_TEXT = "File Not Valid";
/** Text to indicate that the file format is not supported. */
public static final String UNKNOWN_FORMAT_TEXT = "Unknown format";
/** Text to indicate a library is missing. */
public static final String MISSING_LIBRARY_TEXT = "Missing library to "+
"decode the file.";

/** Text to indicate the file is on tape. */
private static final String NETWORK_NAME_TEXT =
"The specified network name is no longer available";
/** Text to indicate the file is on tape. */
private static final String SPACE_TEXT = "No space left on device";

/** Indicates that the compression is not supported.*/
public static int COMPRESSION = 0;
/** Indicates that a library is missing.*/
public static int MISSING_LIBRARY = 1;
/** Indicates that a library is missing.*/
public static int FILE_ON_TAPE = 2;
/** Indicates that there is no space left.*/
public static int NO_SPACE = 3;

/** Indicates that there was a checksum mismatch.*/
public static int CHECKSUM_MISMATCH = 4;
/** Indicates that the file is not valid.*/
public static int NOT_VALID = 5;
/** Indicates that the file format is not supported.*/
public static int UNKNOWN_FORMAT = 6;

/** The status associated to the exception.*/
private int status;
/**
* Returns the message corresponding to the error thrown while importing the
* files.
*
* @param t The exception to handle.
* @return See above.
*/
public static String getImportFailureMessage(Throwable t)
{
String message;
Throwable cause = t.getCause();
if (cause instanceof FormatException) {
message = cause.getMessage();
cause.printStackTrace();
if (message == null) return null;
if (message.contains("ome-xml.jar"))
return "Missing ome-xml.jar required to read OME-TIFF files";
String[] s = message.split(":");
if (s.length > 0) return s[0];
} else if (cause instanceof IOException) {
} else if (cause instanceof omero.ChecksumValidationException) {
return ((omero.ChecksumValidationException) cause).getMessage();
}
return null;
}
/**
* Constructs a new exception with the specified detail message.
*
* @param message Short explanation of the problem.
* @param readerType The type of reader used while trying to import an image.
*/
public ImportException(String message)
{
this(message, null);
if (FILE_NOT_VALID_TEXT.equals(message)) status = NOT_VALID;
else if (UNKNOWN_FORMAT_TEXT.equals(message)) status = UNKNOWN_FORMAT;
else if (MISSING_LIBRARY_TEXT.equals(message))
status = MISSING_LIBRARY;
}
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message Short explanation of the problem.
* @param cause The exception that caused this one to be risen.
* @param readerType The type of reader used while trying to import an mage.
*/
public ImportException(Throwable cause)
{
this((String) getImportFailureMessage(cause), cause);
}
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message Short explanation of the problem.
* @param cause The exception that caused this one to be risen.
* @param readerType The type of reader used while trying to import an image.
*/
public ImportException(String message, Throwable cause)
{
super(message, cause);
if (FILE_NOT_VALID_TEXT.equals(message)) status = NOT_VALID;
/** Text to indicate that the file, after scanning is not valid. */
public static final String FILE_NOT_VALID_TEXT = "File Not Valid";

/** Text to indicate that the file format is not supported. */
public static final String UNKNOWN_FORMAT_TEXT = "Unknown format";

/** Text to indicate a library is missing. */
public static final String MISSING_LIBRARY_TEXT = "Missing library to "+
"decode the file.";

/** Text to indicate the file is on tape. */
private static final String NETWORK_NAME_TEXT =
"The specified network name is no longer available";

/** Text to indicate the file is on tape. */
private static final String SPACE_TEXT = "No space left on device";

/** Indicates that the compression is not supported.*/
public static int COMPRESSION = 0;

/** Indicates that a library is missing.*/
public static int MISSING_LIBRARY = 1;

/** Indicates that a library is missing.*/
public static int FILE_ON_TAPE = 2;

/** Indicates that there is no space left.*/
public static int NO_SPACE = 3;

/** Indicates that there was a checksum mismatch.*/
public static int CHECKSUM_MISMATCH = 4;

/** Indicates that the file is not valid.*/
public static int NOT_VALID = 5;

/** Indicates that the file format is not supported.*/
public static int UNKNOWN_FORMAT = 6;

/** The status associated to the exception.*/
private int status;

/**
* Returns the message corresponding to the error thrown while importing the
* files.
*
* @param t The exception to handle.
* @return See above.
*/
public static String getImportFailureMessage(Throwable t)
{
String message;
Throwable cause = t.getCause();
if (cause instanceof FormatException) {
message = cause.getMessage();
cause.printStackTrace();
if (message == null) return null;
if (message.contains("ome-xml.jar"))
return "Missing ome-xml.jar required to read OME-TIFF files";
String[] s = message.split(":");
if (s.length > 0) return s[0];
} else if (cause instanceof IOException) {

} else if (cause instanceof omero.ChecksumValidationException) {
return ((omero.ChecksumValidationException) cause).getMessage();
}
return null;
}

/**
* Constructs a new exception with the specified detail message.
*
* @param message Short explanation of the problem.
* @param readerType The type of reader used while trying to import an image.
*/
public ImportException(String message)
{
this(message, null);
if (FILE_NOT_VALID_TEXT.equals(message)) status = NOT_VALID;
else if (UNKNOWN_FORMAT_TEXT.equals(message)) status = UNKNOWN_FORMAT;
else if (MISSING_LIBRARY_TEXT.equals(message))
status = MISSING_LIBRARY;
}

/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message Short explanation of the problem.
* @param cause The exception that caused this one to be risen.
* @param readerType The type of reader used while trying to import an mage.
*/
public ImportException(Throwable cause)
{
this((String) getImportFailureMessage(cause), cause);
}

/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message Short explanation of the problem.
* @param cause The exception that caused this one to be risen.
* @param readerType The type of reader used while trying to import an image.
*/
public ImportException(String message, Throwable cause)
{
super(message, cause);
if (FILE_NOT_VALID_TEXT.equals(message)) status = NOT_VALID;
else if (UNKNOWN_FORMAT_TEXT.equals(message)) status = UNKNOWN_FORMAT;
else if (MISSING_LIBRARY_TEXT.equals(message)) status = MISSING_LIBRARY;
else status = -1;
}
/**
* Returns one of the constant defined by this class.
*
* @return See above.
*/
public int getStatus()
{
Throwable cause = getCause();
if (cause == null) return status;
if (cause instanceof UnsupportedCompressionException) {
return COMPRESSION;
} else if (cause instanceof FormatException) {
String message = cause.getMessage();
if (message.contains(MISSING_LIBRARY_TEXT.toLowerCase()))
return MISSING_LIBRARY;
} else if (cause instanceof IOException) {
String message = cause.getMessage();
if (message.contains(NETWORK_NAME_TEXT))
return FILE_ON_TAPE;
} else if (cause.getCause() instanceof IOException) {
String message = cause.getCause().getMessage();
if (message.contains(NETWORK_NAME_TEXT))
return FILE_ON_TAPE;
} else if (cause instanceof ResourceError) {
String message = cause.getMessage();
if (message.contains(SPACE_TEXT))
return NO_SPACE;
} else if (cause instanceof ChecksumValidationException) {
return CHECKSUM_MISMATCH;
}
return status;
}
/**
* Overridden to return the cause of the problem.
* @see Exception#toString()
*/
public String toString()
{
Throwable cause = getCause();
if (cause != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
cause.printStackTrace(pw);
return sw.toString();
}
return super.toString();
}
}

/**
* Returns one of the constant defined by this class.
*
* @return See above.
*/
public int getStatus()
{
Throwable cause = getCause();
if (cause == null) return status;
if (cause instanceof UnsupportedCompressionException) {
return COMPRESSION;
} else if (cause instanceof FormatException) {
String message = cause.getMessage();
if (message.contains(MISSING_LIBRARY_TEXT.toLowerCase()))
return MISSING_LIBRARY;
} else if (cause instanceof IOException) {
String message = cause.getMessage();
if (message.contains(NETWORK_NAME_TEXT))
return FILE_ON_TAPE;
} else if (cause.getCause() instanceof IOException) {
String message = cause.getCause().getMessage();
if (message.contains(NETWORK_NAME_TEXT))
return FILE_ON_TAPE;
} else if (cause instanceof ResourceError) {
String message = cause.getMessage();
if (message.contains(SPACE_TEXT))
return NO_SPACE;
} else if (cause instanceof ChecksumValidationException) {
return CHECKSUM_MISMATCH;
}
return status;
}

/**
* Overridden to return the cause of the problem.
* @see Exception#toString()
*/
public String toString()
{
Throwable cause = getCause();
if (cause != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
cause.printStackTrace(pw);
return sw.toString();
}
return super.toString();
}

}