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