1 21 22 package org.opensubsystems.patterns.listdata.www; 23 24 import java.io.IOException ; 25 import java.sql.Timestamp ; 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.StringTokenizer ; 31 import java.util.logging.Level ; 32 import java.util.logging.Logger ; 33 34 import javax.servlet.ServletConfig ; 35 import javax.servlet.ServletException ; 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpServletResponse ; 38 39 import org.opensubsystems.core.data.DataConstant; 40 import org.opensubsystems.core.data.DataObject; 41 import org.opensubsystems.core.error.OSSException; 42 import org.opensubsystems.core.logic.ControllerManager; 43 import org.opensubsystems.core.util.DateUtils; 44 import org.opensubsystems.core.util.GlobalConstants; 45 import org.opensubsystems.core.util.Log; 46 import org.opensubsystems.core.util.StringUtils; 47 import org.opensubsystems.core.www.WebUIServlet; 48 import org.opensubsystems.core.www.WebUtils; 49 import org.opensubsystems.patterns.listdata.data.DataCondition; 50 import org.opensubsystems.patterns.listdata.data.ListDefinition; 51 import org.opensubsystems.patterns.listdata.data.ListOptions; 52 import org.opensubsystems.patterns.listdata.data.SimpleRule; 53 import org.opensubsystems.patterns.listdata.logic.ListController; 54 55 66 public class ListBrowserServlet extends WebUIServlet 67 { 68 70 73 public static final String LISTBROWSER_LIST_MAIN_PAGE 74 = "oss.listbrowser.list.page"; 75 76 79 public static final String LISTBROWSER_DATA_FACTORY_CLASS_NAME 80 = "oss.listbrowser.datafactory.classname"; 81 82 84 87 public static final String LISTBROWSER_ITEM_ID_EXTENTION_SEPARATOR = "_"; 88 89 92 public static final String PARAMETER_DATA_OBJECT_LIST_NAME = "listdata"; 93 94 97 public static final String PARAMETER_GENERIC_DATA_LIST_NAME 98 = "listdefinitiondata"; 99 100 103 public static final String PARAMETER_LIST_OPTIONS_NAME = "listoptions"; 104 105 108 public static final String PARAMETER_EXTRA_CONDITION_NAME = "extracondition"; 109 110 112 115 public static final String ACTION_SHOW_LIST_NAME = "show"; 116 117 120 public static final String ACTION_SET_FILTER_NAME = "filter"; 121 122 125 public static final String ACTION_SET_ORDER_NAME = "order"; 126 127 130 public static final String ACTION_PAGE_SIZE_NAME = "pagesize"; 131 132 135 public static final String ACTION_PREV_PAGE_NAME = "previous"; 136 137 140 public static final String ACTION_NEXT_PAGE_NAME = "next"; 141 142 145 public static final String ACTION_GO_TO_PAGE_NAME = "goto"; 146 147 149 152 public static final int ACTION_SHOW_LIST_ID = FORM_COUNT_WEBUI + 1; 153 154 157 public static final int ACTION_SET_FILTER_ID = FORM_COUNT_WEBUI + 2; 158 159 162 public static final int ACTION_SET_ORDER_ID = FORM_COUNT_WEBUI + 3; 163 164 167 public static final int ACTION_PAGE_SIZE_ID = FORM_COUNT_WEBUI + 4; 168 169 172 public static final int ACTION_PREV_PAGE_ID = FORM_COUNT_WEBUI + 5; 173 174 177 public static final int ACTION_NEXT_PAGE_ID = FORM_COUNT_WEBUI + 6; 178 179 182 public static final int ACTION_GO_TO_PAGE_ID = FORM_COUNT_WEBUI + 7; 183 184 187 public static final int FORM_COUNT_LISTBROWSER = FORM_COUNT_WEBUI + 8; 188 189 191 194 public static final String LIST_PARAM_LIST_FILTER_ID = "LIST_FILTER_ID"; 195 196 199 public static final String LIST_PARAM_LIST_PAGE_SIZE = "LIST_PAGE_SIZE"; 200 201 204 public static final String LIST_PARAM_ORDER_CODE = "ORDER_CODE"; 205 206 209 public static final String LIST_PARAM_ORDER_TYPE = "ORDER_TYPE"; 210 211 215 public static final String LIST_PARAM_CLIENT_ORDER_CODE = "CLIENT_ORDER_CODE"; 216 217 221 public static final String LIST_PARAM_CLIENT_ORDER_TYPE = "CLIENT_ORDER_TYPE"; 222 223 226 public static final String LIST_PARAM_BEGIN_POSITION = "BEGIN_POSITION"; 227 228 231 public static final String LIST_PARAM_END_POSITION = "END_POSITION"; 232 233 236 public static final String LIST_PARAM_ACTUAL_PAGE = "ACTUAL_PAGE"; 237 238 242 public static final String LIST_PARAM_SHOW_COLUMN_CODES = "SHOW_COLUMN_CODES"; 243 244 249 public static final String LIST_PARAM_FIRST_VISIBLE_ITEM 250 = "FIRST_VISIBLE_ITEM"; 251 252 255 public static final String LIST_PARAM_SELECTED_ITEMS = "SELECTED_ITEMS"; 256 257 260 public static final String LIST_PARAM_MARKED_ITEMS = "MARKED_ITEMS"; 261 262 265 public static final String LIST_PARAM_IGNORED_ITEMS = "IGNORED_ITEMS"; 266 267 271 public static final String LIST_PARAM_LIST_PARENT_DATA_TYPE 272 = "LIST_PARENT_DATA_TYPE"; 273 274 278 public static final String LIST_PARAM_LIST_PARENT_IDENTIFIER 279 = "LIST_PARENT_IDENTIFIER"; 280 281 285 public static final String LIST_PARAM_KEEP_SELECTED = "KEEP_SELECTED"; 286 287 290 public static final String LIST_PARAM_LIST_DOMAIN_ID = "LIST_DOMAIN_ID"; 291 292 296 public static final String LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE 297 = "EXTRA_CONDITION_ATTRIBUTE"; 298 299 303 public static final String LIST_PARAM_EXTRA_CONDITION_OPERAND 304 = "EXTRA_CONDITION_OPERAND"; 305 306 310 public static final String LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE 311 = "EXTRA_CONDITION_VALUE_TYPE"; 312 313 317 public static final String LIST_PARAM_EXTRA_CONDITION_VALUE 318 = "EXTRA_CONDITION_VALUE"; 319 320 322 325 private static Logger s_logger = Log.getInstance(ListBrowserServlet.class); 326 327 329 332 private static final long serialVersionUID = -5132755699822556778L; 333 334 337 protected String m_strFactoryClassName; 338 339 342 protected Class m_clsFactory; 343 344 346 349 public void init( 350 ServletConfig scConfig 351 ) throws ServletException 352 { 353 super.init(scConfig); 354 355 cacheUIPath(scConfig, LISTBROWSER_LIST_MAIN_PAGE, 357 "Path to main list page is not set in property " 358 + LISTBROWSER_LIST_MAIN_PAGE); 359 360 m_strFactoryClassName = WebUtils.readProperty(scConfig, 361 LISTBROWSER_DATA_FACTORY_CLASS_NAME, 362 null, false); 363 s_logger.config(LISTBROWSER_DATA_FACTORY_CLASS_NAME + " = " 364 + m_strFactoryClassName); 365 if (m_strFactoryClassName == null) 366 { 367 throw new ServletException ("Name of list data factory is not specified in property " 368 + LISTBROWSER_DATA_FACTORY_CLASS_NAME); 369 } 370 try 371 { 372 m_clsFactory = Class.forName(m_strFactoryClassName); 373 } 374 catch (ClassNotFoundException cnfExc) 375 { 376 throw new ServletException ("Cannot create class " + m_strFactoryClassName, 377 cnfExc); 378 } 379 } 380 381 384 public String getServletInfo( 385 ) 386 { 387 return this.getClass().getName(); 388 } 389 390 392 395 protected void doGet( 396 HttpServletRequest hsrqRequest, 397 HttpServletResponse hsrpResponse 398 ) throws ServletException , 399 IOException 400 { 401 switch (getFormToProcess(hsrqRequest)) 402 { 403 case ACTION_SHOW_LIST_ID : 404 { 405 processShowList(hsrqRequest, hsrpResponse); 406 break; 407 } 408 case ACTION_SET_FILTER_ID : 409 { 410 processSetListFilter(hsrqRequest, hsrpResponse); 411 break; 412 } 413 case ACTION_SET_ORDER_ID : 414 { 415 processSetOrder(hsrqRequest, hsrpResponse); 416 break; 417 } 418 case ACTION_PAGE_SIZE_ID : 419 { 420 processSetPageSize(hsrqRequest, hsrpResponse); 421 break; 422 } 423 case ACTION_PREV_PAGE_ID : 424 { 425 processSetPrevPage(hsrqRequest, hsrpResponse); 426 break; 427 } 428 case ACTION_NEXT_PAGE_ID : 429 { 430 processSetNextPage(hsrqRequest, hsrpResponse); 431 break; 432 } 433 case ACTION_GO_TO_PAGE_ID : 434 { 435 processSetExactPage(hsrqRequest, hsrpResponse); 436 break; 437 } 438 default : 439 { 440 super.doGet(hsrqRequest, hsrpResponse); 441 break; 442 } 443 } 444 } 445 446 449 protected void doPost( 450 HttpServletRequest hsrqRequest, 451 HttpServletResponse hsrpResponse 452 ) throws ServletException , 453 IOException 454 { 455 switch (getFormToProcess(hsrqRequest)) 456 { 457 case ACTION_SHOW_LIST_ID : 458 { 459 processShowList(hsrqRequest, hsrpResponse); 460 break; 461 } 462 case ACTION_SET_FILTER_ID : 463 { 464 processSetListFilter(hsrqRequest, hsrpResponse); 465 break; 466 } 467 case ACTION_SET_ORDER_ID : 468 { 469 processSetOrder(hsrqRequest, hsrpResponse); 470 break; 471 } 472 case ACTION_PAGE_SIZE_ID : 473 { 474 processSetPageSize(hsrqRequest, hsrpResponse); 475 break; 476 } 477 case ACTION_PREV_PAGE_ID : 478 { 479 processSetPrevPage(hsrqRequest, hsrpResponse); 480 break; 481 } 482 case ACTION_NEXT_PAGE_ID : 483 { 484 processSetNextPage(hsrqRequest, hsrpResponse); 485 break; 486 } 487 case ACTION_GO_TO_PAGE_ID : 488 { 489 processSetExactPage(hsrqRequest, hsrpResponse); 490 break; 491 } 492 default : 493 { 494 super.doPost(hsrqRequest, hsrpResponse); 495 break; 496 } 497 } 498 } 499 500 508 protected void processShowList( 509 HttpServletRequest hsrqRequest, 510 HttpServletResponse hsrpResponse 511 ) throws IOException , 512 ServletException 513 { 514 s_logger.entering("ListBrowserServlet", "processShowList"); 515 try 516 { 517 Object [] listInfo = getListController().getShowList( 518 parseListFromRequest(hsrqRequest, 519 ACTION_SHOW_LIST_ID)); 520 521 completeAction(listInfo, hsrqRequest, hsrpResponse, 522 LISTBROWSER_LIST_MAIN_PAGE); 523 } 524 catch (Throwable eExc) 525 { 526 s_logger.log(Level.WARNING, 527 "An error has occured while retrieving information" + 528 " about the default list.", eExc); 529 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 530 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 531 } 532 finally 533 { 534 s_logger.exiting("ListBrowseServlet", "processShowList"); 535 } 536 } 537 538 546 protected void processSetListFilter( 547 HttpServletRequest hsrqRequest, 548 HttpServletResponse hsrpResponse 549 ) throws IOException , 550 ServletException 551 { 552 s_logger.entering("ListBrowserServlet", "processSetListFilter"); 553 try 554 { 555 Object [] listInfo = getListController().getSetDefinition( 556 parseListFromRequest(hsrqRequest, 557 ACTION_SET_FILTER_ID)); 558 559 completeAction(listInfo, hsrqRequest, hsrpResponse, 560 LISTBROWSER_LIST_MAIN_PAGE); 561 562 } 563 catch (Throwable eExc) 564 { 565 s_logger.log(Level.WARNING, 566 "An error has occured while retrieving information" + 567 " about list with new filter set.", eExc); 568 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 569 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 570 } 571 finally 572 { 573 s_logger.exiting("ListBrowseServlet", "processSetListFilter"); 574 } 575 576 } 577 578 586 protected void processSetOrder( 587 HttpServletRequest hsrqRequest, 588 HttpServletResponse hsrpResponse 589 ) throws IOException , 590 ServletException 591 { 592 s_logger.entering("ListBrowserServlet", "processSetOrder"); 593 try 594 { 595 Object [] listInfo = getListController().getSetOrder( 596 parseListFromRequest(hsrqRequest, 597 ACTION_SET_ORDER_ID)); 598 599 completeAction(listInfo, hsrqRequest, hsrpResponse, 600 LISTBROWSER_LIST_MAIN_PAGE); 601 602 } 603 catch (Throwable eExc) 604 { 605 s_logger.log(Level.WARNING, 606 "An error has occured while retrieving information" + 607 " about list with order change.", eExc); 608 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 609 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 610 } 611 finally 612 { 613 s_logger.exiting("ListBrowseServlet", "processSetOrder"); 614 } 615 } 616 617 625 protected void processSetPageSize( 626 HttpServletRequest hsrqRequest, 627 HttpServletResponse hsrpResponse 628 ) throws IOException , 629 ServletException 630 { 631 s_logger.entering("ListBrowserServlet", "processSetPageSize"); 632 try 633 { 634 Object [] listInfo = getListController().getSetPageSize( 635 parseListFromRequest(hsrqRequest, 636 ACTION_PAGE_SIZE_ID)); 637 638 completeAction(listInfo, hsrqRequest, hsrpResponse, 639 LISTBROWSER_LIST_MAIN_PAGE); 640 641 } 642 catch (Throwable eExc) 643 { 644 s_logger.log(Level.WARNING, 645 "An error has occured while retrieving information" + 646 " about list with new page size.", eExc); 647 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 648 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 649 } 650 finally 651 { 652 s_logger.exiting("ListBrowseServlet", "processSetPageSize"); 653 } 654 } 655 656 664 protected void processSetPrevPage( 665 HttpServletRequest hsrqRequest, 666 HttpServletResponse hsrpResponse 667 ) throws IOException , 668 ServletException 669 { 670 s_logger.entering("ListBrowserServlet", "processSetPrevPage"); 671 try 672 { 673 Object [] listInfo = getListController().getPreviousPage( 674 parseListFromRequest(hsrqRequest, 675 ACTION_PREV_PAGE_ID)); 676 677 completeAction(listInfo, hsrqRequest, hsrpResponse, 678 LISTBROWSER_LIST_MAIN_PAGE); 679 680 } 681 catch (Throwable eExc) 682 { 683 s_logger.log(Level.WARNING, 684 "An error has occured while retrieving information" + 685 " about previous page list.", eExc); 686 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 687 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 688 } 689 finally 690 { 691 s_logger.exiting("ListBrowseServlet", "processSetPrevPage"); 692 } 693 694 } 695 696 704 protected void processSetNextPage( 705 HttpServletRequest hsrqRequest, 706 HttpServletResponse hsrpResponse 707 ) throws IOException , 708 ServletException 709 { 710 s_logger.entering("ListBrowserServlet", "processSetNextPage"); 711 try 712 { 713 Object [] listInfo = getListController().getNextPage( 714 parseListFromRequest(hsrqRequest, 715 ACTION_NEXT_PAGE_ID)); 716 717 completeAction(listInfo, hsrqRequest, hsrpResponse, 718 LISTBROWSER_LIST_MAIN_PAGE); 719 720 } 721 catch (Throwable eExc) 722 { 723 s_logger.log(Level.WARNING, 724 "An error has occured while retrieving information" + 725 " about next page list.", eExc); 726 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 727 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 728 } 729 finally 730 { 731 s_logger.exiting("ListBrowseServlet", "processSetNextPage"); 732 } 733 } 734 735 743 protected void processSetExactPage( 744 HttpServletRequest hsrqRequest, 745 HttpServletResponse hsrpResponse 746 ) throws IOException , 747 ServletException 748 { 749 s_logger.entering("ListBrowserServlet", "processSetExactPage"); 750 try 751 { 752 Object [] listInfo = getListController().getExactPage( 753 parseListFromRequest(hsrqRequest, 754 ACTION_GO_TO_PAGE_ID)); 755 756 completeAction(listInfo, hsrqRequest, hsrpResponse, 757 LISTBROWSER_LIST_MAIN_PAGE); 758 } 759 catch (Throwable eExc) 760 { 761 s_logger.log(Level.WARNING, 762 "An error has occured while retrieving information" + 763 " about exact page.", eExc); 764 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 765 hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc); 766 } 767 finally 768 { 769 s_logger.exiting("ListBrowseServlet", "processSetExactPage"); 770 } 771 } 772 773 775 778 protected int getFormToProcess( 779 HttpServletRequest hsrqRequest 780 ) 781 { 782 String strActionName; 783 int iReturn = FORM_UNKNOWN_ID; 784 785 strActionName = hsrqRequest.getParameter(FORM_NAME_REQUEST_PARAM); 786 787 if (strActionName == null) 790 { 791 iReturn = ACTION_SHOW_LIST_ID; 792 } 793 else if (strActionName.equals(ACTION_SHOW_LIST_NAME)) 794 { 795 iReturn = ACTION_SHOW_LIST_ID; 797 } 798 else if (strActionName.equals(ACTION_SET_FILTER_NAME)) 799 { 800 iReturn = ACTION_SET_FILTER_ID; 802 } 803 else if (strActionName.equals(ACTION_SET_ORDER_NAME)) 804 { 805 iReturn = ACTION_SET_ORDER_ID; 807 } 808 else if (strActionName.equals(ACTION_PAGE_SIZE_NAME)) 809 { 810 iReturn = ACTION_PAGE_SIZE_ID; 812 } 813 else if (strActionName.equals(ACTION_PREV_PAGE_NAME)) 814 { 815 iReturn = ACTION_PREV_PAGE_ID; 817 } 818 else if (strActionName.equals(ACTION_NEXT_PAGE_NAME)) 819 { 820 iReturn = ACTION_NEXT_PAGE_ID; 822 } 823 else if (strActionName.equals(ACTION_GO_TO_PAGE_NAME)) 824 { 825 iReturn = ACTION_GO_TO_PAGE_ID; 827 } 828 else 829 { 830 iReturn = ACTION_SHOW_LIST_ID; 831 } 832 833 return iReturn; 834 } 835 836 844 protected ListOptions parseListFromRequest( 845 HttpServletRequest hsrqRequest, 846 int actionCode 847 ) throws OSSException 848 { 849 String strFilterID = DataObject.NEW_ID_STR; 850 int iPageSize = -1; 851 int iActualListSize = 0; 852 int[] arrOrderCodes = null; 853 String [] arrOrderTypes = null; 854 int iClientOrderCode = 0; 855 String strClientOrderType = ListDefinition.ORDER_ASCENDING; 856 int iBeginPosition = 0; 857 int iEndPosition = 0; 858 int iActualPage = 0; 859 int iFirstVisibleItem = 0; 860 int iParentDataType = DataConstant.NO_DATA_TYPE; 861 int iParentIdentifier = DataObject.NEW_ID; 862 String strSelectedItemIDs = null; 863 String strMarkedItemIDs = null; 864 int[] arrShowColumnCodes = null; 865 String strIgnoredItemIDs = null; 866 int iExtraConditionAttribute = DataCondition.NO_ATTRIBUTE; 867 int iExtraConditionOperand = DataCondition.NO_OPERAND; 868 Object oExtraConditionValue = null; 869 int iExtraConditionValueType = DataCondition.VALUE_TYPE_BOOLEAN; 870 boolean bKeepSelected = false; 871 int iDomainID = DataObject.NEW_ID; 872 String strTemp; 873 874 strTemp = hsrqRequest.getParameter(LIST_PARAM_SELECTED_ITEMS); 875 if (strTemp != null) 876 { 877 strSelectedItemIDs = strTemp; 878 } 879 880 strTemp = hsrqRequest.getParameter(LIST_PARAM_MARKED_ITEMS); 881 if (strTemp != null) 882 { 883 strMarkedItemIDs = strTemp; 884 } 885 886 if (actionCode != ACTION_SHOW_LIST_ID) 887 { 888 strTemp = hsrqRequest.getParameter( 889 ListBrowserServlet.LIST_PARAM_LIST_FILTER_ID); 890 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 891 { 892 throw new IllegalArgumentException ("Filter ID is not specified."); 894 } 895 strFilterID = strTemp; 896 897 strTemp = hsrqRequest.getParameter(LIST_PARAM_SHOW_COLUMN_CODES); 898 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 899 { 900 throw new IllegalArgumentException ("Show column codes are not specified."); 902 } 903 arrShowColumnCodes = StringUtils.parseStringToIntArray(strTemp, ","); 904 905 if (actionCode != ACTION_SET_FILTER_ID) 906 { 907 strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_PAGE_SIZE); 908 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 909 { 910 throw new IllegalArgumentException ("Page size is not specified."); 912 } 913 iPageSize = Integer.parseInt(strTemp); 914 915 strTemp = hsrqRequest.getParameter(LIST_PARAM_ORDER_CODE); 916 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 917 { 918 throw new IllegalArgumentException ("Order code is not specified."); 920 } 921 arrOrderCodes = StringUtils.parseStringToIntArray(strTemp, ","); 922 923 strTemp = hsrqRequest.getParameter(LIST_PARAM_ORDER_TYPE); 924 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 925 { 926 throw new IllegalArgumentException ("Order type is not specified."); 928 } 929 arrOrderTypes = StringUtils.parseStringToStringArray(strTemp, ","); 930 } 931 } 932 933 if (actionCode == ACTION_PAGE_SIZE_ID 934 || actionCode == ACTION_PREV_PAGE_ID 935 || actionCode == ACTION_NEXT_PAGE_ID 936 || actionCode == ACTION_GO_TO_PAGE_ID 937 ) 938 { 939 strTemp = hsrqRequest.getParameter(LIST_PARAM_CLIENT_ORDER_CODE); 940 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 941 { 942 throw new IllegalArgumentException ("Client order code is not specified."); 944 } 945 iClientOrderCode = Integer.parseInt(strTemp); 946 947 strTemp = hsrqRequest.getParameter(LIST_PARAM_CLIENT_ORDER_TYPE); 948 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 949 { 950 throw new IllegalArgumentException ("Client order type is not specified."); 952 } 953 954 if (ListDefinition.ORDER_ASCENDING.equals(strTemp)) 955 { 956 strClientOrderType = ListDefinition.ORDER_ASCENDING; 957 } 958 else if (ListDefinition.ORDER_DESCENDING.equals(strTemp)) 959 { 960 strClientOrderType = ListDefinition.ORDER_DESCENDING; 961 } 962 else 963 { 964 throw new IllegalArgumentException ("Invalid value for client order " + 965 "type is specified."); 966 } 967 968 strTemp = hsrqRequest.getParameter(LIST_PARAM_FIRST_VISIBLE_ITEM); 969 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 970 { 971 throw new IllegalArgumentException ("First visible item is not specified."); 973 } 974 iFirstVisibleItem = Integer.parseInt(strTemp); 975 } 976 977 if (actionCode == ACTION_PAGE_SIZE_ID || actionCode == ACTION_PREV_PAGE_ID) 978 { 979 strTemp = hsrqRequest.getParameter(LIST_PARAM_BEGIN_POSITION); 980 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 981 { 982 throw new IllegalArgumentException ("Begin position is not specified."); 984 } 985 iBeginPosition = Integer.parseInt(strTemp); 986 } 987 988 if (actionCode == ACTION_NEXT_PAGE_ID) 989 { 990 strTemp = hsrqRequest.getParameter(LIST_PARAM_END_POSITION); 991 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 992 { 993 throw new IllegalArgumentException ("End position is not specified."); 995 } 996 iEndPosition = Integer.parseInt(strTemp); 997 } 998 999 if (actionCode == ACTION_GO_TO_PAGE_ID) 1000 { 1001 strTemp = hsrqRequest.getParameter(LIST_PARAM_ACTUAL_PAGE); 1002 if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID)) 1003 { 1004 throw new IllegalArgumentException ("Actual page is not specified."); 1006 } 1007 iActualPage = Integer.parseInt(strTemp); 1008 } 1009 1010 strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_PARENT_DATA_TYPE); 1011 if (strTemp != null) 1012 { 1013 iParentDataType = Integer.parseInt(strTemp); 1014 } 1015 1016 strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_PARENT_IDENTIFIER); 1017 if (strTemp != null) 1018 { 1019 iParentIdentifier = Integer.parseInt(strTemp); 1020 } 1021 1022 strTemp = hsrqRequest.getParameter(LIST_PARAM_IGNORED_ITEMS); 1023 if (strTemp != null) 1024 { 1025 strIgnoredItemIDs = strTemp; 1026 } 1027 1028 strTemp = hsrqRequest.getParameter(LIST_PARAM_KEEP_SELECTED); 1029 if (strTemp != null) 1030 { 1031 bKeepSelected = Integer.parseInt(strTemp) == 1; 1032 } 1033 1034 strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_DOMAIN_ID); 1035 if (strTemp != null) 1036 { 1037 iDomainID = Integer.parseInt(strTemp); 1038 } 1039 1040 strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE); 1042 if (strTemp != null) 1043 { 1044 iExtraConditionAttribute = Integer.parseInt(strTemp); 1045 } 1046 1047 strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_OPERAND); 1048 if (strTemp != null) 1049 { 1050 iExtraConditionOperand = Integer.parseInt(strTemp); 1051 } 1052 1053 strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE); 1054 if (strTemp != null) 1055 { 1056 iExtraConditionValueType = Integer.parseInt(strTemp); 1057 } 1058 1059 strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_VALUE); 1061 if (strTemp != null && iExtraConditionAttribute != DataCondition.NO_ATTRIBUTE) 1062 { 1063 if (iExtraConditionOperand != DataCondition.OPERAND_IN 1064 && iExtraConditionOperand != DataCondition.OPERAND_NOT_IN) 1065 { 1066 switch (iExtraConditionValueType) 1068 { 1069 case (DataCondition.VALUE_TYPE_ID) : 1070 { 1071 oExtraConditionValue = new Integer (Integer.parseInt(strTemp)); 1072 break; 1073 } 1074 case (DataCondition.VALUE_TYPE_BOOLEAN) : 1075 { 1076 oExtraConditionValue = Boolean.valueOf(strTemp); 1077 break; 1078 } 1079 case (DataCondition.VALUE_TYPE_INTEGER) : 1080 { 1081 oExtraConditionValue = new Integer (Integer.parseInt(strTemp)); 1082 break; 1083 } 1084 case (DataCondition.VALUE_TYPE_DOUBLE) : 1085 { 1086 oExtraConditionValue = new Double (Double.parseDouble(strTemp)); 1087 break; 1088 } 1089 case (DataCondition.VALUE_TYPE_STRING) : 1090 { 1091 oExtraConditionValue = strTemp; 1092 break; 1093 } 1094 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 1095 { 1096 oExtraConditionValue = DateUtils.parseTimestamp(strTemp); 1097 break; 1098 } 1099 default : 1100 { 1101 throw new IllegalArgumentException ("Not supported extra condition value type."); 1102 } 1103 } 1104 } 1105 else 1106 { 1107 List lstValues = StringUtils.parseStringToList(strTemp, ","); 1109 Integer [] arrInteger = null; 1110 Boolean [] arrBoolean = null; 1111 Double [] arrDouble = null; 1112 String [] arrString = null; 1113 Timestamp [] arrTimestamp = null; 1114 if (lstValues != null && lstValues.size() > 0) 1116 { 1117 switch (iExtraConditionValueType) 1118 { 1119 case (DataCondition.VALUE_TYPE_ID) : 1120 { 1121 arrInteger = new Integer [lstValues.size()]; 1122 break; 1123 } 1124 case (DataCondition.VALUE_TYPE_BOOLEAN) : 1125 { 1126 arrBoolean = new Boolean [lstValues.size()]; 1127 break; 1128 } 1129 case (DataCondition.VALUE_TYPE_INTEGER) : 1130 { 1131 arrInteger = new Integer [lstValues.size()]; 1132 break; 1133 } 1134 case (DataCondition.VALUE_TYPE_DOUBLE) : 1135 { 1136 arrDouble = new Double [lstValues.size()]; 1137 break; 1138 } 1139 case (DataCondition.VALUE_TYPE_STRING) : 1140 { 1141 arrString = new String [lstValues.size()]; 1142 break; 1143 } 1144 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 1145 { 1146 arrTimestamp = new Timestamp [lstValues.size()]; 1147 break; 1148 } 1149 default : 1150 { 1151 throw new IllegalArgumentException ( 1152 "Not supported extra condition value type."); 1153 } 1154 } 1155 int iCounter = 0; 1157 String strHelp; 1158 for (Iterator itHelp = lstValues.iterator(); itHelp.hasNext();) 1159 { 1160 strHelp = (String ) itHelp.next(); 1161 switch (iExtraConditionValueType) 1162 { 1163 case (DataCondition.VALUE_TYPE_ID) : 1164 { 1165 arrInteger[iCounter++] = new Integer (Integer.parseInt(strHelp)); 1166 break; 1167 } 1168 case (DataCondition.VALUE_TYPE_BOOLEAN) : 1169 { 1170 arrBoolean[iCounter++] = Boolean.valueOf(strHelp); 1171 break; 1172 } 1173 case (DataCondition.VALUE_TYPE_INTEGER) : 1174 { 1175 arrInteger[iCounter++] = new Integer (Integer.parseInt(strHelp)); 1176 break; 1177 } 1178 case (DataCondition.VALUE_TYPE_DOUBLE) : 1179 { 1180 arrDouble[iCounter++] = new Double (Double.parseDouble(strHelp)); 1181 break; 1182 } 1183 case (DataCondition.VALUE_TYPE_STRING) : 1184 { 1185 arrString[iCounter++] = strHelp; 1186 break; 1187 } 1188 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 1189 { 1190 arrTimestamp[iCounter++] = DateUtils.parseTimestamp(strHelp); 1191 break; 1192 } 1193 default : 1194 { 1195 throw new IllegalArgumentException ( 1196 "Not supported extra condition value type."); 1197 } 1198 } 1199 } 1200 switch (iExtraConditionValueType) 1202 { 1203 case (DataCondition.VALUE_TYPE_ID) : 1204 { 1205 oExtraConditionValue = arrInteger; 1206 break; 1207 } 1208 case (DataCondition.VALUE_TYPE_BOOLEAN) : 1209 { 1210 oExtraConditionValue = arrBoolean; 1211 break; 1212 } 1213 case (DataCondition.VALUE_TYPE_INTEGER) : 1214 { 1215 oExtraConditionValue = arrInteger; 1216 break; 1217 } 1218 case (DataCondition.VALUE_TYPE_DOUBLE) : 1219 { 1220 oExtraConditionValue = arrDouble; 1221 break; 1222 } 1223 case (DataCondition.VALUE_TYPE_STRING) : 1224 { 1225 oExtraConditionValue = arrString; 1226 break; 1227 } 1228 case (DataCondition.VALUE_TYPE_TIMESTAMP) : 1229 { 1230 oExtraConditionValue = arrTimestamp; 1231 break; 1232 } 1233 default : 1234 { 1235 throw new IllegalArgumentException ( 1236 "Not supported extra condition value type."); 1237 } 1238 } 1239 } 1240 } 1241 } 1242 1243 ListOptions options = new ListOptions( 1244 m_clsFactory, 1245 strFilterID, 1246 iPageSize, 1247 iActualListSize, 1248 arrOrderCodes, 1249 arrOrderTypes, 1250 iClientOrderCode, 1251 strClientOrderType, 1252 iBeginPosition, 1253 iEndPosition, 1254 iActualPage, 1255 iFirstVisibleItem, 1256 iParentDataType, 1257 iParentIdentifier, 1258 strSelectedItemIDs, 1259 strMarkedItemIDs, 1260 arrShowColumnCodes, 1261 strIgnoredItemIDs, 1262 false, bKeepSelected, 1264 iDomainID 1265 ); 1266 1267 if (iExtraConditionAttribute != DataCondition.NO_ATTRIBUTE) 1269 { 1270 DataCondition dcDataCondition = new DataCondition( 1271 iExtraConditionAttribute, 1272 iExtraConditionOperand, 1273 oExtraConditionValue, 1274 iExtraConditionValueType 1275 ); 1276 1277 List lstExtraConditions = new ArrayList (); 1278 lstExtraConditions.add(dcDataCondition); 1279 1280 SimpleRule extraRule = new SimpleRule(SimpleRule.LOGICAL_AND, 1281 lstExtraConditions); 1282 1283 options.setExtraFilter(extraRule, SimpleRule.LOGICAL_AND); 1284 } 1285 1286 return options; 1287 } 1288 1289 1300 protected void completeAction( 1301 Object [] listInfo, 1302 HttpServletRequest hsrqRequest, 1303 HttpServletResponse hsrpResponse, 1304 String strUIID 1305 ) throws Exception 1306 { 1307 if (GlobalConstants.ERROR_CHECKING) 1308 { 1309 assert (listInfo[0] != null) : "ListOptions should be never null"; 1310 } 1311 1312 ListOptions options = (ListOptions)listInfo[0]; 1313 List lstDataObjects = (List )listInfo[1]; 1314 int iDataType = ((Integer )listInfo[2]).intValue(); 1315 DataObject data; 1316 StringBuffer sbSelectedItemIDsTemp = new StringBuffer (); 1317 int[] selectedIds; 1318 Iterator itData; 1319 int iCounter; 1320 StringBuffer strFinalSelected = new StringBuffer (); 1321 1322 if ((lstDataObjects != null) && (lstDataObjects.size() > 0)) 1323 { 1324 if (options.getSelectedItemIDs() != null) 1328 { 1329 StringTokenizer stSelectedIds = new StringTokenizer ( 1330 options.getSelectedItemIDs(), ","); 1331 String strHelp; 1332 int iTemp; 1333 1334 while ((stSelectedIds != null) && (stSelectedIds.hasMoreTokens())) 1335 { 1336 strHelp = stSelectedIds.nextToken(); 1337 iTemp = strHelp.indexOf(LISTBROWSER_ITEM_ID_EXTENTION_SEPARATOR); 1338 if (iTemp > -1) 1339 { 1340 strHelp = strHelp.substring(0, iTemp); 1341 } 1342 if (sbSelectedItemIDsTemp.length() > 0) 1343 { 1344 sbSelectedItemIDsTemp.append(","); 1345 } 1346 sbSelectedItemIDsTemp.append(strHelp); 1347 } 1348 } 1349 1350 selectedIds = StringUtils.parseStringToIntArray( 1351 sbSelectedItemIDsTemp.toString(), 1352 ","); 1353 1354 if (selectedIds != null) 1355 { 1356 itData = lstDataObjects.iterator(); 1357 1358 while (itData.hasNext()) 1359 { 1360 data = (DataObject) itData.next(); 1361 for (iCounter = 0; iCounter < selectedIds.length; iCounter++) 1362 { 1363 if (data.getId() == selectedIds[iCounter]) 1364 { 1365 if (strFinalSelected.length() > 0) 1366 { 1367 strFinalSelected.append(","); 1368 } 1369 strFinalSelected.append(selectedIds[iCounter]); 1370 } 1371 } 1372 } 1373 } 1374 } 1375 options.setSelectedItemIDs(strFinalSelected.toString()); 1376 1377 hsrqRequest.setAttribute(PARAMETER_LIST_OPTIONS_NAME, options); 1378 1379 if (lstDataObjects != null) 1380 { 1381 hsrqRequest.setAttribute(PARAMETER_DATA_OBJECT_LIST_NAME, lstDataObjects); 1382 } 1383 1384 if ((options.getExtraFilter() != null) 1385 && (options.getExtraFilter().getConditions().size() == 1)) 1386 { 1387 hsrqRequest.setAttribute(PARAMETER_EXTRA_CONDITION_NAME, 1388 options.getExtraFilter().getConditions().get(0)); 1389 } 1390 else 1391 { 1392 hsrqRequest.setAttribute(PARAMETER_EXTRA_CONDITION_NAME, 1393 new DataCondition()); 1394 } 1395 1396 List lstGenericData = getListController().getDefinitionList(iDataType); 1398 if (lstGenericData == null) 1399 { 1400 lstGenericData = Collections.EMPTY_LIST; 1401 } 1402 hsrqRequest.setAttribute(PARAMETER_GENERIC_DATA_LIST_NAME, lstGenericData); 1403 1404 displayUI(strUIID, hsrqRequest, hsrpResponse); 1405 } 1406 1407 1415 protected ListController getListController( 1416 ) throws OSSException 1417 { 1418 ListController controller; 1419 1420 controller = (ListController)ControllerManager.getInstance( 1421 ListController.class); 1422 1423 return controller; 1424 } 1425} 1426 | Popular Tags |