Package ca.carleton.gcrc.couch.onUpload.conversion

Examples of ca.carleton.gcrc.couch.onUpload.conversion.FileConversionContext


  }

  private void performAnalyzedWork(String docId, String attachmentName) throws Exception {
    JSONObject doc = dd.getDatabase().getDocument(docId);

    FileConversionContext conversionContext =
      new FileConversionContext(doc,dd,attachmentName,mediaDir);
   
    if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
      logger.info("Analysis object not found");

    } else if( false == UploadConstants.UPLOAD_STATUS_ANALYZED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      logger.info("File not in analyzed state");
     
    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();

      if( false == attDescription.isOriginalFileDescriptionAvailable() ) {
        logger.error("Analysis required but original object is not present");
        throw new Exception("Analysis required but original object is not present");
      }
      OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
     
      // Verify if a submitter is specified
      CouchUserContext submitter = attDescription.getSubmitter();

      boolean pluginFound = false;
      String fileClass = attDescription.getFileClass();
      for(FileConversionPlugin fcp : this.fileConverters) {
        if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_ANALYZE) ) {
          fcp.performWork(FileConversionPlugin.WORK_ANALYZE, conversionContext);
          pluginFound = true;
          break;
        }
      }
      if( false == pluginFound ) {
        logger.info("No plugin found to analyze file class: "+fileClass);
       
        // By default, original file is used
        attDescription.setMediaFileName(originalObj.getMediaFileName());
        attDescription.setContentType(originalObj.getContentType());
        attDescription.setEncodingType(originalObj.getEncodingType());
        attDescription.setSize(originalObj.getSize());
      }
     
      // Update document
      if( CouchNunaliitUtils.hasVetterRole(submitter) ) {
        // If submitter has vetter role, then no need to wait for approval
        attDescription.setStatus(UploadConstants.UPLOAD_STATUS_APPROVED);
      } else {
        attDescription.setStatus(UploadConstants.UPLOAD_STATUS_WAITING_FOR_APPROVAL);
      }
      conversionContext.saveDocument();
     
      // Notify that upload is available
      sendContributionApprovalRequest(docId, doc, attachmentName);
    }
  }
View Full Code Here


  }

  private void performApprovedWork(String docId, String attachmentName) throws Exception {
    JSONObject doc = dd.getDatabase().getDocument(docId);
   
    FileConversionContext conversionContext =
      new FileConversionContext(doc,dd,attachmentName,mediaDir);

    if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
      logger.info("Approved object not found");

    } else if( false == UploadConstants.UPLOAD_STATUS_APPROVED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      logger.info("File not in approved state");
     
    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();

      boolean pluginFound = false;
      String fileClass = attDescription.getFileClass();
      for(FileConversionPlugin fcp : this.fileConverters) {
        if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_APPROVE) ) {
          fcp.performWork(FileConversionPlugin.WORK_APPROVE, conversionContext);
          pluginFound = true;
          break;
        }
      }
      if( false == pluginFound ) {
        logger.info("No plugin found for uploaded file class: "+fileClass);
       
        String mimeType = attDescription.getContentType();
        if( null == mimeType ) {
          mimeType = "application/octet-stream";
        }
       
        // By default, upload original file
        conversionContext.uploadFile(
          conversionContext.getAttachmentName()
          ,attDescription.getMediaFile()
          ,mimeType
          );
      }

      // Update status
      attDescription.setStatus(UploadConstants.UPLOAD_STATUS_ATTACHED);
      conversionContext.saveDocument();
    }
  }
View Full Code Here

  }
 
  private void performOrientationWork(String docId, String attachmentName) throws Exception {
    JSONObject doc = dd.getDatabase().getDocument(docId);
   
    FileConversionContext conversionContext =
      new FileConversionContext(doc,dd,attachmentName,mediaDir);

    if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
      logger.info("Approved object not found");

    } else if( false == UploadConstants.UPLOAD_STATUS_ATTACHED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      logger.info("File not in attached state");

    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
      ServerWorkDescriptor serverDescription = attDescription.getServerWorkDescription();
      int orientationLevel = serverDescription.getOrientationLevel();
     
      if( orientationLevel >= UploadConstants.SERVER_ORIENTATION_VALUE ) {
        logger.info("Orientation work already done");
      } else {
        boolean pluginFound = false;
        String fileClass = attDescription.getFileClass();
        for(FileConversionPlugin fcp : this.fileConverters) {
          if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_ORIENT) ) {
            fcp.performWork(FileConversionPlugin.WORK_ORIENT, conversionContext);
            pluginFound = true;
            break;
          }
        }
        if( false == pluginFound ) {
          logger.info("No plugin found for uploaded file class: "+fileClass);
        }
 
        // Update status
        conversionContext.saveDocument();
      }
    }
  }
View Full Code Here

  }
 
  private void performThumbnailWork(String docId, String attachmentName) throws Exception {
    JSONObject doc = dd.getDatabase().getDocument(docId);
   
    FileConversionContext conversionContext =
      new FileConversionContext(doc,dd,attachmentName,mediaDir);

    if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
      logger.info("Approved object not found");

    } else if( false == UploadConstants.UPLOAD_STATUS_ATTACHED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      logger.info("File not in attached state");

    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
      ServerWorkDescriptor serverDescription = attDescription.getServerWorkDescription();
      String thumbnailReference = attDescription.getThumbnailReference();
      int thumbnailLevel = serverDescription.getThumbnailLevel();
     
      if( thumbnailLevel >= UploadConstants.SERVER_THUMBNAIL_VALUE ) {
        logger.info("Orientation work already done");
 
      } else if( null != thumbnailReference ) {
        // This is an instance where the thumbnail was already
        // created but the server work was not noted. This happens
        // with legacy documents.
        // In this case, update server work and save document.
        serverDescription.setThumbnailLevel(UploadConstants.SERVER_THUMBNAIL_VALUE);
       
        // Update status
        conversionContext.saveDocument();
       
        logger.info("Updated server thumbnail status");

      } else {

        boolean pluginFound = false;
        String fileClass = attDescription.getFileClass();
        for(FileConversionPlugin fcp : this.fileConverters) {
          if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_THUMBNAIL) ) {
            fcp.performWork(FileConversionPlugin.WORK_THUMBNAIL, conversionContext);
            pluginFound = true;
           
            logger.info("Created thumbnail");
            break;
          }
        }
        if( false == pluginFound ) {
          logger.info("No plugin found for thumbnail creation, file class: "+fileClass);
        }

        // Update status
        conversionContext.saveDocument();
      }
    }
  }
View Full Code Here

  }
 
  private void performUploadOriginalImageWork(String docId, String attachmentName) throws Exception {
    JSONObject doc = dd.getDatabase().getDocument(docId);
   
    FileConversionContext conversionContext =
      new FileConversionContext(doc,dd,attachmentName,mediaDir);

    if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
      throw new Exception("Approved object not found");

    } else if( false == UploadConstants.UPLOAD_STATUS_ATTACHED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      throw new Exception("File not in attached state");

    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
      WorkDescriptor work = attDescription.getWorkDescription();

      boolean pluginFound = false;
      String fileClass = attDescription.getFileClass();
      for(FileConversionPlugin fcp : this.fileConverters) {
        if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_UPLOAD_ORIGINAL) ) {
          fcp.performWork(FileConversionPlugin.WORK_UPLOAD_ORIGINAL, conversionContext);
          pluginFound = true;
         
          logger.info("Original file uploaded");
          break;
        }
      }
      if( false == pluginFound ) {
        work.setStringAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE, "No plugin found for thumbnail creation, file class: "+fileClass);
      }

      // Update status
      conversionContext.saveDocument();
    }
  }
View Full Code Here

  }
 
  private void performRotateWork(String workType, String docId, String attachmentName) throws Exception {
    JSONObject doc = dd.getDatabase().getDocument(docId);
   
    FileConversionContext conversionContext =
      new FileConversionContext(doc,dd,attachmentName,mediaDir);

    if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
      throw new Exception("Approved object not found");

    } else if( false == UploadConstants.UPLOAD_STATUS_ATTACHED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      throw new Exception("File not in attached state");

    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
      WorkDescriptor work = attDescription.getWorkDescription();

      boolean pluginFound = false;
      String fileClass = attDescription.getFileClass();
      for(FileConversionPlugin fcp : this.fileConverters) {
        if( fcp.handlesFileClass(fileClass, workType) ) {
          fcp.performWork(workType, conversionContext);
          pluginFound = true;
         
          logger.info("Rotation work complete: "+workType);
          break;
        }
      }
      if( false == pluginFound ) {
        work.setStringAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE, "No plugin found for thumbnail creation, file class: "+fileClass);
      }

      // Update status
      conversionContext.saveDocument();
    }
  }
View Full Code Here

                ++counter;
              }
            }
          }

          FileConversionContext conversionContext = new FileConversionContext(doc, dd, attachmentName, mediaDir);
         
          AttachmentDescriptor fileDescription = conversionContext.getAttachmentDescription();
         
          fileDescription.setAttachmentName(attachmentName);
          fileDescription.setStatus(UploadConstants.UPLOAD_STATUS_SUBMITTED);
          fileDescription.setOriginalName(originalName);
          fileDescription.setSubmitterName(userContext.getName());
View Full Code Here

     ){
      throw new Exception("Invalid attachment description");
    }
   
    DocumentDescriptor docDescriptor = attDescription.getDocumentDescriptor();
    FileConversionContext conversionContext = attDescription.getContext();
    OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
    WorkDescriptor work = attDescription.getWorkDescription();
   
    // Figure out media file located on disk
    File originalFile = originalObj.getMediaFile();
    String mimeType = originalObj.getContentType();

    // Is file converted?
    boolean conversionPerformed = attDescription.isConversionPerformed();
    if( false == conversionPerformed ) {
      work.setStringAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE, "No conversion performed. No need to upload.");
      return;
    }
   
    // Are uploaded files allowed?
    if( false == uploadOriginalImages ) {
      work.setStringAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE, "Original file uploads not allowed.");
      return;
    }
   
    // Is it an image?
    String fileClass = attDescription.getFileClass();
    if( false == "image".equals(fileClass) ) {
      work.setStringAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE, "Original file uploads allowed only for images");
      return;
    }
   
    // Does the original file exist?
    if( false == originalFile.exists() || false == originalFile.isFile() ) {
      work.setStringAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE, "Can not find original file from media directory");
      return;
    }
   
    // Create attachment description for original file
    String originalAttachmentName = computeOriginalName(attDescription.getOriginalName());
    AttachmentDescriptor origDescription = docDescriptor.getAttachmentDescription(originalAttachmentName);

    origDescription.setStatus(attDescription.getStatus());
    origDescription.setOriginalName(attDescription.getOriginalName());
    origDescription.setMediaFileName(originalFile.getName());
    origDescription.setSource(attDescription.getAttachmentName());

    origDescription.setSize(originalObj.getSize());
    origDescription.setContentType(originalObj.getContentType());
    origDescription.setEncodingType(originalObj.getEncodingType());

    origDescription.setHeight(originalObj.getHeight());
    origDescription.setWidth(originalObj.getWidth());

    ServerWorkDescriptor serverWork = origDescription.getServerWorkDescription();
    serverWork.setOrientationLevel(UploadConstants.SERVER_ORIENTATION_VALUE);

    // Remember original attachment
    attDescription.setOriginalAttachment(originalAttachmentName);

    // Remember that work was performed
    work.removeAttribute(UploadConstants.UPLOAD_WORK_UPLOAD_ORIGINAL_IMAGE);
   
    // Save before upload
    conversionContext.saveDocument();
   
    // Upload original file
    conversionContext.uploadFile(originalAttachmentName, originalFile, mimeType);
  }
View Full Code Here

//    conversionContext.uploadFile(originalAttachmentName, originalFile, mimeType);
  }

  public void approveFile(AttachmentDescriptor attDescription) throws Exception {
   
    FileConversionContext conversionContext = attDescription.getContext();

    // Upload file
    String attachementName = attDescription.getAttachmentName();
    File file = attDescription.getMediaFile();
    String mimeType = attDescription.getContentType();
    conversionContext.uploadFile(attachementName, file, mimeType);
  }
View Full Code Here

    conversionContext.uploadFile(attachementName, file, mimeType);
  }

  public void orientImage(AttachmentDescriptor attDescription) throws Exception {
    // Get file
    FileConversionContext conversionContext = attDescription.getContext();
    String mimeType = attDescription.getContentType();
    File outputFile = File.createTempFile("original_", attDescription.getMediaFileName());
    conversionContext.downloadFile(attDescription.getAttachmentName(), outputFile);
   
    ImageMagickProcessor imp = ImageMagick.getInfo().getProcessor();
    ImageInfo imageInfo = imp.getImageInfo(outputFile);
   
    if( imageInfo.orientation == ImageInfo.Orientation.REQUIRES_CONVERSION ){
View Full Code Here

TOP

Related Classes of ca.carleton.gcrc.couch.onUpload.conversion.FileConversionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.