Example usage for com.liferay.portal.kernel.service ListTypeLocalServiceUtil getListTypes

List of usage examples for com.liferay.portal.kernel.service ListTypeLocalServiceUtil getListTypes

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ListTypeLocalServiceUtil getListTypes.

Prototype

public static java.util.List<com.liferay.portal.kernel.model.ListType> getListTypes(String type) 

Source Link

Usage

From source file:com.bemis.portal.customer.service.impl.CustomerProfileLocalServiceImpl.java

License:Open Source License

@Override
public void addorUpdateCustomerProfile(CustomerProfile customerProfile) throws PortalException {

    long userId = _bemisPortalService.getDefaultUser().getUserId();
    long companyId = _bemisPortalService.getDefaultCompanyId();
    long countryId = 0;
    long regionId = 0;

    // Get country and region information

    String countryName = formatCountryName(customerProfile.getCustomerCountry());

    Country country = _countryService.getCountryByName(countryName);

    if (country != null) {
        countryId = country.getCountryId();

        Region region = _regionService.fetchRegion(countryId, customerProfile.getCustomerState());

        if (region != null) {
            regionId = region.getRegionId();
        }/* ww w .j a va2 s  . c o  m*/
    }

    // Save the organization

    String bemisCustomerId = customerProfile.getBemisCustomerId();

    Organization storedOrganization = getOrganization(bemisCustomerId);

    // We just update the Organization dont create.

    if (storedOrganization != null) {

        // Validate Address

        if (isValidAddress(customerProfile)) {

            // Update Address

            Address address = storedOrganization.getAddress();

            if (address.getAddressId() == 0) {
                long addressId = counterLocalService.increment(Address.class.getName());

                address.setAddressId(addressId);
            }

            address.setCompanyId(companyId);
            address.setUserId(userId);
            address.setClassName(Organization.class.getName());
            address.setClassPK(storedOrganization.getOrganizationId());

            address.setStreet1(customerProfile.getCustomerAddress2());
            address.setStreet2(customerProfile.getCustomerAddress1());
            address.setStreet3(customerProfile.getCustomerPoBox());

            address.setCity(customerProfile.getCustomerCity());
            address.setCountryId(countryId);
            address.setRegionId(regionId);
            address.setZip(customerProfile.getCustomerPostalCde());

            long orgAddressListTypeId = 12000;

            List<ListType> orgAddressListTypes = ListTypeLocalServiceUtil
                    .getListTypes("com.liferay.portal.kernel.model.Organization.address");

            for (ListType orgAddressListType : orgAddressListTypes) {
                if (orgAddressListType.getName().equals("billing")) {
                    orgAddressListTypeId = orgAddressListType.getListTypeId();
                    break;
                }
            }

            address.setTypeId(orgAddressListTypeId);

            _addressLocalService.updateAddress(address);
        } else {
            if (_log.isWarnEnabled()) {
                _log.warn("Address is not valid for customer profile ");
            }
        }
    }
}