Search in sources :

Example 1 with PhoneNumberService

use of org.kuali.kfs.vnd.service.PhoneNumberService in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method refresh.

@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;
    PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();
    String refreshCaller = baseForm.getRefreshCaller();
    BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
    PhoneNumberService phoneNumberService = SpringContext.getBean(PhoneNumberService.class);
    // Format phone numbers
    document.setInstitutionContactPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getInstitutionContactPhoneNumber()));
    document.setRequestorPersonPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getRequestorPersonPhoneNumber()));
    document.setDeliveryToPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getDeliveryToPhoneNumber()));
    // max lengths
    if (StringUtils.equals(refreshCaller, "kimPersonLookupable")) {
        Integer deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.DELIVERY_TO_NAME);
        // KFSPTS-518/KFSUPGRADE-351
        if (deliveryToNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
            deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.DELIVERY_TO_NAME);
        }
        if (StringUtils.isNotEmpty(document.getDeliveryToName()) && ObjectUtils.isNotNull(deliveryToNameMaxLength) && document.getDeliveryToName().length() > deliveryToNameMaxLength) {
            document.setDeliveryToName(document.getDeliveryToName().substring(0, deliveryToNameMaxLength));
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
            GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.DELIVERY_TO_NAME, PurapKeyConstants.WARNING_DELIVERY_TO_NAME_TRUNCATED);
            GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
        }
        Integer requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.REQUESTOR_PERSON_NAME);
        // KFSPTS-518/KFSUPGRADE-351
        if (requestorNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
            requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.REQUESTOR_PERSON_NAME);
        }
        if (StringUtils.isNotEmpty(document.getRequestorPersonName()) && ObjectUtils.isNotNull(requestorNameMaxLength) && document.getRequestorPersonName().length() > requestorNameMaxLength) {
            document.setRequestorPersonName(document.getRequestorPersonName().substring(0, requestorNameMaxLength));
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
            GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.REQUESTOR_PERSON_NAME, PurapKeyConstants.WARNING_REQUESTOR_NAME_TRUNCATED);
            GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
        }
    }
    // Refreshing the fields after returning from a vendor lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_LOOKUPABLE_IMPL) && document.getVendorDetailAssignedIdentifier() != null && document.getVendorHeaderGeneratedIdentifier() != null) {
        document.setVendorContractGeneratedIdentifier(null);
        document.refreshReferenceObject("vendorContract");
        // retrieve vendor based on selection from vendor lookup
        document.refreshReferenceObject("vendorDetail");
        document.templateVendorDetail(document.getVendorDetail());
        // KFSPTS-1612 : populate vendor contract name
        if (CollectionUtils.isNotEmpty(document.getVendorDetail().getVendorContracts())) {
            for (VendorContract vendorContract : document.getVendorDetail().getVendorContracts()) {
                if (vendorContract.isActive()) {
                    document.setVendorContractGeneratedIdentifier(vendorContract.getVendorContractGeneratedIdentifier());
                    document.refreshReferenceObject("vendorContract");
                }
            }
        }
        // populate default address based on selected vendor
        VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), document.getDeliveryCampusCode());
        if (defaultAddress == null) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
        }
        document.templateVendorAddress(defaultAddress);
        // CU enhancement KFSUPGRDE-348
        document.setPurchaseOrderTransmissionMethodCode(((CuVendorAddressExtension) defaultAddress.getExtension()).getPurchaseOrderTransmissionMethodCode());
    }
    // Refreshing the fields after returning from a contract lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_CONTRACT_LOOKUPABLE_IMPL)) {
        if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_CONTRACT_ID))) {
            // retrieve Contract based on selection from contract lookup
            VendorContract refreshVendorContract = new VendorContract();
            refreshVendorContract.setVendorContractGeneratedIdentifier(document.getVendorContractGeneratedIdentifier());
            refreshVendorContract = (VendorContract) businessObjectService.retrieve(refreshVendorContract);
            // retrieve Vendor based on selected contract
            document.setVendorHeaderGeneratedIdentifier(refreshVendorContract.getVendorHeaderGeneratedIdentifier());
            document.setVendorDetailAssignedIdentifier(refreshVendorContract.getVendorDetailAssignedIdentifier());
            document.refreshReferenceObject("vendorDetail");
            document.templateVendorDetail(document.getVendorDetail());
            // always template contract after vendor to keep contract defaults last
            document.templateVendorContract(refreshVendorContract);
            // populate default address from selected vendor
            VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), "");
            if (defaultAddress == null) {
                GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
            }
            document.templateVendorAddress(defaultAddress);
            // update internal dollar limit for PO since the contract might affect this value
            if (document instanceof PurchaseOrderDocument) {
                PurchaseOrderDocument poDoc = (PurchaseOrderDocument) document;
                KualiDecimal limit = SpringContext.getBean(PurchaseOrderService.class).getInternalPurchasingDollarLimit(poDoc);
                poDoc.setInternalPurchasingLimit(limit);
            }
        }
    }
    // Refreshing the fields after returning from an address lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
        if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
            // retrieve address based on selection from address lookup
            VendorAddress refreshVendorAddress = new VendorAddress();
            refreshVendorAddress.setVendorAddressGeneratedIdentifier(document.getVendorAddressGeneratedIdentifier());
            refreshVendorAddress = (VendorAddress) businessObjectService.retrieve(refreshVendorAddress);
            document.templateVendorAddress(refreshVendorAddress);
        }
    }
    // Refreshing corresponding fields after returning from various kuali lookups
    if (StringUtils.equals(refreshCaller, KFSConstants.KUALI_LOOKUPABLE_IMPL)) {
        if (request.getParameter("document.deliveryCampusCode") != null) {
            // returning from a building or campus lookup on the delivery tab (update billing address)
            BillingAddress billingAddress = new BillingAddress();
            billingAddress.setBillingCampusCode(document.getDeliveryCampusCode());
            Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(billingAddress);
            billingAddress = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(BillingAddress.class, keys);
            document.templateBillingAddress(billingAddress);
            if (request.getParameter("document.deliveryBuildingName") == null) {
                // came from campus lookup not building, so clear building
                clearDeliveryBuildingInfo(document, true);
            } else {
                // came from building lookup then turn off "OTHER" and clear room and line2address
                document.setDeliveryBuildingOtherIndicator(false);
                document.setDeliveryBuildingRoomNumber("");
                document.setDeliveryBuildingLine2Address("");
            }
        } else if (request.getParameter("document.chartOfAccountsCode") != null) {
            // returning from a chart/org lookup on the document detail tab (update receiving address)
            document.loadReceivingAddress();
        } else {
            // returning from a building lookup in a capital asset tab location (update location address)
            String buildingCodeParam = findBuildingCodeFromCapitalAssetBuildingLookup(request);
            if (StringUtils.isNotEmpty(buildingCodeParam)) {
                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
                updateCapitalAssetLocation(request, purchasingForm, document, buildingCodeParam);
            }
        }
    }
    return super.refresh(mapping, form, request, response);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PhoneNumberService(org.kuali.kfs.vnd.service.PhoneNumberService) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) PurchaseOrderService(org.kuali.kfs.module.purap.document.service.PurchaseOrderService) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) DataDictionaryService(org.kuali.kfs.datadictionary.legacy.DataDictionaryService) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) VendorService(org.kuali.kfs.vnd.document.service.VendorService) BillingAddress(org.kuali.kfs.module.purap.businessobject.BillingAddress) PersistenceService(org.kuali.kfs.krad.service.PersistenceService) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 2 with PhoneNumberService

use of org.kuali.kfs.vnd.service.PhoneNumberService in project cu-kfs by CU-CommunityApps.

the class PurchaseOrderTransmissionMethodDataRulesServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    poTransMethodSataRulesService = new PurchaseOrderTransmissionMethodDataRulesServiceImpl();
    PostalCodeValidationService postalCodeValidationSerivce = new testablePostalCodeValidationServiceImpl();
    LocationService mockLocationService = mock(LocationService.class);
    when(mockLocationService.getState(COUNTRY, STATE)).thenReturn(makeState());
    ((PostalCodeValidationServiceImpl) postalCodeValidationSerivce).setLocationService(mockLocationService);
    ((PurchaseOrderTransmissionMethodDataRulesServiceImpl) this.poTransMethodSataRulesService).setPostalCodeValidationService(postalCodeValidationSerivce);
    PhoneNumberService phoneNumberService = new testablePhoneNumberServiceImpl();
    ((PurchaseOrderTransmissionMethodDataRulesServiceImpl) this.poTransMethodSataRulesService).setPhoneNumberService(phoneNumberService);
}
Also used : PostalCodeValidationService(org.kuali.kfs.sys.service.PostalCodeValidationService) PhoneNumberService(org.kuali.kfs.vnd.service.PhoneNumberService) LocationService(org.kuali.kfs.sys.service.LocationService) PostalCodeValidationServiceImpl(org.kuali.kfs.sys.service.impl.PostalCodeValidationServiceImpl) Before(org.junit.Before)

Example 3 with PhoneNumberService

use of org.kuali.kfs.vnd.service.PhoneNumberService in project cu-kfs by CU-CommunityApps.

the class DisbursementVoucherDocument method initiateDocument.

/**
 * generic, shared logic used to initiate a dv document
 */
public void initiateDocument() {
    PhoneNumberService phoneNumberService = SpringContext.getBean(PhoneNumberService.class);
    Person currentUser = GlobalVariables.getUserSession().getPerson();
    setDisbVchrContactPersonName(currentUser.getName());
    if (!phoneNumberService.isDefaultFormatPhoneNumber(currentUser.getPhoneNumber())) {
        setDisbVchrContactPhoneNumber(phoneNumberService.formatNumberIfPossible(currentUser.getPhoneNumber()));
    } else {
        setDisbVchrContactPhoneNumber(currentUser.getPhoneNumber());
    }
    setDisbVchrContactEmailId(currentUser.getEmailAddress());
    ChartOrgHolder chartOrg = SpringContext.getBean(org.kuali.kfs.sys.service.FinancialSystemUserService.class).getPrimaryOrganization(currentUser, KFSConstants.CoreModuleNamespaces.FINANCIAL);
    // the campus code via the business object service.
    if (chartOrg != null && chartOrg.getOrganization() != null) {
        setCampusCode(chartOrg.getOrganization().getOrganizationPhysicalCampusCode());
    } else {
        // A valid campus code was not found; therefore, use the default affiliated  campus code.
        String affiliatedCampusCode = currentUser.getCampusCode();
        setCampusCode(affiliatedCampusCode);
    }
    // due date
    Calendar calendar = getDateTimeService().getCurrentCalendar();
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    setDisbursementVoucherDueDate(new Date(calendar.getTimeInMillis()));
    // default doc location
    if (StringUtils.isBlank(getDisbursementVoucherDocumentationLocationCode())) {
        setDisbursementVoucherDocumentationLocationCode(getParameterService().getParameterValueAsString(DisbursementVoucherDocument.class, FPParameterConstants.DEFAULT_DOC_LOCATION));
    }
    // default bank code
    Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
    if (defaultBank != null) {
        this.disbVchrBankCode = defaultBank.getBankCode();
        this.bank = defaultBank;
    }
}
Also used : PhoneNumberService(org.kuali.kfs.vnd.service.PhoneNumberService) BankService(org.kuali.kfs.sys.service.BankService) Bank(org.kuali.kfs.sys.businessobject.Bank) ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) Calendar(java.util.Calendar) Person(org.kuali.kfs.kim.api.identity.Person) Date(java.sql.Date)

Example 4 with PhoneNumberService

use of org.kuali.kfs.vnd.service.PhoneNumberService in project cu-kfs by CU-CommunityApps.

the class CuDisbursementVoucherDocument method initiateDocument.

public void initiateDocument() {
    PhoneNumberService phoneNumberService = SpringContext.getBean(PhoneNumberService.class);
    Person currentUser = GlobalVariables.getUserSession().getPerson();
    setDisbVchrContactPersonName(currentUser.getName());
    setDisbVchrContactEmailId(currentUser.getEmailAddressUnmasked());
    String phoneNumber = currentUser.getPhoneNumber();
    if (StringUtils.isNotBlank(phoneNumber) && !StringUtils.equalsIgnoreCase("null", phoneNumber)) {
        if (!phoneNumberService.isDefaultFormatPhoneNumber(currentUser.getPhoneNumber())) {
            setDisbVchrContactPhoneNumber(phoneNumberService.formatNumberIfPossible(currentUser.getPhoneNumber()));
        } else if (StringUtils.equalsIgnoreCase(phoneNumber, "null")) {
        // do nothing... we don't want phone number set to invalid value
        } else {
            setDisbVchrContactPhoneNumber(phoneNumber);
        }
    }
    if (!phoneNumberService.isDefaultFormatPhoneNumber(currentUser.getPhoneNumber())) {
        setDisbVchrContactPhoneNumber(phoneNumberService.formatNumberIfPossible(currentUser.getPhoneNumber()));
    }
    setDisbVchrContactEmailId(currentUser.getEmailAddress());
    ChartOrgHolder chartOrg = SpringContext.getBean(org.kuali.kfs.sys.service.FinancialSystemUserService.class).getPrimaryOrganization(currentUser, KFSConstants.CoreModuleNamespaces.FINANCIAL);
    // the campus code via the business object service.
    if (chartOrg != null && chartOrg.getOrganization() != null) {
        setCampusCode(chartOrg.getOrganization().getOrganizationPhysicalCampusCode());
    } else {
        // A valid campus code was not found; therefore, use the default affiliated  campus code.
        String affiliatedCampusCode = currentUser.getCampusCode();
        setCampusCode(affiliatedCampusCode);
    }
    setDisbursementVoucherDueDate(getCuDisbursementVoucherDefaultDueDateService().findDefaultDueDate());
    // default doc location
    if (StringUtils.isBlank(getDisbursementVoucherDocumentationLocationCode())) {
        setDisbursementVoucherDocumentationLocationCode(getParameterService().getParameterValueAsString(DisbursementVoucherDocument.class, FPParameterConstants.DEFAULT_DOC_LOCATION));
    }
    // default bank code
    Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
    if (defaultBank != null) {
        this.disbVchrBankCode = defaultBank.getBankCode();
        this.bank = defaultBank;
    }
}
Also used : PhoneNumberService(org.kuali.kfs.vnd.service.PhoneNumberService) BankService(org.kuali.kfs.sys.service.BankService) Bank(org.kuali.kfs.sys.businessobject.Bank) ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) Person(org.kuali.kfs.kim.api.identity.Person) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Aggregations

PhoneNumberService (org.kuali.kfs.vnd.service.PhoneNumberService)4 Person (org.kuali.kfs.kim.api.identity.Person)2 Bank (org.kuali.kfs.sys.businessobject.Bank)2 ChartOrgHolder (org.kuali.kfs.sys.businessobject.ChartOrgHolder)2 BankService (org.kuali.kfs.sys.service.BankService)2 Date (java.sql.Date)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 Before (org.junit.Before)1 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)1 DataDictionaryService (org.kuali.kfs.datadictionary.legacy.DataDictionaryService)1 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)1 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1 PersistenceService (org.kuali.kfs.krad.service.PersistenceService)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 BillingAddress (org.kuali.kfs.module.purap.businessobject.BillingAddress)1 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)1 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)1 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)1 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)1