001: package projectmanagement.business.project;
002:
003: import projectmanagement.business.ProjectManagementBusinessException;
004: import projectmanagement.data.project.*;
005:
006: import projectmanagement.business.customer.*;
007:
008: import com.lutris.appserver.server.sql.DatabaseManagerException;
009: import com.lutris.appserver.server.sql.ObjectId;
010: import com.lutris.appserver.server.sql.ObjectIdException;
011: import com.lutris.dods.builder.generator.query.*;
012: import com.lutris.appserver.server.Enhydra;
013: import com.lutris.logging.*;
014:
015: import projectmanagement.spec.customer.*;
016: import projectmanagement.spec.project.*;
017:
018: /**
019: * Used to find the instance of Project.
020: *
021: * @author Sasa Bojanic
022: * @version 1.0
023: */
024: public class ProjectManagerImpl implements ProjectManager {
025:
026: /**
027: * The getAllProjects method performs a database query to
028: * return all <CODE>Project</CODE> objects representing the
029: * row in the <CODE>Projects</CODE> table.
030: * @return all the projects, or null if there are no any.
031: * @exception ProjectManagementBusinessException
032: * if there is a problem retrieving project information.
033: */
034: public Project[] getAllProjects()
035: throws ProjectManagementBusinessException {
036: try {
037: ProjectQuery query = new ProjectQuery();
038:
039: ProjectDO[] foundProjects = query.getDOArray();
040: if (foundProjects.length != 0) {
041: ProjectImpl[] cs = new ProjectImpl[foundProjects.length];
042: for (int i = 0; i < foundProjects.length; i++) {
043: cs[i] = new ProjectImpl(foundProjects[i]);
044: }
045: return cs;
046: } else {
047: return null;
048: }
049: } catch (NonUniqueQueryException ex) {
050: Enhydra.getLogChannel().write(
051: Logger.DEBUG,
052: "Non-unique project found in database: "
053: + ex.getMessage());
054: throw new ProjectManagementBusinessException(
055: "Non unique project found");
056: } catch (DataObjectException ex) {
057: throw new ProjectManagementBusinessException(
058: "Database error retrieving projects: ", ex);
059: } /*catch(QueryException ex) {
060: throw new ProjectManagementBusinessException("Query exception retrieving projects: ", ex);
061: }*/
062: }
063:
064: /**
065: * The findProjectByID method performs a database query to
066: * return a <CODE>Project</CODE> object
067: * representing the row in the <CODE>project</CODE> table
068: * that matches the object id.
069: *
070: * @param id, the object id of the project table.
071: * @return
072: * the project. null if there isn't a project associated
073: * the id
074: * @exception ProjectManagementBusinessException
075: * if there is a problem retrieving project information.
076: */
077: public Project findProjectByID(String id)
078: throws ProjectManagementBusinessException {
079: ProjectImpl theProject = null;
080:
081: try {
082: ProjectQuery query = new ProjectQuery();
083: //set query
084: query.setQueryOId(new ObjectId(id));
085: // Throw an exception if more than one user by this name is found
086: query.requireUniqueInstance();
087: ProjectDO theProjectDO = query.getNextDO();
088: theProject = new ProjectImpl(theProjectDO);
089: return theProject;
090: } catch (Exception ex) {
091: throw new ProjectManagementBusinessException(
092: "Exception in findProjectByID()", ex);
093: }
094: }
095:
096: /**
097: * The getAllProjectsForCustomer method performs a database query to
098: * return a <CODE>Project</CODE> objects representing the row in the
099: * <CODE>project</CODE> table that matches the customer given by
100: * customerID.
101: *
102: * @param customerID the object id of Customer for which we need projects.
103: * @return
104: * array of projects for given customer. null if there isn't a project
105: * associated the customerID
106: * @exception ProjectManagementBusinessException
107: * if there is a problem retrieving project information.
108: */
109: public Project[] getAllProjectsForCustomer(String customerID)
110: throws ProjectManagementBusinessException {
111:
112: if (customerID == null)
113: return getAllProjects();
114: try {
115: ProjectQuery query = new ProjectQuery();
116:
117: CustomerManagerImpl customerManager = new CustomerManagerImpl();
118: CustomerImpl customer = (CustomerImpl) customerManager
119: .findCustomerByID(customerID);
120:
121: query
122: .setQueryCustomer(customer.getDO(),
123: QueryBuilder.EQUAL);
124:
125: ProjectDO[] foundProjects = query.getDOArray();
126: if (foundProjects.length != 0) {
127: ProjectImpl[] projs = new ProjectImpl[foundProjects.length];
128: for (int i = 0; i < foundProjects.length; i++) {
129: projs[i] = new ProjectImpl(foundProjects[i]);
130: }
131: return projs;
132: } else {
133: return null;
134: }
135: } catch (NonUniqueQueryException ex) {
136: Enhydra.getLogChannel().write(
137: Logger.DEBUG,
138: "Non-unique worksheet found in database: "
139: + ex.getMessage());
140: throw new ProjectManagementBusinessException(
141: "Non unique worksheet found");
142: } catch (DataObjectException ex) {
143: throw new ProjectManagementBusinessException(
144: "Database error retrieving projects: ", ex);
145: } catch (QueryException ex) {
146: throw new ProjectManagementBusinessException(
147: "Query exception retrieving projects: ", ex);
148: }
149: }
150:
151: /**
152: * The getAllProjectsForCustomer method performs a database query to
153: * return a <CODE>Project</CODE> objects representing the row in the
154: * <CODE>project</CODE> table that matches the customer
155: *
156: * @param customer the customer for which we need projects.
157: * @return
158: * array of projects for given customer. null if there isn't a project
159: * associated the customer
160: * @exception ProjectManagementBusinessException
161: * if there is a problem retrieving project information.
162: */
163: public Project[] getAllProjectsForCustomer(Customer customer)
164: throws ProjectManagementBusinessException {
165:
166: if (customer == null)
167: return getAllProjects();
168: try {
169: ProjectQuery query = new ProjectQuery();
170: query.setQueryCustomer(((CustomerImpl) customer).getDO(),
171: QueryBuilder.EQUAL);
172:
173: ProjectDO[] foundProjects = query.getDOArray();
174: if (foundProjects.length != 0) {
175: ProjectImpl[] projs = new ProjectImpl[foundProjects.length];
176: for (int i = 0; i < foundProjects.length; i++) {
177: projs[i] = new ProjectImpl(foundProjects[i]);
178: }
179: return projs;
180: } else {
181: return null;
182: }
183: } catch (NonUniqueQueryException ex) {
184: Enhydra.getLogChannel().write(
185: Logger.DEBUG,
186: "Non-unique worksheet found in database: "
187: + ex.getMessage());
188: throw new ProjectManagementBusinessException(
189: "Non unique worksheet found");
190: } catch (DataObjectException ex) {
191: throw new ProjectManagementBusinessException(
192: "Database error retrieving projects: ", ex);
193: } catch (QueryException ex) {
194: throw new ProjectManagementBusinessException(
195: "Query exception retrieving projects: ", ex);
196: }
197: }
198:
199: public Project getProject()
200: throws ProjectManagementBusinessException {
201: return new ProjectImpl();
202: }
203:
204: }
|