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