1 package za.org.coefficient.modules.task; 2 3 import java.util.HashMap ; 4 import java.util.Vector ; 5 import java.util.List ; 6 7 import za.org.coefficient.authentication.CoefficientUser; 8 import za.org.coefficient.authentication.ProjectMember; 9 import za.org.coefficient.authentication.Role; 10 import za.org.coefficient.core.Constants; 11 import za.org.coefficient.core.Project; 12 import za.org.coefficient.interfaces.CoefficientContext; 13 import za.org.coefficient.modules.BaseProjectModule; 14 import za.org.coefficient.modules.project.ProjectConstants; 15 import za.org.coefficient.util.common.DateUtil; 16 import za.org.coefficient.util.common.HibernatePager; 17 import za.org.coefficient.util.common.MailUtil; 18 import net.sf.hibernate.util.HibernateUtil; 19 import za.org.coefficient.util.ejb.SecurityUtil; 20 import za.org.coefficient.util.ejb.VelocityScreenUtil; 21 22 import net.sf.hibernate.HibernateException; 23 import net.sf.hibernate.Hibernate; 24 import net.sf.hibernate.Session; 25 import net.sf.hibernate.type.Type; 26 27 44 public class Task extends BaseProjectModule { 45 46 static { 47 try { 48 HibernateUtil.configureHibernateForClass(TaskData.class); 49 } catch (HibernateException he) { 50 he.printStackTrace(); 51 } 52 } 53 54 public final static String TASKPAGER = "TASKPAGER"; 55 public final static String PAGER = "pager"; 56 59 public final static String ADD = "add"; 60 public final static String UPDATE = "update"; 61 public final static String DELETE = "delete"; 62 public final static String EDIT = "edit"; 63 public final static String COMPLETE = "complete"; 64 65 68 public final static String ERROR = "error"; 69 public final static String PROJECT = "project"; 70 public final static String MODULE = "module"; 71 public final static String TASKS = "tasks"; 72 public final static String TASK = "task"; 73 public final static String OP = "op"; 74 public final static String MEMBERS = "members"; 75 public final static String CHAMPION = "champion"; 76 public final static String EMAIL = "email"; 77 public final static String USER = "user"; 78 public final static String COMPLETED = "completed"; 79 public final static String DATEUTIL = "dateutil"; 80 81 84 public final static String BUTTON = "button"; 85 public final static String NAME = "name"; 86 public final static String PERSON = "person"; 87 public final static String DESCRIPTION = "description"; 88 public final static String HOURS = "hours"; 89 public final static String STATUS = "status"; 90 public final static String ID = "id"; 91 public final static String STARTDATE = "startdate"; 92 public final static String STARTYEAR = "startyear"; 93 public final static String STARTMONTH = "startmonth"; 94 public final static String STARTDAY = "startday"; 95 public final static String ENDYEAR = "endyear"; 96 public final static String ENDMONTH = "endmonth"; 97 public final static String ENDDAY = "endday"; 98 public final static String ENDDATE = "enddate"; 99 100 103 public final static String ERRORPAGE = "error.vm"; 104 public final static String ADMINPAGE = "admin.vm"; 105 public final static String SUMMARY_PAGE = "showSummaryForProject.vm"; 106 public final static String SUMMARY = "getSummaryForProject.vm"; 107 public final static String ADDMSG = "add.vm"; 108 public final static String COMPLETEDMSG = "completed.vm"; 109 110 public final static String FINISHED = "100%"; 111 112 115 public final static String NOPROJECT = "You do not have a project"; 116 public final static String ENTERFIELDS = 117 "You must enter a unique name and description"; 118 119 public String getModuleDisplayName () { 120 return "Task"; 121 } 122 123 public String getModuleDescription () { 124 return "task module"; 125 } 126 127 public String getMainMethod () { 128 return "doInitialWork"; 130 } 131 132 String commandRoles[] = { 137 SecurityUtil.SITE_ADMIN_ROLE_DESC, 138 SecurityUtil.PROJECT_CHAMPION_ROLE_DESC 139 }; 140 141 String memberRoles[] = { 145 SecurityUtil.SITE_ADMIN_ROLE_DESC, 146 SecurityUtil.PROJECT_CHAMPION_ROLE_DESC, 147 SecurityUtil.PROJECT_MEMBER_ROLE_DESC 148 }; 149 150 public String canExecuteForRole (CoefficientContext ctx, 151 String methodName, Role usersHighestRole){ 152 int i; 153 String role = usersHighestRole.getDescription(); 154 155 if ( methodName.equals("command") || methodName.equals("deleteAllForProject") ) { 156 for(i=0; i<commandRoles.length; i++) { 157 if (role.equals(commandRoles[i]) ) 158 return null; 159 } 160 return "not authorised"; 161 } 162 163 if ( methodName.equals("member") ) { 164 for(i=0; i<memberRoles.length; i++) { 165 if (role.equals(memberRoles[i]) ) 166 return null; 167 } 168 return "not authorised"; 169 } 170 171 return null; 172 } 173 174 177 public Long getIdForTaskName (CoefficientContext ctx) throws Exception { 178 Long retVal = new Long (-1); 179 String taskName = ctx.getParameter("taskName"); 180 if (taskName != null ) { 181 Object [] vals = new Object [] {ctx.getProject().getId(), 182 taskName}; 183 Type [] types = new Type [] {Hibernate.LONG, Hibernate.STRING}; 184 List tasks = HibernateUtil.find("select tasks.id from " 185 + TaskData.class.getName() 186 + " as tasks where " 187 + "tasks.projectId = ? and " 188 + " tasks.name = ?", 189 vals, types); 190 if (tasks.size() == 1) { 191 retVal = (Long )tasks.get(0); 192 } 193 } 194 return retVal; 195 } 196 197 public boolean isNameUnique (Project project, String name) { 198 if (name != null ) { 199 Object [] vals = new Object [] {project.getId(), 200 name}; 201 Type [] types = new Type [] {Hibernate.LONG, Hibernate.STRING}; 202 203 try { 204 List tasks = HibernateUtil.find("select tasks from " 205 + TaskData.class.getName() 206 + " as tasks where " 207 + "tasks.projectId = ? and " 208 + " tasks.name = ?", 209 vals, types); 210 return tasks.size() == 0; 211 } 212 catch ( Throwable t ) { 213 System.out.println("Hibernate exception " + t); 214 return false; 215 } 216 217 } 218 return false; 219 } 220 221 222 225 public boolean isTaskCompleted (CoefficientContext ctx) 226 throws HibernateException 227 { 228 Object [] vals = new Object [] {ctx.getProject().getId(), FINISHED, 229 ctx.getParameter("taskName")}; 230 Type [] types = new Type [] {Hibernate.LONG, Hibernate.STRING, 231 Hibernate.STRING}; 232 Session sess = HibernateUtil.getSession(); 233 Integer retVal = (Integer )sess.iterate("select count(tasks) from " 234 + TaskData.class.getName() 235 + " as tasks where " 236 + "tasks.projectId = ? and " 237 + "tasks.status = ? and tasks.name = ?", 238 vals, types).next(); 239 HibernateUtil.finalizeSession(); 242 return retVal.intValue() == 1; 243 } 244 245 248 public CoefficientContext deleteAllForProject (CoefficientContext ctx) { 249 Project project = ctx.getProject(); 250 if ( project != null ) { 251 List tasks = getExistingTasks(project); 252 int i; 253 for(i=0; i < tasks.size(); i++) { 254 try { 255 HibernateUtil.delete(tasks.get(i)); 256 } 257 catch ( Throwable t ) { 258 System.out.println("could not delete task " + 259 t); 260 } 261 262 } 263 } 264 return ctx; 265 } 266 267 268 271 private String baseCommand(CoefficientContext ctx) { 272 StringBuffer sb = new StringBuffer (); 273 Project project = ctx.getProject(); 274 HashMap map = new HashMap (); 275 map.put(MODULE, this); 276 if ( project != null ) { 277 return null; 278 } 279 else { 280 map.put(ERROR, NOPROJECT); 281 sb = 282 VelocityScreenUtil.getProcessedScreen(ERRORPAGE, map); 283 } 284 285 return sb.toString(); 286 } 287 288 private String getOp(CoefficientContext ctx) { 289 String role = SecurityUtil.getHighestRoleForUser( 290 ctx.getCurrentUser(), ctx.getProject()).getDescription(); 291 if ( role.equals(SecurityUtil.SITE_ADMIN_ROLE_DESC) || 292 role.equals(SecurityUtil.PROJECT_CHAMPION_ROLE_DESC ) ) { 293 return "command"; 294 } 295 else { 296 if ( role.equals( 297 SecurityUtil.PROJECT_MEMBER_ROLE_DESC) ) { 298 return "member"; 299 } 300 else { 301 return "list"; 302 } 303 } 304 } 305 306 public CoefficientContext doInitialWork (CoefficientContext ctx) { 307 308 Project project = ctx.getProject(); 309 HashMap map = new HashMap (); 310 StringBuffer sb = new StringBuffer ("Problem here"); 311 map.put(MODULE, this); 312 ctx.removeSessionAttribute(TASKPAGER); 313 ctx.setForward("task", getOp(ctx)); 314 return ctx; 315 } 316 317 public String getSummaryForProject(CoefficientContext ctx) 318 throws Exception { 319 Project project = ctx.getProject(); 320 HashMap map = new HashMap (); 321 StringBuffer sb = new StringBuffer (); 322 323 Session sess = HibernateUtil.getSession(); 324 325 Integer openTaskCnt = 327 (Integer )sess.iterate("select count(*) from " 328 + TaskData.class.getName() 329 + " as task where task.projectId = ? and task.completed = ?", 330 new Object []{project.getId(), new Boolean (false)}, 331 new Type[]{Hibernate.LONG, Hibernate.BOOLEAN}).next(); 332 Integer closedTaskCnt = 333 (Integer )sess.iterate("select count(*) from " 334 + TaskData.class.getName() 335 + " as task where task.projectId = ? and task.completed = ?", 336 new Object []{project.getId(), new Boolean (true)}, 337 new Type[]{Hibernate.LONG, Hibernate.BOOLEAN}).next(); 338 339 340 HibernateUtil.finalizeSession(); 343 map.put("openTaskCnt", openTaskCnt); 344 map.put("closedTaskCnt", closedTaskCnt); 345 map.put("projectName", ProjectConstants.PROJECT_NAME); 346 sb = VelocityScreenUtil.getProcessedScreen(SUMMARY, map); 347 return sb.toString(); 348 } 349 350 public CoefficientContext showSummaryForProject(CoefficientContext ctx) 351 throws Exception { 352 HashMap map = new HashMap (); 353 map.put("content", getSummaryForProject(ctx)); 354 StringBuffer sb = VelocityScreenUtil 355 .getProcessedScreen(SUMMARY_PAGE, map); 356 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 357 return ctx; 358 } 359 360 private List getExistingTasks(Project project) { 361 List list = null; 362 try { 363 list = 364 HibernateUtil.find("FROM " + 365 TaskData.class.getName() + 366 " as task " 367 + "WHERE task.projectId = ? " 368 + "ORDER BY task.id" , 369 project.getId(), Hibernate.LONG ); 370 } 371 catch ( Throwable t ) { 372 System.out.println("Hibernate session throws " + t); 373 } 374 return list; 375 } 376 377 private Long nextSequence(List tasks) { 378 if ( tasks.size() == 0 ) 379 return new Long (1); 380 381 int i; 382 Long max = new Long (0); 383 TaskData td; 384 for(i=0; i<tasks.size(); i++) { 385 td = (TaskData) tasks.get(i); 386 if ( max.compareTo(td.getSequence()) < 0 ) 387 max = td.getSequence(); 388 } 389 390 return new Long (max.intValue() + 1); 391 } 392 393 398 public synchronized CoefficientContext list (CoefficientContext ctx) { 399 String st; 400 401 st = baseCommand(ctx); 402 403 if ( st == null ) { 404 Project project = ctx.getProject(); 405 List tasks = getExistingTasks(project); 406 HashMap map = new HashMap (); 407 map.put(PROJECT, project); 409 map.put(OP, getOp(ctx) ); 410 HibernatePager hp = null; 411 hp = (HibernatePager)ctx.getSessionAttribute(TASKPAGER); 412 if ( hp == null ) 413 hp = initPager(ctx); 414 if ( ctx.getParameter("next") != null ) { 415 hp.next(); 416 } 417 if ( ctx.getParameter("page") != null ) { 418 hp.goToPage(ctx.getParameterAsInteger("page").intValue()); 419 } 420 if ( ctx.getParameter("previous") != null ) { 421 hp.previous(); 422 } 423 map.put(PAGER, hp); 424 StringBuffer sb; 425 sb = VelocityScreenUtil.getProcessedScreen( 426 ADMINPAGE, map); 427 st = sb.toString(); 428 } 429 ctx.setModuleContent(st, getModuleDisplayName()); 430 return ctx; 431 } 432 433 private String getEmailAddress(List members, String person) { 434 ProjectMember member; 435 CoefficientUser user; 436 int j; 437 for(j=0; j<members.size(); j++) { 438 member = (ProjectMember)(members.get(j)); 439 user = member.getCoefficientUser(); 440 if ( person.equals(user.getUserName()) ) { 441 return user.getEmail(); 442 } 443 } 444 445 return ""; 446 } 447 448 451 private void sendmail(CoefficientContext ctx, 452 TaskData task, List members, 453 String to, String option) { 454 455 String user = ctx.getCurrentUser().getUserName(); 456 String champion = ctx.getCurrentUser().getFullName(); 457 String toAddress = getEmailAddress(members, to); 458 String fromAddress = getEmailAddress(members, user); 459 HashMap map = new HashMap (); 460 String st = new String (); 461 StringBuffer sb; 462 if ( option.equals(ADD) || option.equals(UPDATE) ) { 463 map.put(PROJECT, ctx.getProject().getName()); 464 map.put(DESCRIPTION, task.getDescription()); 465 map.put(HOURS, task.getEstimatedHours()); 466 map.put(ENDDATE, task.getEstimatedEndDateAsString()); 467 map.put(CHAMPION, champion); 468 map.put(EMAIL, fromAddress); 469 map.put(USER, to); 470 sb = VelocityScreenUtil.getProcessedScreen( 471 ADDMSG, map); 472 st = sb.toString(); 473 MailUtil.sendEmail(st, 474 ctx.getProject().getName() + " task", 475 toAddress, fromAddress); 476 } 477 if ( option.equals(COMPLETED) ) { 478 map.put(TASK, task); 479 map.put(PROJECT, ctx.getProject().getName()); 480 sb = VelocityScreenUtil.getProcessedScreen( 481 COMPLETEDMSG, map); 482 st = sb.toString(); 483 MailUtil.sendEmail(st, 484 ctx.getProject().getName() + " task completed", 485 toAddress, fromAddress); 486 } 487 } 488 489 493 public synchronized CoefficientContext command (CoefficientContext ctx) { 494 String st; 495 496 st = baseCommand(ctx); 497 498 if ( st == null ) { 502 Project project = ctx.getProject(); 503 List tasks = getExistingTasks(project); 504 Vector members = new Vector (); 505 String button = ctx.getParameter(BUTTON, ""); 506 String id = ctx.getParameter(ID, ""); 507 String name = ctx.getParameter(NAME, ""); 508 String description = ctx.getParameter(DESCRIPTION, ""); 509 String status = ctx.getParameter(STATUS, ""); 510 String person = ctx.getParameter(PERSON, ""); 511 String estimatedHours = ctx.getParameter(HOURS, ""); 512 String startyear = ctx.getParameter(STARTYEAR, ""); 513 String startmonth = ctx.getParameter(STARTMONTH, ""); 514 String startday = ctx.getParameter(STARTDAY, ""); 515 String endyear = ctx.getParameter(ENDYEAR, ""); 516 String endmonth = ctx.getParameter(ENDMONTH, ""); 517 String endday = ctx.getParameter(ENDDAY, ""); 518 List membersList = project.getMembers(); 519 520 HibernatePager hp = null; 521 hp = (HibernatePager)ctx.getSessionAttribute(TASKPAGER); 522 if ( hp == null ) { 523 hp = initPager(ctx); 524 } 525 526 int j; 527 for(j=0; j<membersList.size(); j++) { 528 ProjectMember member = (ProjectMember)(membersList.get(j)); 529 CoefficientUser peUser = member.getCoefficientUser(); 530 members.addElement(peUser.getUserName()); 531 } 532 533 StringBuffer sb; 534 Long idLong = new Long (0); 535 try { 536 idLong = new Long (id); 537 } 538 catch ( Throwable t ) { 539 idLong = new Long (0); 540 } 541 542 HashMap map = new HashMap (); 543 map.put(MODULE, this); 544 map.put(PROJECT, project ); 545 map.put(MEMBERS, members); 546 map.put(OP, getOp(ctx)); 547 try { 548 map.put(DATEUTIL, DateUtil.class.newInstance()); 549 } 550 catch ( Throwable t ) { 551 System.out.println("DateUtil instantiation fails " + t); 552 } 553 if ( ctx.getParameter("next") != null ) { 554 hp.next(); 555 } 556 if ( ctx.getParameter("page") != null ) { 557 hp.goToPage(ctx.getParameterAsInteger("page").intValue()); 558 } 559 if ( ctx.getParameter("previous") != null ) { 560 hp.previous(); 561 } 562 if ( button.toLowerCase().equals(ADD) ) { 566 if ( !name.equals("") && !description.equals("") ) { 567 TaskData td = new TaskData(); 568 td.setProjectId(project.getId()); 569 td.setName(name); 570 td.setDescription(description); 571 td.setStatus(status); 572 td.setPerson(person); 573 td.setEstimatedHours(estimatedHours); 574 td.setSequence( nextSequence(tasks) ); 575 td.setStartDate(startyear, startmonth,startday); 576 td.setEstimatedEndDate(endyear, endmonth,endday); 577 578 if ( isNameUnique(project, name) ) { 579 try { 580 HibernateUtil.saveOrUpdate(td); 581 } 582 catch ( Throwable t ) { 583 System.out.println("********Hibernate throws " 584 + t); 585 } 586 sendmail(ctx, td, membersList, person, ADD); 590 hp = initPager(ctx); 594 hp.goToPage(hp.getMaxPageNumber()); 595 } 596 else 597 map.put(ERROR, ENTERFIELDS); 598 599 } 600 else 601 map.put(ERROR, ENTERFIELDS); 602 603 } 604 if ( button.toLowerCase().equals(EDIT) ) { 608 TaskData td; 609 int i; 610 boolean ticked = false; 611 for(i=0; i<tasks.size(); i++) { 612 td = (TaskData)(tasks.get(i)); 613 if ( idLong.equals(td.getId()) ) { 614 map.put(ID, "" + idLong); 615 ticked = true; 616 break; 617 } 618 } 619 int page = hp.getCurrentPageNumber(); 620 hp = initPager(ctx); 621 hp.goToPage(page); 622 if ( !ticked ) { 623 map.put(ERROR, 624 "You must tick a task to edit"); 625 } 626 } 627 628 if ( button.toLowerCase().equals(COMPLETE) ) { 629 TaskData td; 630 int i; 631 boolean ticked = false; 632 for(i=0; i<tasks.size(); i++) { 633 td = (TaskData)(tasks.get(i)); 634 if ( idLong.equals(td.getId()) ) { 635 ticked = true; 636 td.setStatus(FINISHED); 637 try { 638 HibernateUtil. 639 saveOrUpdate(td); 640 } 641 catch ( Throwable t ) { 642 System.out.println("Hibernate throws " 643 + t); 644 } 645 List champs = project.getChampionsAsUsers(); 650 CoefficientUser champ; 651 int k; 652 for(k=0; k<champs.size(); k++) { 653 champ = (CoefficientUser)(champs.get(k)); 654 sendmail(ctx, td, membersList, 655 champ.getUserName(), COMPLETED); 656 } 657 int page = hp.getCurrentPageNumber(); 658 hp = initPager(ctx); 659 hp.goToPage(page); 660 break; 661 } 662 } 663 if ( !ticked ) { 664 map.put(ERROR, 665 "You must tick a task to complete"); 666 } 667 } 668 if ( button.toLowerCase().equals(DELETE) ) { 672 TaskData td; 673 int i; 674 boolean ticked = false; 675 for(i=0; i<tasks.size(); i++) { 676 td = (TaskData)(tasks.get(i)); 677 if ( idLong.equals(td.getId()) ) { 678 ticked = true; 679 try { 680 HibernateUtil.delete(td); 681 } 682 catch ( Throwable t ) { 683 System.out.println( 684 "Hibernate throws " 685 + t); 686 } 687 tasks = getExistingTasks(project); 688 int page = hp.getCurrentPageNumber(); 689 hp = initPager(ctx); 690 hp.goToPage(page); 691 break; 692 } 693 } 694 if ( !ticked ) { 695 map.put(ERROR, 696 "You must tick a task to delete"); 697 } 698 } 699 if ( button.toLowerCase().equals(UPDATE) ) { 703 TaskData td; 704 int i; 705 for(i=0; i<tasks.size(); i++) { 706 td = (TaskData)(tasks.get(i)); 707 if ( idLong.equals(td.getId()) ) { 708 if ( !isNameUnique(project, name) || name.trim().equals("") || 709 description.trim().equals("") ) { 710 map.put(ERROR, ENTERFIELDS); 711 } 712 else { 713 boolean finished = 718 !td.getStatus().equals(FINISHED) && 719 status.equals(FINISHED); 720 boolean newperson = 725 !td.getPerson().trim().equals(person.trim()); 726 td.setName(name); 727 td.setPerson(person); 728 td.setDescription(description); 729 td.setStatus(status); 730 td.setEstimatedHours( 731 estimatedHours); 732 td.setStartDate(startyear, 733 startmonth, 734 startday); 735 td.setEstimatedEndDate(endyear, 736 endmonth,endday); 737 try { 738 HibernateUtil. 739 saveOrUpdate(td); 740 } 741 catch ( Throwable t ) { 742 System.out.println( 743 "Hibernate throws " 744 + t); 745 } 746 if ( newperson ) { 747 sendmail(ctx, td, membersList, 748 person, ADD); 749 } 750 if ( finished ) { 755 List champs = project.getChampionsAsUsers(); 756 CoefficientUser champ; 757 int k; 758 for(k=0; k<champs.size(); k++) { 759 champ = (CoefficientUser)(champs.get(k)); 760 sendmail(ctx, td, membersList, 761 champ.getUserName(), COMPLETED); 762 } 763 } 764 } 766 int page = hp.getCurrentPageNumber(); 767 hp = initPager(ctx); 768 hp.goToPage(page); 769 break; 770 } 771 } 772 } 773 map.put(TASKS, tasks); 774 map.put(PAGER, hp); 775 sb = VelocityScreenUtil.getProcessedScreen(ADMINPAGE, map); 776 st = sb.toString(); 777 } 778 ctx.setModuleContent(st, getModuleDisplayName()); 779 return ctx; 780 } 781 782 private HibernatePager initPager(CoefficientContext ctx) { 783 HibernatePager hp = null; 784 try { 785 HashMap searchParams = new HashMap (); 786 searchParams.put("projectId", ctx.getProject().getId()); 787 hp = new HibernatePager(TaskData.class, "id", 788 Constants.MAX_ELEMENTS_PER_PAGE, 789 searchParams); 790 ctx.setSessionAttribute(TASKPAGER, hp); 791 792 } 793 catch ( Throwable t ) { 794 System.out.println("task.initPager throws " + t); 795 } 796 return hp; 797 } 798 799 private HibernatePager initPagerSamePage(CoefficientContext ctx) { 800 return null; 801 } 802 803 807 public synchronized CoefficientContext member (CoefficientContext ctx) { 808 String st; 809 810 st = baseCommand(ctx); 811 812 if ( st == null ) { 813 Project project = ctx.getProject(); 814 List tasks = getExistingTasks(project); 815 Vector members = new Vector (); 816 String button = ctx.getParameter(BUTTON, ""); 817 String id = ctx.getParameter(ID, ""); 818 String name = ctx.getParameter(NAME, ""); 819 String description = ctx.getParameter(DESCRIPTION, ""); 820 String status = ctx.getParameter(STATUS, ""); 821 String person = ctx.getParameter(PERSON, ""); 822 String estimatedHours = ctx.getParameter(HOURS, ""); 823 String startyear = ctx.getParameter(STARTYEAR, ""); 824 String startmonth = ctx.getParameter(STARTMONTH, ""); 825 String startday = ctx.getParameter(STARTDAY, ""); 826 String endyear = ctx.getParameter(ENDYEAR, ""); 827 String endmonth = ctx.getParameter(ENDMONTH, ""); 828 String endday = ctx.getParameter(ENDDAY, ""); 829 List membersList = project.getMembers(); 830 831 HibernatePager hp = null; 832 hp = (HibernatePager)ctx.getSessionAttribute(TASKPAGER); 833 if ( hp == null ) 834 hp = initPager(ctx); 835 836 837 int j; 838 for(j=0; j<membersList.size(); j++) { 839 ProjectMember member = (ProjectMember)(membersList.get(j)); 840 CoefficientUser user = member.getCoefficientUser(); 841 members.addElement(user.getUserName()); 842 } 843 844 StringBuffer sb; 845 Long idLong = new Long (0); 846 try { 847 idLong = new Long (id); 848 } 849 catch ( Throwable t ) { 850 idLong = new Long (0); 851 } 852 853 HashMap map = new HashMap (); 854 map.put(MODULE, this); 855 map.put(PROJECT, project ); 856 map.put(MEMBERS, members); 857 try { 858 map.put(PERSON, ctx.getCurrentUser().getUserName()); 859 } 860 catch ( Throwable t ) { 861 map.put(PERSON, "guest"); 862 } 863 map.put(OP, getOp(ctx)); 864 if ( ctx.getParameter("next") != null ) { 865 hp.next(); 866 } 867 if ( ctx.getParameter("page") != null ) { 868 hp.goToPage(ctx.getParameterAsInteger("page").intValue()); 869 } 870 if ( ctx.getParameter("previous") != null ) { 871 hp.previous(); 872 } 873 if ( button.toLowerCase().equals(EDIT) ) { 874 TaskData td; 875 int i; 876 boolean ticked = false; 877 for(i=0; i<tasks.size(); i++) { 878 td = (TaskData)(tasks.get(i)); 879 if ( idLong.equals(td.getId()) ) { 880 map.put(ID, "" + idLong); 881 ticked = true; 882 int page = hp.getCurrentPageNumber(); 883 hp = initPager(ctx); 884 hp.goToPage(page); 885 break; 886 } 887 } 888 if ( !ticked ) { 889 map.put(ERROR, 890 "You must tick a task to edit"); 891 } 892 } 893 894 if ( button.toLowerCase().equals(COMPLETE) ) { 895 TaskData td; 896 int i; 897 boolean ticked = false; 898 for(i=0; i<tasks.size(); i++) { 899 td = (TaskData)(tasks.get(i)); 900 if ( idLong.equals(td.getId()) ) { 901 ticked = true; 902 td.setStatus(FINISHED); 903 try { 904 HibernateUtil. 905 saveOrUpdate(td); 906 } 907 catch ( Throwable t ) { 908 System.out.println("Hibernate throws " 909 + t); 910 } 911 int page = hp.getCurrentPageNumber(); 912 hp = initPager(ctx); 913 hp.goToPage(page); 914 List champs = project.getChampionsAsUsers(); 919 CoefficientUser champ; 920 int k; 921 for(k=0; k<champs.size(); k++) { 922 champ = (CoefficientUser)(champs.get(k)); 923 sendmail(ctx, td, membersList, 924 champ.getUserName(), COMPLETED); 925 } 926 break; 927 } 928 else 929 System.out.println("not equals"); 930 } 931 if ( !ticked ) { 932 map.put(ERROR, 933 "You must tick a task to complete"); 934 } 935 } 936 937 if ( button.toLowerCase().equals(UPDATE) ) { 938 TaskData td; 939 int i; 940 for(i=0; i<tasks.size(); i++) { 941 td = (TaskData)(tasks.get(i)); 942 if ( idLong.equals(td.getId()) ) { 943 boolean finished = 948 !td.getStatus().equals(FINISHED) && 949 status.equals(FINISHED); 950 boolean newperson = 955 !td.getPerson().trim().equals(person.trim()); 956 td.setStatus(status); 957 td.setEstimatedHours(estimatedHours); 958 td.setEstimatedEndDate(endyear, 959 endmonth,endday); 960 try { 961 HibernateUtil. 962 saveOrUpdate(td); 963 } 964 catch ( Throwable t ) { 965 System.out.println("Hibernate throws " 966 + t); 967 } 968 int page = hp.getCurrentPageNumber(); 969 hp = initPager(ctx); 970 hp.goToPage(page); 971 if ( finished ) { 976 List champs = project.getChampionsAsUsers(); 977 CoefficientUser champ; 978 int k; 979 for(k=0; k<champs.size(); k++) { 980 champ = (CoefficientUser)(champs.get(k)); 981 sendmail(ctx, td, membersList, 982 champ.getUserName(), COMPLETED); 983 } 984 } 985 if ( newperson ) { 986 sendmail(ctx, td, membersList, 987 person, ADD); 988 } 989 tasks = getExistingTasks(project); 990 break; 991 } 992 else 993 System.out.println("not equals"); 994 } 995 } 996 map.put(TASKS, tasks ); 997 map.put(PAGER, hp); 998 sb = VelocityScreenUtil.getProcessedScreen(ADMINPAGE, map); 999 st = sb.toString(); 1000 } 1001 ctx.setModuleContent(st, getModuleDisplayName()); 1002 return ctx; 1003 } 1004 1005 public final long defSpread = 60 * 60 * 24 * 7 * 1000; 1006 1007 public String getFinishDay() { 1008 return DateUtil.getDay( DateUtil.getFutureDate(defSpread) ); 1009 } 1010 1011 public String getFinishMonth() { 1012 return DateUtil.getMonth( DateUtil.getFutureDate(defSpread) ); 1013 } 1014 1015 public String getFinishYear() { 1016 return DateUtil.getYear( DateUtil.getFutureDate(defSpread) ); 1017 } 1018 1019} 1020 | Popular Tags |