001    /**
002     * Copyright (c) 2000-2011 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.portal.kernel.repository.cmis;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.repository.BaseRepository;
020    import com.liferay.portal.kernel.repository.BaseRepositoryImpl;
021    import com.liferay.portal.kernel.repository.RepositoryException;
022    import com.liferay.portal.kernel.repository.model.FileEntry;
023    import com.liferay.portal.kernel.repository.model.FileVersion;
024    import com.liferay.portal.kernel.repository.model.Folder;
025    import com.liferay.portal.kernel.search.Hits;
026    import com.liferay.portal.kernel.search.Query;
027    import com.liferay.portal.kernel.search.SearchContext;
028    import com.liferay.portal.kernel.search.SearchException;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.Validator;
032    import com.liferay.portal.model.CompanyConstants;
033    import com.liferay.portal.model.Lock;
034    import com.liferay.portal.model.User;
035    import com.liferay.portal.security.auth.PrincipalThreadLocal;
036    import com.liferay.portal.service.ServiceContext;
037    
038    import java.io.InputStream;
039    
040    import java.util.List;
041    import java.util.Map;
042    
043    /**
044     * @author Alexander Chow
045     */
046    public abstract class CMISRepositoryHandler extends BaseRepositoryImpl {
047    
048            public FileEntry addFileEntry(
049                            long folderId, String sourceFileName, String mimeType, String title,
050                            String description, String changeLog, InputStream is, long size,
051                            ServiceContext serviceContext)
052                    throws PortalException, SystemException {
053    
054                    return _baseCmisRepository.addFileEntry(
055                            folderId, sourceFileName, mimeType, title, description, changeLog,
056                            is, size, serviceContext);
057            }
058    
059            public Folder addFolder(
060                            long parentFolderId, String title, String description,
061                            ServiceContext serviceContext)
062                    throws PortalException, SystemException {
063    
064                    return _baseCmisRepository.addFolder(
065                            parentFolderId, title, description, serviceContext);
066            }
067    
068            public void cancelCheckOut(long fileEntryId)
069                    throws PortalException, SystemException {
070    
071                    _baseCmisRepository.cancelCheckOut(fileEntryId);
072            }
073    
074            public void checkInFileEntry(
075                            long fileEntryId, boolean major, String changeLog,
076                            ServiceContext serviceContext)
077                    throws PortalException, SystemException {
078    
079                    _baseCmisRepository.checkInFileEntry(
080                            fileEntryId, major, changeLog, serviceContext);
081            }
082    
083            public void checkInFileEntry(long fileEntryId, String lockUuid)
084                    throws PortalException, SystemException {
085    
086                    _baseCmisRepository.checkInFileEntry(fileEntryId, lockUuid);
087            }
088    
089            public FileEntry checkOutFileEntry(long fileEntryId)
090                    throws PortalException, SystemException {
091    
092                    return _baseCmisRepository.checkOutFileEntry(fileEntryId);
093            }
094    
095            public FileEntry checkOutFileEntry(
096                            long fileEntryId, String owner, long expirationTime)
097                    throws PortalException, SystemException {
098    
099                    return _baseCmisRepository.checkOutFileEntry(
100                            fileEntryId, owner, expirationTime);
101            }
102    
103            public FileEntry copyFileEntry(
104                            long groupId, long fileEntryId, long destFolderId,
105                            ServiceContext serviceContext)
106                    throws PortalException, SystemException {
107    
108                    return _baseCmisRepository.copyFileEntry(
109                            groupId, fileEntryId, destFolderId, serviceContext);
110            }
111    
112            public void deleteFileEntry(long fileEntryId)
113                    throws PortalException, SystemException {
114    
115                    _baseCmisRepository.deleteFileEntry(fileEntryId);
116            }
117    
118            public void deleteFolder(long folderId)
119                    throws PortalException, SystemException {
120    
121                    _baseCmisRepository.deleteFolder(folderId);
122            }
123    
124            public BaseRepository getCmisRepository() {
125                    return _baseCmisRepository;
126            }
127    
128            public List<FileEntry> getFileEntries(
129                            long folderId, int start, int end, OrderByComparator obc)
130                    throws SystemException {
131    
132                    return _baseCmisRepository.getFileEntries(folderId, start, end, obc);
133            }
134    
135            public List<FileEntry> getFileEntries(
136                            long folderId, long fileEntryTypeId, int start, int end,
137                            OrderByComparator obc)
138                    throws SystemException {
139    
140                    return _baseCmisRepository.getFileEntries(
141                            folderId, fileEntryTypeId, start, end, obc);
142            }
143    
144            public int getFileEntriesCount(long folderId) throws SystemException {
145                    return _baseCmisRepository.getFileEntriesCount(folderId);
146            }
147    
148            public int getFileEntriesCount(long folderId, long fileEntryTypeId)
149                    throws SystemException {
150    
151                    return _baseCmisRepository.getFileEntriesCount(
152                            folderId, fileEntryTypeId);
153            }
154    
155            public FileEntry getFileEntry(long fileEntryId)
156                    throws PortalException, SystemException {
157    
158                    return _baseCmisRepository.getFileEntry(fileEntryId);
159            }
160    
161            public FileEntry getFileEntry(long folderId, String title)
162                    throws PortalException, SystemException {
163    
164                    return _baseCmisRepository.getFileEntry(folderId, title);
165            }
166    
167            public FileEntry getFileEntryByUuid(String uuid)
168                    throws PortalException, SystemException {
169    
170                    return _baseCmisRepository.getFileEntryByUuid(uuid);
171            }
172    
173            public FileVersion getFileVersion(long fileVersionId)
174                    throws PortalException, SystemException {
175    
176                    return _baseCmisRepository.getFileVersion(fileVersionId);
177            }
178    
179            public Folder getFolder(long folderId)
180                    throws PortalException, SystemException {
181    
182                    return _baseCmisRepository.getFolder(folderId);
183            }
184    
185            public Folder getFolder(long parentFolderId, String title)
186                    throws PortalException, SystemException {
187    
188                    return _baseCmisRepository.getFolder(parentFolderId, title);
189            }
190    
191            public List<Folder> getFolders(
192                            long parentFolderId, boolean includeMountfolders, int start,
193                            int end, OrderByComparator obc)
194                    throws SystemException {
195    
196                    return _baseCmisRepository.getFolders(
197                            parentFolderId, includeMountfolders, start, end, obc);
198            }
199    
200            @Override
201            public List<Object> getFoldersAndFileEntries(
202                            long folderId, int start, int end, OrderByComparator obc)
203                    throws SystemException {
204    
205                    return _baseCmisRepository.getFoldersAndFileEntries(
206                            folderId, start, end, obc);
207            }
208    
209            @Override
210            public int getFoldersAndFileEntriesCount(long folderId)
211                    throws SystemException {
212    
213                    return _baseCmisRepository.getFoldersAndFileEntriesCount(folderId);
214            }
215    
216            public int getFoldersCount(long parentFolderId, boolean includeMountfolders)
217                    throws SystemException {
218    
219                    return _baseCmisRepository.getFoldersCount(
220                            parentFolderId, includeMountfolders);
221            }
222    
223            public int getFoldersFileEntriesCount(List<Long> folderIds, int status)
224                    throws SystemException {
225    
226                    return _baseCmisRepository.getFoldersFileEntriesCount(
227                            folderIds, status);
228            }
229    
230            public String getLatestVersionId(String objectId) throws SystemException {
231                    return _baseCmisRepository.getLatestVersionId(objectId);
232            }
233    
234            public String getLogin() throws SystemException {
235                    String login = PrincipalThreadLocal.getName();
236    
237                    if (Validator.isNull(login)) {
238                            return login;
239                    }
240    
241                    try {
242                            String authType =
243                                    companyLocalService.getCompany(getCompanyId()).getAuthType();
244    
245                            if (!authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
246                                    User user = userLocalService.getUser(GetterUtil.getLong(login));
247    
248                                    if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
249                                            login = user.getEmailAddress();
250                                    }
251                                    else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
252                                            login = user.getScreenName();
253                                    }
254                            }
255                    }
256                    catch (Exception e) {
257                            throw new RepositoryException(e);
258                    }
259    
260                    return login;
261            }
262    
263            public List<Folder> getMountFolders(
264                            long parentFolderId, int start, int end, OrderByComparator obc)
265                    throws SystemException {
266    
267                    return _baseCmisRepository.getMountFolders(
268                            parentFolderId, start, end, obc);
269            }
270    
271            public int getMountFoldersCount(long parentFolderId)
272                    throws SystemException {
273    
274                    return _baseCmisRepository.getMountFoldersCount(parentFolderId);
275            }
276    
277            public String getObjectName(String objectId)
278                    throws PortalException, SystemException {
279    
280                    return _baseCmisRepository.getObjectName(objectId);
281            }
282    
283            public List<String> getObjectPaths(String objectId)
284                    throws PortalException, SystemException {
285    
286                    return _baseCmisRepository.getObjectPaths(objectId);
287            }
288    
289            public abstract Session getSession()
290                    throws PortalException, SystemException;
291    
292            public List<Long> getSubfolderIds(long folderId, boolean recurse)
293                    throws SystemException {
294    
295                    return _baseCmisRepository.getSubfolderIds(folderId, recurse);
296            }
297    
298            public void getSubfolderIds(List<Long> folderIds, long folderId)
299                    throws SystemException {
300    
301                    _baseCmisRepository.getSubfolderIds(folderIds, folderId);
302            }
303    
304            @Override
305            public void initRepository() throws PortalException, SystemException {
306                    _baseCmisRepository.initRepository();
307            }
308    
309            public boolean isCancelCheckOutAllowable(String objectId)
310                    throws PortalException, SystemException {
311    
312                    return _baseCmisRepository.isCancelCheckOutAllowable(objectId);
313            }
314    
315            public boolean isCheckInAllowable(String objectId)
316                    throws PortalException, SystemException {
317    
318                    return _baseCmisRepository.isCheckInAllowable(objectId);
319            }
320    
321            public boolean isCheckOutAllowable(String objectId)
322                    throws PortalException, SystemException {
323    
324                    return _baseCmisRepository.isCheckOutAllowable(objectId);
325            }
326    
327            public boolean isDocumentRetrievableByVersionSeriesId() {
328                    return true;
329            }
330    
331            public boolean isRefreshBeforePermissionCheck() {
332                    return false;
333            }
334    
335            public boolean isSupportsMinorVersions(String productName) {
336    
337                    // LPS-20509
338    
339                    productName = productName.toLowerCase();
340    
341                    if (productName.contains("filenet") && productName.contains("p8")) {
342                            return false;
343                    }
344                    else {
345                            return true;
346                    }
347            }
348    
349            public Lock lockFolder(long folderId)
350                    throws PortalException, SystemException {
351    
352                    return _baseCmisRepository.lockFolder(folderId);
353            }
354    
355            public Lock lockFolder(
356                            long folderId, String owner, boolean inheritable,
357                            long expirationTime)
358                    throws PortalException, SystemException {
359    
360                    return _baseCmisRepository.lockFolder(
361                            folderId, owner, inheritable, expirationTime);
362            }
363    
364            public FileEntry moveFileEntry(
365                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
366                    throws PortalException, SystemException {
367    
368                    return _baseCmisRepository.moveFileEntry(
369                            fileEntryId, newFolderId, serviceContext);
370            }
371    
372            public Folder moveFolder(
373                            long folderId, long newParentFolderId,
374                            ServiceContext serviceContext)
375                    throws PortalException, SystemException {
376    
377                    return _baseCmisRepository.moveFolder(
378                            folderId, newParentFolderId, serviceContext);
379            }
380    
381            public Lock refreshFileEntryLock(String lockUuid, long expirationTime)
382                    throws PortalException, SystemException {
383    
384                    return _baseCmisRepository.refreshFileEntryLock(
385                            lockUuid, expirationTime);
386            }
387    
388            public Lock refreshFolderLock(String lockUuid, long expirationTime)
389                    throws PortalException, SystemException {
390    
391                    return _baseCmisRepository.refreshFolderLock(lockUuid, expirationTime);
392            }
393    
394            public void revertFileEntry(
395                            long fileEntryId, String version, ServiceContext serviceContext)
396                    throws PortalException, SystemException {
397    
398                    _baseCmisRepository.revertFileEntry(
399                            fileEntryId, version, serviceContext);
400            }
401    
402            @Override
403            public Hits search(SearchContext searchContext) throws SearchException {
404                    return _baseCmisRepository.search(searchContext);
405            }
406    
407            public Hits search(SearchContext searchContext, Query query)
408                    throws SearchException {
409    
410                    return _baseCmisRepository.search(searchContext, query);
411            }
412    
413            public void setCmisRepository(BaseCmisRepository baseCmisRepository) {
414                    _baseCmisRepository = baseCmisRepository;
415            }
416    
417            public FileEntry toFileEntry(String objectId)
418                    throws PortalException, SystemException {
419    
420                    return _baseCmisRepository.toFileEntry(objectId);
421            }
422    
423            public Folder toFolder(String objectId)
424                    throws PortalException, SystemException {
425    
426                    return _baseCmisRepository.toFolder(objectId);
427            }
428    
429            public void unlockFolder(long folderId, String lockUuid)
430                    throws PortalException, SystemException {
431    
432                    _baseCmisRepository.unlockFolder(folderId, lockUuid);
433            }
434    
435            public FileEntry updateFileEntry(
436                            long fileEntryId, String sourceFileName, String mimeType,
437                            String title, String description, String changeLog,
438                            boolean majorVersion, InputStream is, long size,
439                            ServiceContext serviceContext)
440                    throws PortalException, SystemException {
441    
442                    return _baseCmisRepository.updateFileEntry(
443                            fileEntryId, sourceFileName, mimeType, title, description,
444                            changeLog, majorVersion, is, size, serviceContext);
445            }
446    
447            public FileEntry updateFileEntry(
448                            String objectId, String mimeType, Map<String, Object> properties,
449                            InputStream is, String sourceFileName, long size,
450                            ServiceContext serviceContext)
451                    throws PortalException, SystemException {
452    
453                    return _baseCmisRepository.updateFileEntry(
454                            objectId, mimeType, properties, is, sourceFileName, size,
455                            serviceContext);
456            }
457    
458            public Folder updateFolder(
459                            long folderId, String title, String description,
460                            ServiceContext serviceContext)
461                    throws PortalException, SystemException {
462    
463                    return _baseCmisRepository.updateFolder(
464                            folderId, title, description, serviceContext);
465            }
466    
467            public boolean verifyFileEntryCheckOut(long fileEntryId, String lockUuid)
468                    throws PortalException, SystemException {
469    
470                    return _baseCmisRepository.verifyFileEntryCheckOut(
471                            fileEntryId, lockUuid);
472            }
473    
474            public boolean verifyInheritableLock(long folderId, String lockUuid)
475                    throws PortalException, SystemException {
476    
477                    return _baseCmisRepository.verifyInheritableLock(folderId, lockUuid);
478            }
479    
480            private BaseCmisRepository _baseCmisRepository;
481    
482    }