KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > business > project > ProjectManagerImpl


1 package projectmanagement.business.project;
2
3 import projectmanagement.business.ProjectManagementBusinessException;
4 import projectmanagement.data.project.*;
5
6 import projectmanagement.business.customer.*;
7
8 import com.lutris.appserver.server.sql.DatabaseManagerException;
9 import com.lutris.appserver.server.sql.ObjectId;
10 import com.lutris.appserver.server.sql.ObjectIdException;
11 import com.lutris.dods.builder.generator.query.*;
12 import com.lutris.appserver.server.Enhydra;
13 import com.lutris.logging.*;
14
15 import projectmanagement.spec.customer.*;
16 import projectmanagement.spec.project.*;
17 /**
18  * Used to find the instance of Project.
19  *
20  * @author Sasa Bojanic
21  * @version 1.0
22  */

23 public class ProjectManagerImpl implements ProjectManager {
24
25    /**
26     * The getAllProjects method performs a database query to
27     * return all <CODE>Project</CODE> objects representing the
28     * row in the <CODE>Projects</CODE> table.
29     * @return all the projects, or null if there are no any.
30     * @exception ProjectManagementBusinessException
31     * if there is a problem retrieving project information.
32     */

33     public Project[] getAllProjects()
34          throws ProjectManagementBusinessException {
35       try {
36          ProjectQuery query = new ProjectQuery();
37
38          ProjectDO[] foundProjects = query.getDOArray();
39          if(foundProjects.length != 0) {
40             ProjectImpl[] cs=new ProjectImpl[foundProjects.length];
41             for (int i=0; i<foundProjects.length; i++) {
42                cs[i]=new ProjectImpl(foundProjects[i]);
43             }
44             return cs;
45          } else {
46             return null;
47          }
48       } catch(NonUniqueQueryException ex) {
49          Enhydra.getLogChannel().write(Logger.DEBUG,
50             "Non-unique project found in database: "+ex.getMessage());
51          throw new ProjectManagementBusinessException("Non unique project found");
52       } catch(DataObjectException ex) {
53          throw new ProjectManagementBusinessException("Database error retrieving projects: ", ex);
54       } /*catch(QueryException ex) {
55          throw new ProjectManagementBusinessException("Query exception retrieving projects: ", ex);
56       }*/

57    }
58
59    /**
60     * The findProjectByID method performs a database query to
61     * return a <CODE>Project</CODE> object
62     * representing the row in the <CODE>project</CODE> table
63     * that matches the object id.
64     *
65     * @param id, the object id of the project table.
66     * @return
67     * the project. null if there isn't a project associated
68     * the id
69     * @exception ProjectManagementBusinessException
70     * if there is a problem retrieving project information.
71     */

72    public Project findProjectByID(String JavaDoc id)
73          throws ProjectManagementBusinessException {
74       ProjectImpl theProject = null;
75
76       try {
77          ProjectQuery query = new ProjectQuery();
78          //set query
79
query.setQueryOId(new ObjectId(id));
80          // Throw an exception if more than one user by this name is found
81
query.requireUniqueInstance();
82          ProjectDO theProjectDO = query.getNextDO();
83          theProject = new ProjectImpl(theProjectDO);
84          return theProject;
85       } catch(Exception JavaDoc ex) {
86          throw new ProjectManagementBusinessException("Exception in findProjectByID()", ex);
87       }
88    }
89
90     /**
91      * The getAllProjectsForCustomer method performs a database query to
92      * return a <CODE>Project</CODE> objects representing the row in the
93      * <CODE>project</CODE> table that matches the customer given by
94      * customerID.
95      *
96      * @param customerID the object id of Customer for which we need projects.
97      * @return
98      * array of projects for given customer. null if there isn't a project
99      * associated the customerID
100      * @exception ProjectManagementBusinessException
101      * if there is a problem retrieving project information.
102      */

103     public Project[] getAllProjectsForCustomer(String JavaDoc customerID)
104     throws ProjectManagementBusinessException {
105
106         if (customerID == null)
107             return getAllProjects();
108         try {
109             ProjectQuery query = new ProjectQuery();
110             
111             CustomerManagerImpl customerManager = new CustomerManagerImpl();
112             CustomerImpl customer = (CustomerImpl)customerManager.findCustomerByID(customerID);
113             
114             query.setQueryCustomer(customer.getDO(),QueryBuilder.EQUAL);
115             
116             ProjectDO[] foundProjects = query.getDOArray();
117             if(foundProjects.length != 0) {
118                 ProjectImpl[] projs=new ProjectImpl[foundProjects.length];
119                 for (int i=0; i<foundProjects.length; i++) {
120                     projs[i]=new ProjectImpl(foundProjects[i]);
121                 }
122                 return projs;
123             } else {
124                 return null;
125             }
126         } catch(NonUniqueQueryException ex) {
127             Enhydra.getLogChannel().write(Logger.DEBUG,
128             "Non-unique worksheet found in database: "+ex.getMessage());
129             throw new ProjectManagementBusinessException("Non unique worksheet found");
130         } catch(DataObjectException ex) {
131             throw new ProjectManagementBusinessException("Database error retrieving projects: ", ex);
132         } catch(QueryException ex) {
133             throw new ProjectManagementBusinessException("Query exception retrieving projects: ", ex);
134         }
135     }
136
137     /**
138      * The getAllProjectsForCustomer method performs a database query to
139      * return a <CODE>Project</CODE> objects representing the row in the
140      * <CODE>project</CODE> table that matches the customer
141      *
142      * @param customer the customer for which we need projects.
143      * @return
144      * array of projects for given customer. null if there isn't a project
145      * associated the customer
146      * @exception ProjectManagementBusinessException
147      * if there is a problem retrieving project information.
148      */

149     public Project[] getAllProjectsForCustomer(Customer customer)
150     throws ProjectManagementBusinessException {
151
152         if (customer == null)
153             return getAllProjects();
154         try {
155             ProjectQuery query = new ProjectQuery();
156             query.setQueryCustomer(((CustomerImpl)customer).getDO(),QueryBuilder.EQUAL);
157             
158             ProjectDO[] foundProjects = query.getDOArray();
159             if(foundProjects.length != 0) {
160                 ProjectImpl[] projs=new ProjectImpl[foundProjects.length];
161                 for (int i=0; i<foundProjects.length; i++) {
162                     projs[i]=new ProjectImpl(foundProjects[i]);
163                 }
164                 return projs;
165             } else {
166                 return null;
167             }
168         } catch(NonUniqueQueryException ex) {
169             Enhydra.getLogChannel().write(Logger.DEBUG,
170             "Non-unique worksheet found in database: "+ex.getMessage());
171             throw new ProjectManagementBusinessException("Non unique worksheet found");
172         } catch(DataObjectException ex) {
173             throw new ProjectManagementBusinessException("Database error retrieving projects: ", ex);
174         } catch(QueryException ex) {
175             throw new ProjectManagementBusinessException("Query exception retrieving projects: ", ex);
176         }
177     }
178 public Project getProject()
179       throws ProjectManagementBusinessException{
180      return new ProjectImpl();
181     }
182
183 }
184
Popular Tags