001
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.PropsValues;
023 import com.liferay.portlet.journal.model.JournalFolder;
024 import com.liferay.portlet.journal.service.base.JournalFolderServiceBaseImpl;
025 import com.liferay.portlet.journal.service.permission.JournalFolderPermission;
026
027 import java.util.ArrayList;
028 import java.util.List;
029
030
033 public class JournalFolderServiceImpl extends JournalFolderServiceBaseImpl {
034
035 public JournalFolder addFolder(
036 long groupId, long parentFolderId, String name, String description,
037 ServiceContext serviceContext)
038 throws PortalException, SystemException {
039
040 JournalFolderPermission.check(
041 getPermissionChecker(), serviceContext.getScopeGroupId(),
042 parentFolderId, ActionKeys.ADD_FOLDER);
043
044 return journalFolderLocalService.addFolder(
045 getUserId(), groupId, parentFolderId, name, description,
046 serviceContext);
047 }
048
049 public void deleteFolder(long folderId)
050 throws PortalException, SystemException {
051
052 JournalFolder folder = journalFolderLocalService.getFolder(folderId);
053
054 JournalFolderPermission.check(
055 getPermissionChecker(), folder, ActionKeys.DELETE);
056
057 journalFolderLocalService.deleteFolder(folderId);
058 }
059
060 public JournalFolder getFolder(long folderId)
061 throws PortalException, SystemException {
062
063 JournalFolder folder = journalFolderLocalService.getFolder(folderId);
064
065 JournalFolderPermission.check(
066 getPermissionChecker(), folder, ActionKeys.VIEW);
067
068 return folder;
069 }
070
071 public List<JournalFolder> getFolders(long groupId) throws SystemException {
072 return journalFolderPersistence.filterFindByGroupId(groupId);
073 }
074
075 public List<JournalFolder> getFolders(long groupId, long parentFolderId)
076 throws SystemException {
077
078 return journalFolderPersistence.filterFindByG_P(
079 groupId, parentFolderId);
080 }
081
082 public List<JournalFolder> getFolders(
083 long groupId, long parentFolderId, int start, int end)
084 throws SystemException {
085
086 return journalFolderPersistence.filterFindByG_P(
087 groupId, parentFolderId, start, end);
088 }
089
090 public List<Object> getFoldersAndArticles(
091 long groupId, long folderId, int start, int end,
092 OrderByComparator obc)
093 throws SystemException {
094
095 return journalFolderFinder.filterFindF_AByG_F(
096 groupId, folderId, start, end, obc);
097 }
098
099 public int getFoldersAndArticlesCount(
100 long groupId, List<Long> folderIds, int status)
101 throws SystemException {
102
103 if (folderIds.size() <= PropsValues.SQL_DATA_MAX_PARAMETERS) {
104 return journalArticleFinder.filterCountByG_F_S(
105 groupId, folderIds, status);
106 }
107 else {
108 int start = 0;
109 int end = PropsValues.SQL_DATA_MAX_PARAMETERS;
110
111 int articlesCount = journalArticleFinder.filterCountByG_F_S(
112 groupId, folderIds.subList(start, end), status);
113
114 folderIds.subList(start, end).clear();
115
116 articlesCount += getFoldersAndArticlesCount(
117 groupId, folderIds, status);
118
119 return articlesCount;
120 }
121 }
122
123 public int getFoldersAndArticlesCount(long groupId, long folderId)
124 throws SystemException {
125
126 return journalFolderFinder.filterCountF_A_ByG_F(groupId, folderId);
127 }
128
129 public int getFoldersCount(long groupId, long parentFolderId)
130 throws SystemException {
131
132 return journalFolderPersistence.filterCountByG_P(
133 groupId, parentFolderId);
134 }
135
136 public void getSubfolderIds(
137 List<Long> folderIds, long groupId, long folderId)
138 throws SystemException {
139
140 List<JournalFolder> folders = journalFolderPersistence.filterFindByG_P(
141 groupId, folderId);
142
143 for (JournalFolder folder : folders) {
144 folderIds.add(folder.getFolderId());
145
146 getSubfolderIds(
147 folderIds, folder.getGroupId(), folder.getFolderId());
148 }
149 }
150
151 public List<Long> getSubfolderIds(
152 long groupId, long folderId, boolean recurse)
153 throws SystemException {
154
155 List<Long> folderIds = new ArrayList<Long>();
156
157 getSubfolderIds(folderIds, groupId, folderId);
158
159 return folderIds;
160 }
161
162 public JournalFolder moveFolder(
163 long folderId, long parentFolderId, ServiceContext serviceContext)
164 throws PortalException, SystemException {
165
166 JournalFolder folder = journalFolderLocalService.getFolder(folderId);
167
168 JournalFolderPermission.check(
169 getPermissionChecker(), folder, ActionKeys.UPDATE);
170
171 return journalFolderLocalService.moveFolder(
172 folderId, parentFolderId, serviceContext);
173 }
174
175 public JournalFolder updateFolder(
176 long folderId, long parentFolderId, String name, String description,
177 boolean mergeWithParentFolder, ServiceContext serviceContext)
178 throws PortalException, SystemException {
179
180 JournalFolder folder = journalFolderLocalService.getFolder(folderId);
181
182 JournalFolderPermission.check(
183 getPermissionChecker(), folder, ActionKeys.UPDATE);
184
185 return journalFolderLocalService.updateFolder(
186 folderId, parentFolderId, name, description, mergeWithParentFolder,
187 serviceContext);
188 }
189
190 }