001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.NoSuchRepositoryException;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.repository.BaseRepository;
021 import com.liferay.portal.kernel.repository.InvalidRepositoryIdException;
022 import com.liferay.portal.kernel.repository.LocalRepository;
023 import com.liferay.portal.kernel.repository.RepositoryException;
024 import com.liferay.portal.kernel.util.UnicodeProperties;
025 import com.liferay.portal.model.Group;
026 import com.liferay.portal.model.Repository;
027 import com.liferay.portal.repository.util.RepositoryFactoryUtil;
028 import com.liferay.portal.security.permission.ActionKeys;
029 import com.liferay.portal.service.ServiceContext;
030 import com.liferay.portal.service.base.RepositoryServiceBaseImpl;
031 import com.liferay.portal.util.PortalUtil;
032 import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
033 import com.liferay.portlet.documentlibrary.service.permission.DLPermission;
034
035
039 public class RepositoryServiceImpl extends RepositoryServiceBaseImpl {
040
041 @Override
042 public Repository addRepository(
043 long groupId, long classNameId, long parentFolderId, String name,
044 String description, String portletId,
045 UnicodeProperties typeSettingsProperties,
046 ServiceContext serviceContext)
047 throws PortalException, SystemException {
048
049 DLPermission.check(
050 getPermissionChecker(), groupId, ActionKeys.ADD_REPOSITORY);
051
052 return repositoryLocalService.addRepository(
053 getUserId(), groupId, classNameId, parentFolderId, name,
054 description, portletId, typeSettingsProperties, false,
055 serviceContext);
056 }
057
058 @Override
059 public void checkRepository(long repositoryId)
060 throws PortalException, SystemException {
061
062 Group group = groupPersistence.fetchByPrimaryKey(repositoryId);
063
064 if (group != null) {
065 return;
066 }
067
068 try {
069 Repository repository = repositoryPersistence.findByPrimaryKey(
070 repositoryId);
071
072 DLFolderPermission.check(
073 getPermissionChecker(), repository.getGroupId(),
074 repository.getDlFolderId(), ActionKeys.VIEW);
075 }
076 catch (NoSuchRepositoryException nsre) {
077 throw new InvalidRepositoryIdException(nsre.getMessage());
078 }
079 }
080
081 @Override
082 public void deleteRepository(long repositoryId)
083 throws PortalException, SystemException {
084
085 Repository repository = repositoryPersistence.findByPrimaryKey(
086 repositoryId);
087
088 DLFolderPermission.check(
089 getPermissionChecker(), repository.getGroupId(),
090 repository.getDlFolderId(), ActionKeys.DELETE);
091
092 repositoryLocalService.deleteRepository(repository.getRepositoryId());
093 }
094
095 @Override
096 public LocalRepository getLocalRepositoryImpl(long repositoryId)
097 throws PortalException, SystemException {
098
099 checkRepository(repositoryId);
100
101 return repositoryLocalService.getLocalRepositoryImpl(repositoryId);
102 }
103
104 @Override
105 public LocalRepository getLocalRepositoryImpl(
106 long folderId, long fileEntryId, long fileVersionId)
107 throws PortalException, SystemException {
108
109 LocalRepository localRepositoryImpl =
110 repositoryLocalService.getLocalRepositoryImpl(
111 folderId, fileEntryId, fileVersionId);
112
113 checkRepository(localRepositoryImpl.getRepositoryId());
114
115 return localRepositoryImpl;
116 }
117
118 @Override
119 public Repository getRepository(long repositoryId)
120 throws PortalException, SystemException {
121
122 return repositoryPersistence.findByPrimaryKey(repositoryId);
123 }
124
125 @Override
126 public com.liferay.portal.kernel.repository.Repository getRepositoryImpl(
127 long repositoryId)
128 throws PortalException, SystemException {
129
130 checkRepository(repositoryId);
131
132 return repositoryLocalService.getRepositoryImpl(repositoryId);
133 }
134
135 @Override
136 public com.liferay.portal.kernel.repository.Repository getRepositoryImpl(
137 long folderId, long fileEntryId, long fileVersionId)
138 throws PortalException, SystemException {
139
140 com.liferay.portal.kernel.repository.Repository repositoryImpl =
141 repositoryLocalService.getRepositoryImpl(
142 folderId, fileEntryId, fileVersionId);
143
144 checkRepository(repositoryImpl.getRepositoryId());
145
146 return repositoryImpl;
147 }
148
149 @Override
150 public String[] getSupportedConfigurations(long classNameId)
151 throws SystemException {
152
153 try {
154 String repositoryImplClassName = PortalUtil.getClassName(
155 classNameId);
156
157 BaseRepository baseRepository = RepositoryFactoryUtil.getInstance(
158 repositoryImplClassName);
159
160 return baseRepository.getSupportedConfigurations();
161 }
162 catch (Exception e) {
163 throw new SystemException(e);
164 }
165 }
166
167 @Override
168 public String[] getSupportedParameters(
169 long classNameId, String configuration)
170 throws SystemException {
171
172 try {
173 String repositoryImplClassName = PortalUtil.getClassName(
174 classNameId);
175
176 BaseRepository baseRepository = RepositoryFactoryUtil.getInstance(
177 repositoryImplClassName);
178
179 String[] supportedConfigurations =
180 baseRepository.getSupportedConfigurations();
181
182 String[][] supportedParameters =
183 baseRepository.getSupportedParameters();
184
185 for (int i = 0; i < supportedConfigurations.length; i++) {
186 if (supportedConfigurations[i].equals(configuration)) {
187 return supportedParameters[i];
188 }
189 }
190
191 throw new RepositoryException(
192 "Configuration not found for repository with class name id " +
193 classNameId);
194 }
195 catch (Exception e) {
196 throw new SystemException(e);
197 }
198 }
199
200 @Override
201 public UnicodeProperties getTypeSettingsProperties(long repositoryId)
202 throws PortalException, SystemException {
203
204 checkRepository(repositoryId);
205
206 return repositoryLocalService.getTypeSettingsProperties(repositoryId);
207 }
208
209 @Override
210 public void updateRepository(
211 long repositoryId, String name, String description)
212 throws PortalException, SystemException {
213
214 Repository repository = repositoryPersistence.findByPrimaryKey(
215 repositoryId);
216
217 DLFolderPermission.check(
218 getPermissionChecker(), repository.getGroupId(),
219 repository.getDlFolderId(), ActionKeys.UPDATE);
220
221 repositoryLocalService.updateRepository(
222 repositoryId, name, description);
223 }
224
225 }