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.dao.orm.QueryUtil;
18  import com.liferay.portal.kernel.exception.PortalException;
19  import com.liferay.portal.kernel.exception.SystemException;
20  import com.liferay.portal.kernel.util.OrderByComparator;
21  import com.liferay.portal.model.LayoutPrototype;
22  import com.liferay.portal.model.User;
23  import com.liferay.portal.security.permission.ActionKeys;
24  import com.liferay.portal.service.base.LayoutPrototypeServiceBaseImpl;
25  import com.liferay.portal.service.permission.LayoutPrototypePermissionUtil;
26  import com.liferay.portal.service.permission.PortalPermissionUtil;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  import java.util.Locale;
31  import java.util.Map;
32  
33  /**
34   * <a href="LayoutPrototypeServiceImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   * @author Jorge Ferrer
38   */
39  public class LayoutPrototypeServiceImpl extends LayoutPrototypeServiceBaseImpl {
40  
41      public LayoutPrototype addLayoutPrototype(
42              Map<Locale, String> nameMap, String description,
43              boolean active)
44          throws PortalException, SystemException {
45  
46          User user = getUser();
47  
48          PortalPermissionUtil.check(
49              getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
50  
51          return layoutPrototypeLocalService.addLayoutPrototype(
52              user.getUserId(), user.getCompanyId(), nameMap, description,
53              active);
54      }
55  
56      public void deleteLayoutPrototype(long layoutPrototypeId)
57          throws PortalException, SystemException {
58  
59          LayoutPrototypePermissionUtil.check(
60              getPermissionChecker(), layoutPrototypeId, ActionKeys.DELETE);
61  
62          layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototypeId);
63      }
64  
65      public LayoutPrototype getLayoutPrototype(long layoutPrototypeId)
66          throws PortalException, SystemException {
67  
68          LayoutPrototypePermissionUtil.check(
69              getPermissionChecker(), layoutPrototypeId, ActionKeys.VIEW);
70  
71          return layoutPrototypeLocalService.getLayoutPrototype(
72              layoutPrototypeId);
73      }
74  
75      public List<LayoutPrototype> search(
76              long companyId, Boolean active, OrderByComparator obc)
77          throws PortalException, SystemException {
78  
79          List<LayoutPrototype> filteredLayoutPrototypes =
80              new ArrayList<LayoutPrototype>();
81  
82          List<LayoutPrototype> layoutPrototypes =
83              layoutPrototypeLocalService.search(
84                  companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
85  
86          for (LayoutPrototype layoutPrototype : layoutPrototypes) {
87              if (LayoutPrototypePermissionUtil.contains(
88                      getPermissionChecker(),
89                      layoutPrototype.getLayoutPrototypeId(), ActionKeys.VIEW)) {
90  
91                  filteredLayoutPrototypes.add(layoutPrototype);
92              }
93          }
94  
95          return filteredLayoutPrototypes;
96      }
97  
98      public LayoutPrototype updateLayoutPrototype(
99              long layoutPrototypeId, Map<Locale, String> nameMap,
100             String description, boolean active)
101         throws PortalException, SystemException {
102 
103         LayoutPrototypePermissionUtil.check(
104             getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
105 
106         return layoutPrototypeLocalService.updateLayoutPrototype(
107             layoutPrototypeId, nameMap, description, active);
108     }
109 
110 }