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