}
private void performSubmittedWork(String docId, String attachmentName) throws Exception {
JSONObject doc = dd.getDatabase().getDocument(docId);
FileConversionContext conversionContext =
new FileConversionContext(doc,dd,attachmentName,mediaDir);
if( false == conversionContext.isAttachmentDescriptionAvailable() ) {
logger.info("Submission can not be found");
} 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");
}
File file = originalObj.getMediaFile();
if( null == file ){
logger.error("No media file reported");
throw new Exception("No media file reported");
}
if( false == file.exists() || false == file.isFile() ){
logger.error(""+file.getAbsolutePath()+" is not a file.");
throw new Exception(""+file.getAbsolutePath()+" is not a file.");
};
// Set file size
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();
}
}