Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#734 closed (fixed)

Routine for uploading demo files should be made more robust and forgiving

Reported by: olle Owned by: olle
Milestone: Proteios SE 2.15.0 Keywords:
Cc:

Description

The routine for uploading demo files currently assumes an active project to have been selected, and that involved directories and files do not exist. It should be updated be more robust and forgiving:

  • If no active project is selected, the user should be instructed to select one.
  • A directory or file should only be created, if not already existing.
  • A message should display how many files were created, and how many were already existing.

Change History (27)

comment:1 Changed 12 years ago by olle

Status: newassigned

Ticket accepted.

comment:2 Changed 12 years ago by olle

Traceability note:

  • Uploading of demo data for gel based projects was latest updated in Ticket #712 (Make "Upload Demo Files" into a context enabled action).

comment:3 Changed 12 years ago by olle

Design discussion.

  • Routine for uploading demo data for gel based projects is managed by class/file action/project/UploadDemoFiles.java in client/servlet/.
  • When checking if a directory or file instance already exists by calling static methods Directory.exists(DbControl dc, Directory directory, String subdirectoryName) or File.exists(DbControl dc, Directory directory, String fileName), respectively, it is important that a previous check has been made if the parent directory for the item already exists, in which case the item should use that parent directory when specified, for the final check to work. In the current case, directories to be created are placed in the project directory for the active project, and the latter directory does always exist, if an active project has been selected. However, the check for existing files may erroneously return false even if a file with the same path exists, if the checked file item was created with a new directory item, when the directory already exists.

comment:4 Changed 12 years ago by olle

Design update:

  • If no active project is selected, the user should be instructed to select one.
  • Before attempting to create a directory or file, a check if the item already exists should be made.
  • If the directory for a file already exists, this directory should be used when specifying the file item before checking if the file already exists.
  • An attempt to create a directory or file should only be made, if the item does not already exist.
  • Contents of an existing file item will not be updated.
  • The DbControl commit() method should only be called, if any items have been created.
  • A message should display how many files were created, and how many were already existing.
  • In order to simplify inspection of the source code, directories should be created in the order they are addressed in the Hits import wizard.

comment:5 Changed 12 years ago by olle

(In [4092]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to be be made more robust and forgiving:

  1. Private instance variables int numUploadedFiles and int numExistingFiles added. Both are initialized to 0.
  1. Protected method void runMe() updated to instruct the user to select an active project, if no active project has been selected. Directories are now created in the order they are addressed in the Hits import wizard. The DbControl commit() method is only called, if any items have been created. A message displays how many files were created, and how many were already existing.
  1. Methods to add files now calls new private method Directory createDirectoryIfNotExisting(Directory dir, DbControl dc) to obtain the directory to use for the file item to add.
  1. Private method void uploadFile(Directory dir, String fileName, FileType type) updated to call new private method boolean createFileIfNotExisting(File file, DbControl dc) to create the file. The file is now only uploaded, if the file does not already exist. Values of new private instance variables int numUploadedFiles and int numExistingFiles are updated.
  1. New private method Directory createDirectoryIfNotExisting(Directory dir, DbControl dc) added. It creates a directory if not existing, and returns the the functional directory instance, i.e. the created directory or the already existing one.
  1. New private method createFileIfNotExisting(File file, DbControl dc) added. It creates the file if not existing. True is returned if the file is created, false if it already exists.

comment:6 Changed 12 years ago by olle

Tests of updated routine for uploading demo files.

  • The routine was called without selecting an active project. A message was displayed instructing the user to select an active project to upload demo files to.
  • The routine was called to upload demo files to an active project for which a complete set of demo files already had been uploaded. A message was displayed that 0 demo files were uploaded, and 5 files already existing, which was correct.
  • The routine was called to upload demo files to an active project for which demo files previously had been uploaded, but one directory containing two files had been completely deleted, one directory had been left empty with its single file deleted, and one directory had been left with only one of its originally two files. The missing directory was created, and the missing 4 files were created and uploaded in the correct directories. A message was displayed that 4 demo files were uploaded, and 1 file already existing.

In all cases the behavior of the routine was the desired one, so the tests were passed with successful result.

comment:7 Changed 12 years ago by olle

Resolution: fixed
Status: assignedclosed

Ticket closed as the desired functionality has been added.

comment:8 Changed 12 years ago by olle

Resolution: fixed
Status: closedreopened

Ticket reopened in order to improve flexibility of the code regarding what file descriptions are set for different files.

comment:9 Changed 12 years ago by olle

Design update:

  • Currently a fixed file description is set in private method void uploadFile(Directory dir, String fileName, FileType type) in class UploadDemoFiles. Principally, it is not a good idea that a convenience routine like uploadFile(...) sets specific information like this, since it is used for several types of files (at present robot result files, peaklist files, and Mascot result files). This method should therefore be updated to take a new argument String description, which value will be used for the description of the uploaded file, unless the argument value is null. The methods calling uploadFile(...) should be updated to initially set the description to the same string as previously. This update makes it possible to use different file descriptions for different files, which might be used in the future to set descriptions that are more specific and detailed than now.

comment:10 Changed 12 years ago by olle

(In [4111]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to allow different file descriptions for different uploaded files:

  1. Private method uploadFile(Directory dir, String fileName, FileType type) updated to take a new argument String description, which value will be used for the description of the uploaded file, unless the argument value is null, in which case no description will be set.
  1. Private methods void addRobotFiles(Directory parentDir), void addPeakListFiles(Directory parentDir), and void addMascotFiles(Directory parentDir) updated to call uploadFile(...) with the new argument, and set the file description to the same string as used previously.

comment:11 Changed 12 years ago by olle

Design update:

  • Uploading of demo files for gel-based projects currently sets the same file description "Use external plate id 18115042KAISA4 to import" for all uploaded files, whether robot result files, peaklist files, or Mascot result files, although the description is only relevant for import of peaklist files, where an external plate id is selected. File descriptions for the other type of demo files should therefore be updated to specify key data and relationship to other files, in order to clarify traceability (the information is contained in the files, but is currently not easily accessable). The file descriptions should be updated to be as follows (unchanged for peaklist files):

    robotResult.xml: "SHW result for gel external id p3399, p3400 for external plate id 18115042KAISA4"

    qtof_A2.xml: "Use external plate id 18115042KAISA4 to import"
    qtof_A3.xml: "Use external plate id 18115042KAISA4 to import"

    result1.xml: "Mascot results for peaklist file qtof_A2.xml"
    result2.xml: "Mascot results for peaklist file qtof_A3.xml"

comment:12 Changed 12 years ago by olle

(In [4114]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to set more informative file descriptions for robot result and Mascot result demo files:

  1. Private method void addRobotFiles(Directory parentDir) updated to set a file description indicating what gel external id values are covered, as well as the external plate id.
  1. Private method void addMascotFiles(Directory parentDir) updated to set file descriptions indicating what peaklist file was used for a Mascot search.

comment:13 Changed 12 years ago by olle

Traceability note:

  • Ticket #739 (Improved support for viewing text-based files) allows files with MIME type "application/xml" to be opened in the browser from the file properties form, if the file size is not too large. Since currently all demo files for gel-based projects are in XML format, there is now compelling reason for setting the MIME type directly when they are uploaded, even though it is possible to set the MIME type for already uploaded files, e.g. by use of extensions.

comment:14 Changed 12 years ago by olle

Design update:

  • Uploading of demo files for gel-based projects should be updated to allow setting a MIME type for the uploaded files.
  • Uploaded demo files in XML format should be set to MIME type "application/xml".

comment:15 Changed 12 years ago by olle

(In [4119]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to support setting MIME type for uploaded files:

  1. Private method void uploadFile(Directory dir, String fileName, FileType type, String description) updated to take a new argument String mimeType, which value will be used for the MIME type of the uploaded file, unless the argument value is null, in which case no MIME type will be set. The new argument String mimeType will be inserted between existing arguments FileType type and String description, since the MIME type is more related to the file type than the file description.
  1. Private methods void addRobotFiles(Directory parentDir), void addPeakListFiles(Directory parentDir), and addMascotFiles(Directory parentDir) updated to set the MIME type for the uploaded files to "application/xml" when calling private method uploadFile(...), since all the uploaded files are in XML format.

comment:16 Changed 12 years ago by olle

Resolution: fixed
Status: reopenedclosed

Ticket closed as the code has been updated to allow setting of individual descriptions and MIME types for the uploaded files.

comment:17 Changed 12 years ago by olle

Resolution: fixed
Status: closedreopened

Ticket reopened to allow source files to be placed in different directories.

comment:18 Changed 12 years ago by olle

Design update:

  • Currently source files are assumed to be located in the same directory on the server, when the URL is created. This should be updated to allow source files to be placed in different directories.
  • Private method URL getFile(String fileName) should be updated with a new initial argument String dirUrlPath, and should change name to the more appropriate fetchFileUrl(...), since method names starting with "get" should preferably be reserved for accessor methods for instance variables. The updated private method will therefore be URL fetchFileUrl(String dirUrlPath, String fileName).
  • Private method void uploadFile(Directory dir, String fileName, ...) should be updated with a new argument String sourceDirUrlPath, placed after the target directory and source filename: void uploadFile(Directory dir, String sourceDirUrlPath, String fileName, ...). The value of the new argument should be used when calling the updated method fetchFileUrl(String dirUrlPath, String fileName) to obtain a URL to upload the file from.
  • Methods calling private method void uploadFile(...) should be updated to supply the new second argument String sourceDirUrlPath when calling the method.

comment:19 Changed 12 years ago by olle

(In [4130]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to allow source files to be placed in different directories on the server:

  1. Private method URL getFile(String fileName) updated with a new initial argument String dirUrlPath, and name changed to the more appropriate fetchFileUrl(...), since method names starting with "get" should preferably be reserved for accessor methods for instance variables. The updated private method will therefore be URL fetchFileUrl(String dirUrlPath, String fileName).
  1. Private method void uploadFile(Directory dir, String fileName, ...) updated with a new argument String sourceDirUrlPath placed after the target directory and source filename: void uploadFile(Directory dir, String sourceDirUrlPath, String fileName, ...). The value of the new argument is used when calling the updated method fetchFileUrl(String dirUrlPath, String fileName) to obtain a URL to upload the file from.
  1. Methods calling private method void uploadFile(...) updated to supply the new second argument String sourceDirUrlPath when calling the method.

comment:20 Changed 12 years ago by olle

Design update:

  • Class UploadDemoFiles that currently manages uploading of demo files is concerned with gel-based projects. To avoid confusion when uploading of demo files for non gel-based projects is also supported (introduced in Ticket #733 "Add a demo project extension for non-gel based projects"), the file context label displayed in the file extensions menu should be changed from "Upload demo files" to "Upload demo files for gel-based project" for class UploadDemoFiles.

comment:21 Changed 12 years ago by olle

(In [4131]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated in file context label:

  1. Public method List<Context> listContexts() updated by changing the file context label displayed in the file extensions menu from "Upload demo files" to "Upload demo files for gel-based project".

comment:22 Changed 12 years ago by olle

Resolution: fixed
Status: reopenedclosed

Ticket closed as the code has been updated to allow source files to be placed in different directories on the server, and the file context label has been updated to state what type of project the demo files are intended for (gel-based or non gel-based).

comment:23 Changed 12 years ago by olle

(In [4132]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to only set file type of uploaded file if the former differs from null:

  1. Private method void uploadFile(Directory dir, String sourceDirUrlPath, String fileName, FileType type, String mimeType, String description) updated to only set file type of uploaded file if the former differs from null.

comment:24 Changed 12 years ago by olle

(In [4134]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to produce message with better grammar regarding singular and plural:

  1. Protected method void runMe() updated to call new private convenience routine String itemWord(String singular, int number) to use either word "file" or "files", depending on the number of file items.
  1. New private convenience routine String itemWord(String singular, int number) added. It creates singular or plural version of item word, provided plural can simply be created by appending an 's'.

comment:25 Changed 12 years ago by olle

(In [4135]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to use BaseException instead of ActionException, since this will simplify transition to uploading files via a job, as se.lu.thep.waf.ActionException in api/waf/ is not available to plug-in classes, while org.proteios.core.BaseException in api/core/ is.

comment:26 Changed 12 years ago by olle

(In [4136]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to fix bug in log statement that led to NullPointerException when file type of uploaded file was equal to null:

  1. Private method void uploadFile(Directory dir, String sourceDirUrlPath, String fileName, FileType type, String mimeType, String description) updated to fix bug in log statement that led to NullPointerException when file type of uploaded file was equal to null

comment:27 Changed 12 years ago by olle

(In [4137]) Refs #734. Class/file action/project/UploadDemoFiles.java in client/servlet/ updated to fix more bugs in log statements that led to NullPointerException when file type of uploaded file was equal to null:

  1. Private method void uploadFile(Directory dir, String sourceDirUrlPath, String fileName, FileType type, String mimeType, String description) updated to fix more bugs in log statements that led to NullPointerException when file type of uploaded file was equal to null
Note: See TracTickets for help on using tickets.