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