Search in sources :

Example 1 with VendorPhoneNumber

use of org.kuali.kfs.vnd.businessobject.VendorPhoneNumber 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 2 with VendorPhoneNumber

use of org.kuali.kfs.vnd.businessobject.VendorPhoneNumber in project cu-kfs by CU-CommunityApps.

the class VendorBatchServiceImpl method updateVendorPhoneNumbers.

/*
     * update existing vendor phone number or create a new one if it does not exist.
     */
private void updateVendorPhoneNumbers(List<VendorBatchPhoneNumber> phoneNumbers, VendorDetail vendor, VendorDetail vDetail) {
    if (CollectionUtils.isNotEmpty(phoneNumbers)) {
        for (VendorBatchPhoneNumber phoneNumber : phoneNumbers) {
            LOG.info("updateVendor phoneNumber " + phoneNumber + TILDA_DELIMITER + phoneNumber.getVendorPhoneGeneratedIdentifier() + TILDA_DELIMITER + phoneNumber.getVendorPhoneTypeCode());
            VendorPhoneNumber vPhoneNumber = new VendorPhoneNumber();
            if (StringUtils.isNotBlank(phoneNumber.getVendorPhoneGeneratedIdentifier())) {
                vPhoneNumber = getVendorPhoneNumber(vDetail, Integer.valueOf(phoneNumber.getVendorPhoneGeneratedIdentifier()));
            }
            setVendorPhoneNumber(phoneNumber, vPhoneNumber);
            if (vPhoneNumber.getVendorPhoneGeneratedIdentifier() == null) {
                vDetail.getVendorPhoneNumbers().add(vPhoneNumber);
                vendor.getVendorPhoneNumbers().add(new VendorPhoneNumber());
            }
        // TODO : what to do with those existing contacts, but not passed from request
        }
    }
}
Also used : VendorBatchPhoneNumber(edu.cornell.kfs.vnd.businessobject.VendorBatchPhoneNumber) VendorPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorPhoneNumber)

Example 3 with VendorPhoneNumber

use of org.kuali.kfs.vnd.businessobject.VendorPhoneNumber in project cu-kfs by CU-CommunityApps.

the class VendorBatchServiceImpl method getVendorPhoneNumbers.

/*
	 * populate list of vendor batch phone numbers to vendor phone numbers
	 */
private List<VendorPhoneNumber> getVendorPhoneNumbers(List<VendorBatchPhoneNumber> phoneNumbers) {
    List<VendorPhoneNumber> vendorPhoneNumbers = new ArrayList<VendorPhoneNumber>();
    if (CollectionUtils.isNotEmpty(phoneNumbers)) {
        for (VendorBatchPhoneNumber phoneNumber : phoneNumbers) {
            LOG.info("addVendor phoneNumber " + phoneNumber);
            VendorPhoneNumber vPhoneNumber = new VendorPhoneNumber();
            setVendorPhoneNumber(phoneNumber, vPhoneNumber);
            vendorPhoneNumbers.add(vPhoneNumber);
        }
    }
    return vendorPhoneNumbers;
}
Also used : VendorBatchPhoneNumber(edu.cornell.kfs.vnd.businessobject.VendorBatchPhoneNumber) ArrayList(java.util.ArrayList) VendorPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorPhoneNumber)

Example 4 with VendorPhoneNumber

use of org.kuali.kfs.vnd.businessobject.VendorPhoneNumber in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method refresh.

/**
 * @see org.kuali.kfs.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
 * javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    IWantDocumentForm iWantDocForm = (IWantDocumentForm) form;
    IWantDocument iWantDocument = iWantDocForm.getIWantDocument();
    ActionForward actionForward = super.refresh(mapping, form, request, response);
    String refreshCaller = request.getParameter(KFSConstants.REFRESH_CALLER);
    if (refreshCaller != null && refreshCaller.endsWith(KFSConstants.LOOKUPABLE_SUFFIX)) {
        String deliverToNetID = iWantDocument.getDeliverToNetID();
        if (StringUtils.isNotEmpty(deliverToNetID)) {
            IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
            String address = iWantDocumentService.getPersonCampusAddress(deliverToNetID);
            iWantDocument.setDeliverToAddress(address);
        }
        if ("iWantDocVendorLookupable".equalsIgnoreCase(refreshCaller)) {
            Integer vendorHeaderId = iWantDocument.getVendorHeaderGeneratedIdentifier();
            Integer vendorId = iWantDocument.getVendorDetailAssignedIdentifier();
            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 = getBusinessObjectService().findMatching(VendorPhoneNumber.class, fieldValues);
            if (ObjectUtils.isNotNull(vendorPhoneNumbers) && vendorPhoneNumbers.size() > 0) {
                VendorPhoneNumber retrievedVendorPhoneNumber = vendorPhoneNumbers.toArray(new VendorPhoneNumber[1])[0];
                phoneNumber += retrievedVendorPhoneNumber.getVendorPhoneNumber();
            }
            // populate vendor info
            String addressLine1 = iWantDocument.getVendorLine1Address() != null ? iWantDocument.getVendorLine1Address() : StringUtils.EMPTY;
            String addressLine2 = iWantDocument.getVendorLine2Address() != null ? iWantDocument.getVendorLine2Address() : StringUtils.EMPTY;
            String cityName = iWantDocument.getVendorCityName() != null ? iWantDocument.getVendorCityName() : StringUtils.EMPTY;
            String stateCode = iWantDocument.getVendorStateCode() != null ? iWantDocument.getVendorStateCode() : StringUtils.EMPTY;
            String countryCode = iWantDocument.getVendorCountryCode() != null ? iWantDocument.getVendorCountryCode() : StringUtils.EMPTY;
            String postalCode = iWantDocument.getVendorPostalCode() != null ? iWantDocument.getVendorPostalCode() : StringUtils.EMPTY;
            String faxNumber = "Fax: " + (iWantDocument.getVendorFaxNumber() != null ? iWantDocument.getVendorFaxNumber() : StringUtils.EMPTY);
            String url = "URL: " + (iWantDocument.getVendorWebURL() != null ? iWantDocument.getVendorWebURL() : 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);
        }
    }
    return actionForward;
}
Also used : HashMap(java.util.HashMap) ActionForward(org.apache.struts.action.ActionForward) VendorPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorPhoneNumber) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) IWantDocumentService(edu.cornell.kfs.module.purap.document.service.IWantDocumentService)

Aggregations

VendorPhoneNumber (org.kuali.kfs.vnd.businessobject.VendorPhoneNumber)4 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)2 VendorBatchPhoneNumber (edu.cornell.kfs.vnd.businessobject.VendorBatchPhoneNumber)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BatchIWantDocument (edu.cornell.kfs.module.purap.document.BatchIWantDocument)1 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)1 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ActionForward (org.apache.struts.action.ActionForward)1 AdHocRoutePerson (org.kuali.kfs.krad.bo.AdHocRoutePerson)1 SaveDocumentEvent (org.kuali.kfs.krad.rules.rule.event.SaveDocumentEvent)1 ParseException (org.kuali.kfs.sys.exception.ParseException)1 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)1 Person (org.kuali.rice.kim.api.identity.Person)1