Search in sources :

Example 1 with MaintenanceDocument

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

the class CUAccountMaintainableImpl method saveBusinessObject.

@Override
public void saveBusinessObject() {
    boolean isClosingAccount = isClosingAccount();
    Account account = (Account) getBusinessObject();
    AccountExtendedAttribute aea = (AccountExtendedAttribute) (account.getExtension());
    BusinessObjectService bos = SpringContext.getBean(BusinessObjectService.class);
    HashMap<String, String> keys = new HashMap<String, String>();
    keys.put("programCode", aea.getProgramCode());
    keys.put(SUB_FUND_GROUP_CODE, aea.getSubFundGroupCode());
    SubFundProgram sfp = (SubFundProgram) bos.findByPrimaryKey(SubFundProgram.class, keys);
    aea.setSubFundProgram(sfp);
    aea.setSubFundGroupCode(account.getSubFundGroupCode());
    keys = new HashMap<String, String>();
    keys.put("appropriationAccountNumber", aea.getAppropriationAccountNumber());
    keys.put(SUB_FUND_GROUP_CODE, aea.getSubFundGroupCode());
    AppropriationAccount aan = (AppropriationAccount) bos.findByPrimaryKey(AppropriationAccount.class, keys);
    aea.setAppropriationAccount(aan);
    if (account.isClosed() && aea.getAccountClosedDate() == null) {
        aea.setAccountClosedDate(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate());
    } else if (!account.isClosed() && aea.getAccountClosedDate() != null) {
        aea.setAccountClosedDate(null);
    }
    super.saveBusinessObject();
    // trickle down Account Reversion inactivation
    if (isClosingAccount) {
        SpringContext.getBean(AccountReversionTrickleDownInactivationService.class).trickleDownInactivateAccountReversions((Account) getBusinessObject(), getDocumentNumber());
    }
    // content and will display any future notes on account edits as well
    try {
        Document document = SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(getDocumentNumber());
        Account xmlaccount = (Account) ((MaintenanceDocument) document).getNewMaintainableObject().getBusinessObject();
        if (ObjectUtils.isNull(xmlaccount.getObjectId()) && (KFSConstants.MAINTENANCE_NEW_ACTION.equals(getMaintenanceAction()) || KFSConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction()))) {
            ((MaintenanceDocument) document).getNewMaintainableObject().setBusinessObject(account);
            SpringContext.getBean(DocumentService.class).saveDocument(document);
        }
    } catch (Exception e) {
        LOG.error("Account doc not saved successfully " + e.getMessage());
    }
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) Account(org.kuali.kfs.coa.businessobject.Account) AppropriationAccount(edu.cornell.kfs.coa.businessobject.AppropriationAccount) AppropriationAccount(edu.cornell.kfs.coa.businessobject.AppropriationAccount) HashMap(java.util.HashMap) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) AccountExtendedAttribute(edu.cornell.kfs.coa.businessobject.AccountExtendedAttribute) AccountReversionTrickleDownInactivationService(edu.cornell.kfs.coa.service.AccountReversionTrickleDownInactivationService) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) Document(org.kuali.kfs.krad.document.Document) DocumentService(org.kuali.kfs.krad.service.DocumentService) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) SubFundProgram(edu.cornell.kfs.coa.businessobject.SubFundProgram)

Example 2 with MaintenanceDocument

use of org.kuali.kfs.kns.document.MaintenanceDocument 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 MaintenanceDocument

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

the class CheckReconciliationMaintainableImpl method doRouteStatusChange.

/**
 * @see org.kuali.kfs.kns.maintenance.KualiMaintainableImpl#doRouteStatusChange(org.kuali.kfs.kns.bo.DocumentHeader)
 */
public void doRouteStatusChange(DocumentHeader documentHeader) {
    WorkflowDocument workflowDocument = documentHeader.getWorkflowDocument();
    if (workflowDocument.isProcessed() && !KFSConstants.MAINTENANCE_NEW_ACTION.equalsIgnoreCase(getMaintenanceAction())) {
        DocumentService documentService = SpringContext.getBean(DocumentService.class);
        MaintenanceDocument document;
        try {
            document = (MaintenanceDocument) documentService.getByDocumentHeaderId(documentHeader.getDocumentNumber());
            CheckReconciliation oldCr = (CheckReconciliation) document.getOldMaintainableObject().getBusinessObject();
            CheckReconciliation newCr = (CheckReconciliation) document.getNewMaintainableObject().getBusinessObject();
            if (ObjectUtils.isNotNull(oldCr) && !oldCr.getStatus().equalsIgnoreCase(newCr.getStatus())) {
                Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
                newCr.setStatusChangeDate(currentDate);
                // KFSUPGRADE-377
                if (CRConstants.CANCELLED.equalsIgnoreCase(newCr.getStatus())) {
                    newCr.setCancelDocHdrId(documentHeader.getDocumentNumber());
                }
            }
        } catch (WorkflowException e) {
            throw new RuntimeCacheException(e);
        }
    }
}
Also used : RuntimeCacheException(org.apache.ojb.broker.cache.RuntimeCacheException) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) CheckReconciliation(com.rsmart.kuali.kfs.cr.businessobject.CheckReconciliation) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService) DocumentService(org.kuali.kfs.krad.service.DocumentService) Date(java.sql.Date)

Example 4 with MaintenanceDocument

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

the class GlLineServiceImpl method createAssetGlobalDocument.

/**
 * @see GlLineService#createAssetGlobalDocument(List,
 * GeneralLedgerEntry)
 */
@Override
@NonTransactional
public Document createAssetGlobalDocument(GeneralLedgerEntry primary, Integer capitalAssetLineNumber) throws WorkflowException {
    // initiate a new document
    MaintenanceDocument document = (MaintenanceDocument) documentService.getNewDocument(DocumentTypeName.ASSET_ADD_GLOBAL);
    // create asset global
    AssetGlobal assetGlobal = createAssetGlobal(primary, document);
    assetGlobal.setCapitalAssetBuilderOriginIndicator(true);
    assetGlobal.setAcquisitionTypeCode(assetGlobalService.getNewAcquisitionTypeCode());
    updatePreTagInformation(primary, document, assetGlobal, capitalAssetLineNumber);
    assetGlobal.getAssetPaymentDetails().addAll(createAssetPaymentDetails(primary, document, 0, capitalAssetLineNumber));
    // save the document
    document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
    document.getDocumentHeader().setDocumentDescription(CAB_DESC_PREFIX + primary.getDocumentNumber());
    document.getNewMaintainableObject().setBusinessObject(assetGlobal);
    document.getNewMaintainableObject().setBoClass(assetGlobal.getClass());
    documentService.saveDocument(document);
    // mark the capital asset as processed..
    markCapitalAssetProcessed(primary, capitalAssetLineNumber);
    deactivateGLEntries(primary, document, capitalAssetLineNumber);
    return document;
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) AssetGlobal(org.kuali.kfs.module.cam.businessobject.AssetGlobal) NonTransactional(org.kuali.kfs.sys.service.NonTransactional)

Example 5 with MaintenanceDocument

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

the class PaymentWorksDataProcessingIntoKfsServiceImpl method buildVendorMaintenanceDocumentBase.

private MaintenanceDocument buildVendorMaintenanceDocumentBase(VendorDetail newVendorDetail, VendorDetail oldVendorDetail, String documentAction, boolean isNewVendor, List<Note> notesToPersist) throws WorkflowException {
    MaintenanceDocument vendorMaintDoc = (MaintenanceDocument) getDocumentService().getNewDocument(CUVendorConstants.VENDOR_DOCUMENT_TYPE_NAME);
    vendorMaintDoc.getNewMaintainableObject().setBusinessObject(newVendorDetail);
    vendorMaintDoc.getOldMaintainableObject().setBusinessObject(oldVendorDetail);
    vendorMaintDoc.getDocumentHeader().setDocumentDescription(buildVendorMainenanceDocumentDescription(newVendorDetail, isNewVendor));
    vendorMaintDoc.getNewMaintainableObject().setMaintenanceAction(documentAction);
    for (Note note : notesToPersist) {
        note.setRemoteObjectIdentifier(vendorMaintDoc.getObjectId());
        vendorMaintDoc.addNote(note);
    }
    return vendorMaintDoc;
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) Note(org.kuali.kfs.krad.bo.Note)

Aggregations

MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)15 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)7 Date (java.sql.Date)3 UserSession (org.kuali.kfs.krad.UserSession)3 Note (org.kuali.kfs.krad.bo.Note)3 AppropriationAccount (edu.cornell.kfs.coa.businessobject.AppropriationAccount)2 CuAccountGlobal (edu.cornell.kfs.coa.businessobject.CuAccountGlobal)2 Account (org.kuali.kfs.coa.businessobject.Account)2 AccountGlobal (org.kuali.kfs.coa.businessobject.AccountGlobal)2 IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)2 DocumentHeader (org.kuali.kfs.krad.bo.DocumentHeader)2 Document (org.kuali.kfs.krad.document.Document)2 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)2 DocumentService (org.kuali.kfs.krad.service.DocumentService)2 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)2 CheckReconciliation (com.rsmart.kuali.kfs.cr.businessobject.CheckReconciliation)1 AccountExtendedAttribute (edu.cornell.kfs.coa.businessobject.AccountExtendedAttribute)1 SubFundProgram (edu.cornell.kfs.coa.businessobject.SubFundProgram)1 AccountReversionTrickleDownInactivationService (edu.cornell.kfs.coa.service.AccountReversionTrickleDownInactivationService)1 KfsVendorDataWrapper (edu.cornell.kfs.pmw.batch.businessobject.KfsVendorDataWrapper)1