Search in sources :

Example 1 with KualiDocumentFormBase

use of org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase 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)

Example 2 with KualiDocumentFormBase

use of org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase in project cu-kfs by CU-CommunityApps.

the class CuFinancialMaintenanceDocumentAction method deleteBONote.

/**
 * Overridden to include a Rice 2.5.x fix for deleting INITIATED-doc notes and persisting BO note deletions,
 * 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 remove certain comments and unused variables,
 * 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#deleteBONote(
 *      org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
 *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward deleteBONote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    Document document = kualiDocumentFormBase.getDocument();
    Note note = document.getNote(getLineToDelete(request));
    Attachment attachment = note.getAttachment();
    String attachmentTypeCode = null;
    if (attachment != null) {
        attachmentTypeCode = attachment.getAttachmentTypeCode();
    }
    String authorUniversalIdentifier = note.getAuthorUniversalIdentifier();
    if (!WebUtils.canDeleteNoteAttachment(document, attachmentTypeCode, authorUniversalIdentifier)) {
        throw buildAuthorizationException("annotate", document);
    }
    if (attachment != null) {
        // so refreshNonUpdateableReferences() should work the same as refresh()
        if (note.getNoteIdentifier() != null) {
            // KULRICE-2343 don't blow away note reference if the note wasn't persisted
            attachment.refreshNonUpdateableReferences();
        }
        getAttachmentService().deleteAttachmentContents(attachment);
    }
    // Removed the if check so it no longer checks if the document is initiated before deleting the BO's note per KULRICE- 12327
    getNoteService().deleteNote(note);
    document.removeNote(note);
    if (shouldSaveBoNoteAfterUpdate(document, note)) {
        // If this is a maintenance document and we're deleting a BO note then try to save the document so the note is removed from the content
        if (!isTargetReadyForNotes(document)) {
            getDocumentService().saveDocument(document);
        }
    }
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) Note(org.kuali.kfs.krad.bo.Note) Attachment(org.kuali.kfs.krad.bo.Attachment) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) Document(org.kuali.kfs.krad.document.Document)

Example 3 with KualiDocumentFormBase

use of org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method isReasonToChangeRequired.

/*
     * check if reason is required
     */
private boolean isReasonToChangeRequired(ActionForm form) {
    boolean isReasonRequired = false;
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    if (isCreatingReasonNote(form) && StringUtils.isBlank(((PurchasingFormBase) kualiDocumentFormBase).getReasonToChange())) {
        GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_TOPIC_TEXT_PROPERTY_NAME), CUPurapKeyConstants.ERROR_REASON_IS_REQUIRED);
        isReasonRequired = true;
    }
    return isReasonRequired;
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)

Example 4 with KualiDocumentFormBase

use of org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method insertBONote.

@Override
public ActionForward insertBONote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    // TODO : should use 'addnoteevent' ?
    /*
    	 * KFSPTS-794 : add rule check when adding note
    	 */
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    FormFile attachmentFile = kualiDocumentFormBase.getAttachmentFile();
    Note newNote = kualiDocumentFormBase.getNewNote();
    if (StringUtils.equals(CUPurapConstants.AttachemntToVendorIndicators.SEND_TO_VENDOR, newNote.getNoteTopicText())) {
        if (StringUtils.isBlank(attachmentFile.getFileName())) {
            GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_TOPIC_TEXT_PROPERTY_NAME), CUPurapKeyConstants.ERROR_ADD_NEW_NOTE_SEND_TO_VENDOR_NO_ATT);
            return mapping.findForward(KFSConstants.MAPPING_BASIC);
        } else {
            if (isAttachmentSizeExceedSqLimit(form, "add")) {
                return mapping.findForward(KFSConstants.MAPPING_BASIC);
            } else if (attachmentFile.getFileSize() > SIZE_5MB) {
                GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_TOPIC_TEXT_PROPERTY_NAME), CUPurapKeyConstants.ERROR_ATT_FILE_SIZE_OVER_LIMIT, attachmentFile.getFileName(), "5");
                return mapping.findForward(KFSConstants.MAPPING_BASIC);
            }
        }
    }
    newNote.setNoteTypeCode(KFSConstants.NoteTypeEnum.DOCUMENT_HEADER_NOTE_TYPE.getCode());
    return super.insertBONote(mapping, form, request, response);
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) Note(org.kuali.kfs.krad.bo.Note) FormFile(org.apache.struts.upload.FormFile)

Example 5 with KualiDocumentFormBase

use of org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method close.

@Override
public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiDocumentFormBase docForm = (KualiDocumentFormBase) form;
    doProcessingAfterPost(docForm, request);
    // only want to prompt them to save if they already can save
    if (canSave(docForm)) {
        Object question = getQuestion(request);
        // logic for close question
        if (question == null) {
            // ask question if not already asked
            return this.performQuestionWithoutInput(mapping, form, request, response, KRADConstants.DOCUMENT_SAVE_BEFORE_CLOSE_QUESTION, getKualiConfigurationService().getPropertyValueAsString(RiceKeyConstants.QUESTION_SAVE_BEFORE_CLOSE), KRADConstants.CONFIRMATION_QUESTION, KRADConstants.MAPPING_CLOSE, "");
        } else {
            Object buttonClicked = request.getParameter(KRADConstants.QUESTION_CLICKED_BUTTON);
            if ((KRADConstants.DOCUMENT_SAVE_BEFORE_CLOSE_QUESTION.equals(question)) && ConfirmationQuestion.YES.equals(buttonClicked)) {
                // if yes button clicked - save the doc
                if (isAttachmentSizeExceedSqLimit(form, "save") || isReasonToChangeRequired(form)) {
                    return mapping.findForward(KFSConstants.MAPPING_BASIC);
                } else {
                    if (isCreatingReasonNote(form)) {
                        createReasonNote(form);
                    }
                    getDocumentService().saveDocument(docForm.getDocument());
                }
            }
        // else go to close logic below
        }
    }
    return returnToSender(request, mapping, docForm);
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject)

Aggregations

KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)17 ActionForward (org.apache.struts.action.ActionForward)8 Note (org.kuali.kfs.krad.bo.Note)7 Document (org.kuali.kfs.krad.document.Document)3 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)3 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)2 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)2 FormFile (org.apache.struts.upload.FormFile)2 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)2 Attachment (org.kuali.kfs.krad.bo.Attachment)2 AuthorizationException (org.kuali.kfs.krad.exception.AuthorizationException)2 ItemParserException (org.kuali.kfs.module.purap.exception.ItemParserException)2 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)2 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)1 IWantItem (edu.cornell.kfs.module.purap.businessobject.IWantItem)1 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)1 NoteExtendedAttribute (edu.cornell.kfs.sys.businessobject.NoteExtendedAttribute)1 ArrayList (java.util.ArrayList)1 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)1