Changeset 2951


Ignore:
Timestamp:
Nov 24, 2006, 10:03:18 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Moved overwrite of existing file check to job configuration dialogue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r2931 r2951  
    126126          return;
    127127        }
     128
     129        // checking that we are allowed to overwrite a possibly
     130        // existing file
     131        DbControl dc = sc.newDbControl();
     132        String p = (String)request.getParameterValue(saveAsParameter.getName());
     133        if (p.startsWith("~/"))
     134        {
     135          User user = User.getById(dc, sc.getLoggedInUserId());
     136          p = "~" + user.getLogin() + p.substring(1);
     137        }
     138        Path path = new Path(p, Path.Type.FILE);
     139        File file = File.getByPath(dc, path, true);
     140        if (!(Boolean)request.getParameterValue(overwriteParameter.getName()) &&
     141            file.isInDatabase() && !file.isRemoved())
     142        {
     143          response.setError("File exists: " + p, null);
     144          return;
     145        }
     146
    128147        storeValue(job, request, bioAssaySetParameter);
    129148        storeValue(job, request, saveAsParameter);
     
    569588    try
    570589    {
     590      // Checks for file existence and file replacement is done in
     591      // configure(). Here we either replace an existing file or
     592      // create a new file.
    571593      String p = (String)job.getValue("path");
    572       if (p.startsWith("~/"))
    573       {
    574         User user = User.getById(dc, sc.getLoggedInUserId());
    575         p = "~" + user.getLogin() + p.substring(1);
    576       }
    577594      Path path = new Path(p, Path.Type.FILE);
    578 
    579       boolean overwrite = false;
    580       if ((Boolean)job.getValue("overwrite") != null)
    581       {
    582         overwrite = (Boolean)job.getValue("overwrite");
    583       }
    584 
    585       // Get file and set an error if the file already exist but
    586       // shouldn't be replaced
    587595      File file = File.getByPath(dc, path, true);
    588596      file.setMimeType("text/plain");
    589       if (file.isInDatabase() && !overwrite && !file.isRemoved())
    590       {
    591         throw new ItemAlreadyExistsException("File[path="+path+"]");
    592       }
    593       else if(!file.isInDatabase())
    594       {
    595         dc.saveItem(file);
    596       }
     597      if(!file.isInDatabase()) dc.saveItem(file);
    597598
    598599      BioAssaySet bioassayset=(BioAssaySet)job.getValue("bioAssaySet");
Note: See TracChangeset for help on using the changeset viewer.