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