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