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