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