// mjmc // ************************************************************************************************* private PurchaseOrderDocument copyNotesAndAttachmentsToPO( RequisitionDocument reqDoc, PurchaseOrderDocument poDoc) { purapService.saveDocumentNoValidation(poDoc); List<Note> notes = (List<Note>) reqDoc.getNotes(); int noteLength = notes.size(); if (noteLength > 0) { for (Note note : notes) { try { Note copyingNote = SpringContext.getBean(DocumentService.class) .createNoteFromDocument(poDoc, note.getNoteText()); purapService.saveDocumentNoValidation(poDoc); copyingNote.setNotePostedTimestamp(note.getNotePostedTimestamp()); copyingNote.setAuthorUniversalIdentifier(note.getAuthorUniversalIdentifier()); copyingNote.setNoteTopicText(note.getNoteTopicText()); Attachment originalAttachment = SpringContext.getBean(AttachmentService.class) .getAttachmentByNoteId(note.getNoteIdentifier()); NoteExtendedAttribute noteExtendedAttribute = (NoteExtendedAttribute) note.getExtension(); if (originalAttachment != null || (ObjectUtils.isNotNull(noteExtendedAttribute) && noteExtendedAttribute.isCopyNoteIndicator())) { if (originalAttachment != null) { Attachment newAttachment = SpringContext.getBean(AttachmentService.class) .createAttachment( (PersistableBusinessObject) copyingNote, originalAttachment.getAttachmentFileName(), originalAttachment.getAttachmentMimeTypeCode(), originalAttachment.getAttachmentFileSize().intValue(), originalAttachment.getAttachmentContents(), originalAttachment.getAttachmentTypeCode()); // new Attachment(); if (ObjectUtils.isNotNull(originalAttachment) && ObjectUtils.isNotNull(newAttachment)) { copyingNote.addAttachment(newAttachment); } } poDoc.addNote(copyingNote); } } catch (Exception e) { throw new RuntimeException(e); } } } purapService.saveDocumentNoValidation(poDoc); return poDoc; } // mjmc end
/** * @see * org.kuali.rice.krad.service.DocumentService#createNoteFromDocument(org.kuali.rice.krad.document.Document, * java.lang.String) */ @Override public Note createNoteFromDocument(Document document, String text) { Note note = new Note(); note.setNotePostedTimestamp(getDateTimeService().getCurrentTimestamp()); note.setNoteText(text); note.setNoteTypeCode(document.getNoteType().getCode()); PersistableBusinessObject bo = document.getNoteTarget(); // TODO gah! this is awful Person kualiUser = GlobalVariables.getUserSession().getPerson(); if (kualiUser == null) { throw new IllegalStateException("Current UserSession has a null Person."); } return bo == null ? null : getNoteService().createNote(note, bo, kualiUser.getPrincipalId()); }