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(Map,
042             *             String, boolean, ServiceContext)}
043             */
044            @Override
045            public LayoutPrototype addLayoutPrototype(
046                            Map<Locale, String> nameMap, String description, boolean active)
047                    throws PortalException, SystemException {
048    
049                    PortalPermissionUtil.check(
050                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
051    
052                    User user = getUser();
053    
054                    return layoutPrototypeLocalService.addLayoutPrototype(
055                            user.getUserId(), user.getCompanyId(), nameMap, description,
056                            active);
057            }
058    
059            @Override
060            public LayoutPrototype addLayoutPrototype(
061                            Map<Locale, String> nameMap, String description, boolean active,
062                            ServiceContext serviceContext)
063                    throws PortalException, SystemException {
064    
065                    PortalPermissionUtil.check(
066                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
067    
068                    User user = getUser();
069    
070                    return layoutPrototypeLocalService.addLayoutPrototype(
071                            user.getUserId(), user.getCompanyId(), nameMap, description, active,
072                            serviceContext);
073            }
074    
075            @Override
076            public void deleteLayoutPrototype(long layoutPrototypeId)
077                    throws PortalException, SystemException {
078    
079                    LayoutPrototypePermissionUtil.check(
080                            getPermissionChecker(), layoutPrototypeId, ActionKeys.DELETE);
081    
082                    layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototypeId);
083            }
084    
085            @Override
086            public LayoutPrototype getLayoutPrototype(long layoutPrototypeId)
087                    throws PortalException, SystemException {
088    
089                    LayoutPrototypePermissionUtil.check(
090                            getPermissionChecker(), layoutPrototypeId, ActionKeys.VIEW);
091    
092                    return layoutPrototypeLocalService.getLayoutPrototype(
093                            layoutPrototypeId);
094            }
095    
096            @Override
097            public List<LayoutPrototype> search(
098                            long companyId, Boolean active, OrderByComparator obc)
099                    throws PortalException, SystemException {
100    
101                    List<LayoutPrototype> filteredLayoutPrototypes =
102                            new ArrayList<LayoutPrototype>();
103    
104                    List<LayoutPrototype> layoutPrototypes =
105                            layoutPrototypeLocalService.search(
106                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
107    
108                    for (LayoutPrototype layoutPrototype : layoutPrototypes) {
109                            if (LayoutPrototypePermissionUtil.contains(
110                                            getPermissionChecker(),
111                                            layoutPrototype.getLayoutPrototypeId(), ActionKeys.VIEW)) {
112    
113                                    filteredLayoutPrototypes.add(layoutPrototype);
114                            }
115                    }
116    
117                    return filteredLayoutPrototypes;
118            }
119    
120            /**
121             * @deprecated As of 6.2.0, replaced by {@link #updateLayoutPrototype(long,
122             *             Map, String, boolean, ServiceContext)}
123             */
124            @Override
125            public LayoutPrototype updateLayoutPrototype(
126                            long layoutPrototypeId, Map<Locale, String> nameMap,
127                            String description, boolean active)
128                    throws PortalException, SystemException {
129    
130                    LayoutPrototypePermissionUtil.check(
131                            getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
132    
133                    return layoutPrototypeLocalService.updateLayoutPrototype(
134                            layoutPrototypeId, nameMap, description, active);
135            }
136    
137            @Override
138            public LayoutPrototype updateLayoutPrototype(
139                            long layoutPrototypeId, Map<Locale, String> nameMap,
140                            String description, boolean active, ServiceContext serviceContext)
141                    throws PortalException, SystemException {
142    
143                    LayoutPrototypePermissionUtil.check(
144                            getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
145    
146                    return layoutPrototypeLocalService.updateLayoutPrototype(
147                            layoutPrototypeId, nameMap, description, active, serviceContext);
148            }
149    
150    }