// 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( null != request.getOutFile() ){
File convertedFile = request.getOutFile();
String name = convertedFile.getName();
int index = name.lastIndexOf('.');
if( index > 0 ){
expectedExtension = name.substring(index+1);
}
}
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 thumbExtension = "";
{
String name = thumbFile.getName();
int index = name.lastIndexOf('.');
if( index > 0 ){
thumbExtension = name.substring(index+1);
}
}
String thumbnailAttachmentName = computeThumbnailName(attDescription.getAttachmentName(),thumbExtension);
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());