//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.workflow.coreImpl.store;

import java.util.Iterator;

import org.huihoo.workflow.server.WorkflowSession;
import org.huihoo.workflow.store.WorkflowDatabaseImpl;
import org.huihoo.workflow.store.WorkflowTemplate;
import org.huihoo.workflow.store.WorkflowUserDatabase;
import org.huihoo.workflow.usermodel.WorkflowCategory;
import org.huihoo.workflow.usermodel.WorkflowDepartment;
import org.huihoo.workflow.usermodel.WorkflowGroup;
import org.huihoo.workflow.usermodel.WorkflowParticipant;
import org.huihoo.workflow.usermodel.WorkflowRank;
import org.huihoo.workflow.usermodel.WorkflowRole;

public class WorkflowUserDatabaseImpl extends WorkflowDatabaseImpl implements WorkflowUserDatabase
{
	protected transient WorkflowTemplate workflowimpl;
	protected transient InternalUserDatabase gUserDBImpl;

	//------------------------------------------------------------------

	public WorkflowUserDatabaseImpl(WorkflowTemplate workflowimpl)
	{
		this.gUserDBImpl = new InternalUserDatabase();
		setWorkflowTemplate(workflowimpl);
	}

	public WorkflowTemplate getWorkflowTemplate()
	{
		return workflowimpl;
	}

	public void setWorkflowTemplate(WorkflowTemplate workflowimpl)
	{
		this.workflowimpl = workflowimpl;
	}

	// ------------------------------------------------------------- Properties
	/**
	 * Return the set of {@link Group}s defined in this user database.
	 */
	public Iterator getGroups(WorkflowSession session)
	{
		return gUserDBImpl.getGroupsImpl(session, this);
	}

	/**
	 * Return the set of {@link Department}s defined in this user database.
	 */
	public Iterator getDepartments(WorkflowSession session)
	{
		return gUserDBImpl.getDepartmentsImpl(session, this);
	}

	/**
	 * Return the set of {@link WorkflowRole}s defined in this user database.
	 */
	public Iterator getRoles(WorkflowSession session)
	{
		return gUserDBImpl.getRolesImpl(session, this);
	}

	/**
	 * Return the set of {@link WorkflowParticipant}s defined in this user database.
	 */
	public Iterator getParticipants(WorkflowSession session)
	{
		return gUserDBImpl.getParticipantsImpl(session, this);
	}

	/**
	 * Return the set of {@link Rank}s defined in this user database.
	 */
	public Iterator getRanks(WorkflowSession session)
	{
		return gUserDBImpl.getRanksImpl(session, this);
	}

	/**
	 * Return the set of {@link Category}s defined in this user database.
	 */
	public Iterator getCategories(WorkflowSession session)
	{
		return gUserDBImpl.getCategoriesImpl(session, this);
	}

	/**
	 * Return the {@link Group} with the specified group id, if any;
	 * otherwise return <code>null</code>.
	 *
	 * @param groupid id of the group to return
	 */
	public WorkflowGroup findGroup(WorkflowSession session, String groupid)
	{
		return gUserDBImpl.findGroupImpl(session, this, groupid);
	}

	/**
	 * Return the {@link Department} with the specified dept id, if any;
	 * otherwise return <code>null</code>.
	 *
	 * @param deptid id of the dept to return
	 */
	public WorkflowDepartment findDepartment(WorkflowSession session, String deptid)
	{
		return gUserDBImpl.findDepartmentImpl(session, this, deptid);
	}

	/**
	 * Return the {@link WorkflowRole} with the specified role id, if any;
	 * otherwise return <code>null</code>.
	 *
	 * @param roleid id of the role to return
	 */
	public WorkflowRole findRole(WorkflowSession session, String roleid)
	{
		return gUserDBImpl.findRoleImpl(session, this, roleid);
	}

	/**
	 * Return the {@link WorkflowParticipant} with the specified user id, if any;
	 * otherwise return <code>null</code>.
	 *
	 * @param userid id of the user to return
	 */
	public WorkflowParticipant findParticipant(WorkflowSession session, String userid)
	{
		return gUserDBImpl.findParticipantImpl(session, this, userid);
	}

	/**
	 * Return the {@link Rank} with the specified rank id, if any;
	 * otherwise return <code>null</code>.
	 *
	 * @param rankid id of the rank to return
	 */
	public WorkflowRank findRank(WorkflowSession session, String rankid)
	{
		return gUserDBImpl.findRankImpl(session, this, rankid);
	}

	/**
	 * Return the {@link Category} with the specified rank id, if any;
	 * otherwise return <code>null</code>.
	 *
	 * @param cetegoryid id of the Category to return
	 */
	public WorkflowCategory findCategory(WorkflowSession session, String cetegoryid)
	{
		return gUserDBImpl.findCategoryImpl(session, this, cetegoryid);
	}
}
