001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.Address;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.base.AddressServiceBaseImpl;
022    import com.liferay.portal.service.permission.CommonPermissionUtil;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Alexander Chow
029     */
030    public class AddressServiceImpl extends AddressServiceBaseImpl {
031    
032            public Address addAddress(
033                            String className, long classPK, String street1, String street2,
034                            String street3, String city, String zip, long regionId,
035                            long countryId, int typeId, boolean mailing, boolean primary)
036                    throws PortalException, SystemException {
037    
038                    CommonPermissionUtil.check(
039                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
040    
041                    return addressLocalService.addAddress(
042                            getUserId(), className, classPK, street1, street2, street3, city,
043                            zip, regionId, countryId, typeId, mailing, primary);
044            }
045    
046            public void deleteAddress(long addressId)
047                    throws PortalException, SystemException {
048    
049                    Address address = addressPersistence.findByPrimaryKey(addressId);
050    
051                    CommonPermissionUtil.check(
052                            getPermissionChecker(), address.getClassNameId(),
053                            address.getClassPK(), ActionKeys.UPDATE);
054    
055                    addressLocalService.deleteAddress(addressId);
056            }
057    
058            public Address getAddress(long addressId)
059                    throws PortalException, SystemException {
060    
061                    Address address = addressPersistence.findByPrimaryKey(addressId);
062    
063                    CommonPermissionUtil.check(
064                            getPermissionChecker(), address.getClassNameId(),
065                            address.getClassPK(), ActionKeys.VIEW);
066    
067                    return address;
068            }
069    
070            public List<Address> getAddresses(String className, long classPK)
071                    throws PortalException, SystemException {
072    
073                    CommonPermissionUtil.check(
074                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
075    
076                    return addressLocalService.getAddresses(
077                            getUser().getCompanyId(), className, classPK);
078            }
079    
080            public Address updateAddress(
081                            long addressId, String street1, String street2, String street3,
082                            String city, String zip, long regionId, long countryId, int typeId,
083                            boolean mailing, boolean primary)
084                    throws PortalException, SystemException {
085    
086                    Address address = addressPersistence.findByPrimaryKey(addressId);
087    
088                    CommonPermissionUtil.check(
089                            getPermissionChecker(), address.getClassNameId(),
090                            address.getClassPK(), ActionKeys.UPDATE);
091    
092                    return addressLocalService.updateAddress(
093                            addressId, street1, street2, street3, city, zip, regionId,
094                            countryId, typeId, mailing, primary);
095            }
096    
097    }