001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }