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.portlet.journal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.OrderByComparator;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
024    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants;
025    import com.liferay.portlet.journal.model.JournalArticle;
026    import com.liferay.portlet.journal.model.JournalStructure;
027    import com.liferay.portlet.journal.service.base.JournalStructureServiceBaseImpl;
028    import com.liferay.portlet.journal.service.permission.JournalPermission;
029    import com.liferay.portlet.journal.service.permission.JournalStructurePermission;
030    import com.liferay.portlet.journal.util.JournalUtil;
031    
032    import java.util.List;
033    import java.util.Locale;
034    import java.util.Map;
035    
036    /**
037     * @author     Brian Wing Shun Chan
038     * @author     Raymond Aug??
039     * @deprecated As of 6.2.0, since Web Content Administration now uses the
040     *             Dynamic Data Mapping framework to handle templates
041     */
042    public class JournalStructureServiceImpl
043            extends JournalStructureServiceBaseImpl {
044    
045            @Override
046            public JournalStructure addStructure(
047                            long groupId, String structureId, boolean autoStructureId,
048                            String parentStructureId, Map<Locale, String> nameMap,
049                            Map<Locale, String> descriptionMap, String xsd,
050                            ServiceContext serviceContext)
051                    throws PortalException, SystemException {
052    
053                    JournalPermission.check(
054                            getPermissionChecker(), groupId, ActionKeys.ADD_STRUCTURE);
055    
056                    return journalStructureLocalService.addStructure(
057                            getUserId(), groupId, structureId, autoStructureId,
058                            parentStructureId, nameMap, descriptionMap, xsd, serviceContext);
059            }
060    
061            @Override
062            public JournalStructure copyStructure(
063                            long groupId, String oldStructureId, String newStructureId,
064                            boolean autoStructureId)
065                    throws PortalException, SystemException {
066    
067                    JournalPermission.check(
068                            getPermissionChecker(), groupId, ActionKeys.ADD_STRUCTURE);
069    
070                    return journalStructureLocalService.copyStructure(
071                            getUserId(), groupId, oldStructureId, newStructureId,
072                            autoStructureId);
073            }
074    
075            @Override
076            public void deleteStructure(long groupId, String structureId)
077                    throws PortalException, SystemException {
078    
079                    JournalStructurePermission.check(
080                            getPermissionChecker(), groupId, structureId, ActionKeys.DELETE);
081    
082                    journalStructureLocalService.deleteStructure(groupId, structureId);
083            }
084    
085            @Override
086            public JournalStructure getStructure(long groupId, String structureId)
087                    throws PortalException, SystemException {
088    
089                    JournalStructurePermission.check(
090                            getPermissionChecker(), groupId, structureId, ActionKeys.VIEW);
091    
092                    return journalStructureLocalService.getStructure(groupId, structureId);
093            }
094    
095            @Override
096            public JournalStructure getStructure(
097                            long groupId, String structureId, boolean includeGlobalStructures)
098                    throws PortalException, SystemException {
099    
100                    JournalStructurePermission.check(
101                            getPermissionChecker(), groupId, structureId, ActionKeys.VIEW);
102    
103                    return journalStructureLocalService.getStructure(
104                            groupId, structureId, includeGlobalStructures);
105            }
106    
107            @Override
108            public List<JournalStructure> getStructures(long groupId)
109                    throws SystemException {
110    
111                    List<DDMStructure> ddmStructures =
112                            ddmStructurePersistence.filterFindByG_C(
113                                    groupId, PortalUtil.getClassNameId(JournalArticle.class));
114    
115                    return JournalUtil.toJournalStructures(ddmStructures);
116            }
117    
118            @Override
119            public List<JournalStructure> getStructures(long[] groupIds)
120                    throws SystemException {
121    
122                    List<DDMStructure> ddmStructures =
123                            ddmStructurePersistence.filterFindByG_C(
124                                    groupIds, PortalUtil.getClassNameId(JournalArticle.class));
125    
126                    return JournalUtil.toJournalStructures(ddmStructures);
127            }
128    
129            @Override
130            public List<JournalStructure> search(
131                            long companyId, long[] groupIds, String keywords, int start,
132                            int end, OrderByComparator obc)
133                    throws SystemException {
134    
135                    long[] classNameIds = {PortalUtil.getClassNameId(JournalArticle.class)};
136    
137                    List<DDMStructure> ddmStructures =
138                            ddmStructureFinder.filterFindByKeywords(
139                                    companyId, groupIds, classNameIds, keywords, start, end, obc);
140    
141                    return JournalUtil.toJournalStructures(ddmStructures);
142            }
143    
144            @Override
145            public List<JournalStructure> search(
146                            long companyId, long[] groupIds, String structureId, String name,
147                            String description, boolean andOperator, int start, int end,
148                            OrderByComparator obc)
149                    throws SystemException {
150    
151                    long[] classNameIds = {PortalUtil.getClassNameId(JournalArticle.class)};
152    
153                    List<DDMStructure> ddmStructures =
154                            ddmStructureFinder.filterFindByC_G_C_N_D_S_T(
155                                    companyId, groupIds, classNameIds, name, description, null,
156                                    DDMStructureConstants.TYPE_DEFAULT, andOperator, start, end,
157                                    obc);
158    
159                    return JournalUtil.toJournalStructures(ddmStructures);
160            }
161    
162            @Override
163            public int searchCount(long companyId, long[] groupIds, String keywords)
164                    throws SystemException {
165    
166                    long[] classNameIds = {PortalUtil.getClassNameId(JournalArticle.class)};
167    
168                    return ddmStructureFinder.filterCountByKeywords(
169                            companyId, groupIds, classNameIds, keywords);
170            }
171    
172            @Override
173            public int searchCount(
174                            long companyId, long[] groupIds, String structureId, String name,
175                            String description, boolean andOperator)
176                    throws SystemException {
177    
178                    long[] classNameIds = {PortalUtil.getClassNameId(JournalArticle.class)};
179    
180                    return ddmStructureFinder.filterCountByC_G_C_N_D_S_T(
181                            companyId, groupIds, classNameIds, name, description, null,
182                            DDMStructureConstants.TYPE_DEFAULT, andOperator);
183            }
184    
185            @Override
186            public JournalStructure updateStructure(
187                            long groupId, String structureId, String parentStructureId,
188                            Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
189                            String xsd, ServiceContext serviceContext)
190                    throws PortalException, SystemException {
191    
192                    JournalStructurePermission.check(
193                            getPermissionChecker(), groupId, structureId, ActionKeys.UPDATE);
194    
195                    return journalStructureLocalService.updateStructure(
196                            groupId, structureId, parentStructureId, nameMap, descriptionMap,
197                            xsd, serviceContext);
198            }
199    
200    }