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