1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.security.permission.ActionKeys;
28  import com.liferay.portal.model.OrgLabor;
29  import com.liferay.portal.model.Organization;
30  import com.liferay.portal.service.OrgLaborLocalServiceUtil;
31  import com.liferay.portal.service.OrgLaborService;
32  import com.liferay.portal.service.permission.LocationPermissionUtil;
33  import com.liferay.portal.service.permission.OrganizationPermissionUtil;
34  import com.liferay.portal.service.persistence.OrgLaborUtil;
35  import com.liferay.portal.service.persistence.OrganizationUtil;
36  
37  import java.util.List;
38  
39  /**
40   * <a href="OrgLaborServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class OrgLaborServiceImpl
46      extends PrincipalBean implements OrgLaborService {
47  
48      public OrgLabor addOrgLabor(
49              long organizationId, int typeId, int sunOpen, int sunClose,
50              int monOpen, int monClose, int tueOpen, int tueClose, int wedOpen,
51              int wedClose, int thuOpen, int thuClose, int friOpen, int friClose,
52              int satOpen, int satClose)
53          throws PortalException, SystemException {
54  
55          checkPermission(organizationId, ActionKeys.UPDATE);
56  
57          return OrgLaborLocalServiceUtil.addOrgLabor(
58              organizationId, typeId, sunOpen, sunClose, monOpen, monClose,
59              tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose, friOpen,
60              friClose, satOpen, satClose);
61      }
62  
63      public void deleteOrgLabor(long orgLaborId)
64          throws PortalException, SystemException {
65  
66          OrgLabor orgLabor = OrgLaborUtil.findByPrimaryKey(orgLaborId);
67  
68          checkPermission(orgLabor.getOrganizationId(), ActionKeys.UPDATE);
69  
70          OrgLaborLocalServiceUtil.deleteOrgLabor(orgLaborId);
71      }
72  
73      public OrgLabor getOrgLabor(long orgLaborId)
74          throws PortalException, SystemException {
75  
76          OrgLabor orgLabor = OrgLaborUtil.findByPrimaryKey(orgLaborId);
77  
78          checkPermission(orgLabor.getOrganizationId(), ActionKeys.VIEW);
79  
80          return orgLabor;
81      }
82  
83      public List getOrgLabors(long organizationId)
84          throws PortalException, SystemException {
85  
86          checkPermission(organizationId, ActionKeys.VIEW);
87  
88          return OrgLaborLocalServiceUtil.getOrgLabors(organizationId);
89      }
90  
91      public OrgLabor updateOrgLabor(
92              long orgLaborId, int sunOpen, int sunClose, int monOpen,
93              int monClose, int tueOpen, int tueClose, int wedOpen, int wedClose,
94              int thuOpen, int thuClose, int friOpen, int friClose, int satOpen,
95              int satClose)
96          throws PortalException, SystemException {
97  
98          OrgLabor orgLabor = OrgLaborUtil.findByPrimaryKey(orgLaborId);
99  
100         checkPermission(orgLabor.getOrganizationId(), ActionKeys.UPDATE);
101 
102         return OrgLaborLocalServiceUtil.updateOrgLabor(
103             orgLaborId, sunOpen, sunClose, monOpen, monClose, tueOpen, tueClose,
104             wedOpen, wedClose, thuOpen, thuClose, friOpen, friClose, satOpen,
105             satClose);
106     }
107 
108     protected void checkPermission(long organizationId, String actionId)
109         throws PortalException, SystemException {
110 
111         Organization organization =
112             OrganizationUtil.findByPrimaryKey(organizationId);
113 
114         if (!organization.isLocation()) {
115             OrganizationPermissionUtil.check(
116                 getPermissionChecker(), organizationId, actionId);
117         }
118         else {
119             LocationPermissionUtil.check(
120                 getPermissionChecker(), organizationId, actionId);
121         }
122     }
123 
124 }