1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.model.Address;
25  import com.liferay.portal.security.permission.ActionKeys;
26  import com.liferay.portal.service.base.AddressServiceBaseImpl;
27  import com.liferay.portal.service.permission.CommonPermissionUtil;
28  
29  import java.util.List;
30  
31  /**
32   * <a href="AddressServiceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   * @author Alexander Chow
36   *
37   */
38  public class AddressServiceImpl extends AddressServiceBaseImpl {
39  
40      public Address addAddress(
41              String className, long classPK, String street1, String street2,
42              String street3, String city, String zip, long regionId,
43              long countryId, int typeId, boolean mailing, boolean primary)
44          throws PortalException, SystemException {
45  
46          CommonPermissionUtil.check(
47              getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
48  
49          return addressLocalService.addAddress(
50              getUserId(), className, classPK, street1, street2, street3, city,
51              zip, regionId, countryId, typeId, mailing, primary);
52      }
53  
54      public void deleteAddress(long addressId)
55          throws PortalException, SystemException {
56  
57          Address address = addressPersistence.findByPrimaryKey(addressId);
58  
59          CommonPermissionUtil.check(
60              getPermissionChecker(), address.getClassNameId(),
61              address.getClassPK(), ActionKeys.UPDATE);
62  
63          addressLocalService.deleteAddress(addressId);
64      }
65  
66      public Address getAddress(long addressId)
67          throws PortalException, SystemException {
68  
69          Address address = addressPersistence.findByPrimaryKey(addressId);
70  
71          CommonPermissionUtil.check(
72              getPermissionChecker(), address.getClassNameId(),
73              address.getClassPK(), ActionKeys.VIEW);
74  
75          return address;
76      }
77  
78      public List<Address> getAddresses(String className, long classPK)
79          throws PortalException, SystemException {
80  
81          CommonPermissionUtil.check(
82              getPermissionChecker(), className, classPK, ActionKeys.VIEW);
83  
84          return addressLocalService.getAddresses(
85              getUser().getCompanyId(), className, classPK);
86      }
87  
88      public Address updateAddress(
89              long addressId, String street1, String street2, String street3,
90              String city, String zip, long regionId, long countryId, int typeId,
91              boolean mailing, boolean primary)
92          throws PortalException, SystemException {
93  
94          Address address = addressPersistence.findByPrimaryKey(addressId);
95  
96          CommonPermissionUtil.check(
97              getPermissionChecker(), address.getClassNameId(),
98              address.getClassPK(), ActionKeys.UPDATE);
99  
100         return addressLocalService.updateAddress(
101             addressId, street1, street2, street3, city, zip, regionId,
102             countryId, typeId, mailing, primary);
103     }
104 
105 }