package kr.co.kihyun.beans.entity;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import kr.co.kihyun.beans.entity.ecross.NeisParty;
import kr.co.kihyun.beans.entity.util.MPersistenceManager;

public abstract class AbstractOrganization<T extends Comparable<?>> extends MoumiEntity<T> implements Organization<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6570235900133337139L;

	public AbstractOrganization() {
	}

	public List<MDept> getOrgTreePath(PersistenceManager pm) {
		List<MDept> path = new ArrayList<MDept>();
		MDept currentDept = this.getUpperDept(pm);
		if (currentDept != null) {
			path.add(currentDept);
			while (currentDept.getUpperDept(pm) != null)
				path.add(0, currentDept = currentDept.getUpperDept(pm));
		}
		return path;
	}

//	public MDept getRootDept(PersistenceManager pm) {
//		PersistenceManager localPm = new MPersistenceManager(pm);
//		List<MDept> path = this.getOrgTreePath(localPm);
//		if (path.isEmpty())
//			return (MDept) this;
//		return path.get(path.size() - 1);
//	}

	public abstract MDept getRootDept(PersistenceManager pm);

	public abstract NeisParty getNeisParty(PersistenceManager pm);

}
