Package com.centraview.projects.project

Source Code of com.centraview.projects.project.ProjectEJB

/*
* $RCSfile: ProjectEJB.java,v $    $Revision: 1.2 $  $Date: 2005/09/01 15:31:06 $ - $Author: mcallist $
*
* The contents of this file are subject to the Open Software License
* Version 2.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.centraview.com/opensource/license.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is: CentraView Open Source.
*
* The developer of the Original Code is CentraView.  Portions of the
* Original Code created by CentraView are Copyright (c) 2004 CentraView,
* LLC; All Rights Reserved.  The terms "CentraView" and the CentraView
* logos are trademarks and service marks of CentraView, LLC.
*/


package com.centraview.projects.project;

import java.sql.Timestamp;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;

import com.centraview.administration.authorization.AuthorizationLocal;
import com.centraview.administration.authorization.AuthorizationLocalHome;
import com.centraview.administration.authorization.ModuleFieldRightMatrix;
import com.centraview.common.AuthorizationFailedException;
import com.centraview.common.CVDal;
import com.centraview.common.CVUtility;
import com.centraview.common.Constants;
import com.centraview.cvattic.CvAtticLocal;
import com.centraview.cvattic.CvAtticLocalHome;
import com.centraview.projects.helper.CustomFieldVO;
import com.centraview.projects.helper.ProjectDBVO;
import com.centraview.projects.helper.ProjectVO;

public class ProjectEJB implements SessionBean
{
  protected javax.ejb.SessionContext ctx;
  protected Context environment;
  private String dataSource = "MySqlDS";
  private int transactionID = 0;

  public void setSessionContext(SessionContext ctx)
  {
    this.ctx = ctx;
  }

  public void ejbActivate() {}
  public void ejbPassivate() {}
  public void ejbRemove() {}
  public void ejbCreate() {}

  /**
   * Adds a project and details in the database.
   * @param userId  Creator of the project
   * @param pvo    Value of the project
   */
  public int addProject(int userId, ProjectVO pvo)
  {
    CVDal dl = new CVDal(dataSource);
    int projectId = 0;

    try
    {
      if (!CVUtility.isModuleVisible("Projects", userId, this.dataSource))
      {
        throw new AuthorizationFailedException("Projects - addProject");
      }

      dl.setSql("project.addproject");
      dl.setString(1, pvo.getTitle());
      dl.setString(2, pvo.getDescription());
      dl.setInt(3, pvo.getStatusID());
      dl.setDate(4, pvo.getStart());
      dl.setDate(5, pvo.getEnd());
      dl.setInt(6, pvo.getBudgetedHours());
      dl.setInt(7, pvo.getManagerID());
      dl.setInt(8, userId);
      dl.setInt(9, userId);

      dl.executeUpdate();

      projectId = dl.getAutoGeneratedKey();
      dl.clearParameters();
 
    HashMap historyInfo = new HashMap();
    historyInfo.put("recordID",new Integer(projectId));
    historyInfo.put("recordTypeID", new Integer(Constants.ProjectModuleID));
    historyInfo.put("operation", new Integer(Constants.CREATED));
    historyInfo.put("individualID", new Integer(userId));
    historyInfo.put("referenceActivityID", new Integer(0));     
    historyInfo.put("recordName", pvo.getTitle());
      CVUtility.addHistoryRecord(historyInfo,dataSource);

      int recordTypeId = 0;
      Vector vec = null;

      if (pvo.getEntityID() != 0)
      {
        dl.setSqlQuery("select ModuleID from module where name='entity'");
        vec = (Vector)dl.executeQuery();

        if (vec != null)
        {
          Number tempID = (Number) ((HashMap)vec.firstElement()).get("ModuleID");
          recordTypeId = tempID.intValue();
        }
        dl.clearParameters();

        dl.setSql("project.addprojectlink");
        dl.setInt(1, projectId);
        dl.setInt(2, recordTypeId);
        dl.setInt(3, pvo.getEntityID());
        dl.executeUpdate();
      }

      if (pvo.getContactID() != 0)
      {
        dl.setSqlQuery("select ModuleID from module where name='Individual'");
        dl.executeQuery();
        vec = (Vector)dl.executeQuery();

        if (vec != null)
        {
          Number tempID = (Number) ((HashMap)vec.firstElement()).get("ModuleID");
          recordTypeId = tempID.intValue();
        }
        dl.clearParameters();

        dl.setSql("project.addprojectlink");
        dl.setInt(1, projectId);
        dl.setInt(2, recordTypeId);
        dl.setInt(3, pvo.getContactID());
        dl.executeUpdate();
      }

      if (pvo.getGroupID() != 0)
      {
        dl.setSqlQuery("select ModuleID from module where name='Group'");
        vec = (Vector)dl.executeQuery();

        if (vec != null)
        {
          Number tempID = (Number) ((HashMap)vec.firstElement()).get("ModuleID");
          recordTypeId = tempID.intValue();
        }
        dl.clearParameters();

        dl.setSql("project.addprojectlink");
        dl.setInt(1, projectId);
        dl.setInt(2, recordTypeId);
        dl.setInt(3, pvo.getGroupID());
        dl.executeUpdate();
      }

      Vector customField = pvo.getCustomField();
      if (customField != null && customField.size() != 0)
      {
        for (int i = 0; i < customField.size(); i++)
        {
          CustomFieldVO cvo = (CustomFieldVO)customField.get(i);
          if (cvo.getFieldID() != 0)
          {
            dl.setSql("project.addcustomfieldscalar");
            dl.setInt(1, cvo.getFieldID());
            dl.setInt(2, projectId);
            dl.setString(3, cvo.getValue());
            dl.executeUpdate();
          }
        }
      }

      InitialContext ic = CVUtility.getInitialContext();
      AuthorizationLocalHome authorizationHome = (AuthorizationLocalHome)ic.lookup("local/Authorization");
      AuthorizationLocal authorizationLocal = authorizationHome.create();
      authorizationLocal.setDataSource(dataSource);
      authorizationLocal.saveCurrentDefaultPermission("Projects", projectId, userId);
    }catch (Exception e){
      System.out.println("[Exception][ProjectEJB.addProject] Exception Thrown: " + e);
      e.printStackTrace();
    }finally{
      dl.destroy();
      dl = null;
    }
    return projectId;
  }

  /**
   * Updates a project and details in the database.
   * @param userId  Creator of the project
   * @param pvo    Value of the project
   */
  public void updateProject(int userId, ProjectVO pvo)
  {
    try
    {
      if (!CVUtility.canPerformRecordOperation(userId, "Projects", pvo.getProjectID(), ModuleFieldRightMatrix.UPDATE_RIGHT, this.dataSource))
      {
        throw new AuthorizationFailedException("Projects - updateProject");
      }

      int projectId = pvo.getProjectID();

      CVDal dl = new CVDal(dataSource);
      dl.setSql("project.updateproject");

      ProjectDBVO pdbvo = new ProjectDBVO();
      pdbvo = getDBVO(projectId, userId);
      pvo = (ProjectVO)CVUtility.replaceVO(pdbvo, pvo, "Projects", userId, this.dataSource);

      dl.setString(1, pvo.getTitle());
      dl.setString(2, pvo.getDescription());
      dl.setInt(3, pvo.getStatusID());
      dl.setDate(4, pvo.getStart());
      dl.setDate(5, pvo.getEnd());
      dl.setInt(6, pvo.getBudgetedHours());
      dl.setInt(7, pvo.getManagerID());
      dl.setInt(8, userId);
      dl.setInt(9, projectId);

      dl.executeUpdate();

      dl.clearParameters();
      dl.setSql("project.deleteprojectlink");
      dl.setInt(1, projectId);
      dl.executeUpdate();

    HashMap historyInfo = new HashMap();
    historyInfo.put("recordID",new Integer(projectId));
    historyInfo.put("recordTypeID", new Integer(Constants.ProjectModuleID));
    historyInfo.put("operation", new Integer(Constants.UPDATED));
    historyInfo.put("individualID", new Integer(userId));
    historyInfo.put("referenceActivityID", new Integer(0));     
    historyInfo.put("recordName", pvo.getTitle());
      CVUtility.addHistoryRecord(historyInfo,dataSource);

      int recordTypeId = 0;
      Vector vec = null;

      if (pvo.getEntityID() != 0)
      {
        dl.setSqlQuery("select ModuleID from module where name='entity'");
        vec = (Vector)dl.executeQuery();

        if (vec != null)
        {
          Number tempID = (Number) ((HashMap)vec.firstElement()).get("ModuleID");
          recordTypeId = tempID.intValue();
        }
        dl.clearParameters();

        dl.setSql("project.addprojectlink");
        dl.setInt(1, projectId);
        dl.setInt(2, recordTypeId);
        dl.setInt(3, pvo.getEntityID());
        dl.executeUpdate();
      }

      if (pvo.getContactID() != 0)
      {
        dl.setSqlQuery("select ModuleID from module where name='Individual'");
        dl.executeQuery();
        vec = (Vector)dl.executeQuery();

        if (vec != null)
        {
          Number tempID = (Number) ((HashMap)vec.firstElement()).get("ModuleID");
          recordTypeId = tempID.intValue();
        }
        dl.clearParameters();

        dl.setSql("project.addprojectlink");
        dl.setInt(1, projectId);
        dl.setInt(2, recordTypeId);
        dl.setInt(3, pvo.getContactID());
        dl.executeUpdate();
      }

      if (pvo.getGroupID() != 0)
      {
        dl.setSqlQuery("select ModuleID from module where name='Group'");
        vec = (Vector)dl.executeQuery();
        if (vec != null)
        {
          Number tempID = (Number) ((HashMap)vec.firstElement()).get("ModuleID");
          recordTypeId = tempID.intValue();
        }
        dl.clearParameters();

        dl.setSql("project.addprojectlink");
        dl.setInt(1, projectId);
        dl.setInt(2, recordTypeId);
        dl.setInt(3, pvo.getGroupID());
        dl.executeUpdate();
      }

      Vector customField = pvo.getCustomField();
      if (customField != null && customField.size() != 0)
      {
        dl.setSql("project.deletecustomfieldscalar");
        dl.setInt(1, projectId);
        dl.executeUpdate();
        dl.clearParameters();

        for (int i = 0; i < customField.size(); i++)
        {
          CustomFieldVO cvo = (CustomFieldVO)customField.get(i);
          if (cvo.getFieldID() != 0)
          {
            dl.setSql("project.addcustomfieldscalar");
            dl.setInt(1, cvo.getFieldID());
            dl.setInt(2, projectId);
            dl.setString(3, cvo.getValue());
            dl.executeUpdate();
          }
        }
      }
      dl.destroy();
    }catch (Exception e){
      e.printStackTrace();
    }
  }

  /**
   * Gets the project and details from the database.
   * @param userId  current user
   * @param projectId  Id of the project
   * @return      Value object of the project
   */
  public ProjectDBVO getDBVO(int projectId, int userId)throws AuthorizationFailedException
  {
    if (!CVUtility.canPerformRecordOperation(userId, "Projects", projectId, ModuleFieldRightMatrix.VIEW_RIGHT, this.dataSource))
    {
      throw new AuthorizationFailedException("Projects - getProject");
    }

    CVDal cvdl = new CVDal(dataSource);
    cvdl.setSql("project.getproject");
    cvdl.setInt(1, projectId);
    Collection col = cvdl.executeQuery();
    Iterator ite = col.iterator();
    ProjectDBVO pdbvo = new ProjectDBVO();
    if (ite.hasNext())
    {
      HashMap project = (HashMap)ite.next();
      pdbvo.setProjectID(((Long)project.get("ProjectID")).intValue());
      pdbvo.setTitle((String)project.get("ProjectTitle"));
      if (project.get("Description") != null)
        pdbvo.setDescription((String)project.get("Description"));
      if (project.get("StatusID") != null)
        pdbvo.setStatusID(((Long)project.get("StatusID")).intValue());
      if (project.get("Start") != null)
        pdbvo.setStart((java.sql.Date)project.get("Start"));
      if (project.get("End") != null)
        pdbvo.setEnd((java.sql.Date)project.get("End"));
      if (project.get("BudgetedHours") != null)
        pdbvo.setBudgetedHours(((Long)project.get("BudgetedHours")).intValue());
      if (project.get("HoursUsed") != null)
        pdbvo.setUsedHours(((Long)project.get("HoursUsed")).intValue());
      if (project.get("Manager") != null)
        pdbvo.setManagerID(((Long)project.get("Manager")).intValue());
      if (project.get("Owner") != null)
        pdbvo.setOwner(((Long)project.get("Owner")).intValue());
      if (project.get("Creator") != null)
        pdbvo.setCreator(((Long)project.get("Creator")).intValue());
      if (project.get("ModifiedBy") != null)
        pdbvo.setModifiedBy(((Long)project.get("ModifiedBy")).intValue());
      if (project.get("Modified") != null)
        pdbvo.setModified((Timestamp)project.get("Modified"));
      if (project.get("Created") != null)
        pdbvo.setCreated((Timestamp)project.get("Created"));
    }

    cvdl.clearParameters();
    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pdbvo.getCreator());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setCreatorName((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pdbvo.getModifiedBy());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setModifierName((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }
    cvdl.clearParameters();

    cvdl.setSql("project.getprojectentitylink");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setEntityID(((Long)hm.get("entityid")).intValue());
      pdbvo.setEntityName((String)hm.get("name"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getprojectindividuallink");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setContactID(((Long)hm.get("individualid")).intValue());
      pdbvo.setContactName((String)hm.get("CONCAT(firstname , ' ' , lastname)"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getprojectgrouplink");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setGroupID(((Long)hm.get("groupid")).intValue());
      pdbvo.setGroupName((String)hm.get("name"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.projecthoursused");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      if (hm.get("sum(hours)") != null)
      {
        pdbvo.setUsedHours(((Double)hm.get("sum(hours)")).floatValue());
      }
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pdbvo.getOwner());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setOwnerName((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }
    cvdl.clearParameters();

    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pdbvo.getManagerID());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pdbvo.setManager((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }
    cvdl.clearParameters();
    return pdbvo;
  }

  /**
   * Gets the project and details from the database.
   * @param userId  current user
   * @param projectId  Id of the project
   * @return      Value object of the project
   */
  public ProjectVO getProject(int projectId, int userId)throws AuthorizationFailedException
  {
    if (!CVUtility.canPerformRecordOperation(userId, "Projects", projectId, ModuleFieldRightMatrix.VIEW_RIGHT, this.dataSource))
    {
      throw new AuthorizationFailedException("Projects - getProject");
    }

    CVDal cvdl = new CVDal(dataSource);
    cvdl.setSql("project.getproject");
    cvdl.setInt(1, projectId);
    Collection col = cvdl.executeQuery();
    Iterator ite = col.iterator();
    ProjectVO pvo = new ProjectVO();
    if (ite.hasNext())
    {
      HashMap project = (HashMap)ite.next();
      pvo.setProjectID(((Long)project.get("ProjectID")).intValue());
      pvo.setTitle((String)project.get("ProjectTitle"));
      if (project.get("Description") != null)
        pvo.setDescription((String)project.get("Description"));
      if (project.get("StatusID") != null)
        pvo.setStatusID(((Long)project.get("StatusID")).intValue());
      if (project.get("Start") != null)
        pvo.setStart((java.sql.Date)project.get("Start"));
      if (project.get("End") != null)
        pvo.setEnd((java.sql.Date)project.get("End"));
      if (project.get("BudgetedHours") != null)
        pvo.setBudgetedHours(((Long)project.get("BudgetedHours")).intValue());
      if (project.get("HoursUsed") != null)
        pvo.setUsedHours(((Long)project.get("HoursUsed")).intValue());
      if (project.get("Owner") != null)
        pvo.setOwner(((Long)project.get("Owner")).intValue());
      if (project.get("Manager") != null)
        pvo.setManagerID(((Long)project.get("Manager")).intValue());
      if (project.get("Creator") != null)
        pvo.setCreator(((Long)project.get("Creator")).intValue());
      if (project.get("ModifiedBy") != null)
        pvo.setModifiedBy(((Long)project.get("ModifiedBy")).intValue());
      if (project.get("Modified") != null)
        pvo.setModified((Timestamp)project.get("Modified"));
      if (project.get("Created") != null)
        pvo.setCreated((Timestamp)project.get("Created"));
    }

    cvdl.clearParameters();
    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pvo.getCreator());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setCreatorName((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pvo.getModifiedBy());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setModifierName((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }
    cvdl.clearParameters();

    cvdl.setSql("project.getprojectentitylink");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setEntityID(((Long)hm.get("entityid")).intValue());
      pvo.setEntityName((String)hm.get("name"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getprojectindividuallink");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setContactID(((Long)hm.get("individualid")).intValue());
      pvo.setContactName((String)hm.get("CONCAT(firstname , ' ' , lastname)"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getprojectgrouplink");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setGroupID(((Long)hm.get("groupid")).intValue());
      pvo.setGroupName((String)hm.get("name"));
    }

    cvdl.clearParameters();

    cvdl.setSql("project.projecthoursused");
    cvdl.setInt(1, projectId);
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      if (hm.get("sum(hours)") != null)
      {
        pvo.setUsedHours(((Double)hm.get("sum(hours)")).floatValue());
      }
    }

    cvdl.clearParameters();

    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pvo.getOwner());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setOwnerName((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }
    cvdl.clearParameters();

    cvdl.setSql("project.getindname");
    cvdl.setInt(1, pvo.getManagerID());
    col = cvdl.executeQuery();
    ite = col.iterator();
    if (ite.hasNext())
    {
      HashMap hm = (HashMap)ite.next();
      pvo.setManager((String)hm.get("CONCAT(firstname,' ',lastname)"));
    }
    cvdl.clearParameters();
    return pvo;
  }

  /**
   * Delete the project from the database
   * @param projectId  Id of the Project to be deleted
   */
  public void deleteProject(int userID, int projectId) throws AuthorizationFailedException
  {

    if (!CVUtility.canPerformRecordOperation(userID, "Projects", projectId, ModuleFieldRightMatrix.DELETE_RIGHT, this.dataSource))
    {
      throw new AuthorizationFailedException("Projects - Delete Project");
    }

    try
    {
      CVDal cvdl = new CVDal(dataSource);

      cvdl.setSql("project.getproject");
      cvdl.setInt(1, projectId);
      Collection colPrj = cvdl.executeQuery();

      String strTitle = "";
      int intOwner = 0;

      if (colPrj.size() > 0)
      {
        Iterator iter = colPrj.iterator();

        while (iter.hasNext())
        {
          HashMap hm = (HashMap)iter.next();

          if (hm.get("ProjectTitle") != null)
          {
            strTitle = (String)hm.get("ProjectTitle");
          }

          if (hm.get("Owner") != null)
          {
            intOwner = ((Long)hm.get("Owner")).intValue();
          }
        }
      }

      HashMap hmDetails = new HashMap();
      hmDetails.put("title", strTitle);
      hmDetails.put("owner", new Integer(intOwner));
      hmDetails.put("module", new Integer(9));
      hmDetails.put("recordtype", new Integer(48));

      //Get the transactionID
      transactionID = getAtticTransactionID(userID, Constants.CV_GARBAGE, hmDetails);

      HashMap hmPrj = new HashMap();
      hmPrj.put("ProjectID", (new Integer(projectId)).toString());
      sendToAttic(userID, transactionID, "project", hmPrj);

      cvdl.setSql("project.deleteproject");
      cvdl.setInt(1, projectId);
      cvdl.executeUpdate();
      cvdl.clearParameters();

      cvdl.clearParameters();
      cvdl.setSqlQuery("SELECT * FROM projectlink WHERE projectid = ?");
      cvdl.setInt(1, projectId);
      Collection colPrjLink = cvdl.executeQuery();
      cvdl.clearParameters();

      if (colPrjLink.size() > 0)
      {
        Iterator iterator = colPrjLink.iterator();
        while (iterator.hasNext())
        {
          HashMap hm = (HashMap)iterator.next();
          int intRecord = 0;
          if (hm.get("RecordID") != null)
          {
            intRecord = ((Long)hm.get("RecordID")).intValue();
          }

          HashMap hmPrjLink = new HashMap();
          hmPrjLink.put("ProjectID", (new Integer(projectId)).toString());
          hmPrjLink.put("RecordID", (new Integer(intRecord)).toString());
          sendToAttic(userID, transactionID, "projectlink", hmPrjLink);
        }
      }

    HashMap historyInfo = new HashMap();
    historyInfo.put("recordID",new Integer(projectId));
    historyInfo.put("recordTypeID", new Integer(Constants.ProjectModuleID));
    historyInfo.put("operation", new Integer(Constants.DELETED));
    historyInfo.put("individualID", new Integer(userID));
    historyInfo.put("referenceActivityID", new Integer(0));     
    historyInfo.put("recordName", strTitle);
      CVUtility.addHistoryRecord(historyInfo,dataSource);

      cvdl.setSql("project.deleteprojecttimeslip");
      cvdl.setInt(1, projectId);
      cvdl.executeUpdate();
      cvdl.clearParameters();

      cvdl.setSql("project.deleteprojectlink");
      cvdl.setInt(1, projectId);
      cvdl.executeUpdate();
      cvdl.clearParameters();

      cvdl.destroy();
    }catch (Exception e){
      System.out.println("[Exception][ProjectEJB.deleteProject] Exception Thrown: " + e);
    }
  }

  /**
   * Returns the TransactionID
   * @param userID int
   * @param dumpType String
   * @param hm hashmap
   * @return the Attic TransactionID
   */
  private int getAtticTransactionID(int indvID, String dumpType, HashMap hm)
  {
    int transID = 0;
    try
    {
      InitialContext ctx = CVUtility.getInitialContext();
      CvAtticLocalHome home = (CvAtticLocalHome)ctx.lookup("local/CvAttic");
      CvAtticLocal remote = home.create();
      remote.setDataSource(this.dataSource);
      transID = remote.getAtticTransactionID(indvID, dumpType, hm);
    }catch (Exception e){
      System.out.println("Error in sendToAttic(int) Method of Projects " + e);
      e.printStackTrace();
    }
    return transID;
  }

  /**
   * Send to Attic
   * @param indvID int
   * @param transactionID int
   * @param recordType
   * @param primaryMembers
   */
  private void sendToAttic(int indvID, int transactionID, String recordType, HashMap primaryMembers)
  {
    try
    {
      InitialContext ctx = CVUtility.getInitialContext();
      CvAtticLocalHome home = (CvAtticLocalHome)ctx.lookup("local/CvAttic");
      CvAtticLocal remote = home.create();
      remote.setDataSource(this.dataSource);
      remote.dumpData(indvID, transactionID, recordType, primaryMembers);
    }catch (Exception e){
      System.out.println("Error in sendToAttic Method of Projects " + e);
      e.printStackTrace();
    }
  }

  /**
   * @author Kevin McAllister <kevin@centraview.com>
   * This simply sets the target datasource to be used for DB interaction
   * @param ds A string that contains the cannonical JNDI name of the datasource
   */
  public void setDataSource(String ds)
  {
    this.dataSource = ds;
  }

  /**
   * This method returns Project Name Of the Project
   * @param ProjectID The ProjectID to collect the Project Title
   * @return ProjectName The ProjectName
   */
  public String getProjectName(int ProjectID)
  {
    String ProjectName = "";
    CVDal dl = new CVDal(dataSource);
    try
    {
      String ProjectQuery = "select ProjectID, ProjectTitle  from project where ProjectID = ?";
      dl.setSqlQuery(ProjectQuery);
      dl.setInt(1, ProjectID);
      Collection col = dl.executeQuery();

      if (col != null)
      {
        Iterator it = col.iterator();
        while (it.hasNext())
        {
          HashMap hm = (HashMap) it.next();
          ProjectName = (String) hm.get("ProjectTitle");
        }// end of while (it.hasNext())
      }//end of if (col != null)
    }catch (Exception e){
      e.printStackTrace();
    }finally{
      dl.clearParameters();
      dl.destroy();
      dl = null;
    } //end of finally block
    return ProjectName;
  }   // end getProjectName() method

}   // end class definition
TOP

Related Classes of com.centraview.projects.project.ProjectEJB

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.