001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.util.OrderByComparator;
021    import com.liferay.portal.model.LayoutPrototype;
022    import com.liferay.portal.model.User;
023    import com.liferay.portal.security.permission.ActionKeys;
024    import com.liferay.portal.service.ServiceContext;
025    import com.liferay.portal.service.base.LayoutPrototypeServiceBaseImpl;
026    import com.liferay.portal.service.permission.LayoutPrototypePermissionUtil;
027    import com.liferay.portal.service.permission.PortalPermissionUtil;
028    
029    import java.util.ArrayList;
030    import java.util.List;
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     * @author Jorge Ferrer
037     */
038    public class LayoutPrototypeServiceImpl extends LayoutPrototypeServiceBaseImpl {
039    
040            /**
041             * @deprecated As of 6.2.0, replaced by {@link #addLayoutPrototype(long,
042             *             Map, String, boolean, ServiceContext)}
043             */
044            public LayoutPrototype addLayoutPrototype(
045                            Map<Locale, String> nameMap, String description, boolean active)
046                    throws PortalException, SystemException {
047    
048                    PortalPermissionUtil.check(
049                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
050    
051                    User user = getUser();
052    
053                    return layoutPrototypeLocalService.addLayoutPrototype(
054                            user.getUserId(), user.getCompanyId(), nameMap, description,
055                            active);
056            }
057    
058            public LayoutPrototype addLayoutPrototype(
059                            Map<Locale, String> nameMap, String description, boolean active,
060                            ServiceContext serviceContext)
061                    throws PortalException, SystemException {
062    
063                    PortalPermissionUtil.check(
064                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
065    
066                    User user = getUser();
067    
068                    return layoutPrototypeLocalService.addLayoutPrototype(
069                            user.getUserId(), user.getCompanyId(), nameMap, description, active,
070                            serviceContext);
071            }
072    
073            public void deleteLayoutPrototype(long layoutPrototypeId)
074                    throws PortalException, SystemException {
075    
076                    LayoutPrototypePermissionUtil.check(
077                            getPermissionChecker(), layoutPrototypeId, ActionKeys.DELETE);
078    
079                    layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototypeId);
080            }
081    
082            public LayoutPrototype getLayoutPrototype(long layoutPrototypeId)
083                    throws PortalException, SystemException {
084    
085                    LayoutPrototypePermissionUtil.check(
086                            getPermissionChecker(), layoutPrototypeId, ActionKeys.VIEW);
087    
088                    return layoutPrototypeLocalService.getLayoutPrototype(
089                            layoutPrototypeId);
090            }
091    
092            public List<LayoutPrototype> search(
093                            long companyId, Boolean active, OrderByComparator obc)
094                    throws PortalException, SystemException {
095    
096                    List<LayoutPrototype> filteredLayoutPrototypes =
097                            new ArrayList<LayoutPrototype>();
098    
099                    List<LayoutPrototype> layoutPrototypes =
100                            layoutPrototypeLocalService.search(
101                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
102    
103                    for (LayoutPrototype layoutPrototype : layoutPrototypes) {
104                            if (LayoutPrototypePermissionUtil.contains(
105                                            getPermissionChecker(),
106                                            layoutPrototype.getLayoutPrototypeId(), ActionKeys.VIEW)) {
107    
108                                    filteredLayoutPrototypes.add(layoutPrototype);
109                            }
110                    }
111    
112                    return filteredLayoutPrototypes;
113            }
114    
115            /**
116             * @deprecated As of 6.2.0, replaced by {@link #updateLayoutPrototype(long,
117             *             Map, String, boolean, ServiceContext)}
118             */
119            public LayoutPrototype updateLayoutPrototype(
120                            long layoutPrototypeId, Map<Locale, String> nameMap,
121                            String description, boolean active)
122                    throws PortalException, SystemException {
123    
124                    LayoutPrototypePermissionUtil.check(
125                            getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
126    
127                    return layoutPrototypeLocalService.updateLayoutPrototype(
128                            layoutPrototypeId, nameMap, description, active);
129            }
130    
131            public LayoutPrototype updateLayoutPrototype(
132                            long layoutPrototypeId, Map<Locale, String> nameMap,
133                            String description, boolean active, ServiceContext serviceContext)
134                    throws PortalException, SystemException {
135    
136                    LayoutPrototypePermissionUtil.check(
137                            getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
138    
139                    return layoutPrototypeLocalService.updateLayoutPrototype(
140                            layoutPrototypeId, nameMap, description, active, serviceContext);
141            }
142    
143    }