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