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.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.StringPool;
021    
022    import com.liferay.portlet.documentlibrary.model.DLFolder;
023    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * The extended model base implementation for the DLFolder service. Represents a row in the "DLFolder" database table, with each column mapped to a property of this class.
030     *
031     * <p>
032     * This class exists only as a container for the default extended model level methods generated by ServiceBuilder. Helper methods and all application logic should be put in {@link DLFolderImpl}.
033     * </p>
034     *
035     * @author Brian Wing Shun Chan
036     * @see DLFolderImpl
037     * @see com.liferay.portlet.documentlibrary.model.DLFolder
038     * @generated
039     */
040    public abstract class DLFolderBaseImpl extends DLFolderModelImpl
041            implements DLFolder {
042            /*
043             * NOTE FOR DEVELOPERS:
044             *
045             * Never modify or reference this class directly. All methods that expect a document library folder model instance should use the {@link DLFolder} interface instead.
046             */
047            @Override
048            public void persist() throws SystemException {
049                    if (this.isNew()) {
050                            DLFolderLocalServiceUtil.addDLFolder(this);
051                    }
052                    else {
053                            DLFolderLocalServiceUtil.updateDLFolder(this);
054                    }
055            }
056    
057            @Override
058            @SuppressWarnings("unused")
059            public String buildTreePath() throws PortalException, SystemException {
060                    List<DLFolder> dlFolders = new ArrayList<DLFolder>();
061    
062                    DLFolder dlFolder = this;
063    
064                    while (dlFolder != null) {
065                            dlFolders.add(dlFolder);
066    
067                            dlFolder = DLFolderLocalServiceUtil.fetchDLFolder(dlFolder.getParentFolderId());
068                    }
069    
070                    StringBundler sb = new StringBundler((dlFolders.size() * 2) + 1);
071    
072                    sb.append(StringPool.SLASH);
073    
074                    for (int i = dlFolders.size() - 1; i >= 0; i--) {
075                            dlFolder = dlFolders.get(i);
076    
077                            sb.append(dlFolder.getFolderId());
078                            sb.append(StringPool.SLASH);
079                    }
080    
081                    return sb.toString();
082            }
083    
084            @Override
085            public void updateTreePath(String treePath) throws SystemException {
086                    DLFolder dlFolder = this;
087    
088                    dlFolder.setTreePath(treePath);
089    
090                    DLFolderLocalServiceUtil.updateDLFolder(dlFolder);
091            }
092    }