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.portlet.documentlibrary.lar;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.repository.model.Folder;
019    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
020    import com.liferay.portal.repository.liferayrepository.util.LiferayBase;
021    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
022    import com.liferay.portlet.documentlibrary.model.DLFolder;
023    import com.liferay.portlet.documentlibrary.service.persistence.DLFolderUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class FolderUtil extends LiferayBase {
031    
032            public static Folder fetchByR_P_N(
033                            long groupId, long parentFolderId, String name)
034                    throws SystemException {
035    
036                    DLFolder dlFolder = DLFolderUtil.fetchByG_P_N(
037                            groupId, parentFolderId, name);
038    
039                    if (dlFolder == null) {
040                            return null;
041                    }
042    
043                    return new LiferayFolder(dlFolder);
044            }
045    
046            public static Folder fetchByUUID_R(String uuid, long repositoryId)
047                    throws SystemException {
048    
049                    DLFolder dlFolder = DLFolderUtil.fetchByUUID_G(uuid, repositoryId);
050    
051                    if (dlFolder == null) {
052                            return null;
053                    }
054    
055                    return new LiferayFolder(dlFolder);
056            }
057    
058            public static Folder findByPrimaryKey(long folderId)
059                    throws NoSuchFolderException, SystemException {
060    
061                    DLFolder dlFolder = DLFolderUtil.findByPrimaryKey(folderId);
062    
063                    return new LiferayFolder(dlFolder);
064            }
065    
066            public static List<Folder> findByR_P(long repositoryId, long parentFolderId)
067                    throws SystemException {
068    
069                    List<DLFolder> dlFolders = DLFolderUtil.findByG_P(
070                            repositoryId, parentFolderId);
071    
072                    return _instance.toFolders(dlFolders);
073            }
074    
075            public static List<Folder> findByRepositoryId(long repositoryId)
076                    throws SystemException {
077    
078                    List<DLFolder> dlFolders = DLFolderUtil.findByGroupId(repositoryId);
079    
080                    return _instance.toFolders(dlFolders);
081            }
082    
083            private static FolderUtil _instance = new FolderUtil();
084    
085    }