001
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.Group;
022 import com.liferay.portal.service.GroupLocalServiceUtil;
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027
039 public abstract class GroupBaseImpl extends GroupModelImpl implements Group {
040
045 @Override
046 public void persist() throws SystemException {
047 if (this.isNew()) {
048 GroupLocalServiceUtil.addGroup(this);
049 }
050 else {
051 GroupLocalServiceUtil.updateGroup(this);
052 }
053 }
054
055 @Override
056 @SuppressWarnings("unused")
057 public String buildTreePath() throws PortalException, SystemException {
058 List<Group> groups = new ArrayList<Group>();
059
060 Group group = this;
061
062 while (group != null) {
063 groups.add(group);
064
065 group = GroupLocalServiceUtil.fetchGroup(group.getParentGroupId());
066 }
067
068 StringBundler sb = new StringBundler((groups.size() * 2) + 1);
069
070 sb.append(StringPool.SLASH);
071
072 for (int i = groups.size() - 1; i >= 0; i--) {
073 group = groups.get(i);
074
075 sb.append(group.getGroupId());
076 sb.append(StringPool.SLASH);
077 }
078
079 return sb.toString();
080 }
081
082 @Override
083 public void updateTreePath(String treePath) throws SystemException {
084 Group group = this;
085
086 group.setTreePath(treePath);
087
088 GroupLocalServiceUtil.updateGroup(group);
089 }
090 }