001    /**
002     * Copyright (c) 2000-2012 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            public LayoutPrototype addLayoutPrototype(
040                            Map<Locale, String> nameMap, String description, boolean active)
041                    throws PortalException, SystemException {
042    
043                    PortalPermissionUtil.check(
044                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
045    
046                    User user = getUser();
047    
048                    return layoutPrototypeLocalService.addLayoutPrototype(
049                            user.getUserId(), user.getCompanyId(), nameMap, description,
050                            active);
051            }
052    
053            public void deleteLayoutPrototype(long layoutPrototypeId)
054                    throws PortalException, SystemException {
055    
056                    LayoutPrototypePermissionUtil.check(
057                            getPermissionChecker(), layoutPrototypeId, ActionKeys.DELETE);
058    
059                    layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototypeId);
060            }
061    
062            public LayoutPrototype getLayoutPrototype(long layoutPrototypeId)
063                    throws PortalException, SystemException {
064    
065                    LayoutPrototypePermissionUtil.check(
066                            getPermissionChecker(), layoutPrototypeId, ActionKeys.VIEW);
067    
068                    return layoutPrototypeLocalService.getLayoutPrototype(
069                            layoutPrototypeId);
070            }
071    
072            public List<LayoutPrototype> search(
073                            long companyId, Boolean active, OrderByComparator obc)
074                    throws PortalException, SystemException {
075    
076                    List<LayoutPrototype> filteredLayoutPrototypes =
077                            new ArrayList<LayoutPrototype>();
078    
079                    List<LayoutPrototype> layoutPrototypes =
080                            layoutPrototypeLocalService.search(
081                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
082    
083                    for (LayoutPrototype layoutPrototype : layoutPrototypes) {
084                            if (LayoutPrototypePermissionUtil.contains(
085                                            getPermissionChecker(),
086                                            layoutPrototype.getLayoutPrototypeId(), ActionKeys.VIEW)) {
087    
088                                    filteredLayoutPrototypes.add(layoutPrototype);
089                            }
090                    }
091    
092                    return filteredLayoutPrototypes;
093            }
094    
095            public LayoutPrototype updateLayoutPrototype(
096                            long layoutPrototypeId, Map<Locale, String> nameMap,
097                            String description, boolean active)
098                    throws PortalException, SystemException {
099    
100                    LayoutPrototypePermissionUtil.check(
101                            getPermissionChecker(), layoutPrototypeId, ActionKeys.UPDATE);
102    
103                    return layoutPrototypeLocalService.updateLayoutPrototype(
104                            layoutPrototypeId, nameMap, description, active);
105            }
106    
107    }