Search in sources :

Example 51 with Note

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

the class IWantDocumentFeedServiceImpl method addNotes.

/**
 * Adds notes to the I Want document.
 * @param document
 * @param batchIWantDocument
 */
private void addNotes(IWantDocument document, BatchIWantDocument batchIWantDocument) {
    // set notes
    for (Iterator iterator = batchIWantDocument.getNotes().iterator(); iterator.hasNext(); ) {
        Note note = (Note) iterator.next();
        note.setRemoteObjectIdentifier(document.getObjectId());
        note.setAuthorUniversalIdentifier(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
        note.setNoteTypeCode(KFSConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
        note.setNotePostedTimestampToCurrent();
        note.setNoteText("Note: " + note.getNoteText());
        document.addNote(note);
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note) Iterator(java.util.Iterator)

Example 52 with Note

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

the class IWantDocumentFeedServiceImpl method loadDocumentAttachments.

/**
 * Adds attachments to the I Want document.
 * @param document
 * @param attachments
 */
private void loadDocumentAttachments(IWantDocument document, List<BatchIWantAttachment> attachments, String incomingFileName) {
    String attachmentsPath = new File(iWantDocumentInputFileType.getDirectoryPath()).toString() + "/attachment/";
    for (BatchIWantAttachment attachment : attachments) {
        Note note = new Note();
        note.setNoteText(attachment.getAttachmentType());
        note.setRemoteObjectIdentifier(document.getObjectId());
        note.setAuthorUniversalIdentifier(document.getDocumentHeader().getWorkflowDocument().getPrincipalId());
        note.setNoteTypeCode(KFSConstants.NoteTypeEnum.DOCUMENT_HEADER_NOTE_TYPE.getCode());
        note.setNotePostedTimestampToCurrent();
        // attempt to load file
        String fileName = attachmentsPath + "/" + attachment.getAttachmentFileName();
        File attachmentFile = new File(fileName);
        if (!attachmentFile.exists()) {
            continue;
        }
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(fileName);
            Integer fileSize = Integer.parseInt(Long.toString(attachmentFile.length()));
            String mimeTypeCode = attachment.getAttachmentMimeTypeCode();
            String fileExtension = "." + StringUtils.substringAfterLast(fileName, ".");
            if (StringUtils.isNotBlank(fileExtension) && mimeTypeProperties.containsKey(fileExtension)) {
                if (StringUtils.isBlank(mimeTypeCode)) {
                    mimeTypeCode = mimeTypeProperties.getProperty(fileExtension);
                }
            } else {
                LOG.error("Mime type error" + fileName + " " + mimeTypeCode);
            }
            LOG.info("Mime type " + fileName + " " + mimeTypeCode);
            String attachType = KFSConstants.EMPTY_STRING;
            Attachment noteAttachment = attachmentService.createAttachment(document.getDocumentHeader(), attachment.getAttachmentFileName(), mimeTypeCode, fileSize, fileInputStream, attachType);
            note.addAttachment(noteAttachment);
            document.addNote(note);
        } catch (FileNotFoundException e) {
            continue;
        } catch (IOException e1) {
            throw new RuntimeException("Unable to create attachment for File: " + fileName, e1);
        } finally {
            IOUtils.closeQuietly(fileInputStream);
        }
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note) FileNotFoundException(java.io.FileNotFoundException) BatchIWantAttachment(edu.cornell.kfs.module.purap.businessobject.BatchIWantAttachment) BatchIWantAttachment(edu.cornell.kfs.module.purap.businessobject.BatchIWantAttachment) Attachment(org.kuali.kfs.krad.bo.Attachment) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 53 with Note

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

the class PurchasingActionBase method createReasonNote.

/*
     * creating the change to vendor reason note.
     */
private void createReasonNote(ActionForm form) {
    // TODO : move to service ?
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    try {
        Note noteObj = SpringContext.getBean(DocumentService.class).createNoteFromDocument(kualiDocumentFormBase.getDocument(), ((PurchasingFormBase) kualiDocumentFormBase).getReasonToChange());
        populateIdentifierOnNoteAndExtension(noteObj);
        kualiDocumentFormBase.getDocument().addNote(noteObj);
        if (doesDocumentAllowImmediateSaveOfNewNote(kualiDocumentFormBase.getDocument(), noteObj)) {
            getNoteService().save(noteObj);
        }
        ((PurchasingFormBase) kualiDocumentFormBase).setReasonToChange(KFSConstants.EMPTY_STRING);
    } catch (Exception e) {
        String errorMessage = "Error creating and saving close note for reason change requirement with document service";
        LOG.error("createReasonNote " + errorMessage, e);
        throw new RuntimeException(errorMessage, e);
    }
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) Note(org.kuali.kfs.krad.bo.Note) DocumentService(org.kuali.kfs.krad.service.DocumentService) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ItemParserException(org.kuali.kfs.module.purap.exception.ItemParserException)

Example 54 with Note

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

the class PurchasingActionBase method changeSystem.

public ActionForward changeSystem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingAccountsPayableFormBase purchasingForm = (PurchasingAccountsPayableFormBase) form;
    PurchasingDocument document = (PurchasingDocument) purchasingForm.getDocument();
    Object question = request.getParameter(PurapConstants.QUESTION_INDEX);
    Object buttonClicked = request.getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
    if (question == null) {
        String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.PURCHASING_QUESTION_CONFIRM_CHANGE_SYSTEM);
        return this.performQuestionWithoutInput(mapping, form, request, response, PurapConstants.CapitalAssetTabStrings.SYSTEM_SWITCHING_QUESTION, questionText, KFSConstants.CONFIRMATION_QUESTION, KFSConstants.ROUTE_METHOD, "0");
    } else if (ConfirmationQuestion.YES.equals(buttonClicked)) {
        // Add a note if system change occurs when the document is a PO that is being amended.
        if ((document instanceof PurchaseOrderDocument) && (PurapConstants.PurchaseOrderStatuses.APPDOC_CHANGE_IN_PROCESS.equals(document.getApplicationDocumentStatus()))) {
            Integer poId = document.getPurapDocumentIdentifier();
            PurchaseOrderDocument currentPO = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(poId);
            String oldSystemTypeCode = "";
            if (currentPO != null) {
                oldSystemTypeCode = currentPO.getCapitalAssetSystemTypeCode();
            }
            CapitalAssetSystemType oldSystemType = new CapitalAssetSystemType();
            oldSystemType.setCapitalAssetSystemTypeCode(oldSystemTypeCode);
            Map<String, String> keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(oldSystemType);
            oldSystemType = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(CapitalAssetSystemType.class, keys);
            String description = ((oldSystemType == null) ? "(NONE)" : oldSystemType.getCapitalAssetSystemTypeDescription());
            if (document instanceof PurchaseOrderAmendmentDocument) {
                String noteText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.PURCHASE_ORDER_AMEND_MESSAGE_CHANGE_SYSTEM_TYPE);
                noteText = StringUtils.replace(noteText, "{0}", description);
                try {
                    Note systemTypeChangeNote = getDocumentService().createNoteFromDocument(document, noteText);
                    purchasingForm.setNewNote(systemTypeChangeNote);
                    insertBONote(mapping, purchasingForm, request, response);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        if (form instanceof RequisitionForm) {
            ((RequisitionForm) form).resetNewPurchasingCapitalAssetLocationLine();
        }
        // remove capital assets from db
        if (document instanceof PurchaseOrderAmendmentDocument) {
            for (PurchasingCapitalAssetItem assetItem : document.getPurchasingCapitalAssetItems()) {
                SpringContext.getBean(BusinessObjectService.class).delete((PersistableBusinessObject) assetItem);
            }
        }
        document.clearCapitalAssetFields();
        SpringContext.getBean(PurapService.class).saveDocumentNoValidation(document);
        KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PURCHASING_MESSAGE_SYSTEM_CHANGED);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) CapitalAssetSystemType(org.kuali.kfs.module.purap.businessobject.CapitalAssetSystemType) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ItemParserException(org.kuali.kfs.module.purap.exception.ItemParserException) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) Note(org.kuali.kfs.krad.bo.Note) PurchasingCapitalAssetItem(org.kuali.kfs.module.purap.businessobject.PurchasingCapitalAssetItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) ConfigurationService(org.kuali.rice.core.api.config.property.ConfigurationService) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 55 with Note

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

the class PurchasingActionBase method getNumberOfNotesToSendToVendor.

private int getNumberOfNotesToSendToVendor(Document purchaseOrder) {
    int numberOfNotesToSendToVendor = 0;
    // for POA purchaseOrder.getBoNotes() is empty, but purchaseOrder.getDocumentBusinessObject().getBoNotes() is not.
    List<Note> notesToSend = purchaseOrder.getNotes();
    if (CollectionUtils.isNotEmpty(notesToSend)) {
        for (Note note : notesToSend) {
            if (StringUtils.equalsIgnoreCase(note.getNoteTopicText(), CUPurapConstants.AttachemntToVendorIndicators.SEND_TO_VENDOR)) {
                numberOfNotesToSendToVendor++;
            }
        }
    }
    return numberOfNotesToSendToVendor;
}
Also used : Note(org.kuali.kfs.krad.bo.Note)

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