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.LayoutSetPrototype;
022    import com.liferay.portal.model.User;
023    import com.liferay.portal.security.permission.ActionKeys;
024    import com.liferay.portal.service.ServiceContext;
025    import com.liferay.portal.service.base.LayoutSetPrototypeServiceBaseImpl;
026    import com.liferay.portal.service.permission.LayoutSetPrototypePermissionUtil;
027    import com.liferay.portal.service.permission.PortalPermissionUtil;
028    
029    import java.util.ArrayList;
030    import java.util.List;
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     * @author Ryan Park
037     */
038    public class LayoutSetPrototypeServiceImpl
039            extends LayoutSetPrototypeServiceBaseImpl {
040    
041            public LayoutSetPrototype addLayoutSetPrototype(
042                            Map<Locale, String> nameMap, String description, boolean active,
043                            boolean layoutsUpdateable, ServiceContext serviceContext)
044                    throws PortalException, SystemException {
045    
046                    PortalPermissionUtil.check(
047                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
048    
049                    User user = getUser();
050    
051                    return layoutSetPrototypeLocalService.addLayoutSetPrototype(
052                            user.getUserId(), user.getCompanyId(), nameMap, description, active,
053                            layoutsUpdateable, serviceContext);
054            }
055    
056            public void deleteLayoutSetPrototype(long layoutSetPrototypeId)
057                    throws PortalException, SystemException {
058    
059                    LayoutSetPrototypePermissionUtil.check(
060                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.DELETE);
061    
062                    layoutSetPrototypeLocalService.deleteLayoutSetPrototype(
063                            layoutSetPrototypeId);
064            }
065    
066            public LayoutSetPrototype getLayoutSetPrototype(long layoutSetPrototypeId)
067                    throws PortalException, SystemException {
068    
069                    LayoutSetPrototypePermissionUtil.check(
070                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.VIEW);
071    
072                    return layoutSetPrototypeLocalService.getLayoutSetPrototype(
073                            layoutSetPrototypeId);
074            }
075    
076            public List<LayoutSetPrototype> search(
077                            long companyId, Boolean active, OrderByComparator obc)
078                    throws PortalException, SystemException {
079    
080                    List<LayoutSetPrototype> filteredLayoutSetPrototypes =
081                            new ArrayList<LayoutSetPrototype>();
082    
083                    List<LayoutSetPrototype> layoutSetPrototypes =
084                            layoutSetPrototypeLocalService.search(
085                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
086    
087                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
088                            if (LayoutSetPrototypePermissionUtil.contains(
089                                            getPermissionChecker(),
090                                            layoutSetPrototype.getLayoutSetPrototypeId(),
091                                            ActionKeys.VIEW)) {
092    
093                                    filteredLayoutSetPrototypes.add(layoutSetPrototype);
094                            }
095                    }
096    
097                    return filteredLayoutSetPrototypes;
098            }
099    
100            public LayoutSetPrototype updateLayoutSetPrototype(
101                            long layoutSetPrototypeId, Map<Locale, String> nameMap,
102                            String description, boolean active, boolean layoutsUpdateable,
103                            ServiceContext serviceContext)
104                    throws PortalException, SystemException {
105    
106                    LayoutSetPrototypePermissionUtil.check(
107                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.UPDATE);
108    
109                    return layoutSetPrototypeLocalService.updateLayoutSetPrototype(
110                            layoutSetPrototypeId, nameMap, description, active,
111                            layoutsUpdateable, serviceContext);
112            }
113    
114            public LayoutSetPrototype updateLayoutSetPrototype(
115                            long layoutSetPrototypeId, String settings)
116                    throws PortalException, SystemException {
117    
118                    return layoutSetPrototypeLocalService.updateLayoutSetPrototype(
119                            layoutSetPrototypeId, settings);
120            }
121    
122    }