public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    logger.info("******Inside ProductDisplayAction...........");
    ProductDisplayForm theform = null;
    Collection colln = new ArrayList();

    String ndc = request.getParameter("NDC");
    System.out.println("NDC : " + ndc);
    String lotNumber = request.getParameter("lotnum");
    String pedId = request.getParameter("PedigreeId");
    String envId = (String) request.getAttribute("envId");
    logger.info(" NDC =" + ndc);
    logger.info("lotnumber =" + lotNumber);

    try {

      HttpSession sess = request.getSession();
      Helper helper = new Helper();
      clientIP = request.getRemoteAddr();

      Conn = helper.ConnectTL();
      stmt = helper.getStatement(Conn);
      logger.info("Validating The Session");

      // Validating Session
      String sessionID = (String) sess.getAttribute("sessionID");
      logger.info("sessionID in ProductDisplayAction :" + sessionID);
      String validateResult = helper.ValidateUserSession(stmt, sessionID, clientIP);

      if (!validateResult.equals("VALID")) {
        // return a forward to invalid .
        return mapping.findForward("loginPage");
      }

      StringBuffer buf = new StringBuffer();
      // buf.append("tlsp:GetProductId('','')");
      buf.append("for $i in collection('tig:///ePharma/ShippedPedigree')/PedigreeEnvelope ");
      buf.append("where $i/pedigree/shippedPedigree/documentInfo/serialNumber = '" + pedId + "' ");
      buf.append(
          "return <output> <ProductName>{data($i/pedigree/shippedPedigree/initialPedigree/productInfo/drugName)}</ProductName></output> ");
      System.out.println("Query in product display action : " + buf.toString());
      Statement Stmt = helper.getStatement(Conn);

      Enumeration enu = request.getParameterNames();
      while (enu.hasMoreElements()) {
        String str = (String) enu.nextElement();
        logger.info("Str =" + str + "=" + request.getParameter(str));
      }

      List list = (List) queryRunner.executeQuery(buf.toString());

      if (list.size() > 1) {

        return mapping.findForward("successddd");

      } else {
        Node node = XMLUtil.parse((ByteArrayInputStream) list.get(0));
        if (node != null) {

          String productName = XMLUtil.getValue(node, "ProductName");
          System.out.println("Product Name in action : " + productName);
          StringBuffer bfr = new StringBuffer();
          bfr.append(
              " declare namespace bin='http://www.rainingdata.com/TigerLogic/binary-support'; declare binary-encoding none; ");
          /* bfr.append(" for $k in collection('tig:///EAGRFID/Products')[ProductName =  "+productName+"]");
             bfr.append(" for $k in collection ('tig:///EAGRFID/Products')/Product");
          bfr.append(" for $D in collection('tig:///EAGRFID/ProductImage')/Location");
             bfr.append(" where data($D/ID) = data($k/genId) and data($k/ProductName) = '"+productName+"'");
             bfr.append(" return $D/LocIMG/binary() ");
            */

          bfr.append(
              "for $K in collection('tig:///EAGRFID/Products')/Product[ProductName = '"
                  + productName
                  + "' ] ");
          bfr.append(
              " for $D in collection('tig:///EAGRFID/ProductImage')/Product[ID = $K/ProductID]");
          bfr.append(
              " return  if( exists($D/ProdIMG/binary()) ) then $D/ProdIMG/binary() else   bin:base64-decode( $D/ProdIMG ) ");
          System.out.println("Query for getting image: " + bfr.toString());
          logger.info(" Query " + bfr.toString());
          logger.info("query =" + bfr);

          byte[] xmlResults = helper.ReadTL(Stmt, bfr.toString());
          if (xmlResults != null) {
            String str = sess.getServletContext().getRealPath(request.getContextPath());
            logger.info(str + "\\..");
            File file = new File(str + "\\..\\images\\" + productName);
            logger.info("Path =" + file.getAbsolutePath());
            System.out.println("Path : " + file.getAbsolutePath());
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(xmlResults);
            Thread.sleep(2000);
            fos.flush();
            fos.close();
          }
          request.setAttribute("imagefile", "..\\..\\images\\" + productName);
        }
        request.setAttribute("productlists", node);
        StringBuffer buffer = new StringBuffer();
        buffer.append("tlsp:GetProductId('" + pedId + "')");
        System.out.println("Query for getting product id: " + buffer.toString());
        List result = queryRunner.returnExecuteQueryStrings(buffer.toString());
        if (result.size() > 0) {
          String prodId = (String) result.get(0).toString();
          System.out.println("Product Id in action: " + prodId);
          request.setAttribute("ProdId", prodId);
        }
        StringBuffer buff = new StringBuffer();
        buff.append("tlsp:GetProductDetails('" + envId + "','" + pedId + "','" + ndc + "')");
        System.out.println("Query for getting product details: " + buff.toString());
        List res = queryRunner.executeQuery(buff.toString());

        colln = new ArrayList();
        for (int i = 0; i < res.size(); i++) {

          theform = new ProductDisplayForm();
          Node listNode = XMLUtil.parse((InputStream) res.get(i));
          System.out.println("listNode :" + listNode);

          theform.setDosageForm(CommonUtil.jspDisplayValue(listNode, "Product/DosageForm"));
          System.out.println("Dosage form: " + theform.getDosageForm());
          theform.setDosageStrength(CommonUtil.jspDisplayValue(listNode, "Product/DosageStrength"));
          theform.setEpc(CommonUtil.jspDisplayValue(listNode, "Product/EPC"));
          theform.setMfrDate(CommonUtil.jspDisplayValue(listNode, "Product/DosageForm"));
          theform.setMfrName(CommonUtil.jspDisplayValue(listNode, "Product/ManufacturerName"));
          theform.setNdc(CommonUtil.jspDisplayValue(listNode, "Product/NDC"));
          theform.setPbc(CommonUtil.jspDisplayValue(listNode, "Product/BarCode"));
          theform.setProdName(CommonUtil.jspDisplayValue(listNode, "Product/ProductName"));
          theform.setUpc(CommonUtil.jspDisplayValue(listNode, "Product/PackageUPC"));
          colln.add(theform);
          request.setAttribute("Result", listNode);
        }

        request.setAttribute(Constants.PRODUCTDISPLAY_DETAILS, colln);

        return mapping.findForward("success");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      logger.error("Error in ProductDisplayAction  execute()" + ex);
      return mapping.findForward("exception");
    }
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    Collection colln = new ArrayList();
    EnvelopeForm theForm = null;
    try {

      HttpSession sess = request.getSession();
      Helper helper = new Helper();
      clientIP = request.getRemoteAddr();

      conn = helper.ConnectTL();
      stmt = helper.getStatement(conn);
      log.info("Validating The Session");

      // Validating Session
      String sessionID = (String) sess.getAttribute("sessionID");
      log.info("sessionID in Action :" + sessionID);
      String validateResult = helper.ValidateUserSession(stmt, sessionID, clientIP);

      if (!validateResult.equals("VALID")) {
        // return a forward to invalid .
        return mapping.findForward("loginPage");
      }

      String envelopeid = request.getParameter("envelopeId");
      sess.setAttribute("envId", envelopeid);

      String buff1 = "tlsp:ShippingMgnrEnvelopesDisplay_MD('" + envelopeid + "')";
      System.out.println("Query for getting envelope details: " + buff1);
      String enveloped = "tlsp:ShippingMgnrEnvelopeDetails_MD('" + envelopeid + "')";
      System.out.println("Query for getting envelope details: " + enveloped);
      List list1 = queryRunner.returnExecuteQueryStrings(buff1.toString());
      request.setAttribute("envDetails", list1);
      List list2 = queryRunner.returnExecuteQueryStrings(enveloped);
      request.setAttribute("envId", list2);
      colln = new ArrayList();
      theForm = (EnvelopeForm) form;
      Node listNode1 = XMLUtil.parse((String) list2.get(0));

      theForm.setEnvelopeID(CommonUtil.jspDisplayValue(listNode1, "EnvelopeID"));
      theForm.setDate(CommonUtil.jspDisplayValue(listNode1, "Date"));
      String transDateAndTime = CommonUtil.jspDisplayValue(listNode1, "Date");
      String result[] = StringUtils.split(transDateAndTime, "T");
      String date = result[0];
      request.setAttribute("date", date);
      if (result.length > 1) {
        String time = result[1];
        request.setAttribute("time", time);
      } else {
        String time = "N/A";
        request.setAttribute("time", time);
      }

      theForm.setSource(CommonUtil.jspDisplayValue(listNode1, "source"));
      theForm.setDestination(CommonUtil.jspDisplayValue(listNode1, "destination"));

      for (int i = 0; i < list1.size(); i++) {
        theForm = new EnvelopeForm();
        Node listNode = XMLUtil.parse((String) list1.get(i));
        theForm.setContainercode(CommonUtil.jspDisplayValue(listNode, "containerCode"));
        theForm.setPedigreeID(CommonUtil.jspDisplayValue(listNode, "pedigreeid"));
        theForm.setQuantity(CommonUtil.jspDisplayValue(listNode, "Quantity"));
        theForm.setLotnumber(CommonUtil.jspDisplayValue(listNode, "LotNum"));
        theForm.setStatus(CommonUtil.jspDisplayValue(listNode, "status"));
        theForm.setTransactiondate(CommonUtil.jspDisplayValue(listNode, "TransactionDate"));
        String trandate = CommonUtil.jspDisplayValue(listNode, "TransactionDate");
        String trdate[] = StringUtils.split(trandate, "T");
        String trnsdate = trdate[0];
        request.setAttribute("trnsDate", trnsdate);
        if (trdate.length > 1) {
          String trnstime = trdate[1];
          request.setAttribute("transTime", trnstime);
        } else {
          String trnstime = "N/A";
          request.setAttribute("transTime", trnstime);
        }
        theForm.setDrugname(CommonUtil.jspDisplayValue(listNode, "DrugName"));
        theForm.setDrugcode(CommonUtil.jspDisplayValue(listNode, "DrugCode"));
        theForm.setAttachment(CommonUtil.jspDisplayValue(listNode, "Attachement"));
        theForm.setCount(CommonUtil.jspDisplayValue(listNode, "count"));

        colln.add(theForm);
      }

      request.setAttribute(Constants.ENVELOPE_DETAILS, colln);
      sess.setAttribute("envId", envelopeid);

    } catch (Exception ex) {

      ex.printStackTrace();
      log.error("Error in OrderSearchAction execute method........." + ex);
      return mapping.findForward("exception");
    }
    return mapping.findForward("success");
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    try {
      log.info("Inside AuthenticatePedigreesReceivingAction execute Method");
      HttpSession sess = request.getSession();
      Helper helper = new Helper();
      clientIP = request.getRemoteAddr();

      conn = helper.ConnectTL();
      stmt = helper.getStatement(conn);
      System.out.println("validating The Session");

      // Validating Session
      String sessionID = (String) sess.getAttribute("sessionID");
      System.out.println("sessionID in Action :" + sessionID);
      String validateResult = helper.ValidateUserSession(stmt, sessionID, clientIP);

      if (!validateResult.equals("VALID")) {
        // return a forward to invalid .
        return mapping.findForward("loginPage");
      }

      // envelopeId
      envelopeId = request.getParameter("check");
      System.out.println("The envelopeId from form in Not Authentic is " + envelopeId);

      // For Access Priveleges.
      String validate = "tlsp:validateAccess('" + sessionID + "','8.0','Insert')";
      log.info("Query for getting Access" + validate);
      List accessList = queryRunner.returnExecuteQueryStrings(validate);
      String insertStatus = accessList.get(0).toString();
      System.out.println("The insertStatus is " + insertStatus);

      if (insertStatus.equalsIgnoreCase("false")) {
        return mapping.findForward("failure");
      }

      if (envelopeId != null) {

        boolean authentic = true;
        String statusOfPedigrees = "tlsp:getStatusOfPedigrees('" + envelopeId + "')";
        log.info("Query for getting Status of Pedigrees" + statusOfPedigrees);
        List pedigreesStatus = queryRunner.returnExecuteQueryStrings(statusOfPedigrees);
        System.out.println(
            "Pedigrees status list is "
                + pedigreesStatus
                + " its size is "
                + pedigreesStatus.size());
        if (pedigreesStatus.size() == 0) {

          StringBuffer buff = new StringBuffer();
          buff.append(
              "for $ped in collection ('tig:///ePharma/ReceivedPedigree')"
                  + "/*:pedigreeEnvelope[*:serialNumber = '"
                  + envelopeId
                  + "'] ");
          buff.append(
              "return data($ped/*:pedigree/*:shippedPedigree/*:documentInfo/*:serialNumber)");
          log.info("The query for getting pedigrees is " + buff.toString());
          System.out.println("The query for getting pedigrees is " + buff.toString());
          List pedigrees = queryRunner.returnExecuteQueryStrings(buff.toString());
          System.out.println("The pedigrees list size is " + pedigrees.size());

          for (int i = 0; i < pedigrees.size(); i++) {
            String pedigreeId = (String) pedigrees.get(i);
            String changeStatus =
                "tlsp:InsertAndChangeStatus('"
                    + pedigreeId
                    + "','Authenticated','"
                    + sessionID
                    + "')";
            log.info("The query for InsertAndChangeStatus of pedigrees is " + changeStatus);
            List pedigreestatus = queryRunner.returnExecuteQueryStrings(changeStatus);
            System.out.println("The Document in pedigree status is " + pedigreestatus);
          }
        } else {

          authentic = authenticateStatus(pedigreesStatus);
          System.out.println("Authentic value is: " + authentic);
          if (authentic == true) {
            return mapping.findForward("alreadyAuthenticated");
          } else {
            return mapping.findForward("alreadyAuthenticated");
          }
        }
      }

    } catch (PersistanceException e) {
      log.error("Error in AuthenticatePedigreesReceivingAction execute method........." + e);
      throw new PersistanceException(e);
    } catch (Exception ex) {
      ex.printStackTrace();
      log.error("Error in AuthenticatePedigreesReceivingAction execute method........." + ex);
      throw new Exception(ex);
    }
    return mapping.findForward("success");
  }
Example #4
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws PersistanceException {

    log.info("Inside Action OrderSearchAction class....... ");

    try {

      HttpSession sess = request.getSession();
      clientIP = request.getRemoteAddr();

      conn = helper.ConnectTL();
      stmt = helper.getStatement(conn);
      log.info("Validating The Session");

      // Validating Session
      String sessionID = (String) sess.getAttribute("sessionID");
      log.info("sessionID in Action :" + sessionID);
      String validateResult = helper.ValidateUserSession(stmt, sessionID, clientIP);

      if (!validateResult.equals("VALID")) {
        // return a forward to invalid .
        return mapping.findForward("loginPage");
      }

      StringBuffer buf = new StringBuffer();
      buf.append("for $i in collection('tig:///CatalogManager/TradingPartner')/TradingPartner ");
      buf.append("return data($i/name) ");
      List tpNames = queryRunner.returnExecuteQueryStrings(buf.toString());
      System.out.println("TP Names : " + tpNames.toString());
      sess.setAttribute("tpNames", tpNames);

      String accessLevel = null;
      accessLevel = request.getParameter("accesslevel");
      if (accessLevel.equalsIgnoreCase("ordersearch") || accessLevel != null) {
        List accessList =
            queryRunner.returnExecuteQueryStrings(
                "tlsp:validateAccess('" + sessionID + "','2.07','Read')");
        String readStatus = accessList.get(0).toString();
        log.info("The readStatus is : " + readStatus);
        if (readStatus.equalsIgnoreCase("false")) {
          request.setAttribute("status", "false");
          return mapping.findForward("failure");
        }
      }

      String fromDT = request.getParameter("fromDT");
      String toDT = request.getParameter("toDT");
      String lotNum = request.getParameter("lotNum");
      String prodNDC = request.getParameter("prodNDC");
      String orderNum = request.getParameter("orderNum");
      log.info("ORderNumber entered is :  " + orderNum);
      String apndocId = request.getParameter("apndocId");
      String tpName = request.getParameter("tpName");
      if (tpName == null || tpName.equalsIgnoreCase("SelectOne..")) {
        tpName = "";
      }
      Collection colln = new ArrayList();

      log.info(
          "  -------- fromDT:   " + fromDT + "  ---toDT :  " + toDT + "  ---- lotNum: " + lotNum);
      log.info(
          "  -------- prodNDC:   "
              + prodNDC
              + "  ---orderNum :  "
              + orderNum
              + "  ---- apndocId: "
              + apndocId
              + "---- tpName: "
              + tpName);

      boolean apnQueryFlag = false;

      StringBuffer orderCriteria = new StringBuffer();

      StringBuffer apnCriteria = new StringBuffer();

      // if apn docid entered we need to get the order id from the
      // apn document

      if (apndocId != null && !apndocId.trim().equalsIgnoreCase("")) {
        //			apnQueryFlag = true;

        String buyersId =
            queryRunner.returnExecuteQueryStringsAsString("tlsp:getBuyersId('" + apndocId + "')");
        System.out.println("The transaction Number is :" + buyersId);

        // add to apn criteria
        apnCriteria.append(" $k/DocumentId='");
        apnCriteria.append(apndocId);
        apnCriteria.append("' ");

        // add to order criteria also
        orderCriteria.append("and ");
        orderCriteria.append(" $a/BuyersID = '" + buyersId + "' ");

      } else {

        if (orderNum != null && !orderNum.trim().equalsIgnoreCase("")) {
          orderCriteria.append("and ");
          orderCriteria.append("$a/BuyersID='");
          orderCriteria.append(orderNum);
          orderCriteria.append("' ");
        }
      }

      if (prodNDC != null && !prodNDC.trim().equalsIgnoreCase("")) {
        orderCriteria.append("and ");
        orderCriteria.append(" $a/OrderLine/LineItem/Item/SellersItemIdentification/ID='");
        orderCriteria.append(prodNDC);
        orderCriteria.append("' ");
      }

      if (tpName != null && !tpName.trim().equalsIgnoreCase("")) {
        orderCriteria.append("and ");
        orderCriteria.append(" $a/BuyerParty/PartyName/Name='");
        orderCriteria.append(tpName);
        orderCriteria.append("' ");
      }

      if (toDT != null && !toDT.trim().equalsIgnoreCase("")) {
        orderCriteria.append("and ");

        if (fromDT == null || fromDT.trim().equalsIgnoreCase("")) {
          fromDT = df.format(new java.util.Date());
        }

        orderCriteria.append("  $a/IssueDate >='");
        orderCriteria.append(fromDT + "T00:00:00");
        orderCriteria.append("' ");

        orderCriteria.append(" and $a/IssueDate <='");
        orderCriteria.append(toDT + "T23:59:59");
        orderCriteria.append("' ");
      }

      if (lotNum != null && !lotNum.trim().equalsIgnoreCase("")) {
        orderCriteria.append("and ");
        orderCriteria.append(" $a/OrderLine/LineItem/Item/LotIdentification='");
        orderCriteria.append(lotNum);
        orderCriteria.append("' ");
      }

      String orderCriteriaStr = orderCriteria.toString().trim();

      log.info(" criteriaStr :" + orderCriteriaStr);
      if (orderCriteriaStr.startsWith("and")) {
        // remove 'and'
        orderCriteriaStr = orderCriteriaStr.substring(3, orderCriteriaStr.length());
      }

      // out put XML string
      StringBuffer outputQuery = new StringBuffer();

      outputQuery.append(" return <Output> ");
      outputQuery.append(" <BuyersID> {data($a/BuyersID)}  </BuyersID> ");
      outputQuery.append(" <IssueDate> {data($a/IssueDate)}  </IssueDate> ");
      outputQuery.append(
          " <TradingPartner>{ data($a/BuyerParty/PartyName/Name) } </TradingPartner> ");
      outputQuery.append(
          " <TotalNumOfNDCs> {count(distinct-values($a/OrderLine/LineItem/Item/SellersItemIdentification/ID)) }</TotalNumOfNDCs>");
      outputQuery.append(" <TotalLineItems>{count($a/OrderLine/LineItem)} </TotalLineItems>");
      outputQuery.append(" <OrderAmount> { data($a/LineExtensionTotalAmount)}  </OrderAmount>");
      outputQuery.append(" {$a/BuyerParty/Address }");
      outputQuery.append(" </Output>");

      // construct final query with all part queries
      StringBuffer finalQuery = new StringBuffer();

      //		if(apnQueryFlag) {
      //			finalQuery.append("for $k in collection('tig:///ePharma/APN')/APN");
      //			finalQuery.append(" where ");
      //			finalQuery.append(apnCriteria.toString());
      //			finalQuery.append(" return ");
      //		}

      // constructs Order query
      StringBuffer orderquery = new StringBuffer();
      orderquery.append(" for $a in collection('tig:///ePharma/Orders')/Order ");

      if (orderCriteriaStr.length() > 0) {
        orderquery.append(" where  ");
        orderquery.append(orderCriteriaStr);
      } else {
        orderquery.append("where $a/BuyersID = '' ");
      }

      // add order part of teh query
      finalQuery.append(orderquery.toString());

      // add output query
      finalQuery.append(outputQuery.toString());

      log.info(" Query in OrderSearchAction : " + finalQuery.toString());

      List list = queryRunner.executeQuery(finalQuery.toString());
      log.info("Result in OrderSearchAction.........." + list.size());

      // set the results
      sess.setAttribute("List", list);

      for (int i = 0; i < list.size(); i++) {

        OrderSearchForm theForm = new OrderSearchForm();
        Node listNode = XMLUtil.parse((InputStream) list.get(i));

        theForm.setOrderNum(CommonUtil.jspDisplayValue(listNode, "BuyersID"));
        // theForm.setOrderNum(CommonUtil.jspDisplayValue(listNode,"orderNum"));
        log.info("Order NUmber is:" + theForm.getOrderNum());
        theForm.setIssueDate(CommonUtil.jspDisplayValue(listNode, "IssueDate"));
        log.info("Issue Date is:" + theForm.getIssueDate());
        theForm.setTradingPartner(CommonUtil.jspDisplayValue(listNode, "TradingPartner"));
        log.info("TradingPartner is:" + theForm.getTradingPartner());
        theForm.setNumOfNDCs(CommonUtil.jspDisplayValue(listNode, "TotalNumOfNDCs"));
        log.info("Number of NDCs is:" + theForm.getNumOfNDCs());
        theForm.setNumOfLineItems(CommonUtil.jspDisplayValue(listNode, "TotalLineItems"));
        log.info("Number of LineItems is:" + theForm.getNumOfLineItems());
        theForm.setAmount(CommonUtil.jspDisplayValue(listNode, "OrderAmount"));
        log.info("Order Amount is:" + theForm.getAmount());
        theForm.setAddress(CommonUtil.jspDisplayValue(listNode, "Address"));
        log.info("Address is:" + theForm.getAddress());

        // theForm.setScreenEnteredDate(screenEnteredDate);
        colln.add(theForm);
      }

      log.info("Before returning to success");
      request.setAttribute(Constants.ORDER_DETAILS, colln);

    } catch (Exception ex) {
      ex.printStackTrace();
      log.error("Error in OrderSearchAction execute method........." + ex);
      return mapping.findForward("exception");
    } finally {
      // close the connection
      helper.CloseConnectionTL(conn);
    }
    return mapping.findForward("success");
  }