1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.model.Address;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.service.base.AddressServiceBaseImpl;
22  import com.liferay.portal.service.permission.CommonPermissionUtil;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="AddressServiceImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Alexander Chow
31   */
32  public class AddressServiceImpl extends AddressServiceBaseImpl {
33  
34      public Address addAddress(
35              String className, long classPK, String street1, String street2,
36              String street3, String city, String zip, long regionId,
37              long countryId, int typeId, boolean mailing, boolean primary)
38          throws PortalException, SystemException {
39  
40          CommonPermissionUtil.check(
41              getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
42  
43          return addressLocalService.addAddress(
44              getUserId(), className, classPK, street1, street2, street3, city,
45              zip, regionId, countryId, typeId, mailing, primary);
46      }
47  
48      public void deleteAddress(long addressId)
49          throws PortalException, SystemException {
50  
51          Address address = addressPersistence.findByPrimaryKey(addressId);
52  
53          CommonPermissionUtil.check(
54              getPermissionChecker(), address.getClassNameId(),
55              address.getClassPK(), ActionKeys.UPDATE);
56  
57          addressLocalService.deleteAddress(addressId);
58      }
59  
60      public Address getAddress(long addressId)
61          throws PortalException, SystemException {
62  
63          Address address = addressPersistence.findByPrimaryKey(addressId);
64  
65          CommonPermissionUtil.check(
66              getPermissionChecker(), address.getClassNameId(),
67              address.getClassPK(), ActionKeys.VIEW);
68  
69          return address;
70      }
71  
72      public List<Address> getAddresses(String className, long classPK)
73          throws PortalException, SystemException {
74  
75          CommonPermissionUtil.check(
76              getPermissionChecker(), className, classPK, ActionKeys.VIEW);
77  
78          return addressLocalService.getAddresses(
79              getUser().getCompanyId(), className, classPK);
80      }
81  
82      public Address updateAddress(
83              long addressId, String street1, String street2, String street3,
84              String city, String zip, long regionId, long countryId, int typeId,
85              boolean mailing, boolean primary)
86          throws PortalException, SystemException {
87  
88          Address address = addressPersistence.findByPrimaryKey(addressId);
89  
90          CommonPermissionUtil.check(
91              getPermissionChecker(), address.getClassNameId(),
92              address.getClassPK(), ActionKeys.UPDATE);
93  
94          return addressLocalService.updateAddress(
95              addressId, street1, street2, street3, city, zip, regionId,
96              countryId, typeId, mailing, primary);
97      }
98  
99  }