001    /**
002     * Copyright (c) 2000-2010 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.LayoutSetPrototype;
022    import com.liferay.portal.model.User;
023    import com.liferay.portal.security.permission.ActionKeys;
024    import com.liferay.portal.service.base.LayoutSetPrototypeServiceBaseImpl;
025    import com.liferay.portal.service.permission.LayoutSetPrototypePermissionUtil;
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     */
036    public class LayoutSetPrototypeServiceImpl
037            extends LayoutSetPrototypeServiceBaseImpl {
038    
039            public LayoutSetPrototype addLayoutSetPrototype(
040                            Map<Locale, String> nameMap, String description,
041                            boolean active)
042                    throws PortalException, SystemException {
043    
044                    User user = getUser();
045    
046                    PortalPermissionUtil.check(
047                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
048    
049                    return layoutSetPrototypeLocalService.addLayoutSetPrototype(
050                            user.getUserId(), user.getCompanyId(), nameMap, description,
051                            active);
052            }
053    
054            public void deleteLayoutSetPrototype(long layoutSetPrototypeId)
055                    throws PortalException, SystemException {
056    
057                    LayoutSetPrototypePermissionUtil.check(
058                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.DELETE);
059    
060                    layoutSetPrototypeLocalService.deleteLayoutSetPrototype(
061                            layoutSetPrototypeId);
062            }
063    
064            public LayoutSetPrototype getLayoutSetPrototype(long layoutSetPrototypeId)
065                    throws PortalException, SystemException {
066    
067                    LayoutSetPrototypePermissionUtil.check(
068                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.VIEW);
069    
070                    return layoutSetPrototypeLocalService.getLayoutSetPrototype(
071                            layoutSetPrototypeId);
072            }
073    
074            public List<LayoutSetPrototype> search(
075                            long companyId, Boolean active, OrderByComparator obc)
076                    throws PortalException, SystemException {
077    
078                    List<LayoutSetPrototype> filteredLayoutSetPrototypes =
079                            new ArrayList<LayoutSetPrototype>();
080    
081                    List<LayoutSetPrototype> layoutSetPrototypes =
082                            layoutSetPrototypeLocalService.search(
083                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
084    
085                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
086                            if (LayoutSetPrototypePermissionUtil.contains(
087                                            getPermissionChecker(),
088                                            layoutSetPrototype.getLayoutSetPrototypeId(),
089                                            ActionKeys.VIEW)) {
090    
091                                    filteredLayoutSetPrototypes.add(layoutSetPrototype);
092                            }
093                    }
094    
095                    return filteredLayoutSetPrototypes;
096            }
097    
098            public LayoutSetPrototype updateLayoutSetPrototype(
099                            long layoutSetPrototypeId, Map<Locale, String> nameMap,
100                            String description, boolean active)
101                    throws PortalException, SystemException {
102    
103                    LayoutSetPrototypePermissionUtil.check(
104                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.UPDATE);
105    
106                    return layoutSetPrototypeLocalService.updateLayoutSetPrototype(
107                            layoutSetPrototypeId, nameMap, description, active);
108            }
109    
110    }