if (appId == null || file == null) {
log.warn("The document upload file failed to save, it had null input.");
return null;
}
Application application = applicationDao.retrieveById(appId);
if (application == null) {
log.warn("Unable to retrieve Application - document save failed.");
return null;
}
if (!contentTypeService.isValidUpload(file.getContentType())){
log.warn("Invalid filetype for upload: "+file.getContentType());
return null;
}
Document doc = new Document();
String fileFullName;
if(overrideFilename != null) {
fileFullName = overrideFilename;
} else {
fileFullName = file.getOriginalFilename();
}
doc.setApplication(application);
doc.setName(getFileName(fileFullName));
doc.setType(getFileType(fileFullName));
if(!doc.getType().equals("json")){
doc.setContentType(contentTypeService.translateContentType(file.getContentType()));
}else{
doc.setContentType(contentTypeService.translateContentType("json"));
}
try {
Blob blob = new SerialBlob(file.getBytes());
doc.setFile(blob);
List<Document> appDocs = application.getDocuments();
if (appDocs == null) {
appDocs = list();
}
appDocs.add(doc);