Package org.huihoo.workflow.impl.usermodel

Source Code of org.huihoo.workflow.impl.usermodel.WorkflowDepartmentImpl

//----------------------------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.impl.usermodel;

import java.util.ArrayList;
import java.util.Iterator;

import org.huihoo.workflow.ComplexComponentObject;
import org.huihoo.workflow.store.spi.SpiUserDatabase;
import org.huihoo.workflow.usermodel.WorkflowCategory;
import org.huihoo.workflow.usermodel.WorkflowDepartment;
import org.huihoo.workflow.usermodel.WorkflowGroup;
import org.huihoo.workflow.usermodel.WorkflowParticipant;

/**
* @author reic
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class WorkflowDepartmentImpl extends ComplexComponentObject implements WorkflowDepartment
{
  protected WorkflowCategory category;

  public WorkflowCategory getCategory()
  {
    return category;
  }

  public void setCategory(WorkflowCategory departCategory)
  {
    this.category = departCategory;
  }
  //----------------------------------------------------------- Constructors
  /**
    * @param database The {@link LiveUserDatabase} that owns this department
    * @param departmentid   Group id of this department
    * @param departmentname Group name of this department
    * @param description Description of this department
    */
  public WorkflowDepartmentImpl(
    SpiUserDatabase database,
    String departmentid,
    String departmentname,
    String description)
  {
    super(departmentid, departmentname, description);
    this.database = database;
  }
  public WorkflowDepartmentImpl(
    SpiUserDatabase database,
    String departmentid,
    String departmentname,
    String description,
    WorkflowDepartment parentDepartment)
  {
    super(departmentid, departmentname, description);
    this.database = database;
    this.parentDepartment = parentDepartment;
  }
  // ----------------------------------------------------- Instance Variables
  protected WorkflowDepartment parentDepartment;

  protected WorkflowParticipant president;

  /**
    * The {@link SpiUserDatabase} that owns this group.
    */
  protected SpiUserDatabase database = null;
  // ------------------------------------------------------------- Properties
  public WorkflowDepartment getParentDepartment()
  {
    return parentDepartment;
  }
  /**
    * Return the {@link LiveUserDatabase} within which this Group is defined.
    */
  public SpiUserDatabase getUserDatabase()
  {
    return (this.database);
  }
  /**
    * Return the set of {@link WorkflowParticipant}s that are members of this group.
    */
  public Iterator getParticipants()
  {
    ArrayList results = new ArrayList();
    Iterator users = database.getParticipants();
    while (users.hasNext())
    {
      WorkflowParticipant user = (WorkflowParticipant) users.next();
      if (user.isInDepartment(this))
      {
        results.add(user);
      }
    }
    return (results.iterator());
  }

  /**
    * Return the set of {@link WorkflowParticipant}s that are members of this group.
    */
  public Iterator getGroups()
  {
    ArrayList results = new ArrayList();
    Iterator groups = database.getGroups();
    while (groups.hasNext())
    {
      WorkflowGroup group = (WorkflowGroup) groups.next();
      if (group.isInDepartment(this))
      {
        results.add(group);
      }
    }
    return (results.iterator());
  }

  // --------------------------------------------------------- Public Methods

  public void addPaticipant(WorkflowParticipant user)
  {
    user.addDepartment(this);
  }

  public void removeParticipant(WorkflowParticipant user)
  {
    user.removeDepartment(this);
  }

  public void removeParticipants()
  {
    Iterator users = database.getParticipants();
    while (users.hasNext())
    {
      WorkflowParticipant user = (WorkflowParticipant) users.next();
      if (user.isInDepartment(this))
      {
        user.removeDepartment(this);
      }
    }
  }

  public void addGroup(WorkflowGroup group)
  {
    group.setDepartment(this);
  }

  public void removeGroup(WorkflowGroup group)
  {
    group.setDepartment(null);
  }

  public void removeGroups()
  {
    Iterator groups = database.getGroups();
    while (groups.hasNext())
    {
      WorkflowGroup group = (WorkflowGroup) groups.next();
      if (group.isInDepartment(this))
      {
        group.setDepartment(null);
      }
    }
  }

  public void setPresident(WorkflowParticipant president)
  {
    this.president = president;
  }

  public WorkflowParticipant getPresident()
  {
    return president;
  }
}
TOP

Related Classes of org.huihoo.workflow.impl.usermodel.WorkflowDepartmentImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.