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.portal.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    import com.liferay.portal.model.Organization;
023    import com.liferay.portal.service.OrganizationLocalServiceUtil;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * The extended model base implementation for the Organization service. Represents a row in the "Organization_" 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 OrganizationImpl}.
033     * </p>
034     *
035     * @author Brian Wing Shun Chan
036     * @see OrganizationImpl
037     * @see Organization
038     * @generated
039     */
040    @ProviderType
041    public abstract class OrganizationBaseImpl extends OrganizationModelImpl
042            implements Organization {
043            /*
044             * NOTE FOR DEVELOPERS:
045             *
046             * Never modify or reference this class directly. All methods that expect a organization model instance should use the {@link Organization} interface instead.
047             */
048            @Override
049            public void persist() {
050                    if (this.isNew()) {
051                            OrganizationLocalServiceUtil.addOrganization(this);
052                    }
053                    else {
054                            OrganizationLocalServiceUtil.updateOrganization(this);
055                    }
056            }
057    
058            @Override
059            @SuppressWarnings("unused")
060            public String buildTreePath() throws PortalException {
061                    List<Organization> organizations = new ArrayList<Organization>();
062    
063                    Organization organization = this;
064    
065                    while (organization != null) {
066                            organizations.add(organization);
067    
068                            organization = OrganizationLocalServiceUtil.fetchOrganization(organization.getParentOrganizationId());
069                    }
070    
071                    StringBundler sb = new StringBundler((organizations.size() * 2) + 1);
072    
073                    sb.append(StringPool.SLASH);
074    
075                    for (int i = organizations.size() - 1; i >= 0; i--) {
076                            organization = organizations.get(i);
077    
078                            sb.append(organization.getOrganizationId());
079                            sb.append(StringPool.SLASH);
080                    }
081    
082                    return sb.toString();
083            }
084    
085            @Override
086            public void updateTreePath(String treePath) {
087                    Organization organization = this;
088    
089                    organization.setTreePath(treePath);
090    
091                    OrganizationLocalServiceUtil.updateOrganization(organization);
092            }
093    }