Search in sources :

Example 6 with Person

use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class IWantDocumentFeedServiceImpl method populateIWantDocument.

/**
 * Populates an I Want document based on the input data.
 *
 * @param batchIWantDocument
 */
private void populateIWantDocument(BatchIWantDocument batchIWantDocument, String incomingFileName) {
    boolean noErrors = true;
    List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
    LOG.info("Creating I Want document from data related to source number: " + batchIWantDocument.getSourceNumber());
    try {
        if (StringUtils.isBlank(batchIWantDocument.getInitiator())) {
            LOG.error("Initiator net ID cannot be empty: " + batchIWantDocument.getInitiator());
            noErrors = false;
        }
        // if initiator is blank we cannot create the I Want doc
        if (noErrors) {
            Person initiator = personService.getPersonByPrincipalName(batchIWantDocument.getInitiator());
            if (ObjectUtils.isNull(initiator)) {
                LOG.error("Initiator net ID is not valid: " + batchIWantDocument.getInitiator());
                noErrors = false;
            }
            // if initiator is not valid we cannot create the I Want doc
            if (noErrors) {
                IWantDocument iWantDocument = (IWantDocument) documentService.getNewDocument(CUPurapConstants.IWNT_DOC_TYPE, batchIWantDocument.getInitiator());
                iWantDocumentService.setUpIWantDocDefaultValues(iWantDocument, initiator);
                if (StringUtils.isNotBlank(batchIWantDocument.getInitiatorNetID())) {
                    iWantDocument.setInitiatorNetID(batchIWantDocument.getInitiatorNetID());
                }
                iWantDocument.getDocumentHeader().setExplanation(batchIWantDocument.getBusinessPurpose());
                iWantDocument.setExplanation(batchIWantDocument.getBusinessPurpose());
                if (StringUtils.isNotBlank(batchIWantDocument.getCollegeLevelOrganization())) {
                    iWantDocument.setCollegeLevelOrganization(batchIWantDocument.getCollegeLevelOrganization());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getDepartmentLevelOrganization())) {
                    iWantDocument.setDepartmentLevelOrganization(batchIWantDocument.getDepartmentLevelOrganization());
                }
                iWantDocument.getDocumentHeader().setOrganizationDocumentNumber(batchIWantDocument.getSourceNumber());
                // populate requester fields
                populateIWantDocRequestorSection(initiator, batchIWantDocument, iWantDocument);
                // populate deliver to section
                populateIWantDocDeliverToSection(batchIWantDocument, iWantDocument);
                // populate vendor data
                if (StringUtils.isNotBlank(batchIWantDocument.getVendorNumber())) {
                    String[] vendorNumbers = batchIWantDocument.getVendorNumber().split("-");
                    if (vendorNumbers.length == 2) {
                        try {
                            Integer vendorHeaderId = new Integer(vendorNumbers[0]);
                            Integer vendorId = new Integer(vendorNumbers[1]);
                            String phoneNumber = "Phone: ";
                            Map<String, Object> fieldValues = new HashMap<String, Object>();
                            fieldValues.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
                            fieldValues.put("vendorDetailAssignedIdentifier", vendorId);
                            fieldValues.put("vendorPhoneTypeCode", "PH");
                            Collection<VendorPhoneNumber> vendorPhoneNumbers = businessObjectService.findMatching(VendorPhoneNumber.class, fieldValues);
                            if (ObjectUtils.isNotNull(vendorPhoneNumbers) && vendorPhoneNumbers.size() > 0) {
                                VendorPhoneNumber retrievedVendorPhoneNumber = vendorPhoneNumbers.toArray(new VendorPhoneNumber[1])[0];
                                phoneNumber += retrievedVendorPhoneNumber.getVendorPhoneNumber();
                            }
                            Map<String, Object> fieldValuesVendorDetail = new HashMap<String, Object>();
                            fieldValuesVendorDetail.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
                            fieldValuesVendorDetail.put("vendorDetailAssignedIdentifier", vendorId);
                            VendorDetail vendorDetail = businessObjectService.findByPrimaryKey(VendorDetail.class, fieldValuesVendorDetail);
                            if (ObjectUtils.isNotNull(vendorDetail)) {
                                iWantDocument.setVendorHeaderGeneratedIdentifier(vendorHeaderId);
                                iWantDocument.setVendorDetailAssignedIdentifier(vendorId);
                                iWantDocument.setVendorName(vendorDetail.getVendorName());
                                updateDefaultVendorAddress(vendorDetail);
                                // populate vendor info
                                String addressLine1 = vendorDetail.getDefaultAddressLine1() != null ? vendorDetail.getDefaultAddressLine1() : StringUtils.EMPTY;
                                String addressLine2 = vendorDetail.getDefaultAddressLine2() != null ? vendorDetail.getDefaultAddressLine2() : StringUtils.EMPTY;
                                String cityName = vendorDetail.getDefaultAddressCity() != null ? vendorDetail.getDefaultAddressCity() : StringUtils.EMPTY;
                                String stateCode = vendorDetail.getDefaultAddressStateCode() != null ? vendorDetail.getDefaultAddressStateCode() : StringUtils.EMPTY;
                                String countryCode = vendorDetail.getDefaultAddressCountryCode() != null ? vendorDetail.getDefaultAddressCountryCode() : StringUtils.EMPTY;
                                String postalCode = vendorDetail.getDefaultAddressPostalCode() != null ? vendorDetail.getDefaultAddressPostalCode() : StringUtils.EMPTY;
                                String faxNumber = "Fax: " + (vendorDetail.getDefaultFaxNumber() != null ? vendorDetail.getDefaultFaxNumber() : StringUtils.EMPTY);
                                String url = "URL: " + (vendorDetail.getVendorUrlAddress() != null ? vendorDetail.getVendorUrlAddress() : StringUtils.EMPTY);
                                String vendorInfo = new StringBuilder(100).append(addressLine1).append('\n').append(addressLine2).append('\n').append(cityName).append(", ").append(postalCode).append(", ").append(stateCode).append(", ").append(countryCode).append('\n').append(faxNumber).append('\n').append(phoneNumber).append(" \n").append(url).toString();
                                iWantDocument.setVendorDescription(vendorInfo);
                            } else {
                                // Invalid vendor number
                                LOG.error("Vendor with id: " + batchIWantDocument.getVendorNumber() + " does not exist.");
                                noErrors = false;
                            }
                        } catch (NumberFormatException e) {
                            LOG.error("Vendor id: " + batchIWantDocument.getVendorNumber() + " is not valid.");
                            noErrors = false;
                        }
                    } else {
                        // Invalid vendor number
                        LOG.error("Vendor ID is not valid: " + batchIWantDocument.getVendorNumber());
                        noErrors = false;
                    }
                } else {
                    if (StringUtils.isNotEmpty(batchIWantDocument.getVendorName())) {
                        iWantDocument.setVendorName(batchIWantDocument.getVendorName());
                    }
                    if (StringUtils.isNotEmpty(batchIWantDocument.getVendorDescription())) {
                        iWantDocument.setVendorDescription(batchIWantDocument.getVendorDescription());
                    }
                }
                // add items
                noErrors &= populateIWantDocItems(batchIWantDocument, iWantDocument);
                // add accounts
                noErrors &= populateIWantDocAccounts(batchIWantDocument, iWantDocument);
                // account Description
                if (StringUtils.isNotBlank(batchIWantDocument.getAccountDescriptionTxt())) {
                    iWantDocument.setAccountDescriptionTxt(batchIWantDocument.getAccountDescriptionTxt());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getCommentsAndSpecialInstructions())) {
                    iWantDocument.setCommentsAndSpecialInstructions(batchIWantDocument.getCommentsAndSpecialInstructions());
                }
                iWantDocument.setGoods(batchIWantDocument.isGoods());
                if (StringUtils.isNotBlank(batchIWantDocument.getServicePerformedOnCampus())) {
                    iWantDocument.setServicePerformedOnCampus(batchIWantDocument.getServicePerformedOnCampus());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getCurrentRouteToNetId())) {
                    Person adHocRouteTo = personService.getPersonByPrincipalName(batchIWantDocument.getCurrentRouteToNetId());
                    if (ObjectUtils.isNull(adHocRouteTo)) {
                        LOG.error("Ad Hoc Route to net ID is not valid: " + batchIWantDocument.getCurrentRouteToNetId());
                        noErrors = false;
                    } else {
                        iWantDocument.setCurrentRouteToNetId(batchIWantDocument.getCurrentRouteToNetId());
                        AdHocRoutePerson recipient = new AdHocRoutePerson();
                        recipient.setId(iWantDocument.getCurrentRouteToNetId());
                        recipient.setActionRequested(KewApiConstants.ACTION_REQUEST_APPROVE_REQ);
                        adHocRoutePersons.add(recipient);
                        iWantDocument.setAdHocRoutePersons(adHocRoutePersons);
                    }
                }
                iWantDocumentService.setIWantDocumentDescription(iWantDocument);
                // add notes
                addNotes(iWantDocument, batchIWantDocument);
                // add attachments
                loadDocumentAttachments(iWantDocument, batchIWantDocument.getAttachments(), incomingFileName);
                boolean rulePassed = true;
                // call business rules
                rulePassed &= ruleService.applyRules(new SaveDocumentEvent("", iWantDocument));
                if (!rulePassed) {
                    LOG.error("I Want document " + iWantDocument.getDocumentNumber() + "not saved due to errors");
                    logErrorMessages();
                } else if (noErrors) {
                    documentService.saveDocument(iWantDocument);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("error while creating I Want document:  " + e.getMessage(), e);
        throw new RuntimeException("Error encountered while attempting to create I Want document " + e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaveDocumentEvent(org.kuali.kfs.krad.rules.rule.event.SaveDocumentEvent) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) VendorPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorPhoneNumber) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) Person(org.kuali.rice.kim.api.identity.Person) BatchIWantDocument(edu.cornell.kfs.module.purap.document.BatchIWantDocument) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument)

Example 7 with Person

use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class EzraServiceImpl method createProjectDirectors.

private List<ProposalProjectDirector> createProjectDirectors(String projectId, EzraProject project) {
    List<ProposalProjectDirector> projDirs = new ArrayList<ProposalProjectDirector>();
    Investigator investigator = (Investigator) businessObjectService.findBySinglePrimaryKey(Investigator.class, project.getProjectDirectorId());
    if (investigator != null) {
        PersonService ps = SpringContext.getBean(PersonService.class);
        if (investigator.getNetId() != null) {
            Person director = ps.getPersonByPrincipalName(investigator.getNetId());
            if (director != null) {
                Map primaryKeys = new HashMap();
                primaryKeys.put("principalId", director.getPrincipalId());
                primaryKeys.put("proposalNumber", projectId);
                ProposalProjectDirector ppd = (ProposalProjectDirector) businessObjectService.findByPrimaryKey(ProposalProjectDirector.class, primaryKeys);
                if (ObjectUtils.isNull(ppd)) {
                    ppd = new ProposalProjectDirector();
                }
                // else {
                // ppd.setVersionNumber(ppd.getVersionNumber());
                // }
                ppd.setPrincipalId(director.getPrincipalId());
                ppd.setProposalNumber(project.getProjectId());
                ppd.setProposalPrimaryProjectDirectorIndicator(true);
                ppd.setActive(true);
                KimApiServiceLocator.getRoleService().assignPrincipalToRole(director.getPrincipalId(), "KFS-SYS", "Contracts & Grants Project Director", new HashMap<String, String>());
                projDirs.add(ppd);
            } else {
                LOG.error("PI: " + investigator.getNetId() + " for award :" + projectId + " is not in kfs");
            }
        } else {
            LOG.error("PI netId for award :" + projectId + " is null");
        }
    } else {
        LOG.error("Null PI: " + project.getProjectDirectorId());
    }
    Map fieldValues = new HashMap();
    fieldValues.put("projectId", projectId.toString());
    fieldValues.put("investigatorRole", "CO");
    List<ProjectInvestigator> pis = (List<ProjectInvestigator>) businessObjectService.findMatching(ProjectInvestigator.class, fieldValues);
    for (ProjectInvestigator pi : pis) {
        if (pi.getInvestigatorId() != null) {
            Investigator inv = (Investigator) businessObjectService.findBySinglePrimaryKey(Investigator.class, pi.getInvestigatorId());
            if (inv != null) {
                PersonService ps = SpringContext.getBean(PersonService.class);
                if (inv.getNetId() != null) {
                    Person director = ps.getPersonByPrincipalName(inv.getNetId());
                    if (director != null) {
                        Map primaryKeys = new HashMap();
                        primaryKeys.put("principalId", director.getPrincipalId());
                        primaryKeys.put("proposalNumber", projectId);
                        ProposalProjectDirector ppd = (ProposalProjectDirector) businessObjectService.findByPrimaryKey(ProposalProjectDirector.class, primaryKeys);
                        if (ObjectUtils.isNull(ppd)) {
                            ppd = new ProposalProjectDirector();
                        }
                        ppd.setPrincipalId(director.getPrincipalId());
                        ppd.setProposalNumber(project.getProjectId());
                        ppd.setProposalPrimaryProjectDirectorIndicator(false);
                        ppd.setActive(true);
                        KimApiServiceLocator.getRoleService().assignPrincipalToRole(director.getPrincipalId(), "KFS-SYS", "Contracts & Grants Project Director", new HashMap<String, String>());
                        // check to make sure that this project director is not already in the list.
                        for (ProposalProjectDirector projDir : projDirs) {
                            if (projDir.getPrincipalId().equals(ppd.getPrincipalId()))
                                continue;
                        }
                        projDirs.add(ppd);
                    } else {
                        LOG.error("Investigator: " + investigator.getNetId() + " is for award :" + projectId + " is not in kfs");
                    }
                } else {
                    LOG.error("Invesigator netId for award :" + projectId + " is null");
                }
            } else {
                LOG.error("Null investigator: " + pi.getInvestigatorId());
            }
        } else {
            LOG.error("Null investigator id: ");
        }
    }
    return projDirs;
}
Also used : HashMap(java.util.HashMap) PersonService(org.kuali.rice.kim.api.identity.PersonService) ArrayList(java.util.ArrayList) ProposalProjectDirector(org.kuali.kfs.module.cg.businessobject.ProposalProjectDirector) Investigator(edu.cornell.kfs.module.ezra.businessobject.Investigator) ProjectInvestigator(edu.cornell.kfs.module.ezra.businessobject.ProjectInvestigator) ArrayList(java.util.ArrayList) List(java.util.List) ProjectInvestigator(edu.cornell.kfs.module.ezra.businessobject.ProjectInvestigator) Person(org.kuali.rice.kim.api.identity.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with Person

use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class CUFinancialSystemDocumentServiceImpl method setupFYIs.

protected void setupFYIs(Document doc, Set<Person> priorApprovers, String initiatorUserId) {
    List<AdHocRoutePerson> adHocRoutePersons = doc.getAdHocRoutePersons();
    final FinancialSystemTransactionalDocumentAuthorizerBase documentAuthorizer = getDocumentAuthorizer(doc);
    // Add FYI for each approver who has already approved the document
    for (Person approver : priorApprovers) {
        if (documentAuthorizer.canReceiveAdHoc(doc, approver, KewApiConstants.ACTION_REQUEST_FYI_REQ)) {
            String approverPersonUserId = approver.getPrincipalName();
            adHocRoutePersons.add(buildFyiRecipient(approverPersonUserId));
        }
    }
    // Add FYI for initiator
    adHocRoutePersons.add(buildFyiRecipient(initiatorUserId));
}
Also used : FinancialSystemTransactionalDocumentAuthorizerBase(org.kuali.kfs.sys.document.authorization.FinancialSystemTransactionalDocumentAuthorizerBase) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) Person(org.kuali.rice.kim.api.identity.Person)

Example 9 with Person

use of org.kuali.rice.kim.api.identity.Person 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 10 with Person

use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class FormatAction method start.

/**
 * This method prepares the data for the format process
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormatForm formatForm = (FormatForm) form;
    Person kualiUser = GlobalVariables.getUserSession().getPerson();
    FormatSelection formatSelection = formatService.getDataForFormat(kualiUser);
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
    formatForm.setCampus(kualiUser.getCampusCode());
    // no data for format because another format process is already running
    if (formatSelection.getStartDate() != null) {
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.Format.ERROR_PDP_FORMAT_PROCESS_ALREADY_RUNNING, dateTimeService.toDateTimeString(formatSelection.getStartDate()));
    } else {
        List<CustomerProfile> customers = formatSelection.getCustomerList();
        for (CustomerProfile element : customers) {
            if (formatSelection.getCampus().equals(element.getDefaultPhysicalCampusProcessingCode())) {
                element.setSelectedForFormat(Boolean.TRUE);
            } else {
                element.setSelectedForFormat(Boolean.FALSE);
            }
        }
        formatForm.setPaymentDate(dateTimeService.toDateString(dateTimeService.getCurrentTimestamp()));
        formatForm.setPaymentTypes(PdpConstants.PaymentTypes.ALL);
        formatForm.setCustomers(customers);
        formatForm.setRanges(formatSelection.getRangeList());
    }
    return mapping.findForward(PdpConstants.MAPPING_SELECTION);
}
Also used : FormatSelection(org.kuali.kfs.pdp.businessobject.FormatSelection) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) Person(org.kuali.rice.kim.api.identity.Person) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService)

Aggregations

Person (org.kuali.rice.kim.api.identity.Person)64 ArrayList (java.util.ArrayList)12 PersonService (org.kuali.rice.kim.api.identity.PersonService)12 HashMap (java.util.HashMap)10 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)8 List (java.util.List)6 AdHocRoutePerson (org.kuali.kfs.krad.bo.AdHocRoutePerson)6 Map (java.util.Map)5 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)5 Note (org.kuali.kfs.krad.bo.Note)5 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)5 DateTimeService (org.kuali.rice.core.api.datetime.DateTimeService)5 MessageMap (org.kuali.kfs.krad.util.MessageMap)4 CustomerProfile (org.kuali.kfs.pdp.businessobject.CustomerProfile)4 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)4 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)4 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)3 Date (java.util.Date)3 ChartOrgHolder (org.kuali.kfs.sys.businessobject.ChartOrgHolder)3 AccountingXmlDocumentNote (edu.cornell.kfs.fp.batch.xml.AccountingXmlDocumentNote)2