public static int getPartyActivationLevelForPartyRole(String partyRoleCode) throws Exception {
   int activationLevel = 0;
   if (partyRoleCode != null && !"".equals(partyRoleCode)) {
     if (roleActivationLevelMap.containsKey(partyRoleCode)) {
       activationLevel = ((Integer) roleActivationLevelMap.get(partyRoleCode)).intValue();
     } else if (roleActivationLevelMap.size() == 0) {
       try {
         LogicModuleService lms = LogicModuleServiceUtil.getHome().create();
         ObjectQueryCommand additionalCommand =
             new ObjectQueryCommand("com.foursoft.etrans.entities.PartyRoleType", Locale.US);
         additionalCommand.setAttributeNames(new String[] {"code", "roleDependencyIndicator"});
         additionalCommand.sethasLocaleData(false);
         Object[][] data = lms.getTableModel(additionalCommand).getData();
         if (data != null && data.length > 0) {
           for (int i = 0; i < data.length; i++) {
             String code = (String) data[i][0];
             Integer roleActivationLevel =
                 (Integer) ((RoleDependencyIndicatorEnumeration) data[i][1]).getEnumCode();
             if (code != null && !"".equals(code) && roleActivationLevel != null) {
               if (partyRoleCode.equals(code)) activationLevel = roleActivationLevel.intValue();
               roleActivationLevelMap.put(code, roleActivationLevel);
             }
           }
         }
       } finally {
       }
     }
   }
   return activationLevel;
 }
 /**
  * Created the initial query command for the given requst and backing object
  *
  * @param request
  * @param backingObject
  * @return
  */
 protected ObjectQueryCommand createQueryCommand(
     HttpServletRequest request, DefaultFormBackingObject backingObject) {
   ObjectQueryCommand command =
       new ObjectQueryCommand(super.getClassName(), getUserLocale(request), getAttributeNames());
   command.sethasLocaleData(false);
   // System.out.println("------------createQueryCommand------hasLocaleData-----"+command.hasLocaleData());
   return command;
 }
 public String[] getRelatedPartiesForParty(String partyId, String relationshipType)
     throws Exception {
   String[] ret = null;
   try {
     LogicModuleService lms = LogicModuleServiceUtil.getHome().create();
     Serializable mainPartyId = null;
     ObjectQueryCommand additionalCommand =
         new ObjectQueryCommand("com.foursoft.etrans.entities.BusinessParty", Locale.US);
     additionalCommand.setAttributeNames(new String[] {"code"});
     additionalCommand.sethasLocaleData(false);
     additionalCommand.setPaginationEnabled(false);
     additionalCommand.addFilterCriterion("code", ObjectQueryCommand.OPERATOR_EQUALS, partyId);
     IdTableModel additionalTableModel = lms.getTableModel(additionalCommand);
     Object[][] data = additionalTableModel.getData();
     if (data != null && data.length > 0) {
       mainPartyId = additionalTableModel.getIdForRow(0); // Id retrieval
     }
     if (mainPartyId != null) {
       additionalCommand =
           new ObjectQueryCommand("com.foursoft.etrans.entities.PartyRelationShip", Locale.US);
       additionalCommand.setAttributeNames(new String[] {"relatedParty.code"});
       additionalCommand.setPaginationEnabled(false);
       additionalCommand.sethasLocaleData(false);
       ParentInfo parentInfo = null;
       parentInfo = new ParentInfo();
       parentInfo.setClassname("com.foursoft.etrans.entities.BusinessParty");
       parentInfo.setId(mainPartyId);
       parentInfo.setChildRelationName("partyRelationShips");
       additionalCommand.setParentInfo(parentInfo);
       additionalCommand.addFilterCriterion(
           "partyRelshipType.code", ObjectQueryCommand.OPERATOR_EQUALS, relationshipType);
       data = lms.getTableModel(additionalCommand).getData();
       if (data != null && data.length > 0) {
         ArrayList relatedParties = new ArrayList();
         for (int i = 0; i < data.length; i++) relatedParties.add((String) data[i][0]);
         if (relatedParties.size() > 0)
           ret = (String[]) relatedParties.toArray(new String[relatedParties.size()]);
       }
     }
   } finally {
   }
   return ret;
 }
 public String[] getDefaultSalespersonForCustomer(String customerId, String branchId)
     throws Exception {
   String[] ret = null;
   try {
     String[] salesPersonArray = getRelatedPartiesForParty(customerId, "*SALESPERSON");
     LogicModuleService lms = LogicModuleServiceUtil.getHome().create();
     ObjectQueryCommand additionalCommand =
         new ObjectQueryCommand("com.foursoft.etrans.entities.BusinessParty", Locale.US);
     additionalCommand.setAttributeNames(new String[] {"code", "nickName"});
     additionalCommand.sethasLocaleData(false);
     additionalCommand.addFilterCriterion(
         "partyRoleCrossRefs.partyRoleType.code",
         ObjectQueryCommand.OPERATOR_EQUALS,
         "*SALESPERSON");
     int salesPersonActivationLevel = getPartyActivationLevelForPartyRole("*SALESPERSON");
     if (salesPersonActivationLevel == 2
         && branchId != null
         && !"".equals(branchId)
         && branchId.length() >= 3)
       additionalCommand.addFilterCriterion(
           "partyRoleCrossRefs.activatedCompanyPartyId",
           ObjectQueryCommand.OPERATOR_EQUALS,
           branchId.substring(0, 3));
     if (salesPersonActivationLevel == 3
         && branchId != null
         && !"".equals(branchId)
         && branchId.length() == 6)
       additionalCommand.addFilterCriterion(
           "partyRoleCrossRefs.activatedBranchPartyId",
           ObjectQueryCommand.OPERATOR_EQUALS,
           branchId);
     additionalCommand.addFilterCriterion(
         "code", ObjectQueryCommand.OPERATOR_IN, salesPersonArray);
     Object[][] data = lms.getTableModel(additionalCommand).getData();
     if (data != null && data.length == 1) {
       ret = new String[2];
       ret[0] = (String) data[0][0];
       ret[1] = (String) data[0][1];
     }
   } finally {
   }
   return ret;
 }
 /** Overriding default implementation to remove LocaleData */
 protected ObjectQueryCommand createQueryCommand(
     HttpServletRequest request, DefaultFormBackingObject backingObject) {
   ObjectQueryCommand command = super.createQueryCommand(request, backingObject);
   command.sethasLocaleData(false);
   return command;
 }
 /**
  * Actually runs the query and puts the returned table model on the request as attribute
  * 'tableModel'.
  *
  * @param request
  * @param criteria
  * @throws ServletException
  */
 protected void runQuery(HttpServletRequest request, DefaultListFormBackingObject backingObject)
     throws ServletException {
   IdTableModel tm = null;
   ObjectQueryCommand command = createQueryCommand(request, backingObject);
   SearchFormCriteria criteria = (SearchFormCriteria) backingObject.getDataObject();
   // FOR RETERIVING SEARCH CRITERIA WRITTEN BY SUBHASH CHANDRASHAKER.V START
   String searchCriteriaFunctionCode =
       (String) request.getSession().getAttribute("searchCriteriaFunctionCode");
   if (request.getSession().getAttribute("searchCriteriaObject") != null
       && searchCriteriaFunctionCode != null
       && searchCriteriaFunctionCode.equals(getFunctionCode())) {
     criteria = (SearchFormCriteria) request.getSession().getAttribute("searchCriteriaObject");
     backingObject.setDataObject(criteria);
     request.getSession().removeAttribute("searchCriteriaObject");
     request.getSession().removeAttribute("searchCriteriaFunctionCode");
   } else if (searchCriteriaFunctionCode != null
       && !searchCriteriaFunctionCode.equals(getFunctionCode())) {
     request.getSession().removeAttribute("searchCriteriaObject");
     request.getSession().removeAttribute("searchCriteriaFunctionCode");
   }
   // FOR RETERIVING SEARCH CRITERIA WRITTEN BY SUBHASH CHANDRASHAKER.V END
   if (criteria.getParentInfo() != null) {
     command.setParentInfo(criteria.getParentInfo());
   }
   /*
    * If we have criteria, then add them to the command.
    */
   if (criteria.getCriteria() != null && criteria.getCriteria().size() > 0) {
     Iterator i = criteria.getCriteria().values().iterator();
     while (i.hasNext()) {
       ObjectQueryCommandFilterCriterion crit = (ObjectQueryCommandFilterCriterion) i.next();
       if (crit.getValue()
           != null) { // the validator resets all empty strings to null, so we don't have to check
                      // here
         // Modified by SIVAPRASAD for single quotes handling
         if (crit.getAttributeName() != null && crit.getAttributeName().equals("code")) {
           command.addFilterCriterion(
               crit.getAttributeName(),
               crit.getOperator(),
               StringUtility.escapeCharsSQLQuery(((String) crit.getValue()).toUpperCase()));
         } else {
           command.addFilterCriterion(
               crit.getAttributeName(),
               crit.getOperator(),
               StringUtility.escapeCharsSQLQuery((String) crit.getValue()));
         }
       }
     }
   }
   /*PAGINATION RELATED CODE STARTS*/
   String currentPageNumber = backingObject.getPageNumber();
   if (currentPageNumber != null
       && !"".equals(currentPageNumber)
       && backingObject.getTotalPages() != null
       && !"".equals(backingObject.getTotalPages())) {
     int oldTotal = Integer.parseInt(backingObject.getTotalPages());
     int selectedPage = Integer.parseInt(currentPageNumber);
     if (selectedPage > oldTotal) currentPageNumber = backingObject.getTotalPages();
   }
   String pageOperation = backingObject.getPageOperation();
   if ((currentPageNumber == null)
       || ("").equals(currentPageNumber)
       || (Integer.parseInt(currentPageNumber) <= 0)
           && (pageOperation == null || ("").equals(pageOperation))) {
     currentPageNumber = "1";
   } else {
     // check the Operation requested
     if (Constants.PAGE_FIRST.equals(pageOperation)) {
       currentPageNumber = "1";
       backingObject.setPageOffset(null);
     } else if (Constants.PAGE_PREVIOUS.equals(pageOperation)) {
       int tempCount = (Integer.parseInt(currentPageNumber));
       if (tempCount >= 1) {
         currentPageNumber = Integer.toString(tempCount - 1);
         if (tempCount == 2
             && backingObject.getPageOffset() != null
             && Integer.parseInt(backingObject.getPageOffset()) > 0) {
           backingObject.setPageOffset(null);
         }
       }
     } else if (Constants.PAGE_NEXT.equals(pageOperation)) {
       currentPageNumber = Integer.toString((Integer.parseInt(currentPageNumber)) + 1);
     } else if (Constants.PAGE_LAST.equals(pageOperation)) {
       currentPageNumber = Integer.toString(Integer.parseInt(backingObject.getTotalPages()));
     } else if (Constants.PAGE_CLICK_ENTER.equals(pageOperation)) {
       // Modified by SIVAPRASAD to display the first page when 0 is entered in the page number
       if (currentPageNumber.equals("0")) currentPageNumber = "1";
       else currentPageNumber = currentPageNumber;
     }
     // added above condition for pagenation for WPBN Issue 67620
   }
   setPositionToValues(request, backingObject, command);
   // enable pagination
   command.setPaginationEnabled(backingObject.isPaginationEnabled());
   command.setCurrentPageNum(Integer.parseInt(currentPageNumber));
   //     	if (backingObject.getSelectedEntityId() != null) {
   //     		command.setPositionToEntity(backingObject.getSelectedEntityId());
   //     	}
   String defaultFetchSize = backingObject.getPageSize();
   // set the Fetch Size
   try {
     //	Modified by Yogesh for Auto Grid Functionality
     //			Modified by Kiran sajja for WPBN ISSUE ID 98681
     if (defaultFetchSize != null && !("").equals(defaultFetchSize)) {
       int defaultFetchSizeInt = Integer.parseInt(defaultFetchSize);
       command.setPageSize(defaultFetchSizeInt);
     } else {
       command.setPageSize(getDefaultAutoSize()); // set the default fetch size to 10
       backingObject.setPageNumber("" + getDefaultAutoSize());
     }
   } catch (NumberFormatException ex) {
     command.setPageSize(getDefaultAutoSize()); // set the default fetch size to 10
     backingObject.setPageSize("" + getDefaultAutoSize());
   }
   // modified by lokesh for issue 159432
   request.setAttribute("defaultAutoSize", getDefaultAutoSize() + "");
   // setup page offset (if required)
   if (backingObject.getPageOffset() != null) {
     if (backingObject.getPageSize().equals(backingObject.getPageOffsetForPageSize())) {
       command.setPageOffset(Integer.parseInt(backingObject.getPageOffset()));
     } else {
       // page size has changed, recalc the offset and page
       int rowPosition = 0;
       int pageOffset = Integer.parseInt(backingObject.getPageOffset());
       if (pageOffset != 0) {
         rowPosition =
             pageOffset
                 + ((Integer.parseInt(backingObject.getPageNumber()) - 2)
                     * Integer.parseInt(backingObject.getPageOffsetForPageSize()));
         pageOffset = rowPosition % command.getPageSize();
         command.setPageOffset(pageOffset);
         command.setCurrentPageNum(((rowPosition - pageOffset) / command.getPageSize()) + 2);
       }
     }
   }
   // work out if we have a pagination-related change
   boolean paginationChange = false;
   // page changed
   if (backingObject.getPageNumber() != null && backingObject.getTableModel() != null) {
     int requestedPageNumber = Integer.parseInt(backingObject.getPageNumber());
     if (requestedPageNumber != backingObject.getTableModel().getPageNumber()) {
       paginationChange = true;
     }
   }
   if (backingObject.getPageSize() != null && backingObject.getPageOffsetForPageSize() != null) {
     if (!backingObject.getPageSize().equals(backingObject.getPageOffsetForPageSize())) {
       paginationChange = true;
     }
   }
   if (backingObject.getPageOperation() != null && !"".equals(backingObject.getPageOperation())) {
     paginationChange = true;
   }
   // if the pagination has not changed, reset to the first page because we're doing a search
   if (!paginationChange) {
     command.setCurrentPageNum(1);
     backingObject.setPageNumber("1");
     command.setPageOffset(0);
     backingObject.setPageOffset("0");
   }
   try {
     command.setCurrentPageNum(Integer.parseInt(currentPageNumber));
   } catch (NumberFormatException e) {
     command.setCurrentPageNum(1);
   }
   /* PAGINATION RELATED CODE CONTINUES */
   tm = retrieveQueryResults(command);
   /* PAGINATION RELATED CODE CONTINUED */
   // CALCULATE THE TOTAL PAGE COUNT
   Object[][] data = tm.getData();
   if (data.length > 0) {
     int totalPages = 1;
     if ((tm.getTotalRowCount() > command.getPageSize()) || tm.getPageOffset() != 0) {
       int totalRows = tm.getTotalRowCount();
       int offset = tm.getPageOffset();
       int overhang = (totalRows - offset) % command.getPageSize();
       // normal pages in the set
       totalPages = 0;
       // if we overhang, e.g. 15 rows on page size 10, then add extra page
       if (offset > 0) totalPages += 1;
       if (overhang > 0) totalPages += 1;
       totalPages += (totalRows - (offset + overhang)) / command.getPageSize();
     }
     command.setTotalPageCount(totalPages);
     // commented for pagenation for WPBN Issue 67620
     // currentPageNumber = Integer.toString(tm.getPageNumber());
   } else {
     request.setAttribute(
         "successmessage", ResourceUtils.getLiteral("norecordsfound", getUserLocale(request)));
     command.setTotalPageCount(1);
     currentPageNumber = "1";
   }
   // set the new Total Page Count
   backingObject.setTotalPages(Integer.toString(command.getTotalPageCount()));
   // set the new Page Number
   backingObject.setPageNumber(currentPageNumber);
   // set the defaultFetchSize
   backingObject.setPageSize(Integer.toString(command.getPageSize()));
   // set the page offset (for position to)
   backingObject.setPageOffset(Integer.toString(tm.getPageOffset()));
   backingObject.setPageOffsetForPageSize(backingObject.getPageSize());
   // reset for the next query
   backingObject.setPageOperation(null);
   /*PAGINATION RELATED CODE ENDS*/
   request.setAttribute("tableModel", tm);
   backingObject.setTableModel(tm);
   TableLayoutDescriptor layoutDescriptor = new TableLayoutDescriptor(tm);
   setTableLayout(layoutDescriptor, tm, backingObject, request);
   ((DefaultListFormBackingObject) backingObject).setTableLayout(layoutDescriptor);
   request.setAttribute("tableColumnHeadings", getColumnHeadings(getUserLocale(request)));
   // Added By vara for Issue Id: 88316 to retain the customized grid column width
   String tableColumnString = request.getParameter("tableColumnSize");
   String tableColumnSize[] = setColumnSize();
   if (tableColumnString != null && tableColumnString != "" && !tableColumnString.equals("")) {
     tableColumnSize = tableColumnString.split(",");
   }
   request.setAttribute("tableColumnSize", tableColumnSize);
   // End
   backingObject.setDisplayTab(Constants.ACTION_LIST);
   request.setAttribute(Constants.REQUEST_FORM_ACTION_FIELD, Constants.ACTION_LIST);
   // make sure the view knows what URL to access to maintain an instance
   request.setAttribute(Constants.REQUEST_MAINTAINER_URL, getMaintainerUrl());
 }