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.portlet.journal.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portlet.journal.NoSuchFolderException;
019    import com.liferay.portlet.journal.model.JournalFolder;
020    import com.liferay.portlet.journal.model.JournalFolderConstants;
021    import com.liferay.portlet.journal.service.JournalFolderLocalServiceUtil;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * @author Juan Fern??ndez
028     */
029    public class JournalFolderImpl extends JournalFolderBaseImpl {
030    
031            @Override
032            public List<Long> getAncestorFolderIds() throws PortalException {
033                    List<Long> ancestorFolderIds = new ArrayList<Long>();
034    
035                    JournalFolder folder = this;
036    
037                    while (!folder.isRoot()) {
038                            try {
039                                    folder = folder.getParentFolder();
040    
041                                    ancestorFolderIds.add(folder.getFolderId());
042                            }
043                            catch (NoSuchFolderException nsfe) {
044                                    if (folder.isInTrash()) {
045                                            break;
046                                    }
047    
048                                    throw nsfe;
049                            }
050                    }
051    
052                    return ancestorFolderIds;
053            }
054    
055            @Override
056            public List<JournalFolder> getAncestors() throws PortalException {
057                    List<JournalFolder> ancestors = new ArrayList<JournalFolder>();
058    
059                    JournalFolder folder = this;
060    
061                    while (!folder.isRoot()) {
062                            folder = folder.getParentFolder();
063    
064                            ancestors.add(folder);
065                    }
066    
067                    return ancestors;
068            }
069    
070            @Override
071            public JournalFolder getParentFolder() throws PortalException {
072                    if (getParentFolderId() ==
073                                    JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
074    
075                            return null;
076                    }
077    
078                    return JournalFolderLocalServiceUtil.getFolder(getParentFolderId());
079            }
080    
081            @Override
082            public boolean isRoot() {
083                    if (getParentFolderId() ==
084                                    JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
085    
086                            return true;
087                    }
088    
089                    return false;
090            }
091    
092    }