001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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.model.User;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portal.service.base.AddressServiceBaseImpl;
024    import com.liferay.portal.service.permission.CommonPermissionUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Alexander Chow
031     */
032    public class AddressServiceImpl extends AddressServiceBaseImpl {
033    
034            /**
035             * @deprecated As of 6.2.0, replaced by {@link #addAddress( String, long,
036             *             String, String, String, String, String, long, long, int,
037             *             boolean, boolean, ServiceContext)}
038             */
039            @Override
040            public Address addAddress(
041                            String className, long classPK, String street1, String street2,
042                            String street3, String city, String zip, long regionId,
043                            long countryId, int typeId, boolean mailing, boolean primary)
044                    throws PortalException, SystemException {
045    
046                    CommonPermissionUtil.check(
047                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
048    
049                    return addressLocalService.addAddress(
050                            getUserId(), className, classPK, street1, street2, street3, city,
051                            zip, regionId, countryId, typeId, mailing, primary);
052            }
053    
054            @Override
055            public Address addAddress(
056                            String className, long classPK, String street1, String street2,
057                            String street3, String city, String zip, long regionId,
058                            long countryId, int typeId, boolean mailing, boolean primary,
059                            ServiceContext serviceContext)
060                    throws PortalException, SystemException {
061    
062                    CommonPermissionUtil.check(
063                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
064    
065                    return addressLocalService.addAddress(
066                            getUserId(), className, classPK, street1, street2, street3, city,
067                            zip, regionId, countryId, typeId, mailing, primary, serviceContext);
068            }
069    
070            @Override
071            public void deleteAddress(long addressId)
072                    throws PortalException, SystemException {
073    
074                    Address address = addressPersistence.findByPrimaryKey(addressId);
075    
076                    CommonPermissionUtil.check(
077                            getPermissionChecker(), address.getClassNameId(),
078                            address.getClassPK(), ActionKeys.UPDATE);
079    
080                    addressLocalService.deleteAddress(addressId);
081            }
082    
083            @Override
084            public Address getAddress(long addressId)
085                    throws PortalException, SystemException {
086    
087                    Address address = addressPersistence.findByPrimaryKey(addressId);
088    
089                    CommonPermissionUtil.check(
090                            getPermissionChecker(), address.getClassNameId(),
091                            address.getClassPK(), ActionKeys.VIEW);
092    
093                    return address;
094            }
095    
096            @Override
097            public List<Address> getAddresses(String className, long classPK)
098                    throws PortalException, SystemException {
099    
100                    CommonPermissionUtil.check(
101                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
102    
103                    User user = getUser();
104    
105                    return addressLocalService.getAddresses(
106                            user.getCompanyId(), className, classPK);
107            }
108    
109            @Override
110            public Address updateAddress(
111                            long addressId, String street1, String street2, String street3,
112                            String city, String zip, long regionId, long countryId, int typeId,
113                            boolean mailing, boolean primary)
114                    throws PortalException, SystemException {
115    
116                    Address address = addressPersistence.findByPrimaryKey(addressId);
117    
118                    CommonPermissionUtil.check(
119                            getPermissionChecker(), address.getClassNameId(),
120                            address.getClassPK(), ActionKeys.UPDATE);
121    
122                    return addressLocalService.updateAddress(
123                            addressId, street1, street2, street3, city, zip, regionId,
124                            countryId, typeId, mailing, primary);
125            }
126    
127    }