Пример #1
0
  public String getRepackageXSLString(String str, String pedigreeID, String uri) throws Exception {

    StringBuffer buffer = new StringBuffer("<shippedPedigree>");

    Node n1 = XMLUtil.parse(str);
    Node n2 = XMLUtil.getNode(n1, "/shippedPedigree");

    String strName = XMLUtil.getValue(n2, "signatureInfo/signerInfo/name");
    String signEmail = XMLUtil.getValue(n2, "signatureInfo/signerInfo/email");

    // adding business name
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "transactionInfo/senderInfo/businessAddress/businessName"), true));

    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/drugName"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/strength"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/dosageForm"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/containerSize"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/productCode"), true));
    if ((XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/manufacturer")) != null) {
      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(n2, "descendant::repackagedPedigree/productInfo/manufacturer"),
              true));
    }
    buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n2, "signatureInfo/signerInfo"), true));

    Node n3 = XMLUtil.getNode(n2, "descendant::repackagedPedigree");
    // to check if any altPedigree exists
    if ((XMLUtil.getNode(n3, "descendant::altPedigree")) != null) {
      buffer.append("<altPedigree>yes</altPedigree>");
    }

    int i = 0;
    List ls = new ArrayList();
    Iterator it = XMLUtil.executeQuery(n2, "itemInfo").iterator();
    // Iterator it=XMLUtil.executeQuery(n3,"itemInfo").iterator();
    while (it.hasNext()) {

      Node n4 = (Node) it.next();

      buffer.append(XMLUtil.convertToString(n4, true));
      i++;
    }

    // adding new code here...

    if (i == 0) {
      Node shippedNode = XMLUtil.getNode(n2, "child::*/child::shippedPedigree");

      while (true) {

        if (shippedNode != null) {
          Iterator itemIterator = XMLUtil.executeQuery(shippedNode, "itemInfo").iterator();
          // Iterator it=XMLUtil.executeQuery(n3,"itemInfo").iterator();
          while (it.hasNext()) {

            Node itemNode = (Node) itemIterator.next();

            buffer.append(XMLUtil.convertToString(itemNode, true));
            i++;
          }
          shippedNode = XMLUtil.getNode(shippedNode, "child::*/child::shippedPedigree");
        }

        if (i > 0 || shippedNode == null) break;
      }
      if (i == 0) {

        Iterator initialItemInfoIt = XMLUtil.executeQuery(n3, "itemInfo").iterator();
        // Iterator it=XMLUtil.executeQuery(n3,"itemInfo").iterator();
        while (initialItemInfoIt.hasNext()) {

          Node n4 = (Node) initialItemInfoIt.next();

          buffer.append(XMLUtil.convertToString(n4, true));
        }
      }
    }

    buffer.append(
        XMLUtil.convertToString(XMLUtil.getNode(n2, "transactionInfo/transactionDate"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "transactionInfo/transactionIdentifier/identifier"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "transactionInfo/transactionIdentifier/identifierType"), true));

    Iterator it1 =
        XMLUtil.executeQuery(n2, "descendant::repackagedPedigree/previousProducts").iterator();
    while (it1.hasNext()) {
      Node n4 = (Node) it1.next();
      buffer.append(XMLUtil.convertToString(n4, true));
    }

    buffer.append("<custodyChain>");
    String serialNumber = "";
    Node intialShipped = XMLUtil.getNode(n2, "descendant-or-self::*[repackagedPedigree]");

    Node repackTransactionInfo = getTransactionInfo(n3);

    if (intialShipped != null) {
      buffer.append("<transactionInfo>");
      boolean flag = compare(intialShipped);

      serialNumber = XMLUtil.getValue(intialShipped, "documentInfo/serialNumber");
      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/businessAddress"), true));
      // Setting the business Address
      /*buffer.append(XMLUtil.convertToString(XMLUtil.getNode(intialShipped,"transactionInfo/transactionIdentifier/identifier"),true));
      buffer.append(XMLUtil.convertToString(XMLUtil.getNode(intialShipped,"transactionInfo/transactionIdentifier/identifierType"),true));
      buffer.append(XMLUtil.convertToString(XMLUtil.getNode(intialShipped,"transactionInfo/transactionDate"),true));
      */
      if (repackTransactionInfo != null) {
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(repackTransactionInfo, "transactionIdentifier/identifier"), true));
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(repackTransactionInfo, "transactionIdentifier/identifierType"),
                true));
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(repackTransactionInfo, "transactionDate"), true));
      }

      if ((XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/contactInfo")) != null) {
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/contactInfo"), true));
      }
      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(intialShipped, "transactionInfo/recipientInfo"), true));
      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(intialShipped, "signatureInfo/signerInfo"), true));

      if (!flag) {
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/shippingAddress"),
                true));
      }
      buffer.append("</transactionInfo>");
    }

    if (!(pedigreeID.equals(serialNumber))) {

      Node shippedNode = XMLUtil.getNode(intialShipped, "ancestor::shippedPedigree");
      Node testNode = intialShipped;
      while (true) {

        // Node shippedNode =
        // XMLUtil.getNode(n2,".[descendant-or-self::*/shippedPedigree/documentInfo/serialNumber='"+serialNumber+"']");

        if (shippedNode != null) {

          buffer.append("<transactionInfo>");
          boolean flag = compare(shippedNode);

          serialNumber = XMLUtil.getValue(shippedNode, "documentInfo/serialNumber");

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/businessAddress"),
                  true));
          // Setting the business Address
          /*buffer.append(XMLUtil.convertToString(XMLUtil.getNode(shippedNode,"transactionInfo/transactionIdentifier/identifier"),true));
          buffer.append(XMLUtil.convertToString(XMLUtil.getNode(shippedNode,"transactionInfo/transactionIdentifier/identifierType"),true));
          buffer.append(XMLUtil.convertToString(XMLUtil.getNode(shippedNode,"transactionInfo/transactionDate"),true));
          */
          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(testNode, "transactionInfo/transactionIdentifier/identifier"),
                  true));
          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(testNode, "transactionInfo/transactionIdentifier/identifierType"),
                  true));
          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(testNode, "transactionInfo/transactionDate"), true));

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/contactInfo"), true));

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "transactionInfo/recipientInfo"), true));

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "signatureInfo/signerInfo"), true));

          // Setting the Shipping Address

          if (!flag) {
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/shippingAddress"),
                    true));
          }

          testNode = shippedNode;
          shippedNode = XMLUtil.getNode(shippedNode, "ancestor::shippedPedigree");

          buffer.append("</transactionInfo>");
        }

        if (pedigreeID.equals(serialNumber) || shippedNode == null) break;
      }
    }

    buffer.append("</custodyChain>");

    buffer.append("<date>" + CommonUtil.dateToString(new Date()) + "</date>");
    buffer.append("<path>" + uri + "</path>");
    buffer.append("<signPath>" + uri + "</signPath>");
    buffer.append("</shippedPedigree>");
    log.info("XML :" + buffer.toString());
    getSignatureImage1(strName, signEmail);
    return buffer.toString();
  }
Пример #2
0
  public String getInitialXSLString(String str, String pedigreeID, String uri) throws Exception {

    StringBuffer buffer = new StringBuffer("<shippedPedigree>");

    Node n1 = XMLUtil.parse(str);
    Node n2 = XMLUtil.getNode(n1, "/shippedPedigree");

    String strName = XMLUtil.getValue(n2, "signatureInfo/signerInfo/name");
    String signEmail = XMLUtil.getValue(n2, "signatureInfo/signerInfo/email");
    // adding business name
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "transactionInfo/senderInfo/businessAddress/businessName"), true));

    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::initialPedigree/productInfo/drugName"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::initialPedigree/productInfo/strength"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::initialPedigree/productInfo/dosageForm"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::initialPedigree/productInfo/containerSize"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "descendant::initialPedigree/productInfo/productCode"), true));

    Node n3 = XMLUtil.getNode(n2, "descendant::initialPedigree");
    System.out.println("Value of node ***** : " + n2 + " signer Name : " + str);
    if ((XMLUtil.getNode(n2, "descendant::initialPedigree/altPedigree")) != null) {
      buffer.append("<altPedigree>yes</altPedigree>");
    }

    int i = 0;
    List ls = new ArrayList();
    Iterator it = XMLUtil.executeQuery(n2, "itemInfo").iterator();
    // Iterator it=XMLUtil.executeQuery(n3,"itemInfo").iterator();
    while (it.hasNext()) {

      Node n4 = (Node) it.next();

      buffer.append(XMLUtil.convertToString(n4, true));
      i++;
      System.out.println("Value of i in iterator loop***** : " + i);
    }

    // adding new code here...
    System.out.println("Value of i ***** : " + i);
    if (i == 0) {
      Node shippedNode = XMLUtil.getNode(n2, "child::*/child::shippedPedigree");

      while (true) {

        if (shippedNode != null) {
          Iterator itemIterator = XMLUtil.executeQuery(shippedNode, "itemInfo").iterator();
          // Iterator it=XMLUtil.executeQuery(n3,"itemInfo").iterator();
          while (it.hasNext()) {

            Node itemNode = (Node) itemIterator.next();

            buffer.append(XMLUtil.convertToString(itemNode, true));
            i++;
          }
          shippedNode = XMLUtil.getNode(shippedNode, "child::*/child::shippedPedigree");
        }

        if (i > 0 || shippedNode == null) break;
      }

      if (i == 0) {

        Iterator initialItemInfoIt = XMLUtil.executeQuery(n3, "itemInfo").iterator();
        // Iterator it=XMLUtil.executeQuery(n3,"itemInfo").iterator();
        while (initialItemInfoIt.hasNext()) {

          Node n4 = (Node) initialItemInfoIt.next();

          buffer.append(XMLUtil.convertToString(n4, true));
        }
      }
    }

    buffer.append(
        XMLUtil.convertToString(XMLUtil.getNode(n2, "transactionInfo/transactionDate"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "transactionInfo/transactionIdentifier/identifier"), true));
    buffer.append(
        XMLUtil.convertToString(
            XMLUtil.getNode(n2, "transactionInfo/transactionIdentifier/identifierType"), true));

    buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3, "productInfo/manufacturer"), true));

    Node n5 = XMLUtil.getNode(n3, "descendant::transactionInfo");

    /*if(n3!=null && n5 != null){


    	boolean flag = compare(n3);

    	buffer.append("<initialTransaction>");
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/senderInfo/businessAddress"),true));
    	//Setting the business Address
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/transactionIdentifier/identifier"),true));
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/transactionIdentifier/identifierType"),true));
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/transactionDate"),true));

    	//buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/senderInfo/contactInfo"),true));

    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/recipientInfo"),true));
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/senderInfo/contactInfo"),true));




    	//Setting the Shipping Address
    	if(!flag){
    		buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/senderInfo/shippingAddress"),true));

    	}
    	buffer.append("</initialTransaction>");
    }*/

    buffer.append("<custodyChain>");
    String serialNumber = "";
    Node intialShipped = XMLUtil.getNode(n2, "descendant-or-self::*[initialPedigree]");

    if (intialShipped != null) {
      buffer.append("<transactionInfo>");
      boolean flag = compare(intialShipped);

      serialNumber = XMLUtil.getValue(intialShipped, "documentInfo/serialNumber");

      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/businessAddress"), true));

      // Setting the business Address
      /*buffer.append(XMLUtil.convertToString(XMLUtil.getNode(intialShipped,"transactionInfo/transactionIdentifier/identifier"),true));
      buffer.append(XMLUtil.convertToString(XMLUtil.getNode(intialShipped,"transactionInfo/transactionIdentifier/identifierType"),true));
      buffer.append(XMLUtil.convertToString(XMLUtil.getNode(intialShipped,"transactionInfo/transactionDate"),true));
      */

      if (n5 != null) {
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(n3, "transactionInfo/transactionIdentifier/identifier"), true));
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(n3, "transactionInfo/transactionIdentifier/identifierType"), true));
        buffer.append(
            XMLUtil.convertToString(XMLUtil.getNode(n3, "transactionInfo/transactionDate"), true));

      } else {
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(intialShipped, "transactionInfo/transactionIdentifier/identifier"),
                true));
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(
                    intialShipped, "transactionInfo/transactionIdentifier/identifierType"),
                true));
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(intialShipped, "transactionInfo/transactionDate"), true));
      }

      if (XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/contactInfo") != null)
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/contactInfo"), true));
      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(intialShipped, "transactionInfo/recipientInfo"), true));
      buffer.append(
          XMLUtil.convertToString(
              XMLUtil.getNode(intialShipped, "signatureInfo/signerInfo"), true));

      if (!flag) {
        buffer.append(
            XMLUtil.convertToString(
                XMLUtil.getNode(intialShipped, "transactionInfo/senderInfo/shippingAddress"),
                true));
      }
      /*if((XMLUtil.getNode(n2,"descendant::initialPedigree/transactionInfo"))!=null){
      	buffer.append("<checkPedigree>yes</checkPedigree>");
      }*/
      if ((XMLUtil.getNode(n2, "descendant::initialPedigree/altPedigree")) != null) {
        buffer.append("<altPedigree>yes</altPedigree>");
      }

      buffer.append("</transactionInfo>");
    }

    // intialTransaction information inside the custody chain

    /*
    if(n5!=null){

    	buffer.append("<transactionInfo>");

    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/transactionIdentifier/identifier"),true));
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/transactionIdentifier/identifierType"),true));
    	buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n3,"transactionInfo/transactionDate"),true));

    	buffer.append("</transactionInfo>");


    }
    */

    if (!(pedigreeID.equals(serialNumber))) {

      Node shippedNode = XMLUtil.getNode(intialShipped, "ancestor::shippedPedigree");
      Node testNode = intialShipped;
      while (true) {

        // Node shippedNode =
        // XMLUtil.getNode(n2,".[descendant-or-self::*/shippedPedigree/documentInfo/serialNumber='"+serialNumber+"']");

        if (shippedNode != null) {

          buffer.append("<transactionInfo>");
          boolean flag = compare(shippedNode);

          serialNumber = XMLUtil.getValue(shippedNode, "documentInfo/serialNumber");

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/businessAddress"),
                  true));
          // Setting the business Address
          /*buffer.append(XMLUtil.convertToString(XMLUtil.getNode(shippedNode,"transactionInfo/transactionIdentifier/identifier"),true));
          buffer.append(XMLUtil.convertToString(XMLUtil.getNode(shippedNode,"transactionInfo/transactionIdentifier/identifierType"),true));
          buffer.append(XMLUtil.convertToString(XMLUtil.getNode(shippedNode,"transactionInfo/transactionDate"),true));
          */

          if (n5 != null) {
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(testNode, "transactionInfo/transactionIdentifier/identifier"),
                    true));
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(
                        testNode, "transactionInfo/transactionIdentifier/identifierType"),
                    true));
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(testNode, "transactionInfo/transactionDate"), true));

          } else {
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(
                        shippedNode, "transactionInfo/transactionIdentifier/identifier"),
                    true));
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(
                        shippedNode, "transactionInfo/transactionIdentifier/identifierType"),
                    true));
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(shippedNode, "transactionInfo/transactionDate"), true));
          }

          if (XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/contactInfo") != null)
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/contactInfo"), true));

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "transactionInfo/recipientInfo"), true));

          buffer.append(
              XMLUtil.convertToString(
                  XMLUtil.getNode(shippedNode, "signatureInfo/signerInfo"), true));

          // Setting the Shipping Address

          if (!flag) {
            buffer.append(
                XMLUtil.convertToString(
                    XMLUtil.getNode(shippedNode, "transactionInfo/senderInfo/shippingAddress"),
                    true));
          }

          /*if((XMLUtil.getNode(n2,"descendant::initialPedigree/transactionInfo"))!=null){
          	buffer.append("<checkPedigree>yes</checkPedigree>");
          }*/
          testNode = shippedNode;
          shippedNode = XMLUtil.getNode(shippedNode, "ancestor::shippedPedigree");

          buffer.append("</transactionInfo>");
        }

        if (pedigreeID.equals(serialNumber) || shippedNode == null) break;
      }
    }

    buffer.append("</custodyChain>");

    buffer.append(XMLUtil.convertToString(XMLUtil.getNode(n2, "signatureInfo/signerInfo"), true));
    buffer.append("<date>" + CommonUtil.dateToString(new Date()) + "</date>");
    // buffer.append("<path>C:\\Documents and Settings\\Ajay
    // Reddy\\workspace\\ePharma_SW\\xsl\\logo.gif</path>");
    buffer.append("<path>" + uri + "</path>");
    buffer.append("<signPath>" + uri + "</signPath>");
    buffer.append("</shippedPedigree>");
    log.info("XML :" + buffer.toString());

    getSignatureImage1(strName, signEmail);
    return buffer.toString();
  }