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