use of org.kuali.kfs.krad.bo.Attachment in project cu-kfs by CU-CommunityApps.
the class CuAttachmentDaoOjb method getAttachmentByAttachmentId.
@Override
public Attachment getAttachmentByAttachmentId(String attachmentIdentifier) {
Criteria crit = new Criteria();
crit.addEqualTo(CUKRADPropertyConstants.ATTACHMENT_IDENTIFIER, attachmentIdentifier);
return (Attachment) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Attachment.class, crit));
}
use of org.kuali.kfs.krad.bo.Attachment in project cu-kfs by CU-CommunityApps.
the class VendorBatchServiceImpl method loadDocumentAttachments.
/*
* add 'attachments' to vendor document. attachment file names is in input csv file.
* Attachment files are upload to "staging.directory"/vendorBatch/attachment folder
*/
private void loadDocumentAttachments(Document document, List<String> attachments) {
String attachmentsPath = new File(batchInputFileTypes.get(0).getDirectoryPath()).toString() + "/attachment";
for (String attachment : attachments) {
Note note = new Note();
note.setNoteText("Procurement vendor batch process - add attachment");
note.setRemoteObjectIdentifier(document.getObjectId());
note.setAuthorUniversalIdentifier(getSystemUser().getPrincipalId());
note.setNoteTypeCode(KFSConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
note.setNotePostedTimestampToCurrent();
// attempt to load file
String fileName = attachmentsPath + "/" + attachment;
File attachmentFile = new File(fileName);
if (!attachmentFile.exists()) {
continue;
}
try {
FileInputStream fileInputStream = new FileInputStream(fileName);
Integer fileSize = Integer.parseInt(Long.toString(attachmentFile.length()));
// TODO : Files.probeContentType is supported by java 7. Not sure if this will be an issue
String mimeTypeCode = getMimeTypeFromAttachmentFile(attachmentFile);
// TODO : urlconnection is working for java 7 and under, but it return null for 'docx/pptx/xslx'
// String type = URLConnection.guessContentTypeFromName(attachmentFile.getAbsolutePath());
LOG.info("Mime type " + fileName + " " + mimeTypeCode);
String attachType = KFSConstants.EMPTY_STRING;
Attachment noteAttachment = attachmentService.createAttachment(document.getDocumentHeader(), attachment, mimeTypeCode, fileSize, fileInputStream, attachType);
note.addAttachment(noteAttachment);
document.addNote(note);
} catch (FileNotFoundException e) {
continue;
} catch (IOException e1) {
throw new RuntimeException("Unable to create attachment for File: " + fileName, e1);
}
}
}
use of org.kuali.kfs.krad.bo.Attachment in project cu-kfs by CU-CommunityApps.
the class IWantDocumentFeedServiceImpl method loadDocumentAttachments.
/**
* Adds attachments to the I Want document.
* @param document
* @param attachments
*/
private void loadDocumentAttachments(IWantDocument document, List<BatchIWantAttachment> attachments, String incomingFileName) {
String attachmentsPath = new File(iWantDocumentInputFileType.getDirectoryPath()).toString() + "/attachment/";
for (BatchIWantAttachment attachment : attachments) {
Note note = new Note();
note.setNoteText(attachment.getAttachmentType());
note.setRemoteObjectIdentifier(document.getObjectId());
note.setAuthorUniversalIdentifier(document.getDocumentHeader().getWorkflowDocument().getPrincipalId());
note.setNoteTypeCode(KFSConstants.NoteTypeEnum.DOCUMENT_HEADER_NOTE_TYPE.getCode());
note.setNotePostedTimestampToCurrent();
// attempt to load file
String fileName = attachmentsPath + "/" + attachment.getAttachmentFileName();
File attachmentFile = new File(fileName);
if (!attachmentFile.exists()) {
continue;
}
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(fileName);
Integer fileSize = Integer.parseInt(Long.toString(attachmentFile.length()));
String mimeTypeCode = attachment.getAttachmentMimeTypeCode();
String fileExtension = "." + StringUtils.substringAfterLast(fileName, ".");
if (StringUtils.isNotBlank(fileExtension) && mimeTypeProperties.containsKey(fileExtension)) {
if (StringUtils.isBlank(mimeTypeCode)) {
mimeTypeCode = mimeTypeProperties.getProperty(fileExtension);
}
} else {
LOG.error("Mime type error" + fileName + " " + mimeTypeCode);
}
LOG.info("Mime type " + fileName + " " + mimeTypeCode);
String attachType = KFSConstants.EMPTY_STRING;
Attachment noteAttachment = attachmentService.createAttachment(document.getDocumentHeader(), attachment.getAttachmentFileName(), mimeTypeCode, fileSize, fileInputStream, attachType);
note.addAttachment(noteAttachment);
document.addNote(note);
} catch (FileNotFoundException e) {
continue;
} catch (IOException e1) {
throw new RuntimeException("Unable to create attachment for File: " + fileName, e1);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
}
}
use of org.kuali.kfs.krad.bo.Attachment in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method attachInvoiceXMLWithRejectDoc.
protected void attachInvoiceXMLWithRejectDoc(ElectronicInvoiceRejectDocument eInvoiceRejectDocument, File attachmentFile, String noteText) {
Note note = null;
try {
note = SpringContext.getBean(DocumentService.class).createNoteFromDocument(eInvoiceRejectDocument, noteText);
// KFSCNTRB-1369: Can't add note without remoteObjectIdentifier
note.setRemoteObjectIdentifier(eInvoiceRejectDocument.getNoteTarget().getObjectId());
} catch (Exception e1) {
throw new RuntimeException("Unable to create note from document: ", e1);
}
String attachmentType = null;
BufferedInputStream fileStream = null;
try {
fileStream = new BufferedInputStream(new FileInputStream(attachmentFile));
} catch (FileNotFoundException e) {
LOG.error("Exception opening attachment file", e);
}
Attachment attachment = null;
try {
attachment = SpringContext.getBean(AttachmentService.class).createAttachment(eInvoiceRejectDocument.getNoteTarget(), attachmentFile.getName(), INVOICE_FILE_MIME_TYPE, (int) attachmentFile.length(), fileStream, attachmentType);
} catch (Exception e) {
// it may have more than one kind of Exception
// if attachment is not created for any reason, then don't include in note and proceed.
// otherwise it will throw runtimeexception and cause job to stop
LOG.error("Unable to create attachment", e);
// throw new RuntimeException("Unable to create attachment", e);
} finally {
if (fileStream != null) {
try {
fileStream.close();
} catch (IOException e) {
LOG.error("Exception closing file", e);
}
}
}
if (attachment != null) {
// if attachment is not created for any reason, then don't ininclude in note and proceed.
// otherwise it will throw runtimeexception and cause job to stop
note.setAttachment(attachment);
attachment.setNote(note);
}
SpringContext.getBean(NoteService.class).save(note);
}
use of org.kuali.kfs.krad.bo.Attachment in project cu-kfs by CU-CommunityApps.
the class CreateAccountingDocumentServiceImplTest method buildSimpleAttachment.
private Attachment buildSimpleAttachment(String fileName) {
Attachment attachment = new Attachment();
attachment.setAttachmentFileName(fileName);
return attachment;
}
Aggregations