001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.Repository;
019    import com.liferay.portal.kernel.repository.cmis.CMISRepositoryHandler;
020    import com.liferay.portal.kernel.repository.model.FileEntry;
021    import com.liferay.portal.kernel.repository.model.FileVersion;
022    import com.liferay.portal.kernel.repository.model.Folder;
023    import com.liferay.portal.repository.cmis.CMISRepository;
024    import com.liferay.portal.service.base.CMISRepositoryLocalServiceBaseImpl;
025    
026    import org.apache.chemistry.opencmis.client.api.Document;
027    
028    /**
029     * @author Alexander Chow
030     */
031    public class CMISRepositoryLocalServiceImpl
032            extends CMISRepositoryLocalServiceBaseImpl {
033    
034            @Override
035            public Object getSession(long repositoryId) throws PortalException {
036                    CMISRepository cmisRepository = getCmisRepository(repositoryId);
037    
038                    return cmisRepository.getSession();
039            }
040    
041            @Override
042            public FileEntry toFileEntry(long repositoryId, Object object)
043                    throws PortalException {
044    
045                    CMISRepository cmisRepository = getCmisRepository(repositoryId);
046    
047                    Document document = (Document)object;
048    
049                    return cmisRepository.toFileEntry(document);
050            }
051    
052            @Override
053            public FileVersion toFileVersion(long repositoryId, Object object)
054                    throws PortalException {
055    
056                    CMISRepository cmisRepository = getCmisRepository(repositoryId);
057    
058                    Document document = (Document)object;
059    
060                    return cmisRepository.toFileVersion(document);
061            }
062    
063            @Override
064            public Folder toFolder(long repositoryId, Object object)
065                    throws PortalException {
066    
067                    CMISRepository cmisRepository = getCmisRepository(repositoryId);
068    
069                    org.apache.chemistry.opencmis.client.api.Folder cmisFolder =
070                            (org.apache.chemistry.opencmis.client.api.Folder)object;
071    
072                    return cmisRepository.toFolder(cmisFolder);
073            }
074    
075            protected CMISRepository getCmisRepository(long repositoryId)
076                    throws PortalException {
077    
078                    Repository repositoryImpl = repositoryLocalService.getRepositoryImpl(
079                            repositoryId);
080    
081                    CMISRepositoryHandler cmisRepositoryHandler =
082                            repositoryImpl.getCapability(CMISRepositoryHandler.class);
083    
084                    return (CMISRepository)cmisRepositoryHandler.getCmisRepository();
085            }
086    
087    }