<p>Process entity request.</p>
@param pRqVs request scoped vars
@param pRqDt Request Data
@throws Exception - an exception
772700
@Override
  public final void process(final Map<String, Object> pRqVs,
    final IRequestData pRqDt) throws Exception {
    TradingSettings ts = (TradingSettings) pRqVs.get("tradSet");
    Cart cart = this.srvCart.getShoppingCart(pRqVs, pRqDt, true, false);
    CartLn cartLn = null;
    String lnIdStr = pRqDt.getParameter("lnId");
    String quantStr = pRqDt.getParameter("quant");
    String avQuanStr = pRqDt.getParameter("avQuan");
    String unStepStr = pRqDt.getParameter("unStep");
    BigDecimal quant = new BigDecimal(quantStr);
    BigDecimal avQuan = new BigDecimal(avQuanStr);
    if (quant.compareTo(avQuan) == 1) {
      quant = avQuan;
    }
    BigDecimal unStep = new BigDecimal(unStepStr);
    String itIdStr = pRqDt.getParameter("itId");
    String itTypStr = pRqDt.getParameter("itTyp");
    Long itId = Long.valueOf(itIdStr);
    AccSettings as = (AccSettings) pRqVs.get("accSet");
    TaxDestination txRules = this.srvCart
      .revealTaxRules(pRqVs, cart, as);
    EShopItemType itTyp = EShopItemType.class.
      getEnumConstants()[Integer.parseInt(itTypStr)];
    boolean redoPr = false;
    if (lnIdStr != null) { //change quantity
      Long lnId = Long.valueOf(lnIdStr);
      cartLn = findCartItemById(cart, lnId);
    } else { //add
      redoPr = true;
      String uomIdStr = pRqDt.getParameter("uomId");
      Long uomId = Long.valueOf(uomIdStr);
      for (CartLn ci : cart.getItems()) {
        //check for duplicate cause "weird" but accepted request
        if (!ci.getDisab() && ci.getItTyp().equals(itTyp)
          && ci.getItId().equals(itId)) {
          cartLn = ci;
          break;
        }
      }
      if (cartLn == null) {
        for (CartLn ci : cart.getItems()) {
          if (ci.getDisab()) {
            cartLn = ci;
            cartLn.setDisab(false);
            cartLn.setForc(false);
            cartLn.setSeller(null);
            cartLn.setTxCat(null);
            cartLn.setTxDsc(null);
            break;
          }
        }
      }
      if (cartLn == null) {
        cartLn = createCartItem(cart);
      }
      UnitOfMeasure uom = new UnitOfMeasure();
      uom.setItsId(uomId);
      cartLn.setUom(uom);
      cartLn.setItId(itId);
      cartLn.setItTyp(itTyp);
    }
    if (!cartLn.getForc()) {
      cartLn.setAvQuan(avQuan);
      cartLn.setQuant(quant);
      cartLn.setUnStep(unStep);
      BigDecimal amount = cartLn.getPrice().multiply(cartLn.getQuant()).
        setScale(as.getPricePrecision(), as.getRoundingMode());
      if (ts.getTxExcl()) {
        cartLn.setSubt(amount);
      } else {
        cartLn.setTot(amount);
      }
      this.srvCart.makeCartLine(pRqVs, cartLn, as, ts, txRules, redoPr, true);
      this.srvCart.makeCartTotals(pRqVs, ts, cartLn, as, txRules);
      this.srvCart.hndCartChan(pRqVs, cart, txRules);
    }
    if (txRules != null) {
      pRqDt.setAttribute("txRules", txRules);
    }
    redir(pRqVs, pRqDt);
  }
815990
@Override
  public final AItemSpecifics<T, ID> process(
    final Map<String, Object> pReqVars,
      final AItemSpecifics<T, ID> pEntity,
        final IRequestData pRequestData) throws Exception {
    File fileToDel;
    if (pEntity.getStringValue2() != null) {
      fileToDel = new File(pEntity.getStringValue2());
      if (fileToDel.exists() && !fileToDel.delete()) {
        throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
          "Can not delete file: " + fileToDel);
      }
    }
    if (pEntity.getStringValue3() != null) {
      int idhHtml = pEntity.getStringValue1().indexOf(".html");
      String urlWithoutHtml = pEntity.getStringValue1().substring(0, idhHtml);
      for (String lang : pEntity.getStringValue3().split(",")) {
        String filePath = this.webAppPath + File.separator
          + urlWithoutHtml + "_" + lang + ".html";
        fileToDel = new File(filePath);
        if (fileToDel.exists() && !fileToDel.delete()) {
          throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
            "Can not delete file: " + fileToDel);
        }
      }
    }
    getSrvOrm().deleteEntity(pReqVars, pEntity);
    return null;
  }
846085
@Override
  public final SeGoodsSpecifics process(
    final Map<String, Object> pReqVars,
      final SeGoodsSpecifics pEntity,
        final IRequestData pRequestData) throws Exception {
    SeSeller ses = this.findSeSeller.find(pReqVars, pRequestData.getUserName());
    pEntity.setSeller(ses);
    SeGoodsSpecifics entOld = this.srvOrm.retrieveEntity(pReqVars, pEntity);
    if (!entOld.getSeller().getItsId().getItsId()
      .equals(pEntity.getSeller().getItsId().getItsId())) {
      throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
      "Attempt to delete smb. else's entity: user/entity/EID/SEOLDID/SEID - "
        + pRequestData.getUserName() + "/" + pEntity.getClass()
         .getSimpleName() + "/" + pEntity.getItsId() + "/" + entOld
          .getSeller().getItsId().getItsId() + "/" + pEntity.getSeller()
            .getItsId().getItsId());
    }
    File fileToDel;
    if (pEntity.getStringValue2() != null) {
      fileToDel = new File(pEntity.getStringValue2());
      if (fileToDel.exists() && !fileToDel.delete()) {
        throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
          "Can not delete file: " + fileToDel);
      }
    }
    if (pEntity.getStringValue3() != null) {
      int idhHtml = pEntity.getStringValue1().indexOf(".html");
      String urlWithoutHtml = pEntity.getStringValue1().substring(0, idhHtml);
      for (String lang : pEntity.getStringValue3().split(",")) {
        String filePath = this.webAppPath + File.separator
          + urlWithoutHtml + "_" + lang + ".html";
        fileToDel = new File(filePath);
        if (fileToDel.exists() && !fileToDel.delete()) {
          throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
            "Can not delete file: " + fileToDel);
        }
      }
    }
    getSrvOrm().deleteEntity(pReqVars, pEntity);
    return null;
  }
350958
public final void saveSords(final Map<String, Object> pRqVs,
    final Purch pPur, final Cart pCart) throws Exception {
    List<CuOrSe> dels = null;
    for (CuOrSe co : pPur.getSords()) {
      if (co.getCurr() == null) { //stored unused order
        //remove it and all its lines:
        for (CuOrSeGdLn gl : co.getGoods()) {
          for (CuOrSeGdTxLn gtl : gl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, gtl);
          }
          getSrvOrm().deleteEntity(pRqVs, gl);
        }
        for (CuOrSeSrLn sl : co.getServs()) {
          for (CuOrSeSrTxLn stl : sl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, stl);
          }
          getSrvOrm().deleteEntity(pRqVs, sl);
        }
        for (CuOrSeTxLn otlt : co.getTaxes()) {
          getSrvOrm().deleteEntity(pRqVs, otlt);
        }
        getSrvOrm().deleteEntity(pRqVs, co);
        if (dels == null) {
          dels = new ArrayList<CuOrSe>();
        }
        dels.add(co);
        continue;
      }
      if (co.getIsNew()) {
        getSrvOrm().insertEntity(pRqVs, co);
      }
      BigDecimal tot = BigDecimal.ZERO;
      BigDecimal subt = BigDecimal.ZERO;
      List<CuOrSeGdLn> delsGd = null;
      for (CuOrSeGdLn gl : co.getGoods()) {
        gl.setItsOwner(co);
        if (gl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, gl);
        }
        if (gl.getItTxs() != null && gl.getItTxs().size() > 0) {
          for (CuOrSeGdTxLn gtl : gl.getItTxs()) {
            gtl.setItsOwner(gl);
            if (gtl.getIsNew()) {
              getSrvOrm().insertEntity(pRqVs, gtl);
            } else if (gl.getGood() == null || gtl.getTax() == null) {
              getSrvOrm().deleteEntity(pRqVs, gtl);
            } else {
              getSrvOrm().updateEntity(pRqVs, gtl);
            }
          }
        }
        if (!gl.getIsNew() && gl.getGood() == null) {
          getSrvOrm().deleteEntity(pRqVs, gl);
          if (delsGd == null) {
            delsGd = new ArrayList<CuOrSeGdLn>();
          }
          delsGd.add(gl);
        } else {
          tot = tot.add(gl.getTot());
          subt = subt.add(gl.getSubt());
          if (!gl.getIsNew()) {
            getSrvOrm().updateEntity(pRqVs, gl);
          }
        }
      }
      if (delsGd != null) {
        for (CuOrSeGdLn gl : delsGd) {
          co.getGoods().remove(gl);
        }
      }
      List<CuOrSeSrLn> delsSr = null;
      for (CuOrSeSrLn sl : co.getServs()) {
        sl.setItsOwner(co);
        if (sl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, sl);
        }
        if (sl.getItTxs() != null && sl.getItTxs().size() > 0) {
          for (CuOrSeSrTxLn stl : sl.getItTxs()) {
            stl.setItsOwner(sl);
            if (stl.getIsNew()) {
              getSrvOrm().insertEntity(pRqVs, stl);
            } else if (sl.getService() == null || stl.getTax() == null) {
              getSrvOrm().deleteEntity(pRqVs, stl);
            } else {
              getSrvOrm().updateEntity(pRqVs, stl);
            }
          }
        }
        if (!sl.getIsNew() && sl.getService() == null) {
          getSrvOrm().deleteEntity(pRqVs, sl);
          if (delsSr == null) {
            delsSr = new ArrayList<CuOrSeSrLn>();
          }
          delsSr.add(sl);
        } else {
          tot = tot.add(sl.getTot());
          subt = subt.add(sl.getSubt());
          if (!sl.getIsNew()) {
            getSrvOrm().updateEntity(pRqVs, sl);
          }
        }
      }
      if (delsSr != null) {
        for (CuOrSeSrLn sl : delsSr) {
          co.getServs().remove(sl);
        }
      }
      BigDecimal totTx = BigDecimal.ZERO;
      for (CartTxLn ctl : pCart.getTaxes()) {
        if (ctl.getDisab() || ctl.getSeller() == null
          || !ctl.getSeller().getSeller().getItsId()
            .equals(co.getSel().getSeller().getItsId())) {
          continue;
        }
        CuOrSeTxLn otl = null;
        if (!co.getIsNew()) {
          for (CuOrSeTxLn otlt : co.getTaxes()) {
            if (otlt.getTax() == null) {
              otl = otlt;
              break;
            }
          }
        }
        if (otl == null) {
          otl = new CuOrSeTxLn();
          otl.setIsNew(true);
          co.getTaxes().add(otl);
        }
        otl.setItsOwner(co);
        Tax tx = new Tax();
        tx.setItsId(ctl.getTax().getItsId());
        tx.setItsName(ctl.getTax().getItsName());
        otl.setTax(tx);
        otl.setTot(ctl.getTot());
        otl.setTaxab(ctl.getTaxab());
        totTx = totTx.add(otl.getTot());
        if (otl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, otl);
        } else {
          getSrvOrm().updateEntity(pRqVs, otl);
        }
      }
      if (!co.getIsNew()) {
        List<CuOrSeTxLn> delsTx = null;
        for (CuOrSeTxLn otlt : co.getTaxes()) {
          if (otlt.getTax() == null) {
            getSrvOrm().deleteEntity(pRqVs, otlt);
            if (delsTx == null) {
              delsTx = new ArrayList<CuOrSeTxLn>();
            }
            delsTx.add(otlt);
          }
        }
        if (delsTx != null) {
          for (CuOrSeTxLn tl : delsTx) {
            co.getTaxes().remove(tl);
          }
        }
      }
      co.setTot(tot);
      co.setSubt(subt);
      co.setTotTx(totTx);
      getSrvOrm().updateEntity(pRqVs, co);
    }
    if (dels != null) {
      for (CuOrSe co : dels) {
        pPur.getSords().remove(co);
      }
    }
  }
337692
public final void redir(final Map<String, Object> pRqVs,
    final IRequestData pRqDt) throws Exception {
    String procNm = pRqDt.getParameter("nmPrcRed");
    IProcessor proc = this.procFac.lazyGet(pRqVs, procNm);
    proc.process(pRqVs, pRqDt);
  }
157655
@Override
  public final SeServiceSpecifics process(
    final Map<String, Object> pReqVars,
      final SeServiceSpecifics pEntity,
        final IRequestData pRequestData) throws Exception {
    SeSeller ses = this.findSeSeller.find(pReqVars, pRequestData.getUserName());
    pEntity.setSeller(ses);
    SeServiceSpecifics entOld = this.srvOrm.retrieveEntity(pReqVars, pEntity);
    if (!entOld.getSeller().getItsId().getItsId()
      .equals(pEntity.getSeller().getItsId().getItsId())) {
      throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
      "Attempt to update smb. else's entity: user/entity/EID/SEOLDID/SEID - "
        + pRequestData.getUserName() + "/" + pEntity.getClass()
         .getSimpleName() + "/" + pEntity.getItsId() + "/" + entOld
          .getSeller().getItsId().getItsId() + "/" + pEntity.getSeller()
            .getItsId().getItsId());
    }
    String fileToUploadName = (String) pRequestData
      .getAttribute("fileToUploadName");
    OutputStream outs = null;
    InputStream ins = null;
    try {
      String filePath;
      if (pEntity.getStringValue1() == null) { //in base language:
        String ft = String.valueOf(new Date().getTime());
        filePath = this.webAppPath + File.separator
          + this.uploadDirectory + File.separator
            + ft + fileToUploadName;
        pEntity.setStringValue2(filePath);
        pEntity.setStringValue1(this.uploadDirectory
              + "/" + ft + fileToUploadName);
      } else { //I18N files:
        String fileLang = pRequestData.getParameter("fileLang");
        if (pEntity.getStringValue3() == null
          || !pEntity.getStringValue3().contains(fileLang)) {
          throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
            "notset_language");
        }
        int idhHtml = pEntity.getStringValue1().indexOf(".html");
        String urlWithoutHtml = pEntity.getStringValue1().substring(0, idhHtml);
        filePath = this.webAppPath + File.separator
          + urlWithoutHtml + "_" + fileLang + ".html";
      }
      ins = (InputStream) pRequestData.getAttribute("fileToUploadInputStream");
      outs = new BufferedOutputStream(new FileOutputStream(filePath));
      byte[] data = new byte[1024];
      int count;
      while ((count = ins.read(data)) != -1) {
        outs.write(data, 0, count);
      }
      outs.flush();
    } finally {
      if (ins != null) {
        ins.close();
      }
      if (outs != null) {
        outs.close();
      }
    }
    getSrvOrm().updateEntity(pReqVars, pEntity);
    return pEntity;
  }
823563
@Override
  public final synchronized void handleSeSellerChanged(
    final Map<String, Object> pReqVars,
      final String pName) throws Exception {
    this.sesellers = null;
  }
1242354
@Override
  public final void handle(final Map<String, Object> pReqVars,
    final IRequestData pRequestData,
      final OutputStream pSous) throws Exception {
    String csvMethodIdStr = pRequestData.getParameter("csvMethod");
    Long csvMethodId = Long.parseLong(csvMethodIdStr);
    String priceCategoryIdStr = pRequestData.getParameter("priceCategory");
    Long priceCategoryId = Long.parseLong(priceCategoryIdStr);
    pReqVars.put("priceCategoryId", priceCategoryId);
    String unavailablePriceStr = pRequestData.getParameter("unavailablePrice");
    if (unavailablePriceStr != null && !"".equals(unavailablePriceStr)) {
      BigDecimal unavailablePrice = new BigDecimal(unavailablePriceStr);
      if (unavailablePrice.compareTo(BigDecimal.ZERO) != 0) {
        pReqVars.put("unavailablePrice", unavailablePrice);
      }
    }
    String optimisticQuantityStr = pRequestData
      .getParameter("optimisticQuantity");
    if (optimisticQuantityStr != null && !"".equals(optimisticQuantityStr)) {
      BigDecimal optimisticQuantity = new BigDecimal(optimisticQuantityStr);
      pReqVars.put("optimisticQuantity", optimisticQuantity);
    }
    CsvMethod csvMethod = null;
    List<List<Object>> data = null;
    ICsvDataRetriever ret = null;
    try {
      this.srvDatabase.setIsAutocommit(false);
      this.srvDatabase.
        setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED);
      this.srvDatabase.beginTransaction();
      csvMethod = getSrvOrm().retrieveEntityById(pReqVars,
        CsvMethod.class, csvMethodId);
      List<CsvColumn> cols = getSrvOrm()
        .retrieveListWithConditions(pReqVars,
          CsvColumn.class, "where ITSOWNER=" + csvMethod.getItsId());
      csvMethod.setColumns(cols);
      ret = this.retrievers.get(csvMethod.getRetrieverName());
      if (ret == null) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "Can't find retriever " + csvMethod.getRetrieverName());
      }
      data = ret.retrieveData(pReqVars);
      this.srvDatabase.commitTransaction();
    } catch (Exception ex) {
      this.srvDatabase.rollBackTransaction();
      throw ex;
    } finally {
      this.srvDatabase.releaseResources();
    }
    if (data != null) {
      this.csvWriter.write(pReqVars, data, csvMethod, pSous);
    }
  }
592031
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    this.srvEntitiesPage.retrievePage(pAddParam, pRequestData);
  }
1211380
private void handleQueries(
      final HttpServletResponse response,
      final Map<String, List<String>> queries,
      final String version) throws IOException {

    LOG.log(Level.INFO, "HttpServerReefEventHandler handleQueries is called");

    for (final Map.Entry<String, List<String>> entry : queries.entrySet()) {
      final String queryTarget = entry.getKey().toLowerCase();

      switch (queryTarget) {
      case "id":
        if (version.equals(VER)) {
          writeEvaluatorInfoJsonOutput(response, entry.getValue());
        } else {
          writeEvaluatorInfoWebOutput(response, entry.getValue());
        }
        break;
      default:
        response.getWriter().println("Unsupported query : " + queryTarget);
        break;
      }
    }
  }
1034133
@Override
  public final void handle(final Map<String, Object> pRqVs,
    final IRequestData pRqDt) throws Exception {
    TradingSettings ts = srvTradingSettings
      .lazyGetTradingSettings(pRqVs);
    pRqVs.put("tradSet", ts);
    pRqVs.put("setAdd", srvSettingsAdd.lazyGetSettingsAdd(pRqVs));
    pRqDt.setAttribute("utlTradeJsp", this.utlTradeJsp);
    List<CurrRate> curRatesTmp = null;
    List<Deliv> dlvMtsTmp = null;
    if (ts.getUseAdvancedI18n()) {
      String lang = (String) pRqVs.get("lang");
      String langDef = (String) pRqVs.get("langDef");
      if (lang != null && langDef != null && !lang.equals(langDef)) {
        List<I18nWebStore> i18nTrTmp = null;
        List<I18nCatalogGs> i18nCtTmp;
        synchronized (this) {
          if (this.i18nWebStoreList == null) {
            try {
              this.logger.info(null, HndlTradeVarsRequest.class,
                "Refreshing I18N data...");
              this.srvDatabase.setIsAutocommit(false);
              this.srvDatabase.setTransactionIsolation(ISrvDatabase
                .TRANSACTION_READ_UNCOMMITTED);
              this.srvDatabase.beginTransaction();
              List<I18nWebStore> i18ntr = this.srvOrm.retrieveList(pRqVs,
                I18nWebStore.class);
              List<I18nCatalogGs> i18nct = this.srvOrm.retrieveList(pRqVs,
                I18nCatalogGs.class);
              List<CurrRate> cRnct = this.srvOrm.retrieveList(pRqVs,
                CurrRate.class);
              List<Deliv> dlvMt = getSrvOrm().retrieveList(pRqVs, Deliv.class);
              this.srvDatabase.commitTransaction();
              //assigning fully initialized data:
              this.i18nWebStoreList = i18ntr;
              this.i18nCatalogs = i18nct;
              this.currRates = cRnct;
              this.dlvMts = dlvMt;
            } catch (Exception ex) {
              if (!this.srvDatabase.getIsAutocommit()) {
                this.srvDatabase.rollBackTransaction();
              }
              throw ex;
            } finally {
              this.srvDatabase.releaseResources();
            }
          }
          i18nTrTmp = this.i18nWebStoreList;
          i18nCtTmp = this.i18nCatalogs;
          curRatesTmp = this.currRates;
          dlvMtsTmp = this.dlvMts;
        }
        pRqVs.put("i18nCatalogs", i18nCtTmp);
        pRqVs.put("i18nWebStoreList", i18nTrTmp);
      }
    }
    if (curRatesTmp == null) {
      synchronized (this) {
        try {
          this.srvDatabase.setIsAutocommit(false);
          this.srvDatabase.setTransactionIsolation(ISrvDatabase
            .TRANSACTION_READ_UNCOMMITTED);
          this.srvDatabase.beginTransaction();
          List<CurrRate> cRnct = this.srvOrm.retrieveList(pRqVs,
            CurrRate.class);
          List<Deliv> dlvMt = getSrvOrm().retrieveList(pRqVs, Deliv.class);
          this.srvDatabase.commitTransaction();
          //assigning fully initialized data:
          this.currRates = cRnct;
          this.dlvMts = dlvMt;
        } catch (Exception ex) {
          if (!this.srvDatabase.getIsAutocommit()) {
            this.srvDatabase.rollBackTransaction();
          }
          throw ex;
        } finally {
          this.srvDatabase.releaseResources();
        }
        curRatesTmp = this.currRates;
        dlvMtsTmp = this.dlvMts;
      }
    }
    pRqVs.put("currRates", curRatesTmp);
    pRqVs.put("dlvMts", dlvMtsTmp);
    Currency wscurr = null;
    if (curRatesTmp.size() > 0) {
      String wscurrs = pRqDt.getParameter("wscurr");
      if (wscurrs != null) {
        Long wscurrl = Long.parseLong(wscurrs);
        for (CurrRate cr : curRatesTmp) {
          if (cr.getCurr().getItsId().equals(wscurrl)) {
            wscurr = cr.getCurr();
            pRqDt.setCookieValue("wscurr", wscurr.getItsId().toString());
            break;
          }
        }
      } else {
        String  wscurrsc = pRqDt.getCookieValue("wscurr");
        if (wscurrsc != null) {
          Long wscurrl = Long.parseLong(wscurrsc);
          for (CurrRate cr : curRatesTmp) {
            if (cr.getCurr().getItsId().equals(wscurrl)) {
              wscurr = cr.getCurr();
              break;
            }
          }
        }
      }
    }
    if (wscurr == null) {
      AccSettings as = (AccSettings) pRqVs.get("accSet");
      wscurr = as.getCurrency();
      pRqDt.setCookieValue("wscurr", wscurr.getItsId().toString());
    }
    pRqVs.put("wscurr", wscurr);
    Boolean shTxDet;
    String shTxDets = pRqDt.getParameter("shTxDet");
    if (shTxDets == null) {
      String shTxDetsc = pRqDt.getCookieValue("shTxDet");
      if (shTxDetsc == null) {
        shTxDet = Boolean.FALSE;
        pRqDt.setCookieValue("shTxDet", shTxDet.toString());
      } else {
        shTxDet = Boolean.valueOf(shTxDetsc);
      }
    } else {
      shTxDet = Boolean.valueOf(shTxDets);
      pRqDt.setCookieValue("shTxDet", shTxDet.toString());
    }
    pRqVs.put("shTxDet", shTxDet);
  }
521452
public final void doWork(final HttpServletRequest pReq,
    final HttpServletResponse pResp) throws ServletException, IOException {
    pReq.setCharacterEncoding("UTF-8");
    pResp.setCharacterEncoding("UTF-8");
    try {
      HashMap<String, Object> reqVars = new HashMap<String, Object>();
      HttpRequestData requestData = new HttpRequestData(pReq, pResp);
      requestData.setAttribute("reqVars", reqVars);
      IHandlerRequest hndlI18nRequest = (IHandlerRequest) this
        .factoryAppBeans.lazyGet("hndlI18nRequest");
      hndlI18nRequest.handle(reqVars, requestData);
      String nmRnd = pReq.getParameter("nmRnd");
      if (this.defaultJsp != null && "index".equals(this.defaultJsp)) {
        //TODO extract into handler
        if (pReq.getParameter("logoff") != null) {
          pReq.getSession().invalidate();
        }
        @SuppressWarnings("rawtypes")
        SrvAddTheFirstUser srvAddFiU = (SrvAddTheFirstUser) getServletContext()
          .getAttribute("srvAddTheFirstUser");
        if (srvAddFiU != null && !srvAddFiU.checkIsThereAnyUser()) {
          nmRnd = "addFirstUser";
        }
      }
      if (nmRnd == null) {
        nmRnd = this.defaultJsp;
      }
      if (this.handlerName != null) {
        IHandlerRequest handleRequest = (IHandlerRequest) this
          .factoryAppBeans.lazyGet(this.handlerName);
        handleRequest.handle(reqVars, requestData);
      }
      ISrvI18n srvI18n = (ISrvI18n) this.factoryAppBeans.lazyGet("ISrvI18n");
      UtlJsp utlJsp = (UtlJsp) this.factoryAppBeans.lazyGet("UtlJsp");
      pReq.setAttribute("srvI18n", srvI18n);
      pReq.setAttribute("utlJsp", utlJsp);
      //renderer maybe overridden:
      String nmRnRd = (String) pReq.getAttribute("nmRnd");
      if (nmRnRd != null) {
        nmRnd = nmRnRd;
      }
      //processor can set redirect servlet, e.g. transactional to non-one:
      String srvlRd = (String) pReq.getAttribute("srvlRed");
      if (srvlRd != null) {
        RequestDispatcher rd = getServletContext().getRequestDispatcher(srvlRd);
        rd.forward(pReq, pResp);
      } else {
        String path = dirJsp + nmRnd + ".jsp";
        RequestDispatcher rd = getServletContext().getRequestDispatcher(path);
        rd.include(pReq, pResp);
      }
    } catch (Exception e) {
      if (this.factoryAppBeans != null) {
        ILog logger = null;
        try {
          logger = (ILog) this.factoryAppBeans.lazyGet("ILog");
          logger.error(null, getClass(), "WORK", e);
        } catch (Exception e1) {
          e1.printStackTrace();
          e.printStackTrace();
        }
      } else {
        e.printStackTrace();
      }
      if (e instanceof ExceptionWithCode) {
        pReq.setAttribute("error_code",
          ((ExceptionWithCode) e).getCode());
        pReq.setAttribute("short_message",
          ((ExceptionWithCode) e).getShortMessage());
      } else {
        pReq.setAttribute("error_code",
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      }
      pReq.setAttribute("javax.servlet.error.status_code",
        HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      pReq.setAttribute("javax.servlet.error.exception", e);
      pReq.setAttribute("javax.servlet.error.request_uri",
        pReq.getRequestURI());
      pReq.setAttribute("javax.servlet.error.servlet_name", this.getClass()
        .getCanonicalName());
      pResp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
63096
public void processRequest(RequestEvent requestEvent) {
        // This will be invoked only by external endpoint
    	BalancerAppContent content=(BalancerAppContent)requestEvent.getSource();
    	boolean isIpv6 = content.isIpv6();
        final SipProvider sipProvider = content.getProvider();
        final Request request = requestEvent.getRequest();
        final String requestMethod = request.getMethod();

        if(logger.isDebugEnabled()) {
            logger.debug("got request:\n"+request);
        }
        
        if((requestMethod.equals(Request.OPTIONS) ||
                requestMethod.equals(Request.INFO)) &&
                request.getHeader("Mobicents-Heartbeat") != null &&
                sipProvider == balancerRunner.balancerContext.internalSipProvider) {
            byte[] bytes = (byte[]) request.getContent();
            Properties prop = new Properties();
            try {
                prop.load(new ByteArrayInputStream(bytes, 0, bytes.length));
                Node node = new Node(prop.getProperty("hostname"), prop.getProperty("ip"));
                for(String id : prop.stringPropertyNames()) {
                    node.getProperties().put(id, prop.getProperty(id));
                }
                ArrayList<Node> list = new ArrayList<Node>();
                list.add(node);
                this.register.handlePingInRegister(list);
                Response response = balancerRunner.balancerContext.messageFactory.createResponse(Response.OK, request);			
                sipProvider.sendResponse(response);	
                return;
            } catch (Exception e) {
                logger.error("Failure parsing heartbeat properties from this request " + request, e);
            }
        }
        //Issue 10: https://telestax.atlassian.net/browse/LB-10
        if (request.getContent() != null || (requestMethod.equals(Request.REGISTER) && sipProvider != balancerRunner.balancerContext.internalSipProvider)) {
            SIPMessage message = (SIPMessage)request;            

            String initialRemoteAddr = message.getPeerPacketSourceAddress().getHostAddress();
            String initialRemotePort = String.valueOf(message.getPeerPacketSourcePort());

            Header remoteAddrHeader = null;
            Header remotePortHeader = null;
            try {
                remoteAddrHeader = SipFactory.getInstance().createHeaderFactory().createHeader("X-Sip-Balancer-InitialRemoteAddr", initialRemoteAddr);
                remotePortHeader = SipFactory.getInstance().createHeaderFactory().createHeader("X-Sip-Balancer-InitialRemotePort", initialRemotePort);
            } catch (PeerUnavailableException e) {
                logger.error("Unexpected exception while creating custom headers for REGISTER message ", e);
            } catch (ParseException e) {
                logger.error("Unexpected exception while creating custom headers for REGISTER message ", e);
            }
            if (remoteAddrHeader != null)
                request.addHeader(remoteAddrHeader);
            if (remotePortHeader != null)
                request.addHeader(remotePortHeader);
        } 
        try {	
            updateStats(request);
            forwardRequest(sipProvider,request, isIpv6);          						
        } catch (Throwable throwable) {
            logger.error("Unexpected exception while forwarding the request " + request, throwable);
            if(!Request.ACK.equalsIgnoreCase(requestMethod)) {
                try {
                    Response response = balancerRunner.balancerContext.messageFactory.createResponse(Response.SERVER_INTERNAL_ERROR, request);			
                    sipProvider.sendResponse(response);	
                } catch (Exception e) {
                    logger.error("Unexpected exception while trying to send the error response for this " + request, e);
                }
            }
        }
    }
677002
public void execute() throws Exception {
        ActionRequest request = requestBuilder.request();

        //todo: maby change to instanceof multi?
        if(requestBuilder instanceof JoinRequestBuilder){
            executeJoinRequestAndSendResponse();
        }
		else if (request instanceof SearchRequest) {
			client.search((SearchRequest) request, new RestStatusToXContentListener<SearchResponse>(channel));
		} else if (requestBuilder instanceof SqlElasticDeleteByQueryRequestBuilder) {
            throw new UnsupportedOperationException("currently not support delete on elastic 2.0.0");
        }
        else if(request instanceof GetIndexRequest) {
            this.requestBuilder.getBuilder().execute( new GetIndexRequestRestListener(channel, (GetIndexRequest) request));
        }


		else {
			throw new Exception(String.format("Unsupported ActionRequest provided: %s", request.getClass().getName()));
		}
	}
1091581
public final void saveOrds(final Map<String, Object> pRqVs,
    final Purch pPur, final Cart pCart) throws Exception {
    List<CustOrder> dels = null;
    for (CustOrder co : pPur.getOrds()) {
      if (co.getCurr() == null) { //stored unused order
        //remove it and all its lines:
        for (CustOrderGdLn gl : co.getGoods()) {
          for (CuOrGdTxLn gtl : gl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, gtl);
          }
          getSrvOrm().deleteEntity(pRqVs, gl);
        }
        for (CustOrderSrvLn sl : co.getServs()) {
          for (CuOrSrTxLn stl : sl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, stl);
          }
          getSrvOrm().deleteEntity(pRqVs, sl);
        }
        for (CustOrderTxLn otlt : co.getTaxes()) {
          getSrvOrm().deleteEntity(pRqVs, otlt);
        }
        getSrvOrm().deleteEntity(pRqVs, co);
        if (dels == null) {
          dels = new ArrayList<CustOrder>();
        }
        dels.add(co);
        continue;
      }
      if (co.getIsNew()) {
        getSrvOrm().insertEntity(pRqVs, co);
      }
      BigDecimal tot = BigDecimal.ZERO;
      BigDecimal subt = BigDecimal.ZERO;
      List<CustOrderGdLn> delsGd = null;
      for (CustOrderGdLn gl : co.getGoods()) {
        gl.setItsOwner(co);
        if (gl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, gl);
        }
        if (gl.getItTxs() != null && gl.getItTxs().size() > 0) {
          for (CuOrGdTxLn gtl : gl.getItTxs()) {
            gtl.setItsOwner(gl);
            if (gtl.getIsNew()) {
              getSrvOrm().insertEntity(pRqVs, gtl);
            } else if (gl.getGood() == null || gtl.getTax() == null) {
              getSrvOrm().deleteEntity(pRqVs, gtl);
            } else {
              getSrvOrm().updateEntity(pRqVs, gtl);
            }
          }
        }
        if (!gl.getIsNew() && gl.getGood() == null) {
          getSrvOrm().deleteEntity(pRqVs, gl);
          if (delsGd == null) {
            delsGd = new ArrayList<CustOrderGdLn>();
          }
          delsGd.add(gl);
        } else {
          tot = tot.add(gl.getTot());
          subt = subt.add(gl.getSubt());
          if (!gl.getIsNew()) {
            getSrvOrm().updateEntity(pRqVs, gl);
          }
        }
      }
      if (delsGd != null) {
        for (CustOrderGdLn gl : delsGd) {
          co.getGoods().remove(gl);
        }
      }
      List<CustOrderSrvLn> delsSr = null;
      for (CustOrderSrvLn sl : co.getServs()) {
        sl.setItsOwner(co);
        if (sl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, sl);
        }
        if (sl.getItTxs() != null && sl.getItTxs().size() > 0) {
          for (CuOrSrTxLn stl : sl.getItTxs()) {
            stl.setItsOwner(sl);
            if (stl.getIsNew()) {
              getSrvOrm().insertEntity(pRqVs, stl);
            } else if (sl.getService() == null || stl.getTax() == null) {
              getSrvOrm().deleteEntity(pRqVs, stl);
            } else {
              getSrvOrm().updateEntity(pRqVs, stl);
            }
          }
        }
        if (!sl.getIsNew() && sl.getService() == null) {
          getSrvOrm().deleteEntity(pRqVs, sl);
          if (delsSr == null) {
            delsSr = new ArrayList<CustOrderSrvLn>();
          }
          delsSr.add(sl);
        } else {
          tot = tot.add(sl.getTot());
          subt = subt.add(sl.getSubt());
          if (!sl.getIsNew()) {
            getSrvOrm().updateEntity(pRqVs, sl);
          }
        }
      }
      if (delsSr != null) {
        for (CustOrderSrvLn sl : delsSr) {
          co.getServs().remove(sl);
        }
      }
      List<CustOrderTxLn> delsTx = null;
      BigDecimal totTx = BigDecimal.ZERO;
      for (CartTxLn ctl : pCart.getTaxes()) {
        if (ctl.getDisab() || ctl.getSeller() != null) {
          continue;
        }
        CustOrderTxLn otl = null;
        if (!co.getIsNew()) {
          for (CustOrderTxLn otlt : co.getTaxes()) {
            if (otlt.getTax() == null) {
              otl = otlt;
              break;
            }
          }
        }
        if (otl == null) {
          otl = new CustOrderTxLn();
          otl.setIsNew(true);
          co.getTaxes().add(otl);
        }
        otl.setItsOwner(co);
        Tax tx = new Tax();
        tx.setItsId(ctl.getTax().getItsId());
        tx.setItsName(ctl.getTax().getItsName());
        otl.setTax(tx);
        otl.setTot(ctl.getTot());
        otl.setTaxab(ctl.getTaxab());
        totTx = totTx.add(otl.getTot());
        if (otl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, otl);
        } else {
          getSrvOrm().updateEntity(pRqVs, otl);
        }
      }
      if (!co.getIsNew()) {
        for (CustOrderTxLn otlt : co.getTaxes()) {
          if (otlt.getTax() == null) {
            getSrvOrm().deleteEntity(pRqVs, otlt);
            if (delsTx == null) {
              delsTx = new ArrayList<CustOrderTxLn>();
            }
            delsTx.add(otlt);
          }
        }
      }
      if (delsTx != null) {
        for (CustOrderTxLn tl : delsTx) {
          co.getTaxes().remove(tl);
        }
      }
      co.setTot(tot);
      co.setSubt(subt);
      co.setTotTx(totTx);
      getSrvOrm().updateEntity(pRqVs, co);
    }
    if (dels != null) {
      for (CustOrder co : dels) {
        pPur.getOrds().remove(co);
      }
    }
  }
256964
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    String itemType = pRequestData.getParameter("itemType");
    if (InvItem.class.getSimpleName().equals(itemType)) {
      makeIt(pAddParam, pRequestData, InvItem.class);
    } else if (ServiceToSale.class.getSimpleName().equals(itemType)) {
      makeIt(pAddParam, pRequestData, ServiceToSale.class);
    } else {
      throw new Exception("NYI: " + itemType);
    }
  }
239132
public void doProcess(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        Utility.getLogger().info("doProcess called in xmlws servlet");
        XMLMessageTransport xmlMessageTransport = null;
        ServletTask servletTask = null;
        BaseMessage msgReplyInternal = null;
        try {
            Map<String,Object> properties = m_initProperties;
        	String strDomain = BaseHttpTask.getParam(req, DBParams.DOMAIN);
        	if (strDomain != null)
        	{
		        properties = new HashMap<String,Object>();
		        if (m_initProperties != null)
		        	properties.putAll(m_initProperties);
				properties.put(DBParams.DOMAIN, strDomain);
        	}
            servletTask = new ServletTask(this, BasicServlet.SERVLET_TYPE.XML);
            servletTask.setProperties(properties);
            Environment env = null;
            if (servletTask.getApplication() != null)
                env = ((BaseApplication)servletTask.getApplication()).getEnvironment();
            if (env == null)
                env = Environment.getEnvironment(null);
            App app = env.getMessageApplication(true, properties);
            servletTask.setApplication(app);

            xmlMessageTransport = new XMLMessageTransport(servletTask);
            InputStream inStream = req.getInputStream();	// .getReader();
            Reader in = new InputStreamReader(inStream);
            String message = Utility.transferURLStream(null, null, in, null);
            try   {
                message = URLDecoder.decode(message, DBConstants.URL_ENCODING);
            } catch (java.io.UnsupportedEncodingException ex) {
                ex.printStackTrace();
            }
            //xMap<String,Object> properties = PropertiesField.stringToProperties(message);
            if (message.startsWith("xml="))	// Always
                message = message.substring(4);
            Map<String, Object> propMessage = null;
            if (message.length() == 0)
            {
            	Enumeration<?> names = req.getParameterNames();
            	while (names.hasMoreElements())
            	{
            		String key = names.nextElement().toString();
            		if ("xml".equalsIgnoreCase(key))
            			message = (String)req.getParameter(key);
            		else
            		{
            			if (propMessage == null)
            				propMessage = new HashMap<String, Object>();
            			propMessage.put(key, req.getParameter(key));	// RESTful params
            		}
            	}
            }

            BaseMessage messageIn = new TreeMessage(null, null);
            new XmlTrxMessageIn(messageIn, message);
            if (propMessage != null)
            {
            	for (String key : propMessage.keySet())
            	{
            		messageIn.put(key, propMessage.get(key));
            	}
            }

            msgReplyInternal = xmlMessageTransport.processIncomingMessage(messageIn, null);
            Utility.getLogger().info("msgReplyInternal: " + msgReplyInternal);

            int iErrorCode = xmlMessageTransport.convertToExternal(msgReplyInternal, null);
            Utility.getLogger().info("externalMessageReply: " + msgReplyInternal);

            if (iErrorCode == DBConstants.NORMAL_RETURN)
            {
            	if (msgReplyInternal.getExternalMessage() != null)
            	{	// Always
	                String strReply = msgReplyInternal.getExternalMessage().toString();
    	            res.getWriter().print(strReply);
        	        String strTrxID = (String)msgReplyInternal.getMessageHeader().get(TrxMessageHeader.LOG_TRX_ID);
            	    xmlMessageTransport.logMessage(strTrxID, msgReplyInternal, MessageInfoTypeModel.REPLY, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.SENTOK, null, null);    // Sent (no reply required)
            	}
            }
        } catch (Throwable ex)  {
            ex.printStackTrace();
            String strError = "Error in processing or replying to a message";
            Utility.getLogger().warning(strError);
            if ((msgReplyInternal != null) && (xmlMessageTransport != null))
            {
                String strTrxID = (String)msgReplyInternal.getMessageHeader().get(TrxMessageHeader.LOG_TRX_ID);
                xmlMessageTransport.logMessage(strTrxID, msgReplyInternal, MessageInfoTypeModel.REPLY, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.ERROR, strError, null);
            }
            return; // Error
        } finally   {
            if (xmlMessageTransport != null)
            {
                xmlMessageTransport.free();
                xmlMessageTransport = null;
            }
            if (servletTask != null)
                servletTask.free();
        }
    }