Package com.commander4j.db

Examples of com.commander4j.db.JDBInterfaceLog


  public Boolean processMessage(Long transactionRef) {
    Boolean result = false;
    String path = "";
    String defaultBatchStatus = "";

    JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
    GenericMessageHeader gmh = new GenericMessageHeader();
    JDBInterface inter = new JDBInterface(getHostID(), getSessionID());
    JDBUom uoml = new JDBUom(getHostID(), getSessionID());
    inter.getInterfaceProperties("Despatch Confirmation", "Output");
    String device = inter.getDevice();
   
    JDBDespatch desp = new JDBDespatch(getHostID(), getSessionID());
    desp.setTransactionRef(transactionRef);
    desp.getDespatchPropertiesFromTransactionRef();

    String sourceGLN = JUtility.replaceNullStringwithBlank(desp.getLocationDBFrom().getGLN());
    String destinationGLN = JUtility.replaceNullStringwithBlank(desp.getLocationDBTo().getGLN());
    Boolean suppressMessage = false;

    gmh.setMessageRef(desp.getTransactionRef().toString());
    gmh.setInterfaceType(inter.getInterfaceType());
    gmh.setMessageInformation("Despatch=" + desp.getDespatchNo());
    gmh.setInterfaceDirection(inter.getInterfaceDirection());
    gmh.setMessageDate(JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));

    if (sourceGLN.length() == 0)
    {
      setErrorMessage("Message Suppressed - No GLN Source (From) GLN for Location [" + desp.getLocationIDFrom() + "]");
      suppressMessage = true;
    }

    if (destinationGLN.length() == 0)
    {
      setErrorMessage("Message Suppressed - No GLN Destination (To) GLN for Location [" + desp.getLocationIDTo() + "]");
      suppressMessage = true;
    }

    if (suppressMessage == true)
    {
      result = true;
      il.write(gmh, GenericMessageHeader.msgStatusWarning, getErrorMessage(), "File Write", "");

    }
    else
    {
      if (inter.getFormat().equals("EANCOM"))
      {

        if (sourceGLN.endsWith(""))
        {

        }

        int segments = 0;
        int optional = 0;
        String document = "";
        String despdateShort = new java.text.SimpleDateFormat("yyMMdd:HHmm").format(desp.getDespatchDate());
        String despdateLong = new java.text.SimpleDateFormat("yyyyMMddHHmm").format(desp.getDespatchDate());

        document = document + "UNA:+.? 'UNB+UNOA:3+" + desp.getLocationDBFrom().getGLN() + ":14+" + desp.getLocationDBTo().getGLN() + ":14+";
        document = document + despdateShort + "+" + desp.getDespatchNo() + "'";
        document = document + "UNH+" + desp.getDespatchNo() + "+DESADV:D:96A:EN:EAN005'";
        document = document + "BGM+351+" + desp.getDespatchNo() + "+9'";
        document = document + "DTM+11:" + despdateLong + ":203'";
        document = document + "RFF+LO:" + desp.getDespatchNo() + "'";
        document = document + "RFF+ZCO:'";
        document = document + "RFF+ZAF:'";
        document = document + "RFF+ZPI:1'";
        document = document + "RFF+ZCH:'";
        document = document + "NAD+SF+" + desp.getLocationDBFrom().getGLN() + "::9'";

        if (desp.getLocationDBFrom().getStorageLocation().equals("") == false)
        {
          if (desp.getLocationDBTo().getStorageLocation().equals("") == false)
          {
            document = document + "LOC+198+" + desp.getLocationDBFrom().getStorageLocation() + "::91'";
            optional++;
          }
        }

        document = document + "NAD+ST+" + desp.getLocationDBTo().getGLN() + "::9'";

        if (desp.getLocationDBFrom().getStorageLocation().equals("") == false)
        {
          if (desp.getLocationDBTo().getStorageLocation().equals("") == false)
          {
            document = document + "LOC+195+" + desp.getLocationDBTo().getStorageLocation() + "::91'";
            optional++;
          }
        }

        document = document + "TDT+20++30+31+::9:" + JUtility.stripEANCOMSpecialCharacters(JUtility.replaceNullStringwithBlank(desp.getHaulier())) + "+++:::" + JUtility.stripEANCOMSpecialCharacters(JUtility.replaceNullStringwithBlank(desp.getTrailer())) + "'";
        document = document + "EQD+CN+123'";
        document = document + "SEL+123+CA'";

        segments = 13 + optional;

        JDBPalletHistory palhist = new JDBPalletHistory(getHostID(), getSessionID());
        ResultSet rs = palhist.getInterfacingData(transactionRef, "DESPATCH", "TO", Long.valueOf(0), "SSCC", "asc");

        int x = 1;
        try
        {
          rs.beforeFirst();
          while (rs.next())
          {
            palhist.getPropertiesfromResultSet(rs);

            document = document + "CPS+" + JUtility.padString(String.valueOf(x).trim(), false, 4, "0") + "'";
            document = document + "PAC+1++202'";
            document = document + "PCI+33E'";
            document = document + "GIN+BJ+" + palhist.getPallet().getSSCC() + "'";
            document = document + "LIN+1++" + palhist.getPallet().getEAN() + ":EN'";
            document = document + "PIA+1+" + palhist.getPallet().getVariant() + ":PV+" + palhist.getPallet().getMaterial() + ":SA'";

            NumberFormat formatter = new DecimalFormat("#.#");
            String outqty = formatter.format(palhist.getPallet().getQuantity()); // -1234.567000

            document = document + "QTY+12:" + outqty + ":" + palhist.getPallet().getUom() + "'";
            document = document + "DLM+++0::9'";

            String batchExpiryLong = new java.text.SimpleDateFormat("yyyyMMdd").format(palhist.getPallet().getMaterialBatchExpiryDate());
            String dateOfManufactureLong = new java.text.SimpleDateFormat("yyyyMMdd").format(palhist.getPallet().getDateOfManufacture());

            document = document + "DTM+361:" + batchExpiryLong + ":102'";
            document = document + "DTM+94:" + dateOfManufactureLong + ":102'";
            document = document + "RFF+AAJ:" + palhist.getPallet().getDespatchNo() + ":1'";
           
            defaultBatchStatus = palhist.getPallet().getMaterialBatchStatus();
           
            if (defaultBatchStatus.equals("Unrestricted"))
            {
              document = document + "RFF+ZBR:'";
            }
            else
            {
              document = document + "RFF+ZBR:B'";
            }

            document = document + "RFF+ZRB:'";
            document = document + "RFF+ZSR:'";
            document = document + "RFF+ZRC:'";
            document = document + "RFF+ZRT:'";
            document = document + "PCI+36E'";
            document = document + "GIN+BX+" + palhist.getPallet().getBatchNumber() + "'";

            segments = segments + 18;

            x++;
          }
          rs.close();

          segments = segments + 1;

          document = document + "UNT+" + String.valueOf(segments).trim() + "+" + desp.getDespatchNo() + "'";
          document = document + "UNZ+1+" + desp.getDespatchNo() + "'";

          if (device.equals("Disk") | device.equals("Email"))
          {
            path = inter.getRealPath();
            if (fio.writeToDisk(path, document, transactionRef, "_"+desp.getLocationIDTo().replace(" ", "_")+"_DespatchConfirmation.txt") == true)
            {
              result = true;
              il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "File Write", fio.getFilename());
              setErrorMessage("");
              if (device.equals("Email"))
              {
                ogm = new JeMailOutGoingMessage(inter,transactionRef,fio);
                ogm.sendEmail();
              }
            }
            else
            {
              result = false;
              il.write(gmh, GenericMessageHeader.msgStatusError, fio.getErrorMessage(), "File Write", fio.getFilename());
              setErrorMessage(fio.getErrorMessage());
            }

          }

        }
        catch (SQLException e)
        {

        }

      }

      if (inter.getFormat().equals("XML"))
      {

        try
        {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();

          Document document = builder.newDocument();

          Element message = (Element) document.createElement("message");

          Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID());
          message.appendChild(hostUniqueID);

          Element messageRef = addElement(document, "messageRef", String.valueOf(transactionRef));
          message.appendChild(messageRef);

          Element messageType = addElement(document, "interfaceType", "Despatch Confirmation");
          message.appendChild(messageType);

          Element messageInformation = addElement(document, "messageInformation", "Despatch=" + desp.getDespatchNo());
          message.appendChild(messageInformation);

          Element messageDirection = addElement(document, "interfaceDirection", "Output");
          message.appendChild(messageDirection);

          Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));
          message.appendChild(messageDate);

          Element despatchConfirmation = (Element) document.createElement("despatchConfirmation");

          Element noofpallets = addElement(document, "numberOfPallets", String.valueOf(desp.getTotalPallets()));
          despatchConfirmation.appendChild(noofpallets);

          Element haulier = addElement(document, "haulier", String.valueOf(JUtility.replaceNullStringwithBlank(desp.getHaulier())));
          despatchConfirmation.appendChild(haulier);

          Element trailer = addElement(document, "trailer", String.valueOf(JUtility.replaceNullStringwithBlank(desp.getTrailer())));
          despatchConfirmation.appendChild(trailer);

          Element despatch = addElement(document, "despatchNo", desp.getDespatchNo());
          despatchConfirmation.appendChild(despatch);

          Element despatchDate = addElement(document, "despatchDate", JUtility.getISOTimeStampStringFormat(desp.getDespatchDate()));
          despatchConfirmation.appendChild(despatchDate);

          Element locationFrom = addElement(document, "fromLocation", desp.getLocationIDFrom());
          despatchConfirmation.appendChild(locationFrom);

          Element locationFromPlant = addElement(document, "fromPlant", desp.getLocationDBFrom().getPlant());
          despatchConfirmation.appendChild(locationFromPlant);
         
          Element locationFromWarehouse = addElement(document, "fromWarehouse", desp.getLocationDBFrom().getWarehouse());
          despatchConfirmation.appendChild(locationFromWarehouse);
         
          Element locationFromStorageSection = addElement(document, "fromStorageSection", desp.getLocationDBFrom().getStorageSection());
          despatchConfirmation.appendChild(locationFromStorageSection);
         
          Element locationFromStorageType = addElement(document, "fromStorageType", desp.getLocationDBFrom().getStorageType());
          despatchConfirmation.appendChild(locationFromStorageType);
         
          Element locationFromStorageBin = addElement(document, "fromStorageBin", desp.getLocationDBFrom().getStorageBin());
          despatchConfirmation.appendChild(locationFromStorageBin);   
         
         
         
          Element locationFromGLN = addElement(document, "fromGLN", desp.getLocationDBFrom().getGLN());
          despatchConfirmation.appendChild(locationFromGLN);

          Element locationFromStorageLocation = addElement(document, "fromStorageLocation", desp.getLocationDBFrom().getStorageLocation());
          despatchConfirmation.appendChild(locationFromStorageLocation);

          Element locationTo = addElement(document, "toLocation", desp.getLocationIDTo());
          despatchConfirmation.appendChild(locationTo);

          Element locationToPlant = addElement(document, "toPlant", desp.getLocationDBTo().getPlant());
          despatchConfirmation.appendChild(locationToPlant);
         
          Element locationToWarehouse = addElement(document, "toWarehouse", desp.getLocationDBTo().getWarehouse());
          despatchConfirmation.appendChild(locationToWarehouse)
         
          Element locationToStorageSection = addElement(document, "toStorageSection", desp.getLocationDBTo().getStorageSection());
          despatchConfirmation.appendChild(locationToStorageSection);
         
          Element locationToStorageType = addElement(document, "toStorageType", desp.getLocationDBTo().getStorageType());
          despatchConfirmation.appendChild(locationToStorageType);
         
          Element locationToStorageBin = addElement(document, "toStorageBin", desp.getLocationDBTo().getStorageBin());
          despatchConfirmation.appendChild(locationToStorageBin);           
         
          Element locationToGLN = addElement(document, "toGLN", desp.getLocationDBTo().getGLN());
          despatchConfirmation.appendChild(locationToGLN);

          Element locationToStorageLocation = addElement(document, "toStorageLocation", desp.getLocationDBTo().getStorageLocation());
          despatchConfirmation.appendChild(locationToStorageLocation);

          Element contents = (Element) document.createElement("contents");
          despatchConfirmation.appendChild(contents);

          JDBPalletHistory palhist = new JDBPalletHistory(getHostID(), getSessionID());
          ResultSet rs = palhist.getInterfacingData(transactionRef, "DESPATCH", "TO", Long.valueOf(0), "SSCC", "asc");

          int x = 1;
          try
          {
            rs.beforeFirst();
            while (rs.next())
            {
              palhist.getPropertiesfromResultSet(rs);
              Element pallet = (Element) document.createElement("pallet");

              Element item = addElement(document, "item", String.valueOf(x));
              pallet.appendChild(item);
              x++;

              Element sscc = addElement(document, "SSCC", palhist.getPallet().getSSCC());
              pallet.appendChild(sscc);

              Element processOrder = addElement(document, "processOrder", palhist.getPallet().getProcessOrder());
              pallet.appendChild(processOrder);
             
              Element material = addElement(document, "material", palhist.getPallet().getMaterial());
              pallet.appendChild(material);

              Element ean = addElement(document, "ean", palhist.getPallet().getEAN());
              pallet.appendChild(ean);

              Element variant = addElement(document, "variant", palhist.getPallet().getVariant());
              pallet.appendChild(variant);

              Element qty = addElement(document, "quantity", palhist.getPallet().getQuantity().toString());
              pallet.appendChild(qty);

              String paluom = palhist.getPallet().getUom();
              paluom = uoml.convertUom(inter.getUOMConversion(), paluom);

              Element uom = addElement(document, "UOM", paluom);
              pallet.appendChild(uom);

              Element status = addElement(document, "status", palhist.getPallet().getStatus());
              pallet.appendChild(status);

              Element bbe = addElement(document, "bestBefore", JUtility.getISOTimeStampStringFormat(palhist.getPallet().getMaterialBatchExpiryDate()));
              pallet.appendChild(bbe);

              Element dom = addElement(document, "productionDate", JUtility.getISOTimeStampStringFormat(palhist.getPallet().getDateOfManufacture()));
              pallet.appendChild(dom);

              Element batch = addElement(document, "batch", palhist.getPallet().getBatchNumber());
              pallet.appendChild(batch);

              Element batchStatus = addElement(document, "batchStatus", palhist.getPallet().getMaterialBatchStatus());
              pallet.appendChild(batchStatus);

              contents.appendChild(pallet);

            }
            rs.close();
          }
          catch (SQLException e)
          {

          }

          Element messageData = (Element) document.createElement("messageData");
          messageData.appendChild(despatchConfirmation);

          message.appendChild(messageData);

          document.appendChild(message);

 

          JXMLDocument xmld = new JXMLDocument();
          xmld.setDocument(document);
          gmh.decodeHeader(xmld);

          if (device.equals("Disk") | device.equals("Email"))
          {
            path = inter.getRealPath();
            if (fio.writeToDisk(path, document, transactionRef, "_"+desp.getLocationIDTo().replace(" ", "_")+"_DespatchConfirmation.xml") == true)
            {
              result = true;
              il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "File Write", fio.getFilename());
              setErrorMessage("");
             
              if (device.equals("Email"))
              {
                ogm = new JeMailOutGoingMessage(inter,transactionRef,fio);
                ogm.sendEmail();
              }
            }
            else
            {
              result = false;
              il.write(gmh, GenericMessageHeader.msgStatusError, fio.getErrorMessage(), "File Write", fio.getFilename());
              setErrorMessage(fio.getErrorMessage());
            }

          }
View Full Code Here


      dbconnected = true;
    }

    if (dbconnected)
    {
      JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
      JeMail mail = new JeMail(getHostID(), getSessionID());
      JDBInterface inter = new JDBInterface(getHostID(), getSessionID());
      IncommingMaterialDefinition imd = new IncommingMaterialDefinition(getHostID(), getSessionID());
      IncommingProcessOrderStatusChange iposc = new IncommingProcessOrderStatusChange(getHostID(), getSessionID());
      IncommingProductionDeclarationConfirmation ipd = new IncommingProductionDeclarationConfirmation(getHostID(), getSessionID());
      IncommingProcessOrder ipo = new IncommingProcessOrder(getHostID(), getSessionID());
      IncommingPalletStatusChange ipsc = new IncommingPalletStatusChange(getHostID(), getSessionID());
      IncommingBatchStatusChange bsc = new IncommingBatchStatusChange(getHostID(), getSessionID());
      IncommingInspectionResult iirslt = new IncommingInspectionResult(getHostID(), getSessionID());
      IncommingDespatchConfirmation idc = new IncommingDespatchConfirmation(getHostID(), getSessionID());
      IncommingQMInspectionRequest iireq = new IncommingQMInspectionRequest(getHostID(), getSessionID());
      GenericMessageHeader gmh = new GenericMessageHeader();
      LinkedList<String> filenames = new LinkedList<String>();
      BasicFileAttributes attrs;
     
      while (true)
      {

        com.commander4j.util.JWait.milliSec(100);

        if (allDone)
        {
          if (dbconnected)
          {
            Common.hostList.getHost(hostID).disconnect(getSessionID());
          }
          return;
        }

        if (InboundMessageCollectionThread.recoveringFiles == false)
        {

          dir = new File(inputPath);

          chld = dir.listFiles((FileFilter) FileFileFilter.FILE);

          if (chld == null)
          {
            allDone = true;
          } else
          {
            Arrays.sort(chld, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
            filenames.clear();

            for (int i = 0; (i < chld.length) & (i < maxfiles); i++)
            {
              fileName = chld[i].getName();
              try
              {
                attrs = Files.readAttributes(chld[i].getAbsoluteFile().toPath(), BasicFileAttributes.class);

                if (attrs.size() > 0)
                {
                  if (fileName.indexOf(".xml") > 0)
                  {
                    filenames.addFirst(fileName);
                    com.commander4j.util.JWait.milliSec(50);
                  }
                } else
                {
                  try
                  {
                    chld[i].delete();
                  }
                  catch (Exception ex)
                  {
                   
                  }
                }
              } catch (IOException e)
              {

              }

            }

            if (filenames.size() > 0)
            {
              logger.debug("Begin processing " + String.valueOf(filenames.size()) + " files.");
              for (int i = filenames.size() - 1; i >= 0; i--)
              {
                if (allDone)
                {
                  if (dbconnected)
                  {
                    Common.hostList.getHost(hostID).disconnect(getSessionID());
                  }
                  return;
                }

                fromFile = filenames.get(i);

                try
                {
                  logger.debug("<---  START OF PROCESSING " + fromFile + "  ---->");
                  logger.debug("Reading message header : " + inputPath + fromFile);

                  if (gmh.readAddressInfo(inputPath + fromFile, getSessionID()) == true)
                  {

                    messageProcessedOK = true;
                    errorMessage = "";

                    if (gmh.getInterfaceType().length() == 0)
                    {
                      messageProcessedOK = false;
                      errorMessage = "Unrecognised Commander4j XML message format in file " + fromFile;
                      logger.debug(errorMessage);
                      String datetime = "";
                      datetime = JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime());
                      gmh.setMessageDate(datetime);
                      gmh.setInterfaceDirection("Unknown");
                      gmh.setMessageInformation(fromFile);
                      gmh.setInterfaceType("Unknown");
                      gmh.setMessageRef("Unknown");
                    } else
                    {
                      if (gmh.getInterfaceDirection().equals("Input") == false)
                      {
                        messageProcessedOK = false;
                        errorMessage = "Inbound message ignored - Interface Direction = " + gmh.getInterfaceDirection();
                      } else
                      {
                        String interfaceType = gmh.getInterfaceType();
                        logger.debug("Processing " + interfaceType + " started.");
                        if (interfaceType.equals("Despatch Confirmation") == true)
                        {
                          messageProcessedOK = idc.processMessage(gmh);
                          errorMessage = idc.getErrorMessage();
                        }

                        if (interfaceType.equals("Material Definition") == true)
                        {
                          messageProcessedOK = imd.processMessage(gmh);
                          errorMessage = imd.getErrorMessage();
                        }

                        if (interfaceType.equals("Process Order") == true)
                        {
                          messageProcessedOK = ipo.processMessage(gmh);
                          errorMessage = ipo.getErrorMessage();
                        }

                        if (interfaceType.equals("Pallet Status Change") == true)
                        {
                          messageProcessedOK = ipsc.processMessage(gmh);
                          errorMessage = ipsc.getErrorMessage();
                        }

                        if (interfaceType.equals("Batch Status Change") == true)
                        {
                          messageProcessedOK = bsc.processMessage(gmh);
                          errorMessage = bsc.getErrorMessage();
                        }

                        if (interfaceType.equals("Process Order Status Change") == true)
                        {
                          messageProcessedOK = iposc.processMessage(gmh);
                          errorMessage = iposc.getErrorMessage();
                        }

                        if (interfaceType.equals("Production Declaration") == true)
                        {
                          messageProcessedOK = ipd.processMessage(gmh);
                          errorMessage = ipd.getErrorMessage();
                        }

                        if (interfaceType.equals("QM Inspection Request") == true)
                        {
                          messageProcessedOK = iireq.processMessage(gmh);
                          errorMessage = iireq.getErrorMessage();
                        }

                        if (interfaceType.equals("QM Inspection Result") == true)
                        {
                          messageProcessedOK = iirslt.processMessage(gmh);
                          errorMessage = iirslt.getErrorMessage();
                        }

                        GenericMessageHeader.updateStats("Input", interfaceType, messageProcessedOK.toString());
                        logger.debug("Processing " + interfaceType + " finished.");
                      }
                    }

                    logger.debug("    ===  RESULT " + messageProcessedOK.toString() + "  ===");

                    if (messageProcessedOK)
                    {

                      il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "DB Update", fromFile);
                      reader.deleteFile(backupPath + gmh.getInterfaceType() + File.separator + fromFile);
                      reader.move_FileToDirectory(inputPath + fromFile, backupPath + gmh.getInterfaceType(), true);
                    } else
                    {
                      il.write(gmh, GenericMessageHeader.msgStatusError, errorMessage, "DB Update", fromFile);
                      if (inter.getInterfaceProperties(gmh.getInterfaceType(), "Input") == true)
                      {
                        if (inter.getEmailError() == true)
                        {
                          String emailaddresses = inter.getEmailAddresses();
View Full Code Here

    try
    {
      if (cache.containsKey(row)==false)
      {
        mResultSet.absolute(row + 1);
        final JDBInterfaceLog prow = new JDBInterfaceLog(Common.selectedHostID, Common.sessionID);
        prow.getPropertiesfromResultSet(mResultSet);
        cache.put(row, prow);
      }
      switch (col)
      {
      case event_time_Col:
View Full Code Here

  public Boolean processMessage(Long transactionRef)
  {
    Boolean result = false;
    String path = "";

    JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
    GenericMessageHeader gmh = new GenericMessageHeader();
    JDBInterface inter = new JDBInterface(getHostID(), getSessionID());

    inter.getInterfaceProperties("Equipment Tracking", "Output");
    String device = inter.getDevice();

    JDBDespatch desp = new JDBDespatch(getHostID(), getSessionID());
    desp.setTransactionRef(transactionRef);

    Boolean suppressMessage = false;
    if (desp.getDespatchPropertiesFromTransactionRef() == true)
    {

      String sourceEquipmentLocation = JUtility.replaceNullStringwithBlank(desp.getLocationDBFrom().getGLN());
      String destinationEquipmentLocation = JUtility.replaceNullStringwithBlank(desp.getLocationDBTo().getGLN());

      gmh.setMessageRef(desp.getTransactionRef().toString());
      gmh.setInterfaceType(inter.getInterfaceType());
      gmh.setMessageInformation("Despatch=" + desp.getDespatchNo());
      gmh.setInterfaceDirection(inter.getInterfaceDirection());
      gmh.setMessageDate(JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));

      if (sourceEquipmentLocation.length() == 0)
      {
        setErrorMessage("Message Suppressed - No Equipment Destination (From) for Location [" + desp.getLocationIDFrom() + "]");
        suppressMessage = true;
      }

      if (destinationEquipmentLocation.length() == 0)
      {
        setErrorMessage("Message Suppressed - No Equipment Destination (To) for Location [" + desp.getLocationIDTo() + "]");
        suppressMessage = true;
      }
    }
    else
    {
      setErrorMessage("Message Suppressed - Unable to find Despatch with Transaction Ref [" + String.valueOf(transactionRef) + "]");
      suppressMessage = true;

    }

    if (suppressMessage == true)
    {
      result = false;
      il.write(gmh, GenericMessageHeader.msgStatusWarning, getErrorMessage(), "File Write", "");

    }
    else
    {
      if (inter.getFormat().equals("XML"))
      {

        try
        {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();

          Document document = builder.newDocument();

          Element message = (Element) document.createElement("message");

          Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID());
          message.appendChild(hostUniqueID);

          Element messageRef = addElement(document, "messageRef", String.valueOf(transactionRef));
          message.appendChild(messageRef);

          Element messageType = addElement(document, "interfaceType", "Equipment Tracking");
          message.appendChild(messageType);

          Element messageInformation = addElement(document, "messageInformation", "Despatch=" + desp.getDespatchNo());
          message.appendChild(messageInformation);

          Element messageDirection = addElement(document, "interfaceDirection", "Output");
          message.appendChild(messageDirection);

          Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));
          message.appendChild(messageDate);

          Element equipmentTracking = (Element) document.createElement("equipmentTracking");

          Element noofpallets = addElement(document, "numberOfPallets", String.valueOf(desp.getTotalPallets()));
          equipmentTracking.appendChild(noofpallets);

          Element haulier = addElement(document, "haulier", String.valueOf(JUtility.replaceNullStringwithBlank(desp.getHaulier())));
          equipmentTracking.appendChild(haulier);

          Element trailer = addElement(document, "trailer", String.valueOf(JUtility.replaceNullStringwithBlank(desp.getTrailer())));
          equipmentTracking.appendChild(trailer);

          Element despatch = addElement(document, "despatchNo", desp.getDespatchNo());
          equipmentTracking.appendChild(despatch);

          Element despatchDate = addElement(document, "despatchDate", JUtility.getISOTimeStampStringFormat(desp.getDespatchDate()));
          equipmentTracking.appendChild(despatchDate);

          Element locationFrom = addElement(document, "fromLocation", desp.getLocationIDFrom());
          equipmentTracking.appendChild(locationFrom);

          Element locationFromETID = addElement(document, "fromEquipmentTrackingID", desp.getLocationDBFrom().getEquipmentTrackingID());
          equipmentTracking.appendChild(locationFromETID);

          Element locationTo = addElement(document, "toLocation", desp.getLocationIDTo());
          equipmentTracking.appendChild(locationTo);

          Element locationToETID = addElement(document, "toEquipmentTrackingID", desp.getLocationDBTo().getEquipmentTrackingID());
          equipmentTracking.appendChild(locationToETID);

          Element contents = (Element) document.createElement("contents");
          equipmentTracking.appendChild(contents);

          LinkedList<JDBEquipmentList> equipList = new LinkedList<JDBEquipmentList>();
          equipList = desp.getEquipment();

          for (int x = 0; x < equipList.size(); x++)
          {
            Element equipment = (Element) document.createElement("Equipment");

            Element equipmentID = addElement(document, "equipmentID", equipList.get(x).getEquipmentID());
            equipment.appendChild(equipmentID);

            Element count = addElement(document, "count", String.valueOf(equipList.get(x).getCount()));
            equipment.appendChild(count);

            contents.appendChild(equipment);

            if (equipList.get(x).getEquipmentID().equals(""))
            {
              setErrorMessage("Message Suppressed - No Equipment Type defined for one or more Materials in Despatch [" + desp.getDespatchNo() + "]");
              suppressMessage = true;
            }
          }

          Element messageData = (Element) document.createElement("messageData");
          messageData.appendChild(equipmentTracking);

          message.appendChild(messageData);

          document.appendChild(message);

          JXMLDocument xmld = new JXMLDocument();
          xmld.setDocument(document);
          gmh.decodeHeader(xmld);

          if (suppressMessage == true)
          {
            result = false;
            il.write(gmh, GenericMessageHeader.msgStatusWarning, getErrorMessage(), "File Write", "");
          }
          else
          {
            if (device.equals("Disk") | device.equals("Email"))
            {
              path = inter.getRealPath();
              if (fio.writeToDisk(path, document, transactionRef, "_"+desp.getLocationIDTo().replace(" ", "_")+"_EquipmentTracking.xml") == true)
              {
                result = true;
                il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "File Write", fio.getFilename());
                setErrorMessage("");

                if (device.equals("Email"))
                {
                  ogm = new JeMailOutGoingMessage(inter, transactionRef, fio);
                  ogm.sendEmail();
                }
              }

              else
              {
                result = false;
                il.write(gmh, GenericMessageHeader.msgStatusError, fio.getErrorMessage(), "File Write", fio.getFilename());
                setErrorMessage(fio.getErrorMessage());
              }
            }
          }
        }
View Full Code Here

  public Boolean processMessage(Long transactionRef)

  {
    Boolean result = false;
    String path = "";
    JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
    GenericMessageHeader gmh = new GenericMessageHeader();
    JDBInterface inter = new JDBInterface(getHostID(), getSessionID());

    inter.getInterfaceProperties("Pallet Status Change", "Output");
    String device = inter.getDevice();

    JDBPalletHistory palhistfrom = new JDBPalletHistory(getHostID(), getSessionID());
    JDBPalletHistory palhistto = new JDBPalletHistory(getHostID(), getSessionID());
    JDBControl ctrl = new JDBControl(getHostID(), getSessionID());
   
    String origin = ctrl.getKeyValue("DEFAULT_LOCATION");
    JDBMHN mhn = new JDBMHN(getHostID(), getSessionID());
    JDBMHNReasons mhnReasons = new JDBMHNReasons(getHostID(), getSessionID());

    ResultSet rsFrom = palhistfrom.getInterfacingData(transactionRef, "STATUS CHANGE", "FROM", Long.valueOf(1), "SSCC", "asc");

    ResultSet rsTo = palhistfrom.getInterfacingData(transactionRef, "STATUS CHANGE", "TO", Long.valueOf(1), "SSCC", "asc");

    try
    {
      if (rsFrom.next())
      {
        if (rsTo.next())
        {
          palhistfrom.getPropertiesfromResultSet(rsFrom);
          palhistto.getPropertiesfromResultSet(rsTo);

          String mhnNumber = palhistto.getPallet().getMHNNumber();
          String initiator = "";
          String recorder = "";
          String authorisor = "";
          String decision = "";
          String reason1 = "";
          String reason2 = "";
          String reason3 = "";
          String dateCreated = "";
          String dateExpected = "";
          String dateResolved = "";
          String comment = "";
          String status = "";
          String locn = "";
          if (palhistto.getPallet().getMHNNumber().equals("") == false)
          {
            if (mhn.getMHNProperties(palhistto.getPallet().getMHNNumber()))
            {
              initiator = mhn.getInitiator();
              recorder = mhn.getRecorder();
              authorisor = mhn.getAuthorisor();
              reason1 = mhn.getReason1();
              reason2 = mhn.getReason2();
              reason3 = mhn.getReason3();
              dateCreated = JUtility.getISOTimeStampStringFormat(mhn.getDateCreated());
              if (dateCreated.equals("Error"))
                dateCreated = "";
              dateExpected = JUtility.getISOTimeStampStringFormat(mhn.getDateExpected());
              if (dateExpected.equals("Error"))
                dateExpected = "";
              dateResolved = JUtility.getISOTimeStampStringFormat(mhn.getDateResolved());
              if (dateResolved.equals("Error"))
                dateResolved = "";
              comment = mhn.getComments();
              status = mhn.getStatus();
            }
          }

          try
          {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();

            Document document = builder.newDocument();

            Element message = (Element) document.createElement("message");

            Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID());
            message.appendChild(hostUniqueID);

            Element messageRef = addElement(document, "messageRef", String.valueOf(transactionRef));
            message.appendChild(messageRef);

            Element messageType = addElement(document, "interfaceType", "Pallet Status Change");
            message.appendChild(messageType);

            Element messageInformation = addElement(document, "messageInformation", "SSCC=" + palhistto.getPallet().getSSCC());
            message.appendChild(messageInformation);

            Element messageDirection = addElement(document, "interfaceDirection", "Output");
            message.appendChild(messageDirection);

            Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));
            message.appendChild(messageDate);

            Element palletStatusChange = (Element) document.createElement("palletStatusChange");

            Element sscc = addElement(document, "SSCC", palhistto.getPallet().getSSCC());
            palletStatusChange.appendChild(sscc);
           
            Element material = addElement(document, "material", palhistto.getPallet().getMaterial());
            palletStatusChange.appendChild(material);

            Element batch = addElement(document, "batch", palhistto.getPallet().getBatchNumber());
            palletStatusChange.appendChild(batch);

            Element source = addElement(document,"origin",origin);
            palletStatusChange.appendChild(source);
           
            locn = palhistfrom.getPallet().getLocationID();
            Element location = addElement(document, "location", palhistto.getPallet().getLocationID());
            palletStatusChange.appendChild(location);
           
            Element quantity = addElement(document, "quantity", palhistto.getPallet().getQuantity().toString());
            palletStatusChange.appendChild(quantity);
           
            Element uom = addElement(document, "uom", palhistto.getPallet().getUom().toString());
            palletStatusChange.appendChild(uom);           
           
            Element despNo = addElement(document, "despatchNumber", palhistto.getPallet().getDespatchNo());
            palletStatusChange.appendChild(despNo)

            Element statusFrom = addElement(document, "statusFrom", palhistfrom.getPallet().getStatus());
            palletStatusChange.appendChild(statusFrom);

            Element statusTo = addElement(document, "statusTo", palhistto.getPallet().getStatus());
            palletStatusChange.appendChild(statusTo);
           
            decision =  palhistto.getPallet().getDecision();

            Element masterHoldNoticeData = (Element) document.createElement("masterHoldNoticeData");

            Element mhnNo = addElement(document, "MHN", mhnNumber);
            masterHoldNoticeData.appendChild(mhnNo);

            Element mhnRecorder = addElement(document, "recorder", recorder);
            masterHoldNoticeData.appendChild(mhnRecorder);

            Element mhnInitiator = addElement(document, "initiator", initiator);
            masterHoldNoticeData.appendChild(mhnInitiator);

            Element mhnAuthorisor = addElement(document, "authorisor", authorisor);
            masterHoldNoticeData.appendChild(mhnAuthorisor);
           
            Element mhnDecision = addElement(document, "decision", decision);
            masterHoldNoticeData.appendChild(mhnDecision);

            Element masterHoldReasons = (Element) document.createElement("reasons");

            if (reason1.equals("") == false)
            {
              Element masterHoldReason = (Element) document.createElement("reason");
              Element mhnReason1 = addElement(document, "code", reason1);
              masterHoldReason.appendChild(mhnReason1);
             
              mhnReasons.getReasonProperties(reason1);
              String reason1desc = mhnReasons.getDescription();
              Element mhnReason1desc = addElement(document, "description", reason1desc);
              masterHoldReason.appendChild(mhnReason1desc);
              masterHoldReasons.appendChild(masterHoldReason);
            }

            if (reason2.equals("") == false)
            {
              Element masterHoldReason = (Element) document.createElement("reason");
              Element mhnReason2 = addElement(document, "code", reason2);
              masterHoldReason.appendChild(mhnReason2);
             
              mhnReasons.getReasonProperties(reason2);
              String reason2desc = mhnReasons.getDescription();
              Element mhnReason2desc = addElement(document, "description", reason2desc);
              masterHoldReason.appendChild(mhnReason2desc);
              masterHoldReasons.appendChild(masterHoldReason);
            }

            if (reason3.equals("") == false)
            {
              Element masterHoldReason = (Element) document.createElement("reason");
              Element mhnReason3 = addElement(document, "code", reason3);
              masterHoldReason.appendChild(mhnReason3);
             
              mhnReasons.getReasonProperties(reason3);
              String reason3desc = mhnReasons.getDescription();
              Element mhnReason3desc = addElement(document, "description", reason3desc);
              masterHoldReason.appendChild(mhnReason3desc);
              masterHoldReasons.appendChild(masterHoldReason);
            }

            masterHoldNoticeData.appendChild(masterHoldReasons);

            Element mhnCreated = addElement(document, "created", dateCreated);
            masterHoldNoticeData.appendChild(mhnCreated);

            Element mhnExpected = addElement(document, "expected", dateExpected);
            masterHoldNoticeData.appendChild(mhnExpected);

            Element mhnResolved = addElement(document, "resolved", dateResolved);
            masterHoldNoticeData.appendChild(mhnResolved);

            Element mhnComments = addElement(document, "comments", comment);
            masterHoldNoticeData.appendChild(mhnComments);

            Element mhnStatus = addElement(document, "status", status);
            masterHoldNoticeData.appendChild(mhnStatus);

            palletStatusChange.appendChild(masterHoldNoticeData);

            Element messageData = (Element) document.createElement("messageData");
            messageData.appendChild(palletStatusChange);

            message.appendChild(messageData);

            document.appendChild(message);

            JXMLDocument xmld = new JXMLDocument();
            xmld.setDocument(document);
            gmh.decodeHeader(xmld);

            if (device.equals("Disk") | device.equals("Email"))
            {

              path = inter.getRealPath();
              if (fio.writeToDisk(path, document, transactionRef, "_"+locn.replace(" ", "_")+"_PalletStatusChange.xml") == true)
              {
                result = true;
                il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "File Write", fio.getFilename());
                setErrorMessage("");

                if (device.equals("Email"))
                {
                  ogm = new JeMailOutGoingMessage(inter, transactionRef, fio);
                  ogm.sendEmail();
                }
              }
              else
              {
                result = false;
                il.write(gmh, GenericMessageHeader.msgStatusError, fio.getErrorMessage(), "File Write", fio.getFilename());
                setErrorMessage(fio.getErrorMessage());
              }
            }

          }
View Full Code Here

  public Boolean processMessage(Long transactionRef)

  {
    Boolean result = false;
    String path = "";
    JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
    GenericMessageHeader gmh = new GenericMessageHeader();
    JDBInterface inter = new JDBInterface(getHostID(), getSessionID());

    inter.getInterfaceProperties("Pallet Delete", "Output");
    String device = inter.getDevice();

    JDBPalletHistory palhistfrom = new JDBPalletHistory(getHostID(), getSessionID());

    ResultSet rsFrom = palhistfrom.getInterfacingData(transactionRef, "DELETE", "MANUAL", Long.valueOf(1), "SSCC", "asc");

    try
    {
      if (rsFrom.next())
      {
        palhistfrom.getPropertiesfromResultSet(rsFrom);

        String locn = "";

        try
        {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();

          Document document = builder.newDocument();

          Element message = (Element) document.createElement("message");

          Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID());
          message.appendChild(hostUniqueID);

          Element messageRef = addElement(document, "messageRef", String.valueOf(transactionRef));
          message.appendChild(messageRef);

          Element messageType = addElement(document, "interfaceType", "Pallet Delete");
          message.appendChild(messageType);

          Element messageInformation = addElement(document, "messageInformation", "SSCC=" + palhistfrom.getPallet().getSSCC());
          message.appendChild(messageInformation);

          Element messageDirection = addElement(document, "interfaceDirection", "Output");
          message.appendChild(messageDirection);

          Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));
          message.appendChild(messageDate);

          Element palletDelete = (Element) document.createElement("palletDelete");

          Element sscc = addElement(document, "SSCC", palhistfrom.getPallet().getSSCC());
          palletDelete.appendChild(sscc);

          Element material = addElement(document, "material", palhistfrom.getPallet().getMaterial());
          palletDelete.appendChild(material);

          Element batch = addElement(document, "batch", palhistfrom.getPallet().getBatchNumber());
          palletDelete.appendChild(batch);

          locn = palhistfrom.getPallet().getLocationID();
          Element location = addElement(document, "location", palhistfrom.getPallet().getLocationID());
          palletDelete.appendChild(location);

          Element quantity = addElement(document, "quantity", palhistfrom.getPallet().getQuantity().toString());
          palletDelete.appendChild(quantity);

          Element uom = addElement(document, "uom", palhistfrom.getPallet().getUom().toString());
          palletDelete.appendChild(uom);

          Element statusFrom = addElement(document, "status", palhistfrom.getPallet().getStatus());
          palletDelete.appendChild(statusFrom);

          Element confirmed = addElement(document, "confirmed", palhistfrom.getPallet().getConfirmed());
          palletDelete.appendChild(confirmed);
         
          Element messageData = (Element) document.createElement("messageData");
          messageData.appendChild(palletDelete);

          message.appendChild(messageData);

          document.appendChild(message);

          JXMLDocument xmld = new JXMLDocument();
          xmld.setDocument(document);
          gmh.decodeHeader(xmld);

          if (device.equals("Disk") | device.equals("Email"))
          {

            path = inter.getRealPath();
            if (fio.writeToDisk(path, document, transactionRef, "_" + locn.replace(" ", "_") + "_PalletDelete.xml") == true)
            {
              result = true;
              il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "File Write", fio.getFilename());
              setErrorMessage("");

              if (device.equals("Email"))
              {
                ogm = new JeMailOutGoingMessage(inter, transactionRef, fio);
                ogm.sendEmail();
              }
            } else
            {
              result = false;
              il.write(gmh, GenericMessageHeader.msgStatusError, fio.getErrorMessage(), "File Write", fio.getFilename());
              setErrorMessage(fio.getErrorMessage());
            }
          }

        }
View Full Code Here

      dbconnected = true;
    }

    if (dbconnected)
    {
      JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
      JeMail mail = new JeMail(getHostID(), getSessionID());
      JDBInterface inter = new JDBInterface(getHostID(), getSessionID());
      IncommingMaterialDefinition imd = new IncommingMaterialDefinition(getHostID(), getSessionID());
      IncommingProcessOrderStatusChange iposc = new IncommingProcessOrderStatusChange(getHostID(), getSessionID());
      IncommingProductionDeclarationConfirmation ipd = new IncommingProductionDeclarationConfirmation(getHostID(), getSessionID());
      IncommingProcessOrder ipo = new IncommingProcessOrder(getHostID(), getSessionID());
      IncommingPalletStatusChange ipsc = new IncommingPalletStatusChange(getHostID(), getSessionID());
      IncommingBatchStatusChange bsc = new IncommingBatchStatusChange(getHostID(), getSessionID());
      IncommingInspectionResult iirslt = new IncommingInspectionResult(getHostID(), getSessionID());
      IncommingDespatchConfirmation idc = new IncommingDespatchConfirmation(getHostID(), getSessionID());
      IncommingQMInspectionRequest iireq = new IncommingQMInspectionRequest(getHostID(), getSessionID());
      GenericMessageHeader gmh = new GenericMessageHeader();
      LinkedList<String> filenames = new LinkedList<String>();

      while (true)
      {

        com.commander4j.util.JWait.milliSec(100);

        if (allDone)
        {
          if (dbconnected)
          {
            Common.hostList.getHost(hostID).disconnect(getSessionID());
          }
          return;
        }

        if (InboundMessageCollectionThread.recoveringFiles == false)
        {

          dir = new File(inputPath);
          chld = dir.list();

          if (chld == null)
          {
            allDone = true;
          }
          else
          {
            filenames.clear();
            for (int i = 0; (i < chld.length) & (i < maxfiles); i++)
            {
              fileName = chld[i];
              if (fileName.indexOf(".xml") > 0)
              {
                filenames.addFirst(fileName);
                com.commander4j.util.JWait.milliSec(50);
              }
            }

            if (filenames.size() > 0)
            {
              logger.debug("Begin processing " + String.valueOf(filenames.size()) + " files.");
              for (int i = filenames.size() - 1; i >= 0; i--)
              {
                if (allDone)
                {
                  if (dbconnected)
                  {
                    Common.hostList.getHost(hostID).disconnect(getSessionID());
                  }
                  return;
                }

                fromFile = filenames.get(i);

                try
                {
                  logger.debug("<---  START OF PROCESSING " + fromFile + "  ---->");
                  logger.debug("Reading message header : " + inputPath + fromFile);

                  if (gmh.readAddressInfo(inputPath + fromFile, getSessionID()) == true)
                  {

                    messageProcessedOK = true;
                    errorMessage = "";

                    if (gmh.getInterfaceType().length() == 0)
                    {
                      messageProcessedOK = false;
                      errorMessage = "Unrecognised Commander4j XML message format in file " + fromFile;
                      logger.debug(errorMessage);
                      String datetime = "";
                      datetime = JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime());
                      gmh.setMessageDate(datetime);
                      gmh.setInterfaceDirection("Unknown");
                      gmh.setMessageInformation(fromFile);
                      gmh.setInterfaceType("Unknown");
                      gmh.setMessageRef("Unknown");
                    }
                    else
                    {
                      if (gmh.getInterfaceDirection().equals("Input") == false)
                      {
                        messageProcessedOK = false;
                        errorMessage = "Inbound message ignored - Interface Direction = " + gmh.getInterfaceDirection();
                      }
                      else
                      {
                        String interfaceType = gmh.getInterfaceType();
                        logger.debug("Processing " + interfaceType + " started.");
                        if (interfaceType.equals("Despatch Confirmation") == true)
                        {
                          messageProcessedOK = idc.processMessage(gmh);
                          errorMessage = idc.getErrorMessage();
                        }

                        if (interfaceType.equals("Material Definition") == true)
                        {
                          messageProcessedOK = imd.processMessage(gmh);
                          errorMessage = imd.getErrorMessage();
                        }

                        if (interfaceType.equals("Process Order") == true)
                        {
                          messageProcessedOK = ipo.processMessage(gmh);
                          errorMessage = ipo.getErrorMessage();
                        }

                        if (interfaceType.equals("Pallet Status Change") == true)
                        {
                          messageProcessedOK = ipsc.processMessage(gmh);
                          errorMessage = ipsc.getErrorMessage();
                        }

                        if (interfaceType.equals("Batch Status Change") == true)
                        {
                          messageProcessedOK = bsc.processMessage(gmh);
                          errorMessage = bsc.getErrorMessage();
                        }

                        if (interfaceType.equals("Process Order Status Change") == true)
                        {
                          messageProcessedOK = iposc.processMessage(gmh);
                          errorMessage = iposc.getErrorMessage();
                        }

                        if (interfaceType.equals("Production Declaration") == true)
                        {
                          messageProcessedOK = ipd.processMessage(gmh);
                          errorMessage = ipd.getErrorMessage();
                        }
                       
                        if (interfaceType.equals("QM Inspection Request") == true)
                        {
                          messageProcessedOK = iireq.processMessage(gmh);
                          errorMessage = iireq.getErrorMessage();
                        }
                       
                        if (interfaceType.equals("QM Inspection Result") == true)
                        {
                          messageProcessedOK = iirslt.processMessage(gmh);
                          errorMessage = iirslt.getErrorMessage();
                        }
                       
                        GenericMessageHeader.updateStats("Input", interfaceType, messageProcessedOK.toString());
                        logger.debug("Processing " + interfaceType + " finished.");
                      }
                    }

                    logger.debug("    ===  RESULT " + messageProcessedOK.toString() + "  ===");

                    if (messageProcessedOK)
                    {

                      il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "DB Update", fromFile);
                      reader.deleteFile(backupPath + gmh.getInterfaceType() + File.separator + fromFile);
                      reader.move_FileToDirectory(inputPath + fromFile, backupPath + gmh.getInterfaceType(), true);
                    }
                    else
                    {
                      il.write(gmh, GenericMessageHeader.msgStatusError, errorMessage, "DB Update", fromFile);
                      if (inter.getInterfaceProperties(gmh.getInterfaceType(), "Input") == true)
                      {
                        if (inter.getEmailError() == true)
                        {
                          String emailaddresses = inter.getEmailAddresses();
View Full Code Here

  public Boolean processMessage(Long transactionRef) {
    Boolean result = false;
    String path = "";

    JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
    GenericMessageHeader gmh = new GenericMessageHeader();
    JDBInterface inter = new JDBInterface(getHostID(), getSessionID());
    JDBUom uoml = new JDBUom(getHostID(), getSessionID());
    inter.getInterfaceProperties("Despatch Pre Advice", "Output");
    String device = inter.getDevice();

    JDBDespatch desp = new JDBDespatch(getHostID(), getSessionID());
    desp.setTransactionRef(transactionRef);
    desp.getDespatchPropertiesFromTransactionRef();

    String sourceGLN = JUtility.replaceNullStringwithBlank(desp.getLocationDBFrom().getGLN());
    String destinationGLN = JUtility.replaceNullStringwithBlank(desp.getLocationDBTo().getGLN());
    Boolean suppressMessage = false;

    gmh.setMessageRef(desp.getTransactionRef().toString());
    gmh.setInterfaceType(inter.getInterfaceType());
    gmh.setMessageInformation("Despatch=" + desp.getDespatchNo());
    gmh.setInterfaceDirection(inter.getInterfaceDirection());
    gmh.setMessageDate(JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));

    if (sourceGLN.length() == 0)
    {
      setErrorMessage("Message Suppressed - No GLN Source (From) GLN for Location [" + desp.getLocationIDFrom() + "]");
      suppressMessage = true;
    }

    if (destinationGLN.length() == 0)
    {
      setErrorMessage("Message Suppressed - No GLN Destination (To) GLN for Location [" + desp.getLocationIDTo() + "]");
      suppressMessage = true;
    }

    if (suppressMessage == true)
    {
      result = true;
      il.write(gmh, GenericMessageHeader.msgStatusWarning, getErrorMessage(), "File Write", "");

    }
    else
    {

      if (inter.getFormat().equals("XML"))
      {

        try
        {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();

          Document document = builder.newDocument();

          Element message = (Element) document.createElement("message");

          Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID());
          message.appendChild(hostUniqueID);

          Element messageRef = addElement(document, "messageRef", String.valueOf(transactionRef));
          message.appendChild(messageRef);

          Element messageType = addElement(document, "interfaceType", "Despatch Pre Advice");
          message.appendChild(messageType);

          Element messageInformation = addElement(document, "messageInformation", "Despatch=" + desp.getDespatchNo());
          message.appendChild(messageInformation);

          Element messageDirection = addElement(document, "interfaceDirection", "Output");
          message.appendChild(messageDirection);

          Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));
          message.appendChild(messageDate);

          Element despatchConfirmation = (Element) document.createElement("despatchPreAdvice");

          Element noofpallets = addElement(document, "numberOfPallets", String.valueOf(desp.getTotalPallets()));
          despatchConfirmation.appendChild(noofpallets);

          Element haulier = addElement(document, "haulier", String.valueOf(JUtility.replaceNullStringwithBlank(desp.getHaulier())));
          despatchConfirmation.appendChild(haulier);

          Element trailer = addElement(document, "trailer", String.valueOf(JUtility.replaceNullStringwithBlank(desp.getTrailer())));
          despatchConfirmation.appendChild(trailer);

          Element despatch = addElement(document, "despatchNo", desp.getDespatchNo());
          despatchConfirmation.appendChild(despatch);

          Element despatchDate = addElement(document, "despatchDate", JUtility.getISOTimeStampStringFormat(desp.getDespatchDate()));
          despatchConfirmation.appendChild(despatchDate);

          Element locationFrom = addElement(document, "fromLocation", desp.getLocationIDFrom());
          despatchConfirmation.appendChild(locationFrom);

          Element locationFromGLN = addElement(document, "fromGLN", desp.getLocationDBFrom().getGLN());
          despatchConfirmation.appendChild(locationFromGLN);

          Element locationTo = addElement(document, "toLocation", desp.getLocationIDTo());
          despatchConfirmation.appendChild(locationTo);

          Element locationToGLN = addElement(document, "toGLN", desp.getLocationDBTo().getGLN());
          despatchConfirmation.appendChild(locationToGLN);

          Element contents = (Element) document.createElement("contents");
          despatchConfirmation.appendChild(contents);

          JDBPalletHistory palhist = new JDBPalletHistory(getHostID(), getSessionID());
          ResultSet rs = palhist.getInterfacingData(transactionRef, "DESPATCH", "TO", Long.valueOf(0), "SSCC", "asc");

          int x = 1;
          try
          {
            rs.beforeFirst();
            while (rs.next())
            {
              palhist.getPropertiesfromResultSet(rs);
              Element pallet = (Element) document.createElement("pallet");

              Element item = addElement(document, "item", String.valueOf(x));
              pallet.appendChild(item);
              x++;

              Element sscc = addElement(document, "SSCC", palhist.getPallet().getSSCC());
              pallet.appendChild(sscc);

              Element material = addElement(document, "material", palhist.getPallet().getMaterial());
              pallet.appendChild(material);

              Element ean = addElement(document, "ean", palhist.getPallet().getEAN());
              pallet.appendChild(ean);

              Element variant = addElement(document, "variant", palhist.getPallet().getVariant());
              pallet.appendChild(variant);

              Element qty = addElement(document, "quantity", palhist.getPallet().getQuantity().toString());
              pallet.appendChild(qty);

              String paluom = palhist.getPallet().getUom();
              paluom = uoml.convertUom(inter.getUOMConversion(), paluom);

              Element uom = addElement(document, "UOM", paluom);
              pallet.appendChild(uom);

              Element status = addElement(document, "status", palhist.getPallet().getStatus());
              pallet.appendChild(status);

              Element bbe = addElement(document, "bestBefore", JUtility.getISOTimeStampStringFormat(palhist.getPallet().getMaterialBatchExpiryDate()));
              pallet.appendChild(bbe);

              Element dom = addElement(document, "productionDate", JUtility.getISOTimeStampStringFormat(palhist.getPallet().getDateOfManufacture()));
              pallet.appendChild(dom);

              Element batch = addElement(document, "batch", palhist.getPallet().getBatchNumber());
              pallet.appendChild(batch);

              Element batchStatus = addElement(document, "batchStatus", palhist.getPallet().getMaterialBatchStatus());
              pallet.appendChild(batchStatus);

              contents.appendChild(pallet);

            }
            rs.close();
          }
          catch (SQLException e)
          {

          }

          Element messageData = (Element) document.createElement("messageData");
          messageData.appendChild(despatchConfirmation);

          message.appendChild(messageData);

          document.appendChild(message);

          JXMLDocument xmld = new JXMLDocument();
          xmld.setDocument(document);
          gmh.decodeHeader(xmld);

          if (device.equals("Disk") | device.equals("Email"))
          {
            path = inter.getRealPath();
            if (fio.writeToDisk(path, document, transactionRef, "_"+desp.getLocationIDTo().replace(" ", "_")+"_DespatchPreAdvice.xml") == true)
            {
              result = true;
              il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "File Write", fio.getFilename());
              setErrorMessage("");
              if (device.equals("Email"))
              {
                ogm = new JeMailOutGoingMessage(inter,transactionRef,fio);
                ogm.sendEmail();
              }
            }
            else
            {
              result = false;
              il.write(gmh, GenericMessageHeader.msgStatusError, fio.getErrorMessage(), "File Write", fio.getFilename());
              setErrorMessage(fio.getErrorMessage());
            }
          }
        }
View Full Code Here

  private void archive() {
    int n = JOptionPane.showConfirmDialog(Common.mainForm, "Archive Successful/Resolved Log Records ?", "Confirm", JOptionPane.YES_NO_OPTION, 0, Common.icon_confirm);
    if (n == 0)
    {
      JDBInterfaceLog interfaceLog = new JDBInterfaceLog(Common.selectedHostID, Common.sessionID);
      interfaceLog.archive();
      buildSQL();
      populateList();
    }
  }
View Full Code Here

  private void delete() {
    int n = JOptionPane.showConfirmDialog(Common.mainForm, "Delete selected Log record(s) ?", "Confirm", JOptionPane.YES_NO_OPTION, 0, Common.icon_confirm);
    if (n == 0)
    {

      JDBInterfaceLog interfaceLog = new JDBInterfaceLog(Common.selectedHostID, Common.sessionID);

      if (jTable1.getSelectedRowCount() > 0)
      {
        int first = jTable1.getSelectionModel().getMinSelectionIndex();
        int last = jTable1.getSelectionModel().getMaxSelectionIndex();
        for (int x = first; x <= last; x++)
        {
          if (jTable1.getSelectionModel().isSelectedIndex(x))
          {
            jTable1.getModel().getValueAt(x, 2);
            Long logID = (Long) jTable1.getModel().getValueAt(x, 0);
            interfaceLog.setInterfaceLogID(logID);
            interfaceLog.delete();
          }
        }
      }
      buildSQL();
      populateList();
View Full Code Here

TOP

Related Classes of com.commander4j.db.JDBInterfaceLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.