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            @Override
034            public Address addAddress(
035                            String className, long classPK, String street1, String street2,
036                            String street3, String city, String zip, long regionId,
037                            long countryId, long typeId, boolean mailing, boolean primary,
038                            ServiceContext serviceContext)
039                    throws PortalException {
040    
041                    CommonPermissionUtil.check(
042                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
043    
044                    return addressLocalService.addAddress(
045                            getUserId(), className, classPK, street1, street2, street3, city,
046                            zip, regionId, countryId, typeId, mailing, primary, serviceContext);
047            }
048    
049            @Override
050            public void deleteAddress(long addressId) throws PortalException {
051                    Address address = addressPersistence.findByPrimaryKey(addressId);
052    
053                    CommonPermissionUtil.check(
054                            getPermissionChecker(), address.getClassNameId(),
055                            address.getClassPK(), ActionKeys.UPDATE);
056    
057                    addressLocalService.deleteAddress(address);
058            }
059    
060            @Override
061            public Address getAddress(long addressId) throws PortalException {
062                    Address address = addressPersistence.findByPrimaryKey(addressId);
063    
064                    CommonPermissionUtil.check(
065                            getPermissionChecker(), address.getClassNameId(),
066                            address.getClassPK(), ActionKeys.VIEW);
067    
068                    return address;
069            }
070    
071            @Override
072            public List<Address> getAddresses(String className, long classPK)
073                    throws PortalException {
074    
075                    CommonPermissionUtil.check(
076                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
077    
078                    User user = getUser();
079    
080                    return addressLocalService.getAddresses(
081                            user.getCompanyId(), className, classPK);
082            }
083    
084            @Override
085            public Address updateAddress(
086                            long addressId, String street1, String street2, String street3,
087                            String city, String zip, long regionId, long countryId, long typeId,
088                            boolean mailing, boolean primary)
089                    throws PortalException {
090    
091                    Address address = addressPersistence.findByPrimaryKey(addressId);
092    
093                    CommonPermissionUtil.check(
094                            getPermissionChecker(), address.getClassNameId(),
095                            address.getClassPK(), ActionKeys.UPDATE);
096    
097                    return addressLocalService.updateAddress(
098                            addressId, street1, street2, street3, city, zip, regionId,
099                            countryId, typeId, mailing, primary);
100            }
101    
102    }