001    /**
002     * Copyright (c) 2000-2013 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            @Override
042            public LayoutSetPrototype addLayoutSetPrototype(
043                            Map<Locale, String> nameMap, String description, boolean active,
044                            boolean layoutsUpdateable, ServiceContext serviceContext)
045                    throws PortalException, SystemException {
046    
047                    PortalPermissionUtil.check(
048                            getPermissionChecker(), ActionKeys.ADD_LAYOUT_PROTOTYPE);
049    
050                    User user = getUser();
051    
052                    return layoutSetPrototypeLocalService.addLayoutSetPrototype(
053                            user.getUserId(), user.getCompanyId(), nameMap, description, active,
054                            layoutsUpdateable, serviceContext);
055            }
056    
057            @Override
058            public void deleteLayoutSetPrototype(long layoutSetPrototypeId)
059                    throws PortalException, SystemException {
060    
061                    LayoutSetPrototypePermissionUtil.check(
062                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.DELETE);
063    
064                    layoutSetPrototypeLocalService.deleteLayoutSetPrototype(
065                            layoutSetPrototypeId);
066            }
067    
068            @Override
069            public LayoutSetPrototype getLayoutSetPrototype(long layoutSetPrototypeId)
070                    throws PortalException, SystemException {
071    
072                    LayoutSetPrototypePermissionUtil.check(
073                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.VIEW);
074    
075                    return layoutSetPrototypeLocalService.getLayoutSetPrototype(
076                            layoutSetPrototypeId);
077            }
078    
079            @Override
080            public List<LayoutSetPrototype> search(
081                            long companyId, Boolean active, OrderByComparator obc)
082                    throws PortalException, SystemException {
083    
084                    List<LayoutSetPrototype> filteredLayoutSetPrototypes =
085                            new ArrayList<LayoutSetPrototype>();
086    
087                    List<LayoutSetPrototype> layoutSetPrototypes =
088                            layoutSetPrototypeLocalService.search(
089                                    companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);
090    
091                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
092                            if (LayoutSetPrototypePermissionUtil.contains(
093                                            getPermissionChecker(),
094                                            layoutSetPrototype.getLayoutSetPrototypeId(),
095                                            ActionKeys.VIEW)) {
096    
097                                    filteredLayoutSetPrototypes.add(layoutSetPrototype);
098                            }
099                    }
100    
101                    return filteredLayoutSetPrototypes;
102            }
103    
104            @Override
105            public LayoutSetPrototype updateLayoutSetPrototype(
106                            long layoutSetPrototypeId, Map<Locale, String> nameMap,
107                            String description, boolean active, boolean layoutsUpdateable,
108                            ServiceContext serviceContext)
109                    throws PortalException, SystemException {
110    
111                    LayoutSetPrototypePermissionUtil.check(
112                            getPermissionChecker(), layoutSetPrototypeId, ActionKeys.UPDATE);
113    
114                    return layoutSetPrototypeLocalService.updateLayoutSetPrototype(
115                            layoutSetPrototypeId, nameMap, description, active,
116                            layoutsUpdateable, serviceContext);
117            }
118    
119            @Override
120            public LayoutSetPrototype updateLayoutSetPrototype(
121                            long layoutSetPrototypeId, String settings)
122                    throws PortalException, SystemException {
123    
124                    return layoutSetPrototypeLocalService.updateLayoutSetPrototype(
125                            layoutSetPrototypeId, settings);
126            }
127    
128    }