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            public JournalFolderImpl() {
032            }
033    
034            @Override
035            public List<Long> getAncestorFolderIds() throws PortalException {
036                    List<Long> ancestorFolderIds = new ArrayList<Long>();
037    
038                    JournalFolder folder = this;
039    
040                    while (!folder.isRoot()) {
041                            try {
042                                    folder = folder.getParentFolder();
043    
044                                    ancestorFolderIds.add(folder.getFolderId());
045                            }
046                            catch (NoSuchFolderException nsfe) {
047                                    if (folder.isInTrash()) {
048                                            break;
049                                    }
050    
051                                    throw nsfe;
052                            }
053                    }
054    
055                    return ancestorFolderIds;
056            }
057    
058            @Override
059            public List<JournalFolder> getAncestors() throws PortalException {
060                    List<JournalFolder> ancestors = new ArrayList<JournalFolder>();
061    
062                    JournalFolder folder = this;
063    
064                    while (!folder.isRoot()) {
065                            folder = folder.getParentFolder();
066    
067                            ancestors.add(folder);
068                    }
069    
070                    return ancestors;
071            }
072    
073            @Override
074            public JournalFolder getParentFolder() throws PortalException {
075                    if (getParentFolderId() ==
076                                    JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
077    
078                            return null;
079                    }
080    
081                    return JournalFolderLocalServiceUtil.getFolder(getParentFolderId());
082            }
083    
084            @Override
085            public boolean isRoot() {
086                    if (getParentFolderId() ==
087                                    JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
088    
089                            return true;
090                    }
091    
092                    return false;
093            }
094    
095    }