Beispiel #1
0
  /**
   * extract data from segment BIG that is part of the Header <br>
   * Beginning Segment for Invoice used <br>
   * To indicate the beginning of an invoice transaction set and transmit identifying numbers and
   * dates
   *
   * @param inTable table containing this segment
   * @throws OBOEException - most likely segment not found
   */
  public void extractHeaderBSN(Table inTable) throws OBOEException {
    Segment segment;
    // valid = false;
    try {
      segment = inTable.getSegment("BSN");
    } catch (OBOEException oe) {
      errorMsgs.add("Segment BSN missing");
      setValid(false);
      return;
    }
    String purposeCode = getField(segment, 1, true, "Missing Purpose Code in segment BSN");
    if (purposeCode == null) {
      String errorStr = "Purpose Code is null";
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }
    if (!purposeCode.equals("00")) {
      String errorStr = "Invalid value of Purpose Code in segment BSN: " + purposeCode;
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }
    ediInp856Vw.setPurposeCode(purposeCode);

    String shipmentIdentifier =
        getField(segment, 2, true, "Missing Shipment Identification in segment BSN");
    if (shipmentIdentifier == null) {
      String errorStr = "Shipment Identifier is null";
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }
    ediInp856Vw.setTransactionIdentifier(shipmentIdentifier);

    String transactionDateS = getField(segment, 3, true, "Missing Transaction Date in segment BSN");
    if (transactionDateS == null) {
      String errorStr = "Invalid value of Transaction Date in segment BSN: null";
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }

    if (transactionDateS.length() != 8) {
      String errorStr = "Invalid value of Transaction Date in segment BSN: " + transactionDateS;
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }

    String transactionTimeS = getField(segment, 4, true, "Missing Transaction Time in segment BSN");
    if (transactionTimeS == null) {
      String errorStr = "Invalid value of Transaction Time in segment BSN: " + transactionTimeS;
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }

    SimpleDateFormat sdf = null;
    if (transactionTimeS.length() >= 6) {
      if (transactionTimeS.length() > 6) transactionTimeS = transactionTimeS.substring(0, 6);
      sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    } else if (transactionTimeS.length() == 4) {
      sdf = new SimpleDateFormat("yyyyMMddHHmm");
    } else {
      String errorStr = "Invalid value of Transaction Time in segment BSN: " + transactionTimeS;
      errorMsgs.add(errorStr);
      setValid(false);
      return;
    }

    String transactionDateTimeS = transactionDateS + transactionTimeS;
    Date transactionDate = null;
    try {
      transactionDate = sdf.parse(transactionDateTimeS);
    } catch (Exception exc) {
      errorMsgs.add(
          "Invalid value of Transaction Date or Transaction Time: "
              + transactionDateS
              + " "
              + transactionTimeS);
      setValid(false);
      return;
    }
    if (!transactionDateTimeS.equals(sdf.format(transactionDate))) {
      errorMsgs.add(
          "Invalid value of Transaction Date or Transaction Time: "
              + transactionDateS
              + " "
              + transactionTimeS);
      setValid(false);
      return;
    }

    ediInp856Vw.setTransactionDate(transactionDate);
    return;
  }