){
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);
}