Esempio n. 1
0
 /**
  * Saves uploads to database
  *
  * <p>Note: container view such as AnnouncementView must call update method before calling this
  * save method
  */
 public void save(boolean create) {
   if (!readyToSave) {
     super.error("Upload objects are not ready to save");
     LOG.error(
         "Upload objects are not ready to save, container view failed to call update method");
   }
   // check duplicate uploads especially in edit mode
   if (create) {
     super.getBasebo().persist(uploads);
   } else {
     super.getBasebo().update(uploads);
   }
   readyToSave = false;
 }
Esempio n. 2
0
  /**
   * Handle basic single file upload, but not commit to database Keep file in hard drive, and in
   * memory, generate 32 digits MD5 tag for possible deletion request
   */
  public void upload() {
    if (file != null) {
      try {
        String filepath = super.getUploadFolder() + "/" + file.getFileName();
        filepath = FileUtil.alternativeFilepathIfExists(filepath);
        FileUtil.createFile(filepath);

        file.write(filepath);
        super.info("Succesful", file.getFileName() + " is uploaded.");

        Upload upload = new Upload();
        upload.setDescription(description);
        upload.setFilepath(filepath);
        upload.setTag(Md5Util.getMd5Sum(filepath));
        this.description = null;
        uploads.add(upload);
        // update ui and ready for save in db
      } catch (Exception e) {
        System.out.println(e);
      }
    }
  }
Esempio n. 3
0
 /** Delete all uploads from hard drive, memory and database */
 public void deleteAllFromDB() {
   for (int i = 0; i < uploads.size(); i++) {
     FileUtil.deleteFile(uploads.get(i).getFilepath());
   }
   super.getBasebo().remove(uploads);
 }