Package com.zycus.dotproject.impl

Source Code of com.zycus.dotproject.impl.DepartmentManagerImpl

package com.zycus.dotproject.impl;

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

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.zycus.dotproject.api.IDepartmentManager;
import com.zycus.dotproject.bo.BODepartment;
import com.zycus.dotproject.bo.BOUser;
import com.zycus.dotproject.bo.UserType;
import com.zycus.dotproject.persistence.db.hibernate.BaseHibernateDataHandler;
import com.zycus.dotproject.persistence.db.hibernate.HibernateSessionFactory;

public class DepartmentManagerImpl extends BaseHibernateDataHandler implements IDepartmentManager  {

 
  /* (non-Javadoc)
   * @see com.zycus.dotproject.impl.IDepartmentManager#getAllDepartments(com.zycus.dotproject.bo.BOUser)
   */
  public List<BODepartment> getAllDepartments(BOUser user) {
    SessionFactory sessionFactory = null;
    Session session = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();

     
     
      if(user.getUserType()==UserType.Administrator)
      {
        Criteria criteria = session.createCriteria(BODepartment.class);
        return criteria.list();
      }
     
      else
      {
        ArrayList<BODepartment> departmentList = new ArrayList<BODepartment>();
        departmentList.addAll(user.getContact().getContactCompany().getDepartments());
        return departmentList;
      }
     
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
    } finally {
      close(sessionFactory, session);
    }
  }


  /* (non-Javadoc)
   * @see com.zycus.dotproject.impl.IDepartmentManager#deleteDepartment(com.zycus.dotproject.bo.BOUser, com.zycus.dotproject.bo.BODepartment)
   */
  public void deleteDepartment(BOUser user, BODepartment department) {
   
    if(user.getUserType()==UserType.Administrator)
    {
      performDBAction(department, DBActionCriteria.Delete);
    }
   
  }

  /* (non-Javadoc)
   * @see com.zycus.dotproject.impl.IDepartmentManager#saveDepartment(com.zycus.dotproject.bo.BOUser, com.zycus.dotproject.bo.BODepartment)
   */
  public void saveDepartment(BOUser user, BODepartment department)
  {
    if(user.getUserType()==UserType.Administrator)
    {
      performDBAction(department, DBActionCriteria.Update);
    }
  }
 
}
TOP

Related Classes of com.zycus.dotproject.impl.DepartmentManagerImpl

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.