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