Search in sources :

Example 1 with DocumentAuthorizer

use of org.kuali.kfs.kns.document.authorization.DocumentAuthorizer in project cu-kfs by CU-CommunityApps.

the class CuPaymentRequestDocument method prepareForSave.

public void prepareForSave(KualiDocumentEvent event) {
    // LOG.info("preqWireTransfer " + preqWireTransfer != null);
    try {
        // if (preqWireTransfer != null) {
        // if (!StringUtils.equals(preqWireTransfer.getDocumentNumber(),getDocumentNumber())) {
        preqWireTransfer.setDocumentNumber(getDocumentNumber());
    // }
    // }
    } catch (Exception e) {
        LOG.info("preqWireTransfer is null");
        preqWireTransfer = new PaymentRequestWireTransfer();
        preqWireTransfer.setDocumentNumber(getDocumentNumber());
    }
    super.prepareForSave(event);
    for (PaymentRequestItem item : (List<PaymentRequestItem>) getItems()) {
        if (item.getItemIdentifier() == null) {
            Integer generatedItemId = SpringContext.getBean(SequenceAccessorService.class).getNextAvailableSequenceNumber("PMT_RQST_ITM_ID").intValue();
            item.setItemIdentifier(generatedItemId);
            if (item.getExtension() == null) {
                item.setExtension(new CuPaymentRequestItemExtension());
            }
            ((CuPaymentRequestItemExtension) item.getExtension()).setItemIdentifier(generatedItemId);
        }
    }
    // KFSPTS-1891
    if (getDocumentHeader().getWorkflowDocument().isInitiated() || getDocumentHeader().getWorkflowDocument().isSaved()) {
        // need to check whether the user has the permission to edit the bank code
        // if so, don't synchronize since we can't tell whether the value coming in
        // was entered by the user or not.
        DocumentAuthorizer docAuth = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(this);
        if (!docAuth.isAuthorizedByTemplate(this, KFSConstants.ParameterNamespaces.KFS, KFSConstants.PermissionTemplate.EDIT_BANK_CODE.name, GlobalVariables.getUserSession().getPrincipalId())) {
            synchronizeBankCodeWithPaymentMethod();
        } else {
            // ensure that the name is updated properly
            refreshReferenceObject("bank");
        }
    }
}
Also used : CuPaymentRequestItemExtension(edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) PaymentRequestWireTransfer(edu.cornell.kfs.module.purap.businessobject.PaymentRequestWireTransfer) DocumentAuthorizer(org.kuali.kfs.kns.document.authorization.DocumentAuthorizer) List(java.util.List) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentHelperService(org.kuali.kfs.kns.service.DocumentHelperService)

Example 2 with DocumentAuthorizer

use of org.kuali.kfs.kns.document.authorization.DocumentAuthorizer 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 3 with DocumentAuthorizer

use of org.kuali.kfs.kns.document.authorization.DocumentAuthorizer in project cu-kfs by CU-CommunityApps.

the class CuDisbursementVoucherDocument method prepareForSave.

@Override
public void prepareForSave() {
    if (this instanceof AmountTotaling) {
        if (getFinancialSystemDocumentHeader().getFinancialDocumentStatusCode().equals(KFSConstants.DocumentStatusCodes.ENROUTE) && !getFinancialSystemDocumentHeader().getWorkflowDocument().isCompletionRequested()) {
            if (getParameterService().parameterExists(KfsParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class, UPDATE_TOTAL_AMOUNT_IN_POST_PROCESSING_PARAMETER_NAME) && getParameterService().getParameterValueAsBoolean(KfsParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class, UPDATE_TOTAL_AMOUNT_IN_POST_PROCESSING_PARAMETER_NAME)) {
                getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(((AmountTotaling) this).getTotalDollarAmount());
            }
        } else {
            getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(((AmountTotaling) this).getTotalDollarAmount());
        }
    }
    captureWorkflowHeaderInformation();
    if (wireTransfer != null) {
        wireTransfer.setDocumentNumber(this.documentNumber);
        ((DisbursementVoucherWireTransferExtendedAttribute) wireTransfer.getExtension()).setDocumentNumber(this.documentNumber);
    }
    if (dvNonResidentAlienTax != null) {
        dvNonResidentAlienTax.setDocumentNumber(this.documentNumber);
    }
    dvPayeeDetail.setDocumentNumber(this.documentNumber);
    ((CuDisbursementVoucherPayeeDetailExtension) dvPayeeDetail.getExtension()).setDocumentNumber(this.documentNumber);
    if (dvNonEmployeeTravel != null) {
        dvNonEmployeeTravel.setDocumentNumber(this.documentNumber);
        dvNonEmployeeTravel.setTotalTravelAmount(dvNonEmployeeTravel.getTotalTravelAmount());
    }
    if (dvPreConferenceDetail != null) {
        dvPreConferenceDetail.setDocumentNumber(this.documentNumber);
        dvPreConferenceDetail.setDisbVchrConferenceTotalAmt(dvPreConferenceDetail.getDisbVchrConferenceTotalAmt());
    }
    if (shouldClearSpecialHandling()) {
        clearSpecialHandling();
    }
    // CU Customization: Also perform check below when an ENROUTE doc is at the initial "AdHoc" node.
    if (getDocumentHeader().getWorkflowDocument().isInitiated() || getDocumentHeader().getWorkflowDocument().isSaved() || (getDocumentHeader().getWorkflowDocument().isEnroute() && getDocumentHeader().getWorkflowDocument().getCurrentNodeNames().contains("AdHoc"))) {
        // need to check whether the user has the permission to edit the bank code
        // if so, don't synchronize since we can't tell whether the value coming in
        // was entered by the user or not.
        DocumentAuthorizer docAuth = getDocumentHelperService().getDocumentAuthorizer(this);
        if (!docAuth.isAuthorizedByTemplate(this, KFSConstants.ParameterNamespaces.KFS, KFSConstants.PermissionTemplate.EDIT_BANK_CODE.name, GlobalVariables.getUserSession().getPrincipalId())) {
            synchronizeBankCodeWithPaymentMethod();
        } else {
            refreshReferenceObject("bank");
        }
        refreshPayeeTypeSuffixIfPaymentIsEditable();
    }
}
Also used : DisbursementVoucherWireTransferExtendedAttribute(edu.cornell.kfs.fp.businessobject.DisbursementVoucherWireTransferExtendedAttribute) CuDisbursementVoucherPayeeDetailExtension(edu.cornell.kfs.fp.businessobject.CuDisbursementVoucherPayeeDetailExtension) TransactionalDocumentAuthorizer(org.kuali.kfs.kns.document.authorization.TransactionalDocumentAuthorizer) DocumentAuthorizer(org.kuali.kfs.kns.document.authorization.DocumentAuthorizer) AmountTotaling(org.kuali.kfs.sys.document.AmountTotaling)

Example 4 with DocumentAuthorizer

use of org.kuali.kfs.kns.document.authorization.DocumentAuthorizer in project cu-kfs by CU-CommunityApps.

the class WebUtils method canDeleteNoteAttachment.

public static boolean canDeleteNoteAttachment(Document document, String attachmentTypeCode, String authorUniversalIdentifier) {
    boolean canDeleteNoteAttachment = false;
    DocumentAuthorizer documentAuthorizer = KNSServiceLocator.getDocumentHelperService().getDocumentAuthorizer(document);
    canDeleteNoteAttachment = documentAuthorizer.canDeleteNoteAttachment(document, attachmentTypeCode, "false", GlobalVariables.getUserSession().getPerson());
    if (canDeleteNoteAttachment) {
        return canDeleteNoteAttachment;
    } else {
        canDeleteNoteAttachment = documentAuthorizer.canDeleteNoteAttachment(document, attachmentTypeCode, "true", GlobalVariables.getUserSession().getPerson());
        if (canDeleteNoteAttachment && !authorUniversalIdentifier.equals(GlobalVariables.getUserSession().getPerson().getPrincipalId())) {
            canDeleteNoteAttachment = false;
        }
    }
    return canDeleteNoteAttachment;
}
Also used : DocumentAuthorizer(org.kuali.kfs.kns.document.authorization.DocumentAuthorizer)

Example 5 with DocumentAuthorizer

use of org.kuali.kfs.kns.document.authorization.DocumentAuthorizer in project cu-kfs by CU-CommunityApps.

the class WebUtils method canAddNoteAttachment.

public static boolean canAddNoteAttachment(Document document) {
    boolean canViewNoteAttachment = false;
    DocumentAuthorizer documentAuthorizer = KNSServiceLocator.getDocumentHelperService().getDocumentAuthorizer(document);
    canViewNoteAttachment = documentAuthorizer.canAddNoteAttachment(document, null, GlobalVariables.getUserSession().getPerson());
    return canViewNoteAttachment;
}
Also used : DocumentAuthorizer(org.kuali.kfs.kns.document.authorization.DocumentAuthorizer)

Aggregations

DocumentAuthorizer (org.kuali.kfs.kns.document.authorization.DocumentAuthorizer)8 DocumentHelperService (org.kuali.kfs.kns.service.DocumentHelperService)2 CuDisbursementVoucherPayeeDetailExtension (edu.cornell.kfs.fp.businessobject.CuDisbursementVoucherPayeeDetailExtension)1 DisbursementVoucherWireTransferExtendedAttribute (edu.cornell.kfs.fp.businessobject.DisbursementVoucherWireTransferExtendedAttribute)1 CuPaymentRequestItemExtension (edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension)1 PaymentRequestWireTransfer (edu.cornell.kfs.module.purap.businessobject.PaymentRequestWireTransfer)1 List (java.util.List)1 ActionForward (org.apache.struts.action.ActionForward)1 FormFile (org.apache.struts.upload.FormFile)1 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)1 TransactionalDocumentAuthorizer (org.kuali.kfs.kns.document.authorization.TransactionalDocumentAuthorizer)1 DataDictionaryService (org.kuali.kfs.kns.service.DataDictionaryService)1 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)1 Attachment (org.kuali.kfs.krad.bo.Attachment)1 DocumentHeader (org.kuali.kfs.krad.bo.DocumentHeader)1 Note (org.kuali.kfs.krad.bo.Note)1 DataDictionary (org.kuali.kfs.krad.datadictionary.DataDictionary)1 DocumentEntry (org.kuali.kfs.krad.datadictionary.DocumentEntry)1 Document (org.kuali.kfs.krad.document.Document)1 AddNoteEvent (org.kuali.kfs.krad.rules.rule.event.AddNoteEvent)1