Search in sources :

Example 1 with Note

use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.

the class CUAccountMaintainableImpl method getNewBoNote.

/**
 * creates a new bo note and sets the timestamp.
 *
 * @return a newly created note
 */
protected Note getNewBoNote(String prefix) {
    Note newBoNote = new Note();
    newBoNote.setNoteText(prefix + CUKFSConstants.ACCOUNT_NOTE_TEXT + getDocumentNumber());
    newBoNote.setNotePostedTimestampToCurrent();
    try {
        newBoNote = getNoteService().createNote(newBoNote, this.getBusinessObject(), GlobalVariables.getUserSession().getPrincipalId());
    } catch (Exception e) {
        throw new RuntimeException("Caught Exception While Trying To Add Note to Account", e);
    }
    return newBoNote;
}
Also used : Note(org.kuali.kfs.krad.bo.Note)

Example 2 with Note

use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.

the class CUAccountMaintainableImpl method processAfterPost.

@Override
public void processAfterPost(MaintenanceDocument document, Map<String, String[]> requestParameters) {
    super.processAfterPost(document, requestParameters);
    String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
    boolean isPreRoute = DocumentStatus.INITIATED.getCode().equals(statusCode) || DocumentStatus.SAVED.getCode().equals(statusCode);
    if (isPreRoute) {
        // Search for edit note and update it to include the doc description
        for (Note note : document.getNotes()) {
            if (note.getNoteText().startsWith(CUKFSConstants.AccountCreateAndUpdateNotePrefixes.EDIT + CUKFSConstants.ACCOUNT_NOTE_TEXT + getDocumentNumber())) {
                note.setNoteText(CUKFSConstants.AccountCreateAndUpdateNotePrefixes.EDIT + CUKFSConstants.ACCOUNT_NOTE_TEXT + getDocumentNumber() + " " + document.getDocumentHeader().getDocumentDescription());
            }
        }
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note)

Example 3 with Note

use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.

the class AccountingDocumentGeneratorBase method buildDocumentNoteAttachment.

protected Note buildDocumentNoteAttachment(T document, AccountingXmlDocumentBackupLink backupLink) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("buildDocumentNoteAttachment: " + backupLink);
    }
    Person systemUser = personService.getPersonByPrincipalName(KFSConstants.SYSTEM_USER);
    Note note = emptyNoteGenerator.get();
    note.setAuthorUniversalIdentifier(systemUser.getPrincipalId());
    note.setNotePostedTimestampToCurrent();
    addAttachmentToNote(document, backupLink, note);
    note.setNoteText(backupLink.getDescription());
    return note;
}
Also used : AccountingXmlDocumentNote(edu.cornell.kfs.fp.batch.xml.AccountingXmlDocumentNote) Note(org.kuali.kfs.krad.bo.Note) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) Person(org.kuali.rice.kim.api.identity.Person)

Example 4 with Note

use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.

the class CUFinancialSystemDocumentServiceImpl method writeNote.

protected void writeNote(AccountingDocument accountingDocument, String noteText) {
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    // Put a note on the document to record the change to the address
    try {
        // String noteText = buildLineChangedNoteText(newAccountingLine, oldAccountingLine);
        int noteMaxSize = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength("Note", "noteText");
        // Break up the note into multiple pieces if the note is too large to fit in the database field.
        while (noteText.length() > noteMaxSize) {
            int fromIndex = 0;
            fromIndex = noteText.lastIndexOf(';', noteMaxSize);
            String noteText1 = noteText.substring(0, fromIndex);
            Note note1 = documentService.createNoteFromDocument(accountingDocument, noteText1);
            accountingDocument.addNote(note1);
            noteText = noteText.substring(fromIndex);
        }
        Note note = documentService.createNoteFromDocument(accountingDocument, noteText);
        accountingDocument.addNote(note);
    } catch (Exception e) {
        LOG.error("Exception while attempting to create or add note: " + e);
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note) DocumentService(org.kuali.kfs.krad.service.DocumentService) CUFinancialSystemDocumentService(edu.cornell.kfs.sys.document.service.CUFinancialSystemDocumentService) DataDictionaryService(org.kuali.kfs.kns.service.DataDictionaryService) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 5 with Note

use of org.kuali.kfs.krad.bo.Note in project cu-kfs by CU-CommunityApps.

the class CuFinancialMaintenanceDocumentAction method insertBONote.

/**
 * Overridden to include a Rice 2.5.x fix for persisting BO note additions,
 * and to delegate the fix's boolean logic to some new shouldSaveBoNoteAfterUpdate()
 * and isTargetReadyForNotes() methods so that it can be further limited based on BO class and readiness.
 *
 * Some other cleanup has also been done to improve line lengths
 * and remove certain comments, but other than that and the changes stated above,
 * this method is the same as the one from KualiDocumentActionBase.
 *
 * @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 {
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    Document document = kualiDocumentFormBase.getDocument();
    Note newNote = kualiDocumentFormBase.getNewNote();
    newNote.setNotePostedTimestampToCurrent();
    String attachmentTypeCode = null;
    FormFile attachmentFile = kualiDocumentFormBase.getAttachmentFile();
    if (attachmentFile == null) {
        GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_ATTACHMENT_FILE_PROPERTY_NAME), RiceKeyConstants.ERROR_UPLOADFILE_NULL);
    }
    if (newNote.getAttachment() != null) {
        attachmentTypeCode = newNote.getAttachment().getAttachmentTypeCode();
    }
    // check authorization for adding notes
    DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(document);
    if (!documentAuthorizer.canAddNoteAttachment(document, attachmentTypeCode, GlobalVariables.getUserSession().getPerson())) {
        throw buildAuthorizationException("annotate", document);
    }
    // create the attachment first, so that failure-to-create-attachment can be treated as a validation failure
    Attachment attachment = null;
    if (attachmentFile != null && !StringUtils.isBlank(attachmentFile.getFileName())) {
        if (attachmentFile.getFileSize() == 0) {
            GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_ATTACHMENT_FILE_PROPERTY_NAME), RiceKeyConstants.ERROR_UPLOADFILE_EMPTY, attachmentFile.getFileName());
        } else {
            String attachmentType = null;
            Attachment newAttachment = kualiDocumentFormBase.getNewNote().getAttachment();
            if (newAttachment != null) {
                attachmentType = newAttachment.getAttachmentTypeCode();
            }
            attachment = getAttachmentService().createAttachment(document.getNoteTarget(), attachmentFile.getFileName(), attachmentFile.getContentType(), attachmentFile.getFileSize(), attachmentFile.getInputStream(), attachmentType);
        }
    }
    DataDictionary dataDictionary = getDataDictionaryService().getDataDictionary();
    DocumentEntry entry = dataDictionary.getDocumentEntry(document.getClass().getName());
    if (entry.getDisplayTopicFieldInNotes()) {
        String topicText = kualiDocumentFormBase.getNewNote().getNoteTopicText();
        if (StringUtils.isBlank(topicText)) {
            GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_TOPIC_TEXT_PROPERTY_NAME), RiceKeyConstants.ERROR_REQUIRED, "Note Topic (Note Topic)");
        }
    }
    // create a new note from the data passed in
    Person kualiUser = GlobalVariables.getUserSession().getPerson();
    if (kualiUser == null) {
        throw new IllegalStateException("Current UserSession has a null Person.");
    }
    Note tmpNote = getNoteService().createNote(newNote, document.getNoteTarget(), kualiUser.getPrincipalId());
    ActionForward forward = checkAndWarnAboutSensitiveData(mapping, form, request, response, KRADPropertyConstants.NOTE, tmpNote.getNoteText(), "insertBONote", "");
    if (forward != null) {
        return forward;
    }
    // validate the note
    boolean rulePassed = getKualiRuleService().applyRules(new AddNoteEvent(document, tmpNote));
    // if the rule evaluation passed, let's add the note
    if (rulePassed) {
        tmpNote.refresh();
        DocumentHeader documentHeader = document.getDocumentHeader();
        // associate note with object now
        document.addNote(tmpNote);
        // maintenance document BO note should only be saved into table when document is in the PROCESSED workflow status
        if (!documentHeader.getWorkflowDocument().isInitiated() && StringUtils.isNotEmpty(document.getNoteTarget().getObjectId()) && !(document instanceof MaintenanceDocument && NoteType.BUSINESS_OBJECT.getCode().equals(tmpNote.getNoteTypeCode()))) {
            getNoteService().save(tmpNote);
        }
        // autopopulate the id since the note hasn't been persisted yet)
        if (attachment != null) {
            tmpNote.addAttachment(attachment);
            // without the PK on the attachment I think it is safer then trying to get the sequence manually
            if (!documentHeader.getWorkflowDocument().isInitiated() && StringUtils.isNotEmpty(document.getNoteTarget().getObjectId()) && !(document instanceof MaintenanceDocument && NoteType.BUSINESS_OBJECT.getCode().equals(tmpNote.getNoteTypeCode()))) {
                getNoteService().save(tmpNote);
            }
        }
        // Added some logic which saves the document and/or notes list after a BO note is added to the document
        if (shouldSaveBoNoteAfterUpdate(document, tmpNote)) {
            if (isTargetReadyForNotes(document)) {
                getNoteService().save(tmpNote);
            } else {
                getDocumentService().saveDocument(document);
            }
        }
        // reset the new note back to an empty one
        kualiDocumentFormBase.setNewNote(new Note());
    }
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) DocumentAuthorizer(org.kuali.kfs.kns.document.authorization.DocumentAuthorizer) Attachment(org.kuali.kfs.krad.bo.Attachment) AddNoteEvent(org.kuali.kfs.krad.rules.rule.event.AddNoteEvent) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) Document(org.kuali.kfs.krad.document.Document) DataDictionary(org.kuali.kfs.krad.datadictionary.DataDictionary) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) ActionForward(org.apache.struts.action.ActionForward) FormFile(org.apache.struts.upload.FormFile) KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) Note(org.kuali.kfs.krad.bo.Note) DocumentEntry(org.kuali.kfs.krad.datadictionary.DocumentEntry) Person(org.kuali.rice.kim.api.identity.Person)

Aggregations

Note (org.kuali.kfs.krad.bo.Note)76 Attachment (org.kuali.kfs.krad.bo.Attachment)14 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)12 IOException (java.io.IOException)9 FileNotFoundException (java.io.FileNotFoundException)7 ArrayList (java.util.ArrayList)7 NoteService (org.kuali.kfs.krad.service.NoteService)7 FileInputStream (java.io.FileInputStream)6 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)6 NonTransactional (org.kuali.kfs.sys.service.NonTransactional)6 File (java.io.File)5 Iterator (java.util.Iterator)5 DocumentService (org.kuali.kfs.krad.service.DocumentService)5 Person (org.kuali.rice.kim.api.identity.Person)5 NoteExtendedAttribute (edu.cornell.kfs.sys.businessobject.NoteExtendedAttribute)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Document (org.kuali.kfs.krad.document.Document)4 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)4 HashMap (java.util.HashMap)3 List (java.util.List)3