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.base.LayoutPrototypeServiceBaseImpl;
025    import com.liferay.portal.service.permission.LayoutPrototypePermissionUtil;
026    import com.liferay.portal.service.permission.PortalPermissionUtil;
027    
028    import java.util.ArrayList;
029    import java.util.List;
030    import java.util.Locale;
031    import java.util.Map;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     * @author Jorge Ferrer
036     */
037    public class LayoutPrototypeServiceImpl extends LayoutPrototypeServiceBaseImpl {
038    
039            @Override
040            public LayoutPrototype addLayoutPrototype(
041                            Map<Locale, String> nameMap, String description, boolean active)
042                    throws PortalException, SystemException {
043    
044                    PortalPermissionUtil.check(
045                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
046    
047                    User user = getUser();
048    
049                    return layoutPrototypeLocalService.addLayoutPrototype(
050                            user.getUserId(), user.getCompanyId(), nameMap, description,
051                            active);
052            }
053    
054            @Override
055            public void deleteLayoutPrototype(long layoutPrototypeId)
056                    throws PortalException, SystemException {
057    
058                    LayoutPrototypePermissionUtil.check(
059                            getPermissionChecker(), layoutPrototypeId, ActionKeys.DELETE);
060    
061                    layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototypeId);
062            }
063    
064            @Override
065            public LayoutPrototype getLayoutPrototype(long layoutPrototypeId)
066                    throws PortalException, SystemException {
067    
068                    LayoutPrototypePermissionUtil.check(
069                            getPermissionChecker(), layoutPrototypeId, ActionKeys.VIEW);
070    
071                    return layoutPrototypeLocalService.getLayoutPrototype(
072                            layoutPrototypeId);
073            }
074    
075            @Override
076            public List<LayoutPrototype> search(
077                            long companyId, Boolean active, OrderByComparator obc)
078                    throws PortalException, SystemException {
079    
080                    List<LayoutPrototype> filteredLayoutPrototypes =
081                            new ArrayList<LayoutPrototype>();
082    
083                    List<LayoutPrototype> layoutPrototypes =
084                            layoutPrototypeLocalService.search(
085                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
086    
087                    for (LayoutPrototype layoutPrototype : layoutPrototypes) {
088                            if (LayoutPrototypePermissionUtil.contains(
089                                            getPermissionChecker(),
090                                            layoutPrototype.getLayoutPrototypeId(), ActionKeys.VIEW)) {
091    
092                                    filteredLayoutPrototypes.add(layoutPrototype);
093                            }
094                    }
095    
096                    return filteredLayoutPrototypes;
097            }
098    
099            @Override
100            public LayoutPrototype updateLayoutPrototype(
101                            long layoutPrototypeId, Map<Locale, String> nameMap,
102                            String description, boolean active)
103                    throws PortalException, SystemException {
104    
105                    LayoutPrototypePermissionUtil.check(
106                            getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
107    
108                    return layoutPrototypeLocalService.updateLayoutPrototype(
109                            layoutPrototypeId, nameMap, description, active);
110            }
111    
112    }