use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.
the class CuRequisitionDocument method prepareForSave.
/**
* Overridden to also pre-populate note IDs on unsaved notes lacking attachments,
* to avoid persistence problems with note extended attributes. This is necessary
* because of the OJB behavior of trying to persist the 1-1 reference object
* prior to the parent object, which can interfere with saving auto-generated
* notes (like "copied from document" notes).
*
* @see org.kuali.kfs.module.purap.document.PurchasingDocumentBase#prepareForSave(org.kuali.kfs.krad.rules.rule.event.KualiDocumentEvent)
*/
@Override
public void prepareForSave(KualiDocumentEvent event) {
super.prepareForSave(event);
SequenceAccessorService sequenceAccessorService = SpringContext.getBean(SequenceAccessorService.class);
for (Note note : getNotes()) {
if (note.getNoteIdentifier() == null && ObjectUtils.isNull(note.getAttachment())) {
// Pre-populate IDs on unsaved notes without attachments, as well as their extended attributes.
Long newNoteId = sequenceAccessorService.getNextAvailableSequenceNumber(CUKFSConstants.NOTE_SEQUENCE_NAME);
note.setNoteIdentifier(newNoteId);
((NoteExtendedAttribute) note.getExtension()).setNoteIdentifier(newNoteId);
}
}
}
use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method copyIWantdDocAttachmentsToDV.
private void copyIWantdDocAttachmentsToDV(DisbursementVoucherDocument dvDocument, DisbursementVoucherForm disbursementVoucherForm, IWantDocument iWantDocument) {
purapService.saveDocumentNoValidation(dvDocument);
if (iWantDocument.getNotes() != null && iWantDocument.getNotes().size() > 0) {
for (Iterator iterator = iWantDocument.getNotes().iterator(); iterator.hasNext(); ) {
Note note = (Note) iterator.next();
Note copyNote;
try {
copyNote = noteService.createNote(new Note(), dvDocument.getDocumentHeader(), GlobalVariables.getUserSession().getPrincipalId());
copyNote.setNoteText(note.getNoteText());
copyNote.setAuthorUniversalIdentifier(note.getAuthorUniversalIdentifier());
copyNote.setRemoteObjectIdentifier(dvDocument.getObjectId());
copyNote.setNotePostedTimestamp(note.getNotePostedTimestamp());
String attachmentType = StringUtils.EMPTY;
Attachment attachment = note.getAttachment();
if (attachment != null) {
Note newNote = disbursementVoucherForm.getNewNote();
Attachment copyAttachment = attachmentService.createAttachment(iWantDocument.getDocumentHeader(), attachment.getAttachmentFileName(), attachment.getAttachmentMimeTypeCode(), attachment.getAttachmentFileSize().intValue(), attachment.getAttachmentContents(), attachment.getAttachmentTypeCode());
if (copyAttachment != null) {
copyNote.addAttachment(copyAttachment);
noteService.save(copyNote);
dvDocument.addNote(copyNote);
purapService.saveDocumentNoValidation(dvDocument);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method copyIWantDocAttachments.
/**
* Copies all attachments from the I Want document to the accounting document
*
* NOTE: A true extCopyNoteIndicator value will cause the copied notes to also
* include an extended attribute with copyNoteIndicator set to true.
*
* @param document
* @param iWantDocument
* @param copyConfidentialAttachments
* @param extCopyNoteIndicator
* @throws Exception
*/
private void copyIWantDocAttachments(AccountingDocument document, IWantDocument iWantDocument, boolean copyConfidentialAttachments, boolean extCopyNoteIndicator) throws Exception {
purapService.saveDocumentNoValidation(document);
if (iWantDocument.getNotes() != null && iWantDocument.getNotes().size() > 0) {
for (Iterator iterator = iWantDocument.getNotes().iterator(); iterator.hasNext(); ) {
Note note = (Note) iterator.next();
try {
Note copyingNote = documentService.createNoteFromDocument(document, note.getNoteText());
purapService.saveDocumentNoValidation(document);
copyingNote.setNotePostedTimestamp(note.getNotePostedTimestamp());
copyingNote.setAuthorUniversalIdentifier(note.getAuthorUniversalIdentifier());
copyingNote.setNoteTopicText(note.getNoteTopicText());
Attachment originalAttachment = attachmentService.getAttachmentByNoteId(note.getNoteIdentifier());
if (originalAttachment != null && (copyConfidentialAttachments || !ConfidentialAttachmentTypeCodes.CONFIDENTIAL_ATTACHMENT_TYPE.equals(originalAttachment.getAttachmentTypeCode()))) {
// new Attachment();
Attachment newAttachment = attachmentService.createAttachment((PersistableBusinessObject) copyingNote, originalAttachment.getAttachmentFileName(), originalAttachment.getAttachmentMimeTypeCode(), originalAttachment.getAttachmentFileSize().intValue(), originalAttachment.getAttachmentContents(), originalAttachment.getAttachmentTypeCode());
if (ObjectUtils.isNotNull(originalAttachment) && ObjectUtils.isNotNull(newAttachment)) {
copyingNote.addAttachment(newAttachment);
}
document.addNote(copyingNote);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
purapService.saveDocumentNoValidation(document);
// If specified, auto-construct extended attributes on the document notes at this point. (Doing so before initial persistence can cause save problems.)
if (extCopyNoteIndicator && CollectionUtils.isNotEmpty(document.getNotes())) {
for (Note copiedNote : document.getNotes()) {
NoteExtendedAttribute noteExtension = (NoteExtendedAttribute) copiedNote.getExtension();
noteExtension.setNoteIdentifier(copiedNote.getNoteIdentifier());
noteExtension.setCopyNoteIndicator(true);
}
purapService.saveDocumentNoValidation(document);
}
}
use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method insertBONote.
/**
* Use the new attachment description field to set the note text.
*
* @see org.kuali.kfs.kns.web.struts.action.KualiDocumentActionBase#insertBONote(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward insertBONote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
IWantDocumentForm iWantDocumentForm = (IWantDocumentForm) form;
Note note = iWantDocumentForm.getNewNote();
// If trying to add a conf attachment without authorization or not properly flagging a potentially-conf attachment, then treat as a validation failure.
if (!ConfidentialAttachmentUtil.attachmentIsNonConfidentialOrCanAddConfAttachment(note, iWantDocumentForm.getDocument(), iWantDocumentForm.getAttachmentFile(), getDocumentHelperService().getDocumentAuthorizer(iWantDocumentForm.getDocument()))) {
// Just return without adding the note/attachment. The ConfidentialAttachmentUtil method will handle updating the message map accordingly.
return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
// If the note text is blank, set the attachment description as the text. Otherwise, concatenate both to form the text.
if (StringUtils.isBlank(note.getNoteText())) {
note.setNoteText(iWantDocumentForm.getIWantDocument().getAttachmentDescription());
} else {
note.setNoteText(iWantDocumentForm.getIWantDocument().getAttachmentDescription() + ": " + note.getNoteText());
}
ActionForward actionForward = super.insertBONote(mapping, form, request, response);
iWantDocumentForm.getIWantDocument().setAttachmentDescription(StringUtils.EMPTY);
return actionForward;
}
use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.
the class ReceiptProcessingServiceImpl method matchAndAttach.
/**
* Performs match and attach. It will search for a match PCDO document and attempt to attach the receipt.
*
* @param receipts
* @param attachmentsPath
* @param mimeTypeCode
*/
protected void matchAndAttach(List<ReceiptProcessing> receipts, String attachmentsPath, String mimeTypeCode) {
StringBuilder processResults = new StringBuilder();
processResults.append(RESULT_FILE_HEADER_LINE);
for (ReceiptProcessing receipt : receipts) {
Note note = new Note();
java.util.Date pdate = null;
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
try {
pdate = (java.util.Date) df.parse(receipt.getPurchasedate());
} catch (ParseException e) {
processResults.append(receipt.badData(false));
LOG.error("Bad date field on incoming csv");
continue;
} catch (java.text.ParseException e) {
processResults.append(receipt.badData(false));
LOG.error("Bad date field on incoming csv");
continue;
}
Date pdateSQL = null;
if (pdate != null) {
pdateSQL = new Date(pdate.getTime());
}
List<ProcurementCardDocument> pcdoList = procurementCardDocumentDao.getDocumentByCarhdHolderAmountDateVendor(receipt.getCardHolder(), receipt.getAmount(), pdateSQL);
ProcurementCardDocument pcdo = null;
if (ObjectUtils.isNull(pcdoList) || pcdoList.isEmpty()) {
processResults.append(receipt.noMatch(false));
continue;
}
if (pcdoList.size() > 1) {
processResults.append(receipt.multipleMatch(false));
continue;
}
if (pcdoList.size() == 1) {
pcdo = pcdoList.get(0);
}
String pdfFileName = attachmentsPath + "/" + receipt.getFilename();
LOG.info("Start creating note and attaching pdf file " + pdfFileName + " to PCDO document #" + pcdo.getDocumentNumber());
File f = null;
FileInputStream fileInputStream = null;
try {
f = new File(pdfFileName);
fileInputStream = new FileInputStream(pdfFileName);
} catch (FileNotFoundException e) {
LOG.error("File " + pdfFileName + " not found for Document " + pcdo.getDocumentNumber());
processResults.append(receipt.badData(false));
continue;
} catch (IOException e) {
LOG.error("generic Io exception for Document " + pcdo.getDocumentNumber());
processResults.append(receipt.badData(false));
continue;
}
long fileSizeLong = f.length();
Integer fileSize = Integer.parseInt(Long.toString(fileSizeLong));
String attachType = "";
Attachment noteAttachment = null;
try {
noteAttachment = attachmentService.createAttachment(pcdo.getDocumentHeader(), pdfFileName, mimeTypeCode, fileSize, fileInputStream, attachType);
} catch (IOException e) {
LOG.error("Failed to attach file for Document " + pcdo.getDocumentNumber());
processResults.append(receipt.noMatch(false));
e.printStackTrace();
continue;
} catch (IllegalArgumentException e) {
/*
* Our custom attachment service will throw an IllegalArgumentException if the virus scan fails.
* The virus scan could also end up failing if the file size is too large. In such cases,
* return an error code indicating such a problem (or a problem with invalid parameters).
*/
LOG.error("Failed to create attachment for Document " + pcdo.getDocumentNumber(), e);
processResults.append(receipt.attachmentCreationError(false));
continue;
}
if (noteAttachment != null) {
note.setNoteText("Receipt Attached");
note.addAttachment(noteAttachment);
note.setRemoteObjectIdentifier(pcdo.getDocumentHeader().getObjectId());
note.setAuthorUniversalIdentifier(getSystemUser().getPrincipalId());
note.setNoteTypeCode(KFSConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
note.setNotePostedTimestampToCurrent();
try {
noteService.save(note);
} catch (Exception e) {
LOG.error("Failed to save note for Document " + pcdo.getDocumentNumber());
processResults.append(receipt.noMatch(false));
e.printStackTrace();
continue;
}
LOG.info("Attached pdf " + pdfFileName + " for document " + pcdo.getDocumentNumber());
processResults.append(receipt.match(pcdo.getDocumentNumber(), false));
}
}
String outputCsv = processResults.toString();
// this is CALS output folder and it has to stay unchanged
String reportDropFolder = pdfDirectory + "/CIT-csv-archive/";
getcsvWriter(outputCsv, reportDropFolder);
}
Aggregations