throw new Exception("Plugin does not support work: "+work);
}
}
public void analyzeFile(AttachmentDescriptor attDescription) throws Exception {
DocumentDescriptor docDescriptor = attDescription.getDocumentDescriptor();
OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
CouchAuthenticationContext 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( 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( docDescriptor.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 EXIF data
ExifData exifData = request.getExifData();
if( null != exifData
&& exifData.getSize() > 0 ) {
ExifDataDescriptor exifDescriptor = attDescription.getExifDataDescription();
for(String key : exifData.getKeys()){
String value = exifData.getRawData(key);
if( null != value ){
value = value.trim();
if( false == "".equals(value) ){
exifDescriptor.addData(key, value);
}
}
}
// Create geometry if one is present in the EXIF
// data and none is defined in the document
if( exifData.containsLongLat()
&& false == docDescriptor.isGeometryDescriptionAvailable() ) {
Point point = new Point(exifData.computeLong(),exifData.computeLat());
MultiPoint mp = new MultiPoint();
mp.addPoint(point);
GeometryDescriptor geomDesc = docDescriptor.getGeometryDescription();
geomDesc.setGeometry(mp);
}
}
// 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 = docDescriptor.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 = docDescriptor.getAttachmentDescription(originalAttachmentName);
if( CouchNunaliitUtils.hasVetterRole(submitter, atlasName) ) {
origDescription.setStatus(UploadConstants.UPLOAD_STATUS_APPROVED);
} else {
origDescription.setStatus(UploadConstants.UPLOAD_STATUS_WAITING_FOR_APPROVAL);