private void performAnalyzedWork(Work work) throws Exception {
String attachmentName = work.getAttachmentName();
FileConversionContext conversionContext =
new FileConversionContextImpl(work,documentDbDesign,mediaDir);
DocumentDescriptor docDescriptor = conversionContext.getDocument();
AttachmentDescriptor attDescription = null;
if( docDescriptor.isAttachmentDescriptionAvailable(attachmentName) ){
attDescription = docDescriptor.getAttachmentDescription(attachmentName);
}
if( null == attDescription ) {
logger.info("Analysis object not found");
} else if( false == UploadConstants.UPLOAD_STATUS_ANALYZED.equals( attDescription.getStatus() ) ) {
logger.info("File not in analyzed state");
} else {
if( false == attDescription.isOriginalFileDescriptionAvailable() ) {
logger.error("Analysis required but original object is not present");
throw new Exception("Analysis required but original object is not present");
}
OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
// Verify if a submitter is specified
CouchAuthenticationContext submitter = attDescription.getSubmitter();
boolean pluginFound = false;
String fileClass = attDescription.getFileClass();
for(FileConversionPlugin fcp : this.fileConverters) {
if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_ANALYZE) ) {
fcp.performWork(FileConversionPlugin.WORK_ANALYZE, attDescription);
pluginFound = true;
break;
}
}
if( false == pluginFound ) {
logger.info("No plugin found to analyze file class: "+fileClass);
// By default, original file is used
attDescription.setMediaFileName(originalObj.getMediaFileName());
attDescription.setContentType(originalObj.getContentType());
attDescription.setEncodingType(originalObj.getEncodingType());
attDescription.setSize(originalObj.getSize());
}
// Update document
boolean shouldSendNotification = false;
if( CouchNunaliitUtils.hasVetterRole(submitter, settings.getAtlasName()) ) {
// If submitter has vetter role, then no need to wait for approval
attDescription.setStatus(UploadConstants.UPLOAD_STATUS_APPROVED);
} else {
attDescription.setStatus(UploadConstants.UPLOAD_STATUS_WAITING_FOR_APPROVAL);
shouldSendNotification = true;
}
conversionContext.saveDocument();
// Notify that upload is available
if( shouldSendNotification ) {
sendVettingNotification(work.getDocId(), work.getDocument(), attachmentName);
}