}
}
public void analyzeFile(FileConversionContext conversionContext) throws Exception {
AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
CouchUserContext submitter = attDescription.getSubmitter();
// Figure out media file located on disk
File originalFile = originalObj.getMediaFile();
String mimeType = originalObj.getContentType();
// Perform conversion(s)
MultimediaConversionRequest request = new MultimediaConversionRequest();
request.setInFile( originalFile );
request.setThumbnailRequested(true);
request.setProgress( new UploadProgressAdaptor() );
MultimediaClass mmClass = MimeUtils.getMultimediaClassFromMimeType(mimeType);
if( MultimediaClass.VIDEO == mmClass ) {
// For video file, convert to appropriate file type
mmConverter.convertVideo(request);
} else if( MultimediaClass.AUDIO == mmClass ) {
// For audio file, convert to appropriate file type
mmConverter.convertAudio(request);
} else if( MultimediaClass.IMAGE == mmClass ) {
// For image file, convert to appropriate file type
mmConverter.convertImage(request);
} else {
throw new Exception("Unknown multimedia class: "+mmClass);
}
// Compute a new name for the attachment, to reflect the conversion
{
String expectedExtension = "";
if( MultimediaClass.VIDEO == mmClass ){
expectedExtension = "mp4";
} else if( MultimediaClass.AUDIO == mmClass ){
expectedExtension = "mp3";
} else if( MultimediaClass.IMAGE == mmClass ){
expectedExtension = "jpeg";
}
String currentPrefix = attDescription.getAttachmentName();
String currentExtension = "";
{
int index = currentPrefix.lastIndexOf('.');
if( index > 0 ){
currentExtension = currentPrefix.substring(index+1);
currentPrefix = currentPrefix.substring(0, index);
}
}
if( false == currentExtension.equals(expectedExtension) ){
// Must rename
String newAttachmentName = currentPrefix + "." + expectedExtension;
// Check collision
int index = 0;
while( conversionContext.isAttachmentDescriptionAvailable(newAttachmentName) ){
newAttachmentName = currentPrefix + "_" + index + "." + expectedExtension;
++index;
}
attDescription.renameAttachmentTo(newAttachmentName);
}
}
// Report original size
if( request.getInHeight() != 0 && request.getInWidth() != 0 ) {
originalObj.setHeight( request.getInHeight() );
originalObj.setWidth( request.getInWidth() );
}
// Report converted object
{
File convertedFile = request.getOutFile();
SystemFile convertedSf = SystemFile.getSystemFile(convertedFile);
if( CouchNunaliitUtils.hasVetterRole(submitter, atlasName) ) {
attDescription.setStatus(UploadConstants.UPLOAD_STATUS_APPROVED);
} else {
attDescription.setStatus(UploadConstants.UPLOAD_STATUS_WAITING_FOR_APPROVAL);
}
attDescription.setConversionPerformed(request.isConversionPerformed());
attDescription.setMediaFileName(convertedFile.getName());
attDescription.setSize(convertedFile.length());
attDescription.setContentType(convertedSf.getMimeType());
attDescription.setEncodingType(convertedSf.getMimeEncoding());
if( request.getOutHeight() != 0 && request.getOutWidth() != 0 ) {
attDescription.setHeight(request.getOutHeight());
attDescription.setWidth(request.getOutWidth());
}
ServerWorkDescriptor serverWork = attDescription.getServerWorkDescription();
serverWork.setOrientationLevel(UploadConstants.SERVER_ORIENTATION_VALUE);
}
// Report thumbnail object
if( request.isThumbnailCreated() ) {
File thumbFile = request.getThumbnailFile();
SystemFile thumbSf = SystemFile.getSystemFile(thumbFile);
String thumbnailAttachmentName = computeThumbnailName(attDescription.getAttachmentName(),"jpeg");
AttachmentDescriptor thumbnailObj = conversionContext.getAttachmentDescription(thumbnailAttachmentName);
if( CouchNunaliitUtils.hasVetterRole(submitter, atlasName) ) {
thumbnailObj.setStatus(UploadConstants.UPLOAD_STATUS_APPROVED);
} else {
thumbnailObj.setStatus(UploadConstants.UPLOAD_STATUS_WAITING_FOR_APPROVAL);
}
thumbnailObj.setFileClass("image");
thumbnailObj.setOriginalName(attDescription.getOriginalName());
thumbnailObj.setMediaFileName(thumbFile.getName());
thumbnailObj.setSource(attDescription.getAttachmentName());
thumbnailObj.setSize(thumbFile.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);
}
// Report original file
if( request.isConversionPerformed() ) {
// Original is not needed if no conversion performed
String fileClass = attDescription.getFileClass();
if( "image".equals(fileClass) && uploadOriginalImages ) {
String originalAttachmentName = computeOriginalName(attDescription.getOriginalName());
AttachmentDescriptor origDescription = conversionContext.getAttachmentDescription(originalAttachmentName);
if( CouchNunaliitUtils.hasVetterRole(submitter, atlasName) ) {
origDescription.setStatus(UploadConstants.UPLOAD_STATUS_APPROVED);
} else {
origDescription.setStatus(UploadConstants.UPLOAD_STATUS_WAITING_FOR_APPROVAL);
}
origDescription.setContentType(attDescription.getContentType());
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);
attDescription.setOriginalAttachment(originalAttachmentName);