001    /**
002     * Copyright (c) 2000-present 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.model.Address;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.service.base.AddressServiceBaseImpl;
023    import com.liferay.portal.service.permission.CommonPermissionUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Alexander Chow
030     */
031    public class AddressServiceImpl extends AddressServiceBaseImpl {
032    
033            /**
034             * @deprecated As of 6.2.0, replaced by {@link #addAddress(String, long,
035             *             String, String, String, String, String, long, long, int,
036             *             boolean, boolean, ServiceContext)}
037             */
038            @Deprecated
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, long typeId, boolean mailing, boolean primary)
044                    throws PortalException {
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, long typeId, boolean mailing, boolean primary,
059                            ServiceContext serviceContext)
060                    throws PortalException {
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) throws PortalException {
072                    Address address = addressPersistence.findByPrimaryKey(addressId);
073    
074                    CommonPermissionUtil.check(
075                            getPermissionChecker(), address.getClassNameId(),
076                            address.getClassPK(), ActionKeys.UPDATE);
077    
078                    addressLocalService.deleteAddress(address);
079            }
080    
081            @Override
082            public Address getAddress(long addressId) throws PortalException {
083                    Address address = addressPersistence.findByPrimaryKey(addressId);
084    
085                    CommonPermissionUtil.check(
086                            getPermissionChecker(), address.getClassNameId(),
087                            address.getClassPK(), ActionKeys.VIEW);
088    
089                    return address;
090            }
091    
092            @Override
093            public List<Address> getAddresses(String className, long classPK)
094                    throws PortalException {
095    
096                    CommonPermissionUtil.check(
097                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
098    
099                    User user = getUser();
100    
101                    return addressLocalService.getAddresses(
102                            user.getCompanyId(), className, classPK);
103            }
104    
105            @Override
106            public Address updateAddress(
107                            long addressId, String street1, String street2, String street3,
108                            String city, String zip, long regionId, long countryId, long typeId,
109                            boolean mailing, boolean primary)
110                    throws PortalException {
111    
112                    Address address = addressPersistence.findByPrimaryKey(addressId);
113    
114                    CommonPermissionUtil.check(
115                            getPermissionChecker(), address.getClassNameId(),
116                            address.getClassPK(), ActionKeys.UPDATE);
117    
118                    return addressLocalService.updateAddress(
119                            addressId, street1, street2, street3, city, zip, regionId,
120                            countryId, typeId, mailing, primary);
121            }
122    
123    }