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 23 public class ProjectManagerImpl implements ProjectManager { 24 25 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 } 57 } 58 59 72 public Project findProjectByID(String id) 73 throws ProjectManagementBusinessException { 74 ProjectImpl theProject = null; 75 76 try { 77 ProjectQuery query = new ProjectQuery(); 78 query.setQueryOId(new ObjectId(id)); 80 query.requireUniqueInstance(); 82 ProjectDO theProjectDO = query.getNextDO(); 83 theProject = new ProjectImpl(theProjectDO); 84 return theProject; 85 } catch(Exception ex) { 86 throw new ProjectManagementBusinessException("Exception in findProjectByID()", ex); 87 } 88 } 89 90 103 public Project[] getAllProjectsForCustomer(String 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 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 |