public PdfOrderGuideSwiss(HttpServletRequest pRequest, String pCatalogLocaleCd) {
    super();
    if (pCatalogLocaleCd == null) {
      mCatalogLocaleCd = "fr_CH";
    } else {
      mCatalogLocaleCd = pCatalogLocaleCd;
    }
    mCatalogLocale = new Locale(pCatalogLocaleCd);

    mRequest = pRequest;
    try {
      mFormatter = ClwI18nUtil.getInstance(pRequest, mCatalogLocaleCd, -1);
    } catch (Exception exc) {
    }
    ;
    if (mFormatter == null) {
      try {
        mFormatter = ClwI18nUtil.getInstance(pRequest, "fr_CH", -1);
      } catch (Exception exc) {
      }
      ;
    }

    try {
      initFontsUnicode();
    } catch (Exception exc) {
      exc.printStackTrace();
    }
  }
 public List<String> getCategoryNameStartWith(int pStoreId, String pName, int pMaxRows)
     throws RemoteException {
   Connection conn = null;
   try {
     conn = getReportConnection();
     return getCategoryNameStartWith(conn, pStoreId, pName, pMaxRows);
   } catch (Exception exc) {
     exc.printStackTrace();
     throw processException(exc);
   } finally {
     closeConnection(conn);
   }
 }
  private String getMainConnName() throws RemoteException {
    String schema = "";
    try {
      Connection connMain = getConnection();
      schema = connMain.getMetaData().getUserName();
      closeConnection(connMain);
    } catch (Exception exc) {
      exc.printStackTrace();
      throw processException(exc);
    }

    return schema;
  }
  public static ActionErrors refreshContent(HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    HttpSession session = request.getSession();

    try {
      APIAccess factory = (APIAccess) session.getAttribute(Constants.APIACCESS);
      Content cont = factory.getContentAPI();
      cont.refreshBinaryData(false);
      //            APIAccess factory = new APIAccess();
      //            systemAgentEJB = factory.getSystemAgentAPI();
    } catch (Exception e) {
      e.printStackTrace();
      errors.add("SystemManagerLogic", new ActionError("error.genericError", e.getMessage()));
      return errors;
    }

    return errors;
  }
  /**
   * Process this pipeline.
   *
   * @param OrderRequestData the order request object to act upon
   * @param Connection a active database connection
   * @param APIAccess
   */
  public OrderPipelineBaton process(
      OrderPipelineBaton pBaton, OrderPipelineActor pActor, Connection pCon, APIAccess pFactory)
      throws PipelineException {
    try {
      pBaton = PipelineUtil.updateOrder(pBaton, pActor, pCon, pFactory);
      String orderStatusCd = pBaton.getOrderStatus();
      if (orderStatusCd.equals(RefCodeNames.ORDER_STATUS_CD.PENDING_APPROVAL)) {
        PipelineUtil.sendPendingApprovalEmail(pCon, pBaton);
      }

      // Return
      pBaton.setWhatNext(OrderPipelineBaton.GO_NEXT);
      return pBaton;
    } catch (Exception exc) {
      exc.printStackTrace();
      throw new PipelineException(exc.getMessage());
    } finally {
    }
  }
  public int getStoreDimId(String storeId) throws RemoteException {
    Connection conn = null;
    int storeDimId = -1;
    try {
      conn = getReportConnection();
      String sql = " select STORE_DIM_ID from DW_STORE_DIM where STORE_ID = " + storeId;

      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      while (rs.next()) {
        storeDimId = rs.getInt("STORE_DIM_ID");
      }
      stmt.close();
    } catch (Exception exc) {
      exc.printStackTrace();
      throw processException(exc);
    } finally {
      closeConnection(conn);
    }
    return storeDimId;
  }
  public void init(HttpServletRequest pRequest, String pCatalogLocaleCd) {
    mCatalogLocale = new Locale(pCatalogLocaleCd);
    mRequest = pRequest;
    try {
      mFormatter = ClwI18nUtil.getInstance(pRequest, pCatalogLocaleCd, -1);
    } catch (Exception exc) {
    }
    ;
    if (mFormatter == null) {
      try {
        mFormatter = ClwI18nUtil.getInstance(pRequest, "fr_CH", -1);
      } catch (Exception exc) {
      }
      ;
    }

    try {
      initFontsUnicode();
    } catch (Exception exc) {
      exc.printStackTrace();
    }
  }
  /** Gets all of the various failed data and puts it into the HttpServletRequest object. */
  public static ActionErrors getFailedData(HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    SystemAgent systemAgentEJB;
    try {
      // Get a reference to the admin facade
      APIAccess factory = new APIAccess();
      systemAgentEJB = factory.getSystemAgentAPI();
    } catch (Exception e) {
      e.printStackTrace();
      errors.add("SystemManagerLogic", new ActionError("error.genericError", e.getMessage()));
      // without ejb access we can't proceed any farther
      return errors;
    }

    try {

      request.setAttribute("freeMemory", new Long(Runtime.getRuntime().freeMemory()));
      request.setAttribute("totalMemory", new Long(Runtime.getRuntime().totalMemory()));

      OrderDataVector odv = systemAgentEJB.getFailedOrders();
      request.setAttribute("failedOrders", odv);

      odv = systemAgentEJB.getPendingOrders();
      request.setAttribute("pendingOrders", odv);

      InvoiceCustDataVector icdv = systemAgentEJB.getFailedCustomerInvoices();
      request.setAttribute("failedCustInvoice", icdv);

      InvoiceCustDataVector icdvcit = systemAgentEJB.getFailedCITCustomerInvoices();
      request.setAttribute("failedCITCustInvoice", icdvcit);

      InvoiceDistDataVector iddv = systemAgentEJB.getFailedDistributorInvoices();
      request.setAttribute("failedDistInvoice", iddv);

      OrderBatchLogDataVector obldv = systemAgentEJB.getFailedOrderBatchEntries();
      request.setAttribute("failedOrderBatchEntries", obldv);

      PurchaseOrderDataVector podv = systemAgentEJB.getFailedPurchaseOrders();
      request.setAttribute("failedPurchaseOrders", podv);

      RemittanceDataVector rdv = systemAgentEJB.getFailedRemittanceData();
      request.setAttribute("failedRemittanceData", rdv);

      RemittanceDetailDataVector rddv = systemAgentEJB.getFailedRemittanceDetailData();
      request.setAttribute("failedRemittanceDetailData", rddv);

      RemittancePropertyDataVector rpdv = systemAgentEJB.getUnparsableRemittanceData();
      request.setAttribute("unparsableRemittanceData", rpdv);
    } catch (Exception e) {
      e.printStackTrace();
      errors.add("SystemManagerLogic", new ActionError("error.genericError", e.getMessage()));
    }
    return errors;
  }
 /**
  * Uses the system agent bean to verify that the dao layer is the same as the underlying database.
  */
 public static ActionErrors verifyDaoLayer(HttpServletRequest request) {
   ActionErrors errors = new ActionErrors();
   SystemAgent systemAgentEJB;
   try {
     // Get a reference to the admin facade
     APIAccess factory = new APIAccess();
     systemAgentEJB = factory.getSystemAgentAPI();
   } catch (Exception e) {
     e.printStackTrace();
     errors.add("SystemManagerLogic", new ActionError("error.genericError", e.getMessage()));
     // without ejb access we can't proceed any farther
     return errors;
   }
   try {
     List daoErrors = systemAgentEJB.verifyDaoLayer();
     request.setAttribute("daoErrors", daoErrors);
   } catch (Exception e) {
     e.printStackTrace();
     errors.add("SystemManagerLogic", new ActionError("error.genericError", e.getMessage()));
   }
   return errors;
 }
  private void drawOGHeader(
      Document document, UserShopForm sForm, String pImageName, boolean personal)
      throws DocumentException {

    // add the logo
    try {
      Image i = Image.getInstance(pImageName);
      float x = document.leftMargin();
      float y = document.getPageSize().getHeight() - i.getHeight() - 5;
      i.setAbsolutePosition(x, y);
      document.add(i);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (catalogOnly) {
      return;
    }

    // unfortuanately this means we are limited to PDF rendering only.
    // get the user's personal info
    PdfPTable personalInfo;
    if (personal) {
      personalInfo = getPersonalized(sForm);
    } else {
      personalInfo = getNonPersonalized(sForm);
    }

    if (null != sForm.getAppUser().getUserAccount()
        && null != sForm.getAppUser().getUserAccount().getSkuTag()) {
      String t = sForm.getAppUser().getUserAccount().getSkuTag().getValue();
      if (t != null && t.length() > 0) {
        mSkuTag = t;
      }
    }

    // Display the contact info
    PdfPTable contactInfo = new PdfPTable(2);
    contactInfo.setWidthPercentage(50);
    contactInfo.setWidths(sizes);
    contactInfo.getDefaultCell().setBorder(borderType);
    contactInfo.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    String orderOnlineStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderOnLine:", null);
    contactInfo.addCell(makePhrase(orderOnlineStr + " ", smallHeading, false));
    contactInfo.addCell(
        makePhrase(
            sForm.getAppUser().getUserStore().getStorePrimaryWebAddress().getValue(),
            smallHeading,
            true));

    ContactUsInfo contact = null;
    if (sForm.getAppUser().getContactUsList().size() == 1) {
      contact = (ContactUsInfo) sForm.getAppUser().getContactUsList().get(0);
    }

    String orderFaxNumber = null, bscdesc = null;
    if (sForm.getAppUser().getSite().getBSC() != null
        && sForm.getAppUser().getSite().getBSC().getFaxNumber() != null
        && sForm.getAppUser().getSite().getBSC().getFaxNumber().getPhoneNum() != null) {
      orderFaxNumber = sForm.getAppUser().getSite().getBSC().getFaxNumber().getPhoneNum();
      bscdesc = sForm.getAppUser().getSite().getBSC().getBusEntityData().getLongDesc();
    }
    if (orderFaxNumber == null && contact != null) {
      orderFaxNumber = contact.getFax();
    }

    if (orderFaxNumber != null) {
      String faxOrderStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.faxOrder:", null);
      contactInfo.addCell(makePhrase(faxOrderStr + " ", smallHeading, false));
      contactInfo.addCell(makePhrase(orderFaxNumber, smallHeading, true));
    }

    if (null != bscdesc && bscdesc.length() > 0) {
      // if there is a BSC descripton set, then show
      // that information.
      PdfPCell cell = new PdfPCell(new Paragraph(bscdesc, smallHeading));
      cell.disableBorderSide(PdfPCell.LEFT);
      cell.disableBorderSide(PdfPCell.RIGHT);
      cell.disableBorderSide(PdfPCell.TOP);
      cell.disableBorderSide(PdfPCell.BOTTOM);
      cell.setColspan(2);
      cell.setPaddingTop(6);
      contactInfo.addCell(cell);
    } else {

      // otherwise show the standard contact us information
      // request for dmsi - dhl for eric.  durval 11/1/2005.

      if (contact != null) {
        contactInfo.addCell(makePhrase(" ", smallHeading, false));
        contactInfo.addCell(makePhrase(" ", smallHeading, true));
        String contactUsStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.contactUs", null);
        contactInfo.addCell(makePhrase(contactUsStr + " ", smallHeading, false));
        contactInfo.addCell(makePhrase("", smallHeading, true));

        String phoneStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.phone:", null);
        contactInfo.addCell(makePhrase(phoneStr + " ", smallHeading, false));
        contactInfo.addCell(
            makePhrase(
                "" + contact.getPhone() + "  " + contact.getCallHours(), smallHeading, true));

        String emailStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.email:", null);
        contactInfo.addCell(makePhrase(emailStr + " ", smallHeading, false));
        contactInfo.addCell(makePhrase(contact.getEmail(), smallHeading, true));
      }
    }

    // make the two tables into one
    PdfPTable wholeTable = new PdfPTable(2);
    wholeTable.setWidthPercentage(100);

    wholeTable.setWidths(halves);
    wholeTable.getDefaultCell().setBorder(borderType);

    wholeTable.addCell(personalInfo);
    wholeTable.addCell(contactInfo);
    document.add(wholeTable);

    String ogcomments = "";

    if (null != sForm.getAppUser().getSite()
        && null != sForm.getAppUser().getSite().getComments()) {
      ogcomments = sForm.getAppUser().getSite().getComments().getValue();
    }

    if (null == ogcomments || ogcomments.length() == 0) {
      if (null != sForm.getAppUser().getUserAccount()) {
        ogcomments = sForm.getAppUser().getUserAccount().getComments().getValue();
      }
    }

    // add the comments if there are any
    if (ogcomments != null && ogcomments.length() > 0) {
      document.add(makeBlankLine());
      String commentsStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.comments:", null);
      document.add(makePhrase(commentsStr + " " + ogcomments, smallHeading, true));
    }

    document.add(makeBlankLine());
    String commentsStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.comments:", null);
    document.add(
        makePhrase(
            commentsStr
                + " "
                + "__________________________________________"
                + "__________________________________________"
                + "__________",
            smallHeading,
            true));
    document.add(
        makePhrase(
            "__________"
                + "__________________________________________"
                + "__________________________________________"
                + "__________",
            smallHeading,
            true));
    document.add(
        makePhrase(
            "__________"
                + "__________________________________________"
                + "__________________________________________"
                + "__________",
            smallHeading,
            true));

    // Add an order guide note in the next page if a note is present.
    if (null != sForm.getAppUser().getUserAccount()
        && null != sForm.getAppUser().getUserAccount().getOrderGuideNote()) {
      String t = sForm.getAppUser().getUserAccount().getOrderGuideNote().getValue();
      if (t != null && t.length() > 0) {
        document.newPage();
        pageNumber = pageNumber + 1;
        // document.add(makeBlankLine());
        document.add(makePhrase(t, smallHeading, true));
      }
    }

    PdfPTable sort = new PdfPTable(1);
    sort.setWidthPercentage(100);
    sort.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    sort.getDefaultCell().setBorder(borderType);
    if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
      String sortedByCategoryStr =
          ClwI18nUtil.getMessage(mRequest, "shop.og.text.sortedBy:Category", null);
      sort.addCell(makePhrase(sortedByCategoryStr + " ", smallHeading, false));
    } else if (sForm.getOrderBy() == Constants.ORDER_BY_CUST_SKU) {
      String sortedByOurSkuNumStr =
          ClwI18nUtil.getMessage(mRequest, "shop.og.text.sortedBy:OurSkuNum", null);
      sort.addCell(makePhrase(sortedByOurSkuNumStr, smallHeading, false));
    } else {
      String sortedByProductNameStr =
          ClwI18nUtil.getMessage(mRequest, "shop.og.text.sortedBy:ProductName", null);
      sort.addCell(makePhrase(sortedByProductNameStr, smallHeading, false));
    }
    document.add(sort);
  }
  // utility function to make an item Element.
  private Table makeItemElement(ShoppingCartItemData pItm) throws DocumentException {

    Table itmTbl = new PTable(mColumnCount);
    itmTbl.setWidth(100);
    itmTbl.setWidths(itmColumnWidth);
    itmTbl.getDefaultCell().setBorderColor(java.awt.Color.black);
    itmTbl.getDefaultCell().setVerticalAlignment(Cell.ALIGN_TOP);
    itmTbl.setOffset(0);
    itmTbl.setBorder(Table.NO_BORDER);

    if (!catalogOnly) {
      String t0 = "";
      if (pItm.getIsaInventoryItem()) {
        t0 = "i";
      }

      if (null != mSiteData
          && mSiteData.isAnInventoryAutoOrderItem(pItm.getProduct().getProductId())) {
        t0 += "a";
      }

      Cell tpc0 = new Cell(makePhrase(t0, small, true));
      if (!pItm.getIsaInventoryItem()) {
        tpc0.setBorder(0);
      }
      itmTbl.addCell(tpc0);
    }

    Cell tpc01 = new Cell(makePhrase("", normal, true));
    itmTbl.addCell(tpc01);

    String t = "";
    if (pItm.getProduct().isPackProblemSku()) {
      t += "*";
    }
    if (t.length() > 0) t += " ";
    Cell tpc1 = new Cell(makePhrase(t + pItm.getActualSkuNum(), normal, true));
    itmTbl.addCell(tpc1);

    itmTbl.addCell(makePhrase(pItm.getProduct().getCatalogProductShortDesc(), normal, true));
    if (mShowSize) {
      itmTbl.addCell(makePhrase(pItm.getProduct().getSize(), normal, true));
    }
    // itmTbl.addCell(makePhrase(pItm.getProduct().getPack(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getUom(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getManufacturerName(),normal,true));

    if (mShowPrice) {
      BigDecimal price = new BigDecimal(pItm.getPrice());
      String priceStr = "";
      try {
        priceStr = mFormatter.priceFormatWithoutCurrency(price);
      } catch (Exception exc) {
        exc.printStackTrace();
      }
      Cell pcell = new Cell(makePhrase(priceStr, normal, true));
      pcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
      itmTbl.addCell(pcell);
    }

    if (catalogOnly) {
      if (pItm.getProduct() != null
          && pItm.getProduct().getCatalogDistrMapping() != null
          && Utility.isTrue(pItm.getProduct().getCatalogDistrMapping().getStandardProductList())) {
        String yStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.y", null);
        itmTbl.addCell(makePhrase(yStr, normal, true));
      } else {
        String nStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.n", null);
        itmTbl.addCell(makePhrase(nStr, normal, true));
      }
    }

    if (!catalogOnly) {
      // BigDecimal amount = new BigDecimal(pItm.getAmount());
      itmTbl.addCell(makePhrase("", normal, true));
    }

    return itmTbl;
  }
Exemple #12
0
  public void extractItemIdentificationLIN(Loop inLoop) throws OBOEException {
    Segment segment = null;
    boolean ignoreMissingLineInfo =
        Utility.isTrue(
            getTranslator()
                .getConfigurationProperty(
                    RefCodeNames.ENTITY_PROPERTY_TYPE.IGNORE_MISSING_LINE_INFO));
    // valid = false;
    try {
      segment = inLoop.getSegment("LIN");
    } catch (Exception exc) {
      exc.printStackTrace();
    }
    if (segment == null && !ignoreMissingLineInfo) {
      errorMsgs.add("Segment LIN missing");
      setValid(false);
      return;
    }
    String orderLineNumS = getField(segment, 1, true, "Missing order line number in LIN segment");
    if (orderLineNumS == null && !ignoreMissingLineInfo) {
      errorMsgs.add("Order Line Number in LIN segment is null");
      setValid(false);
      return;
    }

    int orderLineNum = 0;
    try {
      orderLineNum = Integer.parseInt(orderLineNumS);
    } catch (Exception exc) {
      // JD China will use line num 3.1 for line 3 if order is split for shipment.
      int ix = orderLineNumS.indexOf('.');
      if (ix > 0) {
        String orderLineNumSs = orderLineNumS.substring(0, ix);
        try {
          orderLineNum = Integer.parseInt(orderLineNumSs);
        } catch (Exception ex) {
        }
      }

      if (orderLineNum == 0 && !ignoreMissingLineInfo) {
        errorMsgs.add("Invalid value of order line number in LIN segment: " + orderLineNumS);
        setValid(false);
        return;
      }
    }

    ediInp856ItemVw.setPurchOrderLineNum(orderLineNum);
    for (int fieldNum = 1; fieldNum <= 7; fieldNum += 2) {
      try {
        String productNumQualifier = getField(segment, 1 + fieldNum, false, "");
        if (productNumQualifier == null) {
          // errorMsgs.add("Product Service Id Qualifier is null");
          // setValid(false);
          // return;
          break;
        }
        String productNum = getField(segment, 1 + fieldNum + 1, false, "");
        if ("VP".equals(productNumQualifier) || "VN".equals(productNumQualifier)) {
          ediInp856ItemVw.setDistSkuNum(productNum);
        }
      } catch (Exception exc) {
        break;
      }
    }
    return;
  }
  /**
   * <code>getDistributorByCriteria</code> returns a vector of DistributorData's meeting the
   * criteria of the BusEntitySearchCriteria.
   *
   * @param pCrit a <code>BusEntitySearchCriteria</code> value the criteria
   * @return a <code>DistributorDataVector</code> value
   * @exception SQLException if an error occurs
   */
  public DistributorDataVector getDistributorByCriteria(BusEntitySearchCriteria pCrit)
      throws RemoteException {

    DistributorDataVector dV = new DistributorDataVector();
    Connection conn = null;
    // STORE FILTER===========================================================//
    Integer storeId = null;
    if (pCrit.getStoreBusEntityIds() != null && pCrit.getStoreBusEntityIds().size() > 0) {
      storeId = (Integer) pCrit.getStoreBusEntityIds().get(0);
    } else {
      throw new RemoteException("Store ID can't be null. ");
    }
    String storeFilter =
        "(select STORE_DIM_ID from DW_STORE_DIM \n" + "  where STORE_ID = " + storeId + " ) \n";

    //  NAMES FILTER=========================================================//
    String nameFilter =
        getSearchSqlByFilterName("JD_DIST_NAME", pCrit.getSearchName(), pCrit.getSearchNameType());
    ;
    // =======================================================================//
    try {
      //        conn = getConnection();
      conn = getReportConnection();
      String sql =
          "select  \n "
              + " DISTRIBUTOR_DIM_ID, \n"
              + " DIST_ID, DIST_NAME, \n"
              + " JD_DIST_ID, JD_DIST_NAME, \n"
              + " JD_DIST_CITY, JD_DIST_STATE, \n"
              + " JD_DIST_ADDRESS, JD_DIST_STATUS_CD \n"
              + "from DW_DISTRIBUTOR_DIM where \n"
              + " STORE_DIM_ID = "
              + storeFilter
              + " \n"
              + nameFilter
              + " order by JD_DIST_NAME";

      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      if (pCrit.getResultLimit() != QueryRequest.UNLIMITED) {
        //          stmt.setMaxRows(2000);
      }
      while (rs.next()) {
        DistributorData dd = DistributorData.createValue();

        BusEntityData be = new BusEntityData();
        be.setBusEntityId(rs.getInt("DISTRIBUTOR_DIM_ID"));
        be.setShortDesc((rs.getString("JD_DIST_NAME") != null) ? rs.getString("JD_DIST_NAME") : "");
        be.setBusEntityStatusCd(
            (rs.getString("JD_DIST_STATUS_CD") != null) ? rs.getString("JD_DIST_STATUS_CD") : "");

        AddressData ad = new AddressData();
        ad.setAddress1(
            (rs.getString("JD_DIST_ADDRESS") != null) ? rs.getString("JD_DIST_ADDRESS") : "");
        ad.setCity((rs.getString("JD_DIST_CITY") != null) ? rs.getString("JD_DIST_CITY") : "");
        ad.setStateProvinceCd(
            (rs.getString("JD_DIST_STATE") != null) ? rs.getString("JD_DIST_STATE") : "");

        dd.setBusEntity(be);
        dd.setPrimaryAddress(ad);

        dV.add(dd);
      }
      stmt.close();
    } catch (Exception exc) {
      exc.printStackTrace();
      throw processException(exc);
    } finally {
      closeConnection(conn);
    }
    return dV;
  }
  /*
   *@param  pCriteria            List of SearchCriteria objects
   *@return  a set of ItemView objects
   *@exception  RemoteException
   */
  public ItemViewVector searchStoreItems(List pCriteria, boolean pDistInfoFl)
      throws RemoteException {
    Connection con = null;
    try {
      con = getReportConnection();

      Integer storeIdI = new Integer(0);
      String categCond = "";
      String shortDescCond = "";
      String manufCond = "";
      String manufSkuCond = "";
      String distSkuCond = "";

      String storeFilter = "";
      /////////////////////
      // Create a set of filters
      for (Iterator iter = pCriteria.iterator(); iter.hasNext(); ) {
        SearchCriteria sc = (SearchCriteria) iter.next();
        String name = sc.getName();
        Object objValue = sc.getObjectValue();
        String strValue = (objValue instanceof String) ? ((String) objValue).trim() : "";
        if (SearchCriteria.STORE_ID.equals(name)) {
          storeIdI = (Integer) objValue;
          storeFilter =
              "select STORE_DIM_ID from DW_STORE_DIM \n"
                  + "  where STORE_ID = "
                  + storeIdI
                  + "  \n";

        } else if (SearchCriteria.CATALOG_CATEGORY.equals(name)) {
          String subStr = " like '%" + strValue.toUpperCase().replaceAll("'", "''") + "%' \n";
          categCond =
              "    and (UPPER(JD_CATEGORY1) "
                  + subStr
                  + " or  \n"
                  + "         UPPER(JD_CATEGORY2) "
                  + subStr
                  + " or  \n"
                  + "         UPPER(JD_CATEGORY3) "
                  + subStr
                  + ") \n";
        } else if (SearchCriteria.PRODUCT_SHORT_DESC.equals(name)) {
          shortDescCond =
              " and UPPER(JD_ITEM_DESC) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        } else if (SearchCriteria.MANUFACTURER_SHORT_DESC.equals(name)) {
          manufCond =
              " and UPPER(JD_MANUF_NAME) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        } else if (SearchCriteria.MANUFACTURER_SKU_NUMBER.equals(name)) {
          manufSkuCond =
              " and UPPER(JD_MANUF_SKU) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        } else if (SearchCriteria.DISTRIBUTOR_SKU_NUMBER.equals(name)) {
          distSkuCond =
              " and UPPER(JD_DIST_SKU) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        }
      }

      // Get catalog id --------------------------------------------------------//
      /*       int catalogId = 0;
             String sql = "select distinct STORE_CATALOG_ID from DW_CATEGORY_DIM \n" +
                          " where STORE_DIM_ID IN (" + storeFilter  + ")";
             log(
             "DWOperationBean ---------------------------> sql1: " + sql);

             Statement stmt = con.createStatement();
             ResultSet rs = stmt.executeQuery(sql);
             int count = 0;
             while (rs.next()) {
               count++;
               catalogId = rs.getInt(1);
             }
             rs.close();
             stmt.close();
             if (count == 0) {
               String errorMess = "No catalog for store. Store id: " + storeIdI;
               throw new Exception(errorMess);
             }
             if (count > 1) {
               String errorMess = "Multiple active catalogs for store. Store id: " +
                                  storeIdI;
               throw new Exception(errorMess);
             }
      */
      // ---------------------------------------------------------------------//
      String sql =
          "select                \n"
              + " id.ITEM_DIM_ID,      \n"
              + " JD_ITEM_DESC  ,      \n"
              + " JD_ITEM_PACK ,       \n"
              + " JD_ITEM_UOM ,        \n"
              + " JD_MANUF_SKU,        \n"
              + " JD_MANUF_NAME,        \n"
              + " JD_CATEGORY1         \n";

      String fromSql =
          " from DW_ITEM_DIM id,                               \n "
              + "      DW_CATEGORY_DIM cd,                           \n"
              + "      DW_MANUFACTURER_DIM md                        \n";
      String whereSql =
          " where id.CATEGORY_DIM_ID = cd.CATEGORY_DIM_ID     \n"
              +
              //          "    and cd.STORE_CATALOG_ID = " + catalogId + "    \n" +
              "    and cd.STORE_DIM_ID IN ("
              + storeFilter
              + ")  \n"
              + "    and md.MANUFACTURER_DIM_ID  = id.MANUFACTURER_DIM_ID   \n";

      // ---------------------------------------------------------------------//

      if (pDistInfoFl) {
        sql +=
            " , JD_DIST_SKU,                                       \n"
                + " (select JD_DIST_NAME from DW_DISTRIBUTOR_DIM dd      \n"
                + "   where DISTRIBUTOR_DIM_ID  = did.DISTRIBUTOR_DIM_ID \n"
                + " ) JD_DIST_NAME                                       \n";

        fromSql += "    ,DW_ITEM_DISTRIBUTOR did  \n";
        whereSql += "    and id.ITEM_DIM_ID   = did.ITEM_DIM_ID (+)         \n" + distSkuCond;
      }
      sql += fromSql + whereSql;
      sql += categCond + shortDescCond + manufCond + manufSkuCond;
      sql += " order by JD_MANUF_SKU ";

      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      ItemViewVector itemVwV = new ItemViewVector();
      while (rs.next()) {
        ItemView itemVw = ItemView.createValue();
        itemVwV.add(itemVw);
        itemVw.setStoreId(storeIdI.intValue());
        //         itemVw.setCatalogId(catalogId);

        itemVw.setItemId(rs.getInt("ITEM_DIM_ID"));
        itemVw.setName(Utility.strNN(rs.getString("JD_ITEM_DESC")));
        itemVw.setSku(Utility.strNN(rs.getString("JD_MANUF_SKU")));
        itemVw.setUom(Utility.strNN(rs.getString("JD_ITEM_UOM")));
        itemVw.setPack(Utility.strNN(rs.getString("JD_ITEM_PACK")));
        itemVw.setCategory(Utility.strNN(rs.getString("JD_CATEGORY1")));
        itemVw.setManufName(Utility.strNN(rs.getString("JD_MANUF_NAME")));
        itemVw.setManufSku(Utility.strNN(rs.getString("JD_MANUF_SKU")));
        if (pDistInfoFl) {
          itemVw.setDistId(0);
          itemVw.setDistName(Utility.strNN(rs.getString("JD_DIST_NAME")));
          itemVw.setDistSku(Utility.strNN(rs.getString("JD_DIST_SKU")));
        } else {
          itemVw.setDistId(0);
          itemVw.setDistName("");
          itemVw.setDistSku("");
        }
        itemVw.setSelected(false);
      }
      rs.close();
      stmt.close();
      return itemVwV;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RemoteException(e.getMessage());
    } finally {
      closeConnection(con);
    }
  }
  /**
   * <code>getAccountsUIByCriteria</code> returns a vector of AccountUIView's meeting the criteria
   * of the BusEntitySearchCriteria.
   *
   * @param pCrit a <code>BusEntitySearchCriteria</code> value the criteria
   * @return a <code>AccountUIViewVector</code> value
   * @exception SQLException if an error occurs
   */
  public AccountUIViewVector getAccountsUIByCriteria(BusEntitySearchCriteria pCrit)
      throws RemoteException {
    Connection conn = null;
    AccountUIViewVector acctVec = new AccountUIViewVector();
    try {
      // USER FILTER ==========================================================//
      Integer userId = null;
      String userFilterForAccounts = "";
      if (pCrit.getUserIds() != null && pCrit.getUserIds().size() > 0) {
        userId = (Integer) pCrit.getUserIds().get(0);
        userFilterForAccounts = getUserFilterForAccounts(userId.intValue());
      }
      // STORE FILTER===========================================================//
      Integer storeId = null;
      if (pCrit.getStoreBusEntityIds() != null && pCrit.getStoreBusEntityIds().size() > 0) {
        storeId = (Integer) pCrit.getStoreBusEntityIds().get(0);
      } else {
        throw new RemoteException("Store ID can't be null. ");
      }
      String storeFilter =
          "(select STORE_DIM_ID from DW_STORE_DIM \n" + "  where STORE_ID = " + storeId + " ) \n";

      String storeFilterForAccounts = getStoreFilterForAccounts(storeId.intValue());

      // ACCOUNT NAMES FILTER==================================================//
      String accountNameFilter =
          getSearchSqlByFilterName(
              "JD_ACCOUNT_NAME", pCrit.getSearchName(), pCrit.getSearchNameType());
      String accountIdFilter =
          (Utility.isSet(pCrit.getSearchId())) ? " and JD_ACCOUNT_ID = " + pCrit.getSearchId() : "";
      // ========================================================================//
      conn = getReportConnection();
      String sql =
          "select  \n "
              + " wm_concat(ACCOUNT_DIM_ID) ACCOUNT_DIM_IDS, \n"
              + " ACCOUNT_ID,  \n"
              + " JD_ACCOUNT_NAME, JD_ACCOUNT_ID, \n"
              + " JD_ACCOUNT_CITY, JD_ACCOUNT_STATE, \n"
              + " JD_MARKET, JD_ACCOUNT_STATUS_CD \n"
              + "from DW_ACCOUNT_DIM where \n"
              + "   STORE_DIM_ID = "
              + storeFilter
              + " \n"
              +
              /*            " and  account_ID in ( " + storeFilterForAccounts +") \n"
               */
              userFilterForAccounts
              + accountIdFilter
              + accountNameFilter
              + " group by  \n "
              + "    ACCOUNT_ID,  \n"
              + "    JD_ACCOUNT_NAME, JD_ACCOUNT_ID, \n"
              + "    JD_ACCOUNT_CITY, JD_ACCOUNT_STATE,  \n"
              + "    JD_MARKET, JD_ACCOUNT_STATUS_CD \n"
              + " order by JD_ACCOUNT_NAME ";

      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      if (pCrit.getResultLimit() != QueryRequest.UNLIMITED) {
        stmt.setMaxRows(2000);
      }
      int rowId = 0;
      while (rs.next()) {
        AccountUIView aui = AccountUIView.createValue();
        rowId--;
        String accountDimIds =
            (rs.getString("ACCOUNT_DIM_IDS") != null) ? rs.getString("ACCOUNT_DIM_IDS") : "";

        BusEntityData be = new BusEntityData();
        be.setBusEntityId(rowId);
        be.setShortDesc(
            (rs.getString("JD_ACCOUNT_NAME") != null) ? rs.getString("JD_ACCOUNT_NAME") : "");
        be.setBusEntityStatusCd(
            (rs.getString("JD_ACCOUNT_STATUS_CD") != null)
                ? rs.getString("JD_ACCOUNT_STATUS_CD")
                : "");

        PropertyData pd = new PropertyData();
        pd.setValue((rs.getString("JD_MARKET") != null) ? rs.getString("JD_MARKET") : "");

        AddressData ad = new AddressData();
        ad.setAddress1("");
        ad.setCity(
            (rs.getString("JD_ACCOUNT_CITY") != null) ? rs.getString("JD_ACCOUNT_CITY") : "");
        ad.setStateProvinceCd(
            (rs.getString("JD_ACCOUNT_STATE") != null) ? rs.getString("JD_ACCOUNT_STATE") : "");

        aui.setAccountDimIds(accountDimIds);
        aui.setBusEntity(be);
        aui.setAccountType(pd);
        aui.setPrimaryAddress(ad);
        acctVec.add(aui);
      }
      stmt.close();
    } catch (Exception exc) {
      exc.printStackTrace();
      throw processException(exc);
    } finally {
      closeConnection(conn);
    }
    return acctVec;
  }
  /**
   * <code>getUserSites</code> returns a vector of SiteView's meeting the criteria of the
   * parameters.
   *
   * @param pStoreId a <code>int</code> ID value (from Main DB) of Store selected
   * @param pUserId a <code>int</code> ID value (from Main DB) of Reporting User selected (appUser
   *     if user is not selected or 0 - if user assigned to All Accounts( has property RepOA^))
   * @param pNameTempl <code>String</code> NANE filter value
   * @param nameBeginsFl <code>int</code> NANE filter type (QueryRequest.BEGINS or
   *     QueryRequest.CONTAINS)
   * @param pCity <code>String</code> filter value for CITY
   * @param pState <code>String</code> filter value for STATE
   * @param pAccountIdv <code>IdVector</code> filter of AccountDimIds (null if no filter)
   * @return a <code>SiteViewVector</code> value
   *     <p>/**
   *     ========================================================================================
   */
  public SiteViewVector getUserSites(
      int pStoreId,
      int pUserId,
      Integer pSiteDimId,
      String pNameTempl,
      int nameBeginsFl,
      String pCity,
      String pState,
      IdVector pAccountIdv,
      boolean showInactiveFl,
      int pResultLimit)
      throws RemoteException {

    Connection conn = null;
    SiteViewVector siteV = new SiteViewVector();

    try {
      String storeDimFilter =
          "(select STORE_DIM_ID from DW_STORE_DIM \n" + "  where STORE_ID = " + pStoreId + " ) \n";

      String userFilterForAccounts = ""; // if user is not RepOA^ and accounts where not selected
      if (pUserId > 0 && (pAccountIdv == null || pAccountIdv.size() == 0)) {
        userFilterForAccounts = getUserFilterForAccounts(pUserId);
      }

      String siteNameFilter = getSearchSqlByFilterName("SITE_NAME", pNameTempl, nameBeginsFl);
      String accountIdsFilter =
          (pAccountIdv != null && pAccountIdv.size() > 0)
              ? "and ACCOUNT_DIM_ID in (" + convertToString(pAccountIdv) + ")"
              : "";
      String cityFilter =
          (Utility.isSet(pCity)) ? " and UPPER(SITE_CITY) LIKE UPPER('" + pCity + "%')" : "";
      String stateFilter =
          (Utility.isSet(pState)) ? " and UPPER(SITE_STATE) LIKE UPPER('" + pState + "%')" : "";

      //     conn = getConnection();
      conn = getReportConnection();

      String sql =
          "select  SITE_DIM_ID, \n"
              + " ACCOUNT_DIM_ID, ACCOUNT_ID, \n"
              + " (Select JD_ACCOUNT_NAME from DW_ACCOUNT_DIM a \n"
              + "  where a.ACCOUNT_DIM_ID = s.ACCOUNT_DIM_ID) JD_ACCOUNT_NAME, \n"
              + " SITE_ID,  \n"
              + " SITE_NAME, SITE_STREET_ADDRESS, SITE_CITY, SITE_STATE, SITE_STATUS_CD \n"
              + "from DW_SITE_DIM  s\n"
              + "where \n"
              + "   STORE_DIM_ID = "
              + storeDimFilter
              + " \n"
              + userFilterForAccounts
              + accountIdsFilter
              + siteNameFilter
              + cityFilter
              + stateFilter
              + "order by SITE_NAME ";

      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      if (pResultLimit != QueryRequest.UNLIMITED) {
        stmt.setMaxRows(Constants.MAX_SITES_TO_RETURN);
      }
      while (rs.next()) {
        SiteView sv = SiteView.createValue();
        sv.setId(rs.getInt("SITE_DIM_ID"));
        sv.setName(rs.getString("SITE_NAME"));
        sv.setAccountId(rs.getInt("ACCOUNT_ID"));
        sv.setAccountName(rs.getString("JD_ACCOUNT_NAME"));
        sv.setAddress(rs.getString("SITE_STREET_ADDRESS"));
        sv.setCity(rs.getString("SITE_CITY"));
        sv.setState(rs.getString("SITE_STATE"));
        sv.setStatus(rs.getString("SITE_STATUS_CD"));
        String targetS = null; // rs.getString("SITE_RANK");
        int target = 0;
        if (targetS != null) {
          try {
            target = Integer.parseInt(targetS);
          } catch (NumberFormatException e) {
          }
        }
        sv.setTargetFacilityRank(target);

        siteV.add(sv);
      }
      stmt.close();

    } catch (Exception exc) {
      exc.printStackTrace();
      throw processException(exc);
    } finally {
      closeConnection(conn);
    }
    return siteV;
  }