1 7 8 package projectmanagement.presentation.worksheets; 9 10 import projectmanagement.spec.employee.*; 11 import projectmanagement.spec.project.*; 12 import projectmanagement.presentation.*; 13 14 import org.w3c.dom.*; 15 import org.w3c.dom.html.*; 16 17 import com.lutris.appserver.server.httpPresentation.HttpPresentation; 19 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 20 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 21 import org.enhydra.xml.xmlc.XMLObject; 22 23 import java.io.IOException ; 25 import java.util.Calendar ; 26 27 30 public class Search extends BasePO { 31 32 private static String EMPLOYEE = "employee"; 33 private static String PROJECT = "project"; 34 private static String FROMYEAR = "fromyear"; 35 private static String FROMMONTH = "frommonth"; 36 private static String FROMDAY = "fromday"; 37 private static String TOYEAR = "toyear"; 38 private static String TOMONTH = "tomonth"; 39 private static String TODAY = "today"; 40 41 private static String IS_PERSONAL = "isPersonal"; 42 43 46 protected int getRequiredAuthLevel() { 47 String isPersonal=""; 48 try { 49 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 50 } catch (Exception ex) {} 51 52 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 53 return 1; 54 } else { 55 return 2; 56 } 57 } 58 59 62 public XMLObject handleDefault() 63 throws HttpPresentationException { 64 SearchHTML page=new SearchHTML(); 65 66 String employee = this.getComms().request.getParameter(EMPLOYEE); 67 HTMLSelectElement sel=page.getElementCboEmployee(); 68 69 70 fillEmployeeSelection(page,sel,employee); 71 72 String project = this.getComms().request.getParameter(PROJECT); 73 sel=page.getElementCboProject(); 74 fillProjectSelection(page,sel,project); 75 76 fillFromDays(page); 77 fillFromMonths(page); 78 fillFromYears(page); 79 80 fillToDays(page); 81 fillToMonths(page); 82 fillToYears(page); 83 84 85 return page; 86 } 87 88 private void fillEmployeeSelection (SearchHTML page,HTMLSelectElement cboEmployees, 89 String selectedEmployeeID) throws ProjectManagementPresentationException { 90 HTMLOptionElement optEmployee = page.getElementOptEmployee(); 91 try { 92 EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl"); 93 Employee[] employees=employeeManager.getAllEmployees(); 94 95 optEmployee.removeChild(optEmployee.getFirstChild()); 97 98 String isPersonal=""; 99 100 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 101 102 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 103 try { 104 selectedEmployeeID=getUser().getHandle(); 105 } catch (Exception ex) {} 106 } 107 108 109 HTMLOptionElement clonedOption=null; 111 Node optionTextNode=null; 112 if (isPersonal==null || !isPersonal.equalsIgnoreCase("true")) { 113 clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true); 114 clonedOption.setValue(""); 115 String all="All"; 116 optionTextNode = clonedOption.getOwnerDocument(). 117 createTextNode(all); 118 clonedOption.appendChild(optionTextNode); 119 clonedOption.setAttribute("selected","selected"); 120 cboEmployees.appendChild(clonedOption); 123 } 124 125 127 if (employees!=null) { 128 for (int i=0; i<employees.length; i++) { 129 Employee e=employees[i]; 130 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true") && 132 !e.getHandle().equals(selectedEmployeeID)) { 133 continue; 134 } 135 136 clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true); 144 clonedOption.setValue(e.getHandle()); 145 optionTextNode = clonedOption.getOwnerDocument(). 146 createTextNode(e.getFirstName()+" "+e.getLastName()); 147 clonedOption.appendChild(optionTextNode); 148 if (selectedEmployeeID!=null && e.getHandle().equals(selectedEmployeeID)) { 149 clonedOption.setAttribute("selected","selected"); 150 } 151 cboEmployees.appendChild(clonedOption); 154 } 155 } 156 if ( this.getComms().request.getParameter("checkFromDate") != null && this.getComms().request.getParameter("checkFromDate").equals("false") ) { 157 ( (HTMLElement)page.getElementColorFrom() ).setAttribute("color","red"); 158 } 159 if ( this.getComms().request.getParameter("checkToDate") != null && this.getComms().request.getParameter("checkToDate").equals("false") ) { 160 ( (HTMLElement)page.getElementColorTo() ).setAttribute("color","red"); 161 } 162 } catch(NullPointerException ex) { 163 } catch (Exception ex) { 164 this.writeDebugMsg("Error populating list of employees: " + ex); 165 throw new ProjectManagementPresentationException("Error populating employee list: ", ex); 166 } 167 168 cboEmployees.removeChild(optEmployee); 169 } 170 171 private void fillProjectSelection (SearchHTML page,HTMLSelectElement cboProjects, 172 String selectedProjectID) throws ProjectManagementPresentationException { 173 HTMLOptionElement optProject = page.getElementOptProject(); 174 try { 175 Project[] projects=null; 176 ProjectManager projectManager = ProjectManagerFactory.getProjectManager("projectmanagement.business.project.ProjectManagerImpl"); 177 178 optProject.removeChild(optProject.getFirstChild()); 180 181 String isPersonal=""; 182 183 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 184 185 186 187 HTMLOptionElement clonedOption = (HTMLOptionElement)optProject.cloneNode(true); 189 clonedOption.setValue(""); 190 String all="All"; 191 Node optionTextNode = clonedOption.getOwnerDocument(). 192 createTextNode(all); 193 clonedOption.appendChild(optionTextNode); 194 clonedOption.setAttribute("selected","selected"); 195 cboProjects.appendChild(clonedOption); 198 199 201 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 202 projects=projectManager.getAllProjects(); 204 } else { 205 projects=projectManager.getAllProjects(); 206 } 207 if (projects!=null) { 208 for (int i=0; i<projects.length; i++) { 209 Project p=projects[i]; 210 clonedOption = (HTMLOptionElement)optProject.cloneNode(true); 218 clonedOption.setValue(p.getHandle()); 219 optionTextNode = clonedOption.getOwnerDocument(). 220 createTextNode(p.getName()); 221 clonedOption.appendChild(optionTextNode); 222 if (selectedProjectID!=null && p.getHandle().equals(selectedProjectID)) { 223 clonedOption.setAttribute("selected","selected"); 224 } 225 cboProjects.appendChild(clonedOption); 228 } 229 } 230 cboProjects.removeChild(optProject); 231 } catch(NullPointerException ex) { 232 } catch (Exception ex) { 233 ex.printStackTrace(); 234 this.writeDebugMsg("Error populating list of projects: " + ex); 235 throw new ProjectManagementPresentationException("Error populating project list: ", ex); 236 } 237 238 239 } 240 241 private void fillFromDays(SearchHTML page) 242 throws ProjectManagementPresentationException { 243 HTMLSelectElement cboFromDay=page.getElementCboFromDay(); 244 HTMLOptionElement optFromDay = page.getElementOptFromDay(); 245 optFromDay.removeChild(optFromDay.getFirstChild()); 247 try { 248 HTMLOptionElement clonedOption = (HTMLOptionElement)optFromDay.cloneNode(true); 250 Node optionTextNode; 251 259 260 for (int i=1; i<=31; i++) { 261 clonedOption = (HTMLOptionElement)optFromDay.cloneNode(true); 269 String curDay=String.valueOf(i); 270 clonedOption.setValue(curDay); 271 optionTextNode = clonedOption.getOwnerDocument(). 272 createTextNode(curDay); 273 clonedOption.appendChild(optionTextNode); 274 if ( i==Calendar.getInstance().get(Calendar.DAY_OF_MONTH) ) { 275 clonedOption.setAttribute("selected","selected"); 276 } 277 278 cboFromDay.appendChild(clonedOption); 281 282 } 283 cboFromDay.removeChild(optFromDay); 284 } catch(NullPointerException ex) { 285 } catch (Exception ex) { 286 this.writeDebugMsg("Error populating list of days: " + ex); 287 throw new ProjectManagementPresentationException("Error populating day list: ", ex); 288 } 289 290 291 } 292 293 private void fillFromMonths(SearchHTML page) 294 throws ProjectManagementPresentationException { 295 HTMLSelectElement cboFromMonth=page.getElementCboFromMonth(); 296 HTMLOptionElement optFromMonth = page.getElementOptFromMonth(); 297 optFromMonth.removeChild(optFromMonth.getFirstChild()); 299 try { 300 301 HTMLOptionElement clonedOption = (HTMLOptionElement)optFromMonth.cloneNode(true); 303 Node optionTextNode; 304 312 313 for (int i=1; i<=12; i++) { 314 clonedOption = (HTMLOptionElement)optFromMonth.cloneNode(true); 322 String curMonth=String.valueOf(i); 323 clonedOption.setValue(curMonth); 324 optionTextNode = clonedOption.getOwnerDocument(). 325 createTextNode(curMonth); 326 clonedOption.appendChild(optionTextNode); 327 if( i==Calendar.getInstance().get(Calendar.MONTH)+1 ) { 328 clonedOption.setAttribute("selected","selected"); 329 } 330 331 cboFromMonth.appendChild(clonedOption); 334 } 335 cboFromMonth.removeChild(optFromMonth); 336 } catch(NullPointerException ex) { 337 } catch (Exception ex) { 338 this.writeDebugMsg("Error populating list of months: " + ex); 339 throw new ProjectManagementPresentationException("Error populating month list: ", ex); 340 } 341 } 342 343 private void fillFromYears(SearchHTML page) 344 throws ProjectManagementPresentationException { 345 HTMLSelectElement cboFromYear=page.getElementCboFromYear(); 346 HTMLOptionElement optFromYear = page.getElementOptFromYear(); 347 optFromYear.removeChild(optFromYear.getFirstChild()); 349 try { 350 HTMLOptionElement clonedOption = (HTMLOptionElement)optFromYear.cloneNode(true); 352 Node optionTextNode; 353 361 362 for (int i=1998; i<=2008; i++) { 363 clonedOption = (HTMLOptionElement)optFromYear.cloneNode(true); 371 String curYear=String.valueOf(i); 372 clonedOption.setValue(curYear); 373 optionTextNode = clonedOption.getOwnerDocument(). 374 createTextNode(curYear); 375 clonedOption.appendChild(optionTextNode); 376 if( i==Calendar.getInstance().get(Calendar.YEAR) ) { 377 clonedOption.setAttribute("selected","selected"); 378 } 379 380 cboFromYear.appendChild(clonedOption); 383 } 384 cboFromYear.removeChild(optFromYear); 385 386 } catch(NullPointerException ex) { 387 } catch (Exception ex) { 388 this.writeDebugMsg("Error populating list of years: " + ex); 389 throw new ProjectManagementPresentationException("Error populating year list: ", ex); 390 } 391 392 393 } 394 395 396 private void fillToDays(SearchHTML page) 397 throws ProjectManagementPresentationException { 398 HTMLSelectElement cboToDay=page.getElementCboToDay(); 399 HTMLOptionElement optToDay = page.getElementOptToDay(); 400 optToDay.removeChild(optToDay.getFirstChild()); 402 try { 403 HTMLOptionElement clonedOption = (HTMLOptionElement)optToDay.cloneNode(true); 405 Node optionTextNode; 406 414 415 for (int i=1; i<=31; i++) { 416 clonedOption = (HTMLOptionElement)optToDay.cloneNode(true); 424 String curDay=String.valueOf(i); 425 clonedOption.setValue(curDay); 426 optionTextNode = clonedOption.getOwnerDocument(). 427 createTextNode(curDay); 428 clonedOption.appendChild(optionTextNode); 429 if( i==Calendar.getInstance().get(Calendar.DAY_OF_MONTH) ) { 430 clonedOption.setAttribute("selected","selected"); 431 } 432 433 cboToDay.appendChild(clonedOption); 436 } 437 cboToDay.removeChild(optToDay); 438 } catch(NullPointerException ex) { 439 } catch (Exception ex) { 440 this.writeDebugMsg("Error populating list of days: " + ex); 441 throw new ProjectManagementPresentationException("Error populating day list: ", ex); 442 } 443 444 445 } 446 447 private void fillToMonths(SearchHTML page) 448 throws ProjectManagementPresentationException { 449 HTMLSelectElement cboToMonth=page.getElementCboToMonth(); 450 HTMLOptionElement optToMonth = page.getElementOptToMonth(); 451 optToMonth.removeChild(optToMonth.getFirstChild()); 453 try { 454 HTMLOptionElement clonedOption = (HTMLOptionElement)optToMonth.cloneNode(true); 456 Node optionTextNode; 457 465 466 for (int i=1; i<=12; i++) { 467 clonedOption = (HTMLOptionElement)optToMonth.cloneNode(true); 475 String curMonth=String.valueOf(i); 476 clonedOption.setValue(curMonth); 477 optionTextNode = clonedOption.getOwnerDocument(). 478 createTextNode(curMonth); 479 clonedOption.appendChild(optionTextNode); 480 if( i==Calendar.getInstance().get(Calendar.MONTH)+1 ) { 481 clonedOption.setAttribute("selected","selected"); 482 } 483 cboToMonth.appendChild(clonedOption); 486 } 487 cboToMonth.removeChild(optToMonth); 488 } catch(NullPointerException ex) { 489 } catch (Exception ex) { 490 this.writeDebugMsg("Error populating list of months: " + ex); 491 throw new ProjectManagementPresentationException("Error populating month list: ", ex); 492 } 493 494 495 } 496 497 private void fillToYears(SearchHTML page) 498 throws ProjectManagementPresentationException { 499 HTMLSelectElement cboToYear=page.getElementCboToYear(); 500 HTMLOptionElement optToYear = page.getElementOptToYear(); 501 optToYear.removeChild(optToYear.getFirstChild()); 503 try { 504 HTMLOptionElement clonedOption = (HTMLOptionElement)optToYear.cloneNode(true); 506 Node optionTextNode; 507 515 516 for (int i=1998; i<=2008; i++) { 517 clonedOption = (HTMLOptionElement)optToYear.cloneNode(true); 525 String curYear=String.valueOf(i); 526 clonedOption.setValue(curYear); 527 optionTextNode = clonedOption.getOwnerDocument(). 528 createTextNode(curYear); 529 clonedOption.appendChild(optionTextNode); 530 if ( i==Calendar.getInstance().get(Calendar.YEAR) ) { 531 clonedOption.setAttribute("selected","selected"); 532 } 533 cboToYear.appendChild(clonedOption); 536 } 537 cboToYear.removeChild(optToYear); 538 } catch(NullPointerException ex) { 539 } catch (Exception ex) { 540 this.writeDebugMsg("Error populating list of years: " + ex); 541 throw new ProjectManagementPresentationException("Error populating year list: ", ex); 542 } 543 544 545 } 546 547 548 } | Popular Tags |