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