1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.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  }