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

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


   
    if( false == conversionContext.isAttachmentDescriptionAvailable() ){
      throw new Exception("Invalid attachment description");
    }
   
    AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
   
    if( false == attDescription.isOriginalFileDescriptionAvailable()
     || false == attDescription.isWorkDescriptionAvailable()
     ){
      throw new Exception("Invalid attachment description");
    }
   
//    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 attached?
    if( false == attDescription.getStatus().equals(UploadConstants.UPLOAD_STATUS_ATTACHED) ) {
      work.setStringAttribute(workType, "Media file is not attached and conversion can not be performed.");
      return;
    }
   
    // Is it an image or video?
    String fileClass = attDescription.getFileClass();
    if( false == "image".equals(fileClass)
     && false == "video".equals(fileClass) ) {
      work.setStringAttribute(workType, "Media file must be imgage or video.");
      return;
    }
View Full Code Here


  }

  public void approveFile(FileConversionContext conversionContext) throws Exception {
    // Upload file
    String attachementName = conversionContext.getAttachmentName();
    AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
    File file = attDescription.getMediaFile();
    String mimeType = conversionContext.getAttachmentDescription().getContentType();
    conversionContext.uploadFile(attachementName, file, mimeType);
  }
View Full Code Here

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

  public void orientImage(FileConversionContext conversionContext) throws Exception {
    // Get file
    AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
    String mimeType = attDescription.getContentType();
    File outputFile = File.createTempFile("original_", attDescription.getMediaFileName());
    conversionContext.downloadFile(outputFile);
   
    ImageMagickProcessor imp = ImageMagick.getInfo().getProcessor();
    ImageInfo imageInfo = imp.getImageInfo(outputFile);
   
    if( imageInfo.orientation == ImageInfo.Orientation.REQUIRES_CONVERSION ){
      File convertedFile = File.createTempFile("oriented_", attDescription.getMediaFileName());
      imp.reorientImage(outputFile, convertedFile);
      attDescription.uploadFile(convertedFile, mimeType);
    }

    ServerWorkDescriptor serverWork = attDescription.getServerWorkDescription();
    serverWork.setOrientationLevel(UploadConstants.SERVER_ORIENTATION_VALUE);
  }
View Full Code Here

    serverWork.setOrientationLevel(UploadConstants.SERVER_ORIENTATION_VALUE);
  }

  public void createThumbnail(FileConversionContext conversionContext) throws Exception {
    // Get file
    AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
    String mimeType = attDescription.getContentType();
    File inFile = File.createTempFile("original_", attDescription.getMediaFileName());
    conversionContext.downloadFile(inFile);

    File outFile = File.createTempFile("thumb_", attDescription.getMediaFileName());
   
    // Perform thumbnail
    MultimediaConversionRequest request = new MultimediaConversionRequest();
    request.setInFile( inFile );
    request.setThumbnailFile(outFile);
    request.setThumbnailRequested(true);
   
    MultimediaClass mmClass = MimeUtils.getMultimediaClassFromMimeType(mimeType);
    if( MultimediaClass.IMAGE == mmClass ) {
      // For image file, convert to appropriate file type
      mmConverter.createImageThumbnail(request);
     
    } else {
      throw new Exception("Unknown multimedia class: "+mmClass);
    }

    // Compute attachment name
    SystemFile thumbSf = SystemFile.getSystemFile(outFile);
    String thumbnailAttachmentName = computeThumbnailName(attDescription.getAttachmentName(),"jpeg");
   
    // Upload thumbnail
    String thumbMimeType = thumbSf.getMimeType();
    conversionContext.uploadFile(thumbnailAttachmentName, outFile, thumbMimeType);
   
    // Report thumbnail object
    if( request.isThumbnailCreated() ) {
     
      AttachmentDescriptor thumbnailObj = conversionContext.getAttachmentDescription(thumbnailAttachmentName);

      thumbnailObj.setStatus(UploadConstants.UPLOAD_STATUS_ATTACHED);
      thumbnailObj.setFileClass("image");
      thumbnailObj.setOriginalName(attDescription.getOriginalName());
      thumbnailObj.setSource(attDescription.getAttachmentName());

      thumbnailObj.setSize(outFile.length());
      thumbnailObj.setContentType(thumbSf.getMimeType());
      thumbnailObj.setEncodingType(thumbSf.getMimeEncoding());

      if( request.getThumbnailHeight() != 0
       && request.getThumbnailWidth() != 0
       ) {
        thumbnailObj.setHeight(request.getThumbnailHeight());
        thumbnailObj.setWidth(request.getThumbnailWidth());
      }
     
      attDescription.setThumbnailReference(thumbnailAttachmentName);
    }
View Full Code Here

    } else if( false == UploadConstants.UPLOAD_STATUS_SUBMITTED.equals( conversionContext.getAttachmentDescription().getStatus() ) ) {
      logger.info("File not in submit state");
     
    } else {
      AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
      OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
     
      if( null == originalObj) {
        logger.error("Submission does not contain original");
        throw new Exception("Submission does not contain original");
     

      // Set file size
      File file = originalObj.getMediaFile();
      long fileSize = file.length();
      originalObj.setSize(fileSize);

      // Mime type, encoding type and file class
      boolean pluginFound = false;
      String mimeType = null;
      String mimeEncoding = null;
      String fileClass = null;
      for(FileConversionPlugin fcp : this.fileConverters) {
        FileConversionMetaData md = fcp.getFileMetaData(file);
        if( md.isFileConvertable() ) {
          mimeType = md.getMimeType();
          fileClass = md.getFileClass();
          mimeEncoding = md.getMimeEncoding();
 
          pluginFound = true;
          break;
        }
      }
      if( false == pluginFound ) {
        logger.info("No plugin found for uploaded file");
       
        SystemFile sf = SystemFile.getSystemFile(file);
        mimeType = sf.getMimeType();
        mimeEncoding = sf.getMimeEncoding();
      }
      if( null != mimeType ) {
        originalObj.setContentType(mimeType);
      }
      if( null != mimeEncoding ) {
        originalObj.setEncodingType(mimeEncoding);
      }
      if( null != fileClass ){
        attDescription.setFileClass(fileClass);
      }

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

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

      // Verify that a file is attached to the document
      if( false == attDescription.isFilePresent() ) {
        // Invalid state
        throw new Exception("Invalid state. A file must be present for submitted_inline");
      }
     
      // Download file
      File outputFile = File.createTempFile("inline", "", mediaDir);
      conversionContext.downloadFile(outputFile);
     
      // Create an original structure to point to the file in the
      // media dir. This way, when we go to "submitted" state, we will
      // be ready.
      OriginalFileDescriptor originalDescription = attDescription.getOriginalFileDescription();
      originalDescription.setMediaFileName(outputFile.getName());

      // Delete current attachment
      attDescription.removeFile();

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

    } 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

    } 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

    } 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;
View Full Code Here

    }
  }

  public void analyzeFile(FileConversionContext conversionContext) throws Exception {
    // No conversion required.
    AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
    OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
    attDescription.setSize(originalObj.getSize());
    attDescription.setContentType(originalObj.getContentType());
    attDescription.setEncodingType(originalObj.getEncodingType());
    attDescription.setMediaFileName(originalObj.getMediaFileName());
  }
View Full Code Here

TOP

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

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.