diff --git a/Dsco.java b/Dsco.java new file mode 100644 index 0000000..a5f1493 --- /dev/null +++ b/Dsco.java @@ -0,0 +1,1795 @@ +package ediFilterTutorial; + +import java.io.File; +import java.text.NumberFormat; +import java.text.ParsePosition; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class Dsco extends EDI { + Error error = new Error(); + Printer printer; + FileIO fileIO; + // EDI_Filter filter = new EDI_Filter(); + ArrayList errorInformation = new ArrayList(); + private String decimalPattern = "\\d*\\.?\\d+"; + + public Dsco(Printer printer) { + this.printer = printer; + } + + public void dscoErrorCheck(String[] fileData, File selectedFile, String elementSeparator) { + // temporary holder for each line of the document + String holder = ""; + String[] element; + + boolean go = true; + + // List containing the segment data from ST to SE, which is where the + // transactions specific data is + ArrayList transactionData = new ArrayList(); + + // List containing the segments ISA, GS, GE, and IEA. (not sure if I need this) + ArrayList documentHeaderData = new ArrayList(); + + // while the variable is true continue the loop + while (go == true) { + for (int i = 0; i < fileData.length; i++) { + // sets the contents of the array into a String where it can be split later + holder = fileData[i]; + // split the holder string into elements using the elementSeparator variable + element = holder.split(elementSeparator); + + element[0] = element[0].trim(); + + if (element[0].equals("ST")) { + transactionData.add(fileData[i]); + if (element[1].isEmpty()) { + + // call printer class here + printer.logError(" " + error.getErrorMessage("General", "ST01 Empty")); + // stop filter because we don't know what the document is going to be doing. + go = false; + break; + } + // if the ST01 isn't empty store it in the variable this is what we are going to + // Switch on later + setTransactionType(element[1]); + + // if any of the 0 position elements are these values add them, but don't filter + // them + } + if (element[0].equals("ISA") || element[0].equals("GS") || element[0].equals("GE")) { + documentHeaderData.add(fileData[i]); + // if the 0 element is "SE" that is the end of the transaction and the data in + // the transactionData array list is what we are going to do the bulk of the + // error checking + } + if (element[0].equals("SE")) { + transactionData.add(fileData[i]); + + // take the variable in the transactionType and do a switch based on that value + // to error check the correct document + switch (getTransactionType()) { + case "846": + // start the error checking process for the Dsco 846 passing the Array List of + // the data and the elementSeparator variable + dsco846(transactionData, elementSeparator); + break; + case "856": + // System.out.println(transactionData); + // formattedEDI.append("\n You got to the 856 Switch statement"); + dsco856(transactionData, elementSeparator); + break; + case "870": + // System.out.println(transactionData); + // formattedEDI.append("\n You got to the 870 Switch statement"); + dsco870(transactionData, elementSeparator); + break; + case "810": + // System.out.println(transactionData); + // formattedEDI.append("\n You got to the 810 Switch statement"); + dsco810(transactionData, elementSeparator); + break; + } + // break; + + } + if (element[0].equals("IEA")) { + documentHeaderData.add(fileData[i]); + // setEDIData(errorInformation); + + printer.printToForm(errorInformation); + errorInformation.clear(); + go = false; + break; + } + if (!element[0].equals("ST") && !element[0].equals("SE") && !element[0].equals("ISA") + && !element[0].equals("GS") && !element[0].equals("GE") && !element[0].equals("IEA")) { + // formattedEDI.setText(element[0]); + transactionData.add(fileData[i]); + } + } + } + } + + private void dsco846(ArrayList transactionData, String elementSeparator) { + + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmmss"; + createFieldsDsco846(); + + HashMap fields = getRequiredFields(); + + String transactionSetControlHeader = ""; + + // Start the loop through the passed transaction data + for (int i = 0; i < transactionData.size(); i++) { + // assign the array element to holder + holder = transactionData.get(i); + + // remove whitespace from beginning and end of the string + holder.trim(); + + // split holder into the element array. So we can evaluate each segment of the + // EDI + element = holder.split(elementSeparator); + switch (element[0].trim()) { + + // Error Checking for the ST segment + case "ST": + fields.put("ST", true); + // checking the length of the array + if (element.length != 3) { + message += error.getErrorMessage("General", "ST Size"); + break; + } + // if the ST02 element isn't empty check the length of the data in that element. + if (!element[2].isEmpty()) { + if (element[2].length() > 9) { + message += error.getErrorMessage("General", "ST02 Size"); + } + } + // check to see if ST02 is empty if it is pull an error + if (element[2].isEmpty()) { + message += error.getErrorMessage("General", "ST02 empty"); + } + // if it isn't empty store the value in the ST02 in the + // transactionSetControlHeader variable for later comparison + else { + transactionSetControlHeader += element[2]; + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + + // Error Checking of the BIA segment + case "BIA": + // Try catch to look out for segments that are out of bounds. Most segments in + // the EDI are optional and don't get checked for formatting errors. So + // sometimes we run into a segment that isn't as long as it should be + // which means that the elements array is shorter than expected. + try { + fields.put("BIA", true); + // most of the logic for the rest of the method is specific to the 846 spec. + if (!element[1].equals("00")) { + message += error.getErrorMessage("846", "BIA01 Value"); + } + if (!element[2].equals("MM")) { + message += error.getErrorMessage("846", "BIA02 Value"); + } + if (element[3].isEmpty()) { + message += error.getErrorMessage("846", "BIA03 Empty"); + } + if (EDI_Filter.dateChecker(element[4], dateFormat) == false) { + message += error.getErrorMessage("846", "BIA04 Date"); + } + if (EDI_Filter.dateChecker(element[5], timeFormat) == false) { + message += error.getErrorMessage("846", "BIA05 Time"); + } + if (element.length < 6 || element.length > 6) { + message += error.getErrorMessage("846", "BIA Size"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error Checking of the CUR segment + case "CUR": + try { + if (element.length > 3 || element.length < 3) { + message += error.getErrorMessage("846", "CUR Size"); + break; + } else if (!element[1].equals("SE")) { + message += error.getErrorMessage("846", "CUR01 Value"); + } else if (!element[2].equals("USD")) { + message += error.getErrorMessage("846", "CUR02 Value"); + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error Checking of the REF segment + case "REF": + try { + // REF segment can be either 2 or 3 segments long. + if (element.length > 4 || element.length < 3) { + message += error.getErrorMessage("846", "REF Size"); + break; + } + // check value of the REF01 + if (element[1].equals("IA")) { + if (element[2].isEmpty()) { + message += error.getErrorMessage("846", "REF02 Empty"); + } + } + // check value of the REF01 + if (element[1].equals("ZZ")) { + if (element[3].equals("status")) { + // checks for all of the possible values that the REF02 can be + if (!element[2].equals("in-stock") && !element[2].equals("out-of-stock") + && !element[2].equals("discontinued") && !element[2].equals("hidden") + && !element[2].equals("pending")) { + message += error.getErrorMessage("846", "REF02ZZ Status Value"); + } + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + // Error checking of the LIN segment + + // This is the big segment where all the item information is populated and + // updated. + case "LIN": + try { + fields.put("LIN", true); + // Check the length for the max and min values + if (element.length > 32 || element.length < 4) { + message += error.getErrorMessage("846", "LIN Size"); + } + // if the LIN02 segment is empty throw error since that field is required + if (element[2].isEmpty()) { + message += error.getErrorMessage("846", "LIN02 Req"); + } + // Check the value of the LIN02, which has to be equal to 'SK' + if (!element[2].equals("SK")) { + message += error.getErrorMessage("846", "LIN02 Value"); + } // LIN03 can't be empty + if (element[3].isEmpty()) { + message += error.getErrorMessage("846", "LIN03 Req"); + } + // Check the length of the element because suppliers can send less than 5 + // segments + if (element.length >= 6) { + if (!element[4].isEmpty()) { + // LIN04 has to be "UP" + if (!element[4].equals("UP")) { + message += error.getErrorMessage("846", "LIN04 Value"); + } + // UPCs have to be either 6 or 12 digits long. They cannot be anything else + // (most common error I see with EDI) + if (element[5].length() != 12 && element[5].length() != 8) { + message += error.getErrorMessage("846", "LIN05 Size"); + } // LIN05 can't be empty when LIN04 has data + if (element[5].isEmpty()) { + message = message + error.getErrorMessage("846", "LIN05 Empty"); + } + } + } + if (element.length >= 7) { + if (!element[6].equals("EN")) { + message += error.getErrorMessage("846", "LIN06 Value"); + } + if (!element[6].isEmpty()) { + if (element[7].isEmpty()) { + message += error.getErrorMessage("846", "LIN07 Empty"); + } else { + // EAN's can only have 13 digits. No more no less. + if (element[7].length() != 13) { + message += error.getErrorMessage("846", "LIN07 Size"); + } + } + } + } + if (element.length >= 9) { + if (!element[8].isEmpty()) { + if (!element[8].equals("MG")) { + message += error.getErrorMessage("846", "LIN08 Value"); + } + if (element[9].isEmpty()) { + message += error.getErrorMessage("846", "LIN09 Empty"); + } + + } + } + if (element.length >= 11) { + if (!element[10].isEmpty()) { + if (!element[10].equals("IB")) { + message += error.getErrorMessage("846", "LIN10 Value"); + } else if (element[11].isEmpty()) { + message += error.getErrorMessage("846", "LIN11 Empty"); + } + } + } + if (element.length >= 13) { + if (!element[12].isEmpty()) { + if (!element[12].equals("UK")) { + message += error.getErrorMessage("846", "LIN12 Value"); + } + if (element[13].isEmpty()) { + message += error.getErrorMessage("846", "LIN13 Empty"); + } + } + } + if (element.length >= 15) { + if (!element[14].isEmpty()) { + if (!element[14].equals("BL")) { + message += error.getErrorMessage("846", "LIN14 Value"); + } + if (element[15].isEmpty()) { + message += error.getErrorMessage("846", "LIN15 Empty"); + } + } + } + if (element.length >= 17) { + if (!element[16].isEmpty()) { + } + if (!element[16].equals("SK")) { + message += error.getErrorMessage("846", "LIN16 Value"); + } + if (element[17].isEmpty()) { + message += error.getErrorMessage("846", "LIN17 Empty"); + } + } + if (element.length >= 19) { + if (!element[18].isEmpty()) { + } + if (!element[18].equals("SK")) { + message += error.getErrorMessage("846", "LIN18 Value"); + } + if (element[19].isEmpty()) { + message += error.getErrorMessage("846", "LIN19 Empty"); + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + // Error checking for the PID segment + + case "PID": + try { + // size if this segment must be 5. + if (element.length != 6) { + message += error.getErrorMessage("846", "PID Size"); + break; + } + if (!element[1].equals("F")) { + message += error.getErrorMessage("846", "PID01 Value"); + } + if (!element[2].equals("08")) { + message += error.getErrorMessage("846", "PID02 Value"); + } + if (!element[1].isEmpty() && !element[2].isEmpty() && element[5].isEmpty()) { + message += error.getErrorMessage("846", "PID05 Empty"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error Checking for the CTP Segment + case "CTP": + try { + if (element.length != 4) { + message += error.getErrorMessage("846", "CTP Size"); + } + if (!element[1].equals("AS")) { + message += error.getErrorMessage("846", "CTP01 Value"); + } + if (!element[2].equals("WHL")) { + message += error.getErrorMessage("846", "CTP02 Value"); + } + if (!element[3].matches("\\d*\\.?\\d+")) { + message += error.getErrorMessage("846", "CTP03 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error check for the QTY segment + case "QTY": + try { + fields.put("QTY", true); + if (element.length != 4) { + message += error.getErrorMessage("846", "QTY Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty()) { + message += error.getErrorMessage("846", "QTY Empty"); + break; + } + if (!element[1].isEmpty()) { + if (!element[1].equals("33")) { + message += error.getErrorMessage("846", "QTY01 Value"); + } + if (!element[3].equals("EA")) { + message += error.getErrorMessage("846", "QTY03 Value"); + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error checking for the SCH01 segment + case "SCH": + try { + if (element.length != 7) { + message += error.getErrorMessage("846", "SCH Size"); + break; + } else if (!element[1].isEmpty()) { + if (!element[2].equals("EA")) { + message += error.getErrorMessage("846", "SCH02 Value"); + } + if (!element[5].equals("018")) { + message += error.getErrorMessage("846", "SCHO5 Value"); + } + if (!element[5].isEmpty()) { + if (element[6].isEmpty()) { + message += error.getErrorMessage("846", "SCH06 Empty"); + } + if (!element[6].equals("20391231")) { + if (!EDI_Filter.dateChecker(element[6], dateFormat)) { + message += error.getErrorMessage("846", "SCH06 Value"); + } + } + + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error Checking for the N1 segment + case "N1": + try { + if (element.length != 5) { + message += error.getErrorMessage("846", "N1 Size"); + } else if (!element[1].isEmpty()) { + if (!element[1].equals("SE")) { + message += error.getErrorMessage("846", "N101 Value"); + } + if (element[2].isEmpty() || element[3].isEmpty() || element[4].isEmpty()) { + message += error.getErrorMessage("846", "N1 Empty"); + } + if (!element[3].equals("ZZ")) { + message += error.getErrorMessage("846", "N103 Value"); + } + if (element[4].isEmpty()) { + message += error.getErrorMessage("846", "N104 Empty"); + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + // Error Checking for the SE segment + + case "SE": + try { + fields.put("SE", true); + int result; + String count = ""; + count += element[1]; + result = Integer.parseInt(count); + if (element.length != 3) { + message += error.getErrorMessage("General", "SE Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage("General", "SE01 Empty"); + break; + } + if (result != transactionData.size()) { + message += error.getErrorMessage("General", "SE01 Value"); + } + if (!element[2].equals(transactionSetControlHeader)) { + message += error.getErrorMessage("General", "SE02 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + default: + message = "Check this segment: " + element[0] + + " there may be whitespace that the filter isn't catching."; + errorInformation.add(holder + message); + message = ""; + break; + } + } + if (getFileWriteFlag()) { + setEDIData(errorInformation); + // fileIO.writeCheckedToFile(getEDIData()); + + } + // printer.printToForm(errorInformation); + errorInformation.add(error.evaluateReqFields(fields)); + } + + private void dsco856(ArrayList transactionData, String elementSeparator) { + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmm"; + createFieldsDsco856(); + + HashMap fields = getRequiredFields(); + + String transactionSetControlHeader = ""; + + // this will be the array that contains what we are going to print to the + // field--- had to do it this way because the error messages weren't getting + // added to the original ArrayList + + // ArrayList errorInformation = new ArrayList(); + + for (int i = 0; i < transactionData.size(); i++) { + // assign the array element to holder + holder = transactionData.get(i); + holder = holder.trim(); + // remove whitespace from beginning and end of the string + + // split holder into the element array. So we can evaluate each segment of the + // EDI + element = holder.split(elementSeparator); + // element[0] = element[0].trim(); + // if(elementSeparator != "/n") { + // element[0] = element[0].replaceAll("/n", ""); + // } + switch (element[0]) { + case "ST": + fields.put("ST", true); + if (element.length != 3) { + message += error.getErrorMessage("General", "ST Size"); + break; + } + // if the ST02 element isn't empty check the length of the data in that element. + if (!element[2].isEmpty()) { + if (element[2].length() > 9) { + message += error.getErrorMessage("General", "ST02 Size"); + } + } + // check to see if ST02 is empty if it is pull an error + if (element[2].isEmpty()) { + message += error.getErrorMessage("General", "ST02 empty"); + } + // if it isn't empty store the value in the ST02 in the + // transactionSetControlHeader variable for later comparison + else { + transactionSetControlHeader += element[2]; + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "CUR": + if (element.length != 3) { + error.getErrorMessage(getTransactionType(), "CUR Size"); + } + if (!element[1].isEmpty() && !element[2].isEmpty()) { + if (!element[1].equals("BY")) { + error.getErrorMessage(getTransactionType(), "CUR01 Value"); + } + if (!element[2].equals("USD")) { + error.getErrorMessage(getTransactionType(), "CUR02 Value"); + } + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "BSN": + fields.put("BSN", true); + try { + if (element.length != 6) { + message += error.getErrorMessage(getTransactionType(), "BSN Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty() || element[4].isEmpty() + || element[5].isEmpty()) { + error.getErrorMessage(getTransactionType(), "BSN Segments Empty"); + } + if (!element[1].equals("00")) { + message += error.getErrorMessage(getTransactionType(), "BSN01 Value"); + } + if (element[2].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "BSN02 Empty"); + } + if (!EDI_Filter.dateChecker(element[3], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "BSN03 Format"); + } + if (!EDI_Filter.dateChecker(element[4], timeFormat)) { + message += error.getErrorMessage(getTransactionType(), "BSN04 Format"); + } + if (!element[5].equals("0004")) { + message += error.getErrorMessage(getTransactionType(), "BSN05 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "HL": + try { + fields.put("HL", true); + if (element.length != 4) { + error.getErrorMessage(getTransactionType(), "HL Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty()) { + error.getErrorMessage(getTransactionType(), "HL Empty"); + } + if (!element[3].equals("O") && !element[3].equals("I") && !element[3].equals("S")) { + error.getErrorMessage(getTransactionType(), "HL03 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "TD5": + try { + fields.put("TD5", true); + if (element.length != 9) { + error.getErrorMessage(getTransactionType(), "TD5 Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty() || element[4].isEmpty() + || element[5].isEmpty() || element[7].isEmpty() || element[8].isEmpty()) { + error.getErrorMessage(getTransactionType(), "TD5 Segments Empty"); + } + if (!element[1].equals("Z")) { + error.getErrorMessage(getTransactionType(), "TD501 Value"); + } + if (!element[2].equals("ZZ")) { + error.getErrorMessage(getTransactionType(), "TD502 Value"); + } + if (!element[4].equals("ZZ")) { + error.getErrorMessage(getTransactionType(), "TD504 Value"); + } + if (!element[7].equals("ZZ")) { + error.getErrorMessage(getTransactionType(), "TD507 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "REF": + try { + fields.put("REF", true); + + if (element.length < 3 || element.length > 4) { + error.getErrorMessage(getTransactionType(), "REF Size"); + } + if (!element[1].equals("IA") && !element[1].equals("CN") && !element[1].equals("CO") + && !element[1].equals("VN") && !element[1].equals("ZZ")) { + error.getErrorMessage(getTransactionType(), "REF01 Value"); + } + if (element[1].isEmpty()) { + error.getErrorMessage(getTransactionType(), "REF01 Empty"); + } + if (!element[1].isEmpty()) { + if (element[2].isEmpty()) { + error.getErrorMessage(getTransactionType(), "REF02 Empty"); + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "DTM": + try { + fields.put("DTM", true); + if (element.length != 4) { + message += error.getErrorMessage(getTransactionType(), "DTM Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "DTM Empty"); + } else { + if (!element[1].equals("011")) { + message += error.getErrorMessage(getTransactionType(), "DTM01 Value"); + } + if (!EDI_Filter.dateChecker(element[2], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "DTM02 Format"); + } + if (!EDI_Filter.dateChecker(element[3], timeFormat)) { + message += error.getErrorMessage(getTransactionType(), "DTM03 Format"); + } + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "LIN": + try { + fields.put("LIN", true); + if (element[2].isEmpty() || element[3].isEmpty()) { + error.getErrorMessage(getTransactionType(), "LIN Empty"); + } + if (!element[2].equals("SK")) { + error.getErrorMessage(getTransactionType(), "LIN02 Value"); + } + if (element[3].length() > 70) { + error.getErrorMessage(getTransactionType(), "LIN03 Char Limit"); + } + if (element.length < 4 || element.length > 18) { + error.getErrorMessage(getTransactionType(), "LIN Size"); + } + if (element.length >= 6) { + if (!element[4].isEmpty()) { + // LIN04 has to be "UP" + if (!element[4].equals("UP")) { + message += error.getErrorMessage("846", "LIN04 Value"); + } + // UPCs have to be either 6 or 12 digits long. They cannot be anything else + // (most common error I see with EDI) + if (element[5].length() != 12 && element[5].length() != 8) { + message += error.getErrorMessage("846", "LIN05 Size"); + } // LIN05 can't be empty when LIN04 has data + if (element[5].isEmpty()) { + message = message + error.getErrorMessage("846", "LIN05 Empty"); + } + } + } + if (element.length >= 7) { + if (!element[6].equals("EN")) { + message += error.getErrorMessage("846", "LIN06 Value"); + } + if (!element[6].isEmpty()) { + if (element[7].isEmpty()) { + message += error.getErrorMessage("846", "LIN07 Empty"); + } else { + // EAN's can only have 13 digits. No more no less. + if (element[7].length() != 13) { + message += error.getErrorMessage("846", "LIN07 Size"); + } + } + } + } + if (element.length >= 9) { + if (!element[8].isEmpty()) { + if (!element[8].equals("MG")) { + message += error.getErrorMessage("846", "LIN08 Value"); + } + if (element[9].isEmpty()) { + message += error.getErrorMessage("846", "LIN09 Empty"); + } + + } + } + if (element.length >= 11) { + if (!element[10].isEmpty()) { + if (!element[10].equals("IB")) { + message += error.getErrorMessage("846", "LIN10 Value"); + } else if (element[11].isEmpty()) { + message += error.getErrorMessage("846", "LIN11 Empty"); + } + } + } + if (element.length >= 13) { + if (!element[12].isEmpty()) { + if (!element[12].equals("UK")) { + message += error.getErrorMessage("846", "LIN12 Value"); + } + if (element[13].isEmpty()) { + message += error.getErrorMessage("846", "LIN13 Empty"); + } + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "PRF": + fields.put("PRF", true); + if (element.length != 2) { + error.getErrorMessage(getTransactionType(), "PRF Size"); + } + if (element[1].isEmpty()) { + error.getErrorMessage(getTransactionType(), "PRF01 Empty"); + } + case "SN1": + fields.put("SN1", true); + try { + if (!element[1].isEmpty()) { + error.getErrorMessage(getTransactionType(), "SN101 Value"); + } + if (element[2].isEmpty() || element[3].isEmpty()) { + error.getErrorMessage(getTransactionType(), "SN1 Empty"); + } + if (!element[3].isEmpty()) { + if (element[3].equals("EA")) { + error.getErrorMessage(getTransactionType(), "SN103 Value"); + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "SAC": + try { + if (element.length != 6) { + message += error.getErrorMessage(getTransactionType(), "SAC Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[5].isEmpty()) { + error.getErrorMessage(getTransactionType(), "SAC Empty"); + } + if (!element[1].equals("C")) { + message += error.getErrorMessage(getTransactionType(), "SAC01 Value"); + } + if (!element[2].equals("G821")) { + message += error.getErrorMessage(getTransactionType(), "SAC02 Value"); + } + if (!element[5].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "SAC05 Decimal"); + } + if (!element[3].isEmpty() || !element[4].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "SAC04 Value"); + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "SE": + try { + fields.put("SE", true); + int result; + String count = ""; + count += element[1]; + result = Integer.parseInt(count); + if (element.length != 3) { + message += error.getErrorMessage("General", "SE Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage("General", "SE01 Empty"); + break; + } + if (result != transactionData.size()) { + message += error.getErrorMessage("General", "SE01 Value"); + } + if (!element[2].equals(transactionSetControlHeader)) { + message += error.getErrorMessage("General", "SE02 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + default: + message = "Check this segment: " + element[0] + + " there may be whitespace that the filter isn't catching."; + errorInformation.add(holder + message); + message = ""; + break; + + } + } + // printer.printToForm(errorInformation); + errorInformation.add(error.evaluateReqFields(fields)); + } + + private void dsco810(ArrayList transactionData, String elementSeparator) { + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmm"; + createFieldsDsco810(); + + int lineItemCount = 0; + + HashMap fields = getRequiredFields(); + + String transactionSetControlHeader = ""; + + // this will be the array that contains what we are going to print to the + // field--- had to do it this way because the error messages weren't getting + // added to the original ArrayList + + // ArrayList errorInformation = new ArrayList(); + + for (int i = 0; i < transactionData.size(); i++) { + // assign the array element to holder + holder = transactionData.get(i); + holder = holder.trim(); + // remove whitespace from beginning and end of the string + + // split holder into the element array. So we can evaluate each segment of the + // EDI + element = holder.split(elementSeparator); + // element[0] = element[0].trim(); + // if(elementSeparator != "/n") { + // element[0] = element[0].replaceAll("/n", ""); + // } + switch (element[0]) { + case "ST": + fields.put("ST", true); + if (element.length != 3) { + message += error.getErrorMessage("General", "ST Size"); + break; + } + // if the ST02 element isn't empty check the length of the data in that element. + if (!element[2].isEmpty()) { + if (element[2].length() > 9) { + message += error.getErrorMessage("General", "ST02 Size"); + } + } + // check to see if ST02 is empty if it is pull an error + if (element[2].isEmpty()) { + message += error.getErrorMessage("General", "ST02 empty"); + } + // if it isn't empty store the value in the ST02 in the + // transactionSetControlHeader variable for later comparison + else { + transactionSetControlHeader += element[2]; + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "BIG": + try { + fields.put("BIG", true); + if (element.length != 5) { + message += error.getErrorMessage(getTransactionType(), "BIG Size"); + } + if (element[1].isEmpty() || element[2].isEmpty() || element[4].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "BIG Req Empty"); + } + if (!EDI_Filter.dateChecker(element[1], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "BIG01 Format"); + } + if (!EDI_Filter.dateChecker(element[3], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "BIG03 Format"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + + case "CUR": + try { + if (element.length != 3) { + message += error.getErrorMessage(getTransactionType(), "CUR Size"); + } + if (!element[1].equals("BY")) { + error.getErrorMessage(getTransactionType(), "CUR01 Value"); + } + if (!element[2].equals("USD")) { + error.getErrorMessage(getTransactionType(), "CUR02 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + case "REF": + try { + if (element.length != 3 && element.length != 4) { + error.getErrorMessage(getTransactionType(), "REF Size"); + } + if (!element[1].equals("ZZ") && !element[1].equals("IA") && !element[1].equals("IV") + && !element[1].equals("CO") && !element[1].equals("CN")) { + message += error.getErrorMessage(getTransactionType(), "REF01 Value"); + } + if (element[2].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "REF02 Empty"); + } + if (!element[3].isEmpty()) { + if (element[1].equals("ZZ")) { + if (element[3].equals("ship_transportation_method_code")) { + if (!element[2].equals("A") && !element[2].equals("J") && !element[2].equals("R") + && !element[2].equals("S")) { + message += error.getErrorMessage(getTransactionType(), "REF ZZTransportation Code"); + } + + } + if (!element[3].equals("ship_carrier") && !element[3].equals("ship_method") + && !element[3].equals("shipping_service_level_code") + && !element[3].equals("ship_transportation_method_code") + && !element[3].equals("ship_reference_number_qualifier") + && !element[3].equals("invoice_subtotal_excluding_line_items") + && !element[3].equals("invoice_line_items_subtotal") + && !element[3].equals("line_item_extended_amount") + && !element[3].equals("line_item_handling_amount") + && !element[3].equals("line_item_ship_amount") + && !element[3].equals("line_item_ship_carrier") + && !element[3].equals("line_item_ship_method") + && !element[3].equals("line_item_shipping_service_level_code") + && !element[3].equals("line_item_promotion_reference") + && !element[3].equals("line_item_promotion_amount") + && !element[3].equals("line_item_tax_amount") + && !element[3].equals("line_item_subtotal")) { + + message += error.getErrorMessage(getTransactionType(), "REF03 ZZValues"); + + } + if (element[3].equals("ship_reference_number_qualifier")) { + if (!element[2].equals("BM") && !element[2].equals("CN")) { + message += error.getErrorMessage(getTransactionType(), "REF Ship_reference Value"); + } + } + if (element[3].equals("invoice_subtotal_excluding_line_items") + || element[3].equals("invoice_line_items_subtotal") + || element[3].equals("line_item_extended_amount") + || element[3].equals("line_item_handling_amount") + || element[3].equals("line_item_ship_amount") + || element[3].equals("line_item_promotion_amount") + || element[3].equals("line_item_tax_amount") + || element[3].equals("line_item_subtotal")) { + if (!element[2].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "REF Decimal"); + } + } + + } + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "N1": + try { + if (element.length != 3) { + message += error.getErrorMessage(getTransactionType(), "N1 Size"); + } + if (!element[1].equals("ST") && !element[1].equals("SF")) { + message += error.getErrorMessage(getTransactionType(), "N101 Value"); + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "N3": + try { + if (element.length != 3) { + error.getErrorMessage(getTransactionType(), "N3 Size"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "N4": + try { + if (element.length != 5) { + + error.getErrorMessage(getTransactionType(), "N4 Size"); + + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "ITD": + fields.put("ITD", true); + try { + if (element.length != 14) { + error.getErrorMessage(getTransactionType(), "ITD Size"); + } + if (!element[1].equals("01") && !element[1].equals("02") && !element[1].equals("05") + && !element[1].equals("08") && !element[1].equals("12")) { + + message += error.getErrorMessage(getTransactionType(), "ITD01 Value"); + } + if (!element[2].equals("3")) { + message += error.getErrorMessage(getTransactionType(), "ITD02 Value"); + } + if (element[1].equals("02") || element[1].equals("12")) { + if (element[4].isEmpty() || element[5].isEmpty() || element[6].isEmpty() || element[7].isEmpty() + || element[13].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ITD Req Empty"); + } + if (!element[9].isEmpty() || !element[10].isEmpty() || !element[11].isEmpty() + || element[12].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ITD09-12 Populated"); + } + if (!element[8].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "ITD08 Value"); + } + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + case "DTM": + try { + if (element.length != 4) { + message += error.getErrorMessage(getTransactionType(), "DTM Size"); + } else { + + if (!element[1].equals("011")) { + message += error.getErrorMessage(getTransactionType(), "DTM01 Value"); + } + if (!EDI_Filter.dateChecker(element[2], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "DTM02 Format"); + } + if (!EDI_Filter.dateChecker(element[3], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "DTM03 Format"); + } + + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "IT1": + fields.put("IT1", true); + lineItemCount++; + try { + + if (element.length < 8 || element.length > 20) { + message += error.getErrorMessage(getTransactionType(), "IT1 Size"); + } + if (element[2].isEmpty() || element[7].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT1 Req Empty"); + } + if (!element[3].equals("EA")) { + message += error.getErrorMessage(getTransactionType(), "IT103 Value"); + } + if (!element[4].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "IT104 Value"); + } + if (!element[5].equals("QT") && !element[5].equals("LE")) { + message += error.getErrorMessage(getTransactionType(), "IT105 Value"); + } + if (!element[6].equals("SK")) { + message += error.getErrorMessage(getTransactionType(), "IT106 Value"); + } + if (element[7].length() > 70) { + message += error.getErrorMessage(getTransactionType(), "IT107 SKU Length"); + } + if (!element[8].isEmpty()) { + if (!element[8].equals("UP")) { + message += error.getErrorMessage(getTransactionType(), "IT108 Value"); + } + if (element[9].length() != 6 && element[9].length() != 12) { + message += error.getErrorMessage(getTransactionType(), "IT109 UPC Length"); + + } + if (element[9].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT109 Empty"); + } + } + if (!element[10].isEmpty()) { + if (!element[10].equals("EN")) { + message += error.getErrorMessage(getTransactionType(), "IT110 Value"); + } + if (element[11].length() != 13) { + message += error.getErrorMessage(getTransactionType(), "IT111 EAN Length"); + } + if (element[11].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT111 Empty"); + } + } + if (!element[12].isEmpty()) { + if (!element[12].equals("MG")) { + message += error.getErrorMessage(getTransactionType(), "IT112 Value"); + } + if (element[13].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT113 Empty"); + } + } + if (!element[14].isEmpty()) { + if (!element[14].equals("ZZ")) { + message += error.getErrorMessage(getTransactionType(), "IT114 Value"); + } + if (element[15].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT115 Empty"); + } + } + if (!element[16].isEmpty()) { + if (!element[16].equals("ZZ")) { + message += error.getErrorMessage(getTransactionType(), "IT116 Value"); + } + if (element[17].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT117 Empty"); + } + } + if (!element[18].isEmpty()) { + if (!element[18].equals("ZZ")) { + message += error.getErrorMessage(getTransactionType(), "IT118 Value"); + } + if (element[19].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "IT119 Empty"); + } + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "TDS": + fields.put("TDS", true); + try { + + if (element.length > 3) { + message += error.getErrorMessage(getTransactionType(), "TDS Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "TDS01 Empty"); + } else { + if (!element[1].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "TDS01 Value"); + } + if (!element[2].isEmpty()) { + if (!element[2].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "TDS02 Value"); + } + } + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "AMT": + try { + if (!element[1].equals("OH") && !element[1].equals("F7")) { + message += error.getErrorMessage(getTransactionType(), "AMT01 Value"); + } + if (!element[2].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "AMT02 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "SAC": + try { + if (element.length != 6) { + message += error.getErrorMessage(getTransactionType(), "SAC Size"); + } + if (!element[1].equals("C")) { + message += error.getErrorMessage(getTransactionType(), "SAC01 Value"); + } + if (!element[2].equals("D240")) { + message += error.getErrorMessage(getTransactionType(), "SAC02 Value"); + } + if (!element[3].isEmpty() || !element[4].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "SAC Req Populated"); + } + if (!element[5].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "SAC05 Value"); + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + case "ISS": + try { + + if (element.length != 5) { + message += error.getErrorMessage(getTransactionType(), "ISS Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ISS01 Empty"); + } + if (!element[2].equals("CA") && !element[2].equals("BX") && !element[2].equals("PK")) { + + message += error.getErrorMessage(getTransactionType(), "ISS02 Value"); + } + if (element[3].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ISS03 Empty"); + } + if (!element[4].equals("LB") && !element[4].equals("OZ") && !element[4].equals("50")) { + message += error.getErrorMessage(getTransactionType(), "ISS04 Value"); + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "CTT": + String tempHolder = ""; + int transactionLines; + try { + fields.put("CTT", true); + + tempHolder += element[1]; + + transactionLines = Integer.parseInt(tempHolder); + + if (element.length != 2) { + message += error.getErrorMessage(getTransactionType(), "CTT Size"); + } + if (transactionLines != lineItemCount) { + message += error.getErrorMessage(getTransactionType(), "CTT01 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + + errorInformation.add(holder + message); + message = ""; + break; + + case "SE": + try { + fields.put("SE", true); + int result; + String count = ""; + count += element[1]; + result = Integer.parseInt(count); + if (element.length != 3) { + message += error.getErrorMessage("General", "SE Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage("General", "SE01 Empty"); + break; + } + if (result != transactionData.size()) { + message += error.getErrorMessage("General", "SE01 Value"); + } + if (!element[2].equals(transactionSetControlHeader)) { + message += error.getErrorMessage("General", "SE02 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + } + + } + errorInformation.add(error.evaluateReqFields(fields)); + } + + private void dsco870(ArrayList transactionData, String elementSeparator) { + + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmm"; + int size = transactionData.size(); + + HashMap fields = getRequiredFields(); + + String transactionSetControlHeader = ""; + + for (int i = 0; i < transactionData.size(); i++) { + // assign the array element to holder + holder = transactionData.get(i); + holder = holder.trim(); + // remove whitespace from beginning and end of the string + + // split holder into the element array. So we can evaluate each segment of the + // EDI + element = holder.split(elementSeparator); + // element[0] = element[0].trim(); + // if(elementSeparator != "/n") { + // element[0] = element[0].replaceAll("/n", ""); + // } + switch (element[0]) { + case "ST": + fields.put("ST", true); + if (element.length != 3) { + message += error.getErrorMessage("General", "ST Size"); + break; + } + // if the ST02 element isn't empty check the length of the data in that element. + if (!element[2].isEmpty()) { + if (element[2].length() > 9) { + message += error.getErrorMessage("General", "ST02 Size"); + } + } + // check to see if ST02 is empty if it is pull an error + if (element[2].isEmpty()) { + message += error.getErrorMessage("General", "ST02 empty"); + } + // if it isn't empty store the value in the ST02 in the + // transactionSetControlHeader variable for later comparison + else { + transactionSetControlHeader += element[2]; + } + // add the data with any errors to the errorInformation ArrayList + errorInformation.add(holder + message); + // set message to blank to be ready for the next set of errors + message = ""; + // get out of the loop so we can move on to the next segment in the EDI + break; + + case "BSR": + try { + fields.put("BSR", true); + + if (element.length != 5) { + message += error.getErrorMessage(getTransactionType(), "BSR Size"); + } + if (!element[1].equals("2")) { + message += error.getErrorMessage(getTransactionType(), "BSR01 Value"); + } + if (!element[2].equals("PP")) { + message += error.getErrorMessage(getTransactionType(), "BSR02 Value"); + } + if (element[3].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "BSR03 Empty"); + } + if (!EDI_Filter.dateChecker(element[4], dateFormat)) { + message += error.getErrorMessage(getTransactionType(), "BSR04 Format"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + case "HL": + fields.put("HL", true); + + try { + if (element.length != 4) { + message += error.getErrorMessage(getTransactionType(), "HL Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "HL01 Empty"); + } + if (element[2].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "HL02 Empty"); + } + if (!element[3].equals("O") && !element[3].equals("I")) { + message += error.getErrorMessage(getTransactionType(), "HL03 Value"); + } + if (!isNumber(element[2])) { + message += error.getErrorMessage(getTransactionType(), "HL02 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + + case "PRF": + fields.put("PRF", true); + + try { + if (element.length != 2) { + message += error.getErrorMessage(getTransactionType(), "PRF Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PRF01 Empty"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + case "REF": + try { + + if (element.length < 3 && element.length > 4) { + message += error.getErrorMessage(getTransactionType(), "REF Size"); + } + if (!element[1].equals("IA") && !element[1].equals("CO") && !element[1].equals("VN")) { + message += error.getErrorMessage(getTransactionType(), "REF01 Value"); + } + if (element[2].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "REF02 Empty"); + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + case "PO1": + fields.put("PO1", true); + try { + if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty() || element[4].isEmpty() + || element[6].isEmpty() || element[7].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PO1 Req Empty"); + } else { + if (convertToNumber(element[1]) < 1) { + message += error.getErrorMessage(getTransactionType(), "PO101 Value"); + } + if (convertToNumber(element[2]) < 1) { + message += error.getErrorMessage(getTransactionType(), "PO102 Value"); + } + if (!element[3].equals("EA")) { + message += error.getErrorMessage(getTransactionType(), "PO103 Value"); + } + if (!element[4].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "PO104 Decimal"); + } + if (!element[5].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PO105 Not Empty"); + } + if (!element[6].equals("SK")) { + message += error.getErrorMessage(getTransactionType(), "PO106 Value"); + } + if (element[7].length() > 70) { + message += error.getErrorMessage(getTransactionType(), "PO107 Length"); + } + if (!element[8].isEmpty() && !element[8].equals("UP")) { + message += error.getErrorMessage(getTransactionType(), "PO108 Value"); + } + if (!element[8].isEmpty() && element[9].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PO109 Empty"); + } + if (element[9].length() != 6 && element[9].length() != 12) { + message += error.getErrorMessage(getTransactionType(), "PO109 Length"); + } + if (!isNumber(element[9])) { + message += error.getErrorMessage(getTransactionType(), "PO109 Number"); + } + if (!element[10].equals("EN")) { + message += error.getErrorMessage(getTransactionType(), "PO110 Value"); + } + if (!element[10].isEmpty() && element[11].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PO111 Empty"); + } + if (element[11].length() != 13) { + message += error.getErrorMessage(getTransactionType(), "PO111 Length"); + } + if (!isNumber(element[11])) { + message += error.getErrorMessage(getTransactionType(), "PO111 Number"); + } + if (!element[12].equals("MG")) { + message += error.getErrorMessage(getTransactionType(), "PO112 Value"); + } + if (!element[12].isEmpty() && element[13].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PO113 Value"); + } + if (!element[14].isEmpty() && !element[14].equals("ZZ")) { + message += error.getErrorMessage(getTransactionType(), "PO114 Value"); + } + if (!element[15].isEmpty() && element[15].equals("dsco_item_id")) { + message += error.getErrorMessage(getTransactionType(), "PO115 Value"); + } + if (!element[16].isEmpty() && !element[16].equals("ZZ")) { + message += error.getErrorMessage(getTransactionType(), "PO116 Value"); + } + if (!element[18].isEmpty() && !element[18].equals("ZZ")) { + message += error.getErrorMessage(getTransactionType(), "PO118 Value"); + } + } + + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + case "ISR": + fields.put("ISR", true); + try { + if (element.length != 2) { + message += error.getErrorMessage(getTransactionType(), "ISR Size"); + } + if (!element[1].equals("IC") || element[1].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ISR01 Value"); + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; + case "SE": +// try { +// fields.put("SE", true); +// int result; +// String count = ""; +// count += element[1]; +// result = Integer.parseInt(count); +// if (element.length != 3) { +// message += error.getErrorMessage("General", "SE Size"); +// } +// if (element[1].isEmpty()) { +// message += error.getErrorMessage("General", "SE01 Empty"); +// break; +// } +// if (result != transactionData.size()) { +// message += error.getErrorMessage("General", "SE01 Value"); +// } +// if (!element[2].equals(transactionSetControlHeader)) { +// message += error.getErrorMessage("General", "SE02 Value"); +// } +// } catch (ArrayIndexOutOfBoundsException e) { +// message += error.getErrorMessage("General", "ArrayBoundsError"); +// } + errorInformation.add(holder + transactionTrailerValidation(element,size,fields,transactionSetControlHeader)); + break; + } + + } + errorInformation.add(error.evaluateReqFields(fields)); + } + + private String transactionTrailerValidation(String[] element, int size, + HashMap fields, String transactionSetControlHeader) { + String message = ""; + try { + fields.put("SE", true); + int result = convertToNumber(element[1]); +// String count = ""; +// count += element[1]; +// result = Integer.parseInt(count); + if (element.length != 3) { + message += error.getErrorMessage("General", "SE Size"); + } + if (element[1].isEmpty()) { + message += error.getErrorMessage("General", "SE01 Empty"); + } + if (result != size) { + message += error.getErrorMessage("General", "SE01 Value"); + } + if (!element[2].equals(transactionSetControlHeader)) { + message += error.getErrorMessage("General", "SE02 Value"); + } + return message; + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + return message; + } + } + + private int convertToNumber(String value) { + int number = Integer.parseInt(value); + return number; + } + + private boolean isNumber(String value) { + NumberFormat formatter = NumberFormat.getInstance(); + ParsePosition pos = new ParsePosition(0); + formatter.parse(value, pos); + if (value.length() == pos.getIndex()) { + return true; + } else { + return false; + } + } + +} diff --git a/Dsco3.java b/Dsco3.java new file mode 100644 index 0000000..5be2196 --- /dev/null +++ b/Dsco3.java @@ -0,0 +1,5 @@ +package ediFilterTutorial; + +public class Dsco3 extends EDI { + +} diff --git a/EDI.java b/EDI.java new file mode 100644 index 0000000..880e56d --- /dev/null +++ b/EDI.java @@ -0,0 +1,208 @@ +package ediFilterTutorial; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.JTextArea; + +public class EDI { + + private boolean fileWriteFlag; + private ArrayList EDI_Data; + private String fileWriteLocation; + private String[] segments; + private String segmentTerminator; + private String transactionType; + private File ediFile; + private String unfilteredEdi; + + private boolean dscoRadioStatus; + private boolean nordRadioStatus; + private boolean kohlRadioStatus; + private boolean dsco3RadioStatus; + +// private JTextArea form; +// +// public void setForm(JTextArea form) { +// this.form = form; +// } +// public JTextArea getForm() { +// return form; +// } + + private HashMap requiredFields = new HashMap(); + + + private HashMap Dsco856 = new HashMap(); + private HashMap Dsco846 = new HashMap(); + private HashMap Dsco810 = new HashMap(); + private HashMap Dsco870 = new HashMap(); + +// public void clearEDIData() { +// EDI_Data.clear(); +// ediFile = null; +// } + + public void createFieldsDsco870() { + Dsco870.put("ST", false); + Dsco870.put("BSR", false); + Dsco870.put("HL", false); + Dsco870.put("PRF", false); + Dsco870.put("PO1", false); + Dsco870.put("ISR", false); + Dsco870.put("SE", false); + + setRequiredFields(Dsco870); + } + + + public void createFieldsDsco810() { + Dsco810.put("ST", false); + Dsco810.put("BIG", false); + Dsco810.put("ITD", false); + Dsco810.put("IT1", false); + Dsco810.put("TDS", false); + Dsco810.put("CTT", false); + Dsco810.put("SE", false); + + setRequiredFields(Dsco810); + } + + public void createFieldsDsco856() { + Dsco856.put("ST", false); + Dsco856.put("BSN", false); + Dsco856.put("HL", false); + Dsco856.put("TD5", false); + Dsco856.put("REF", false); + Dsco856.put("DTM", false); + Dsco856.put("LIN", false); + Dsco856.put("SN1", false); + Dsco856.put("PRF", false); + Dsco856.put("SE", false); + + setRequiredFields(Dsco856); + } + + public void createFieldsDsco846() { + + Dsco846.put("ST", false); + Dsco846.put("BIA", false); + Dsco846.put("LIN", false); + Dsco846.put("QTY", false); + Dsco846.put("SE", false); + + setRequiredFields(Dsco846); + } + + public void setRequiredFields(HashMap data) { + this.requiredFields = data; + } + + public HashMap getRequiredFields(){ + return this.requiredFields; + } + + public String getUnfilteredEDI() { + return this.unfilteredEdi; + } + + + public void setUnfilteredEDI(String data) { + this.unfilteredEdi = data; + } + + public boolean getDsco3RadioStatus() { + return this.dsco3RadioStatus; + } + + + public void setDsco3RadioStatus(boolean status) { + this.dsco3RadioStatus = status; + } + + public boolean getNordRadioStatus() { + return this.nordRadioStatus; + } + + public void setNordRadioStatus(boolean nordRadioStatus) { + this.nordRadioStatus = nordRadioStatus; + } + + public boolean getKohlRadioStatus() { + return this.kohlRadioStatus; + } + + public void setKohlRadioStatus(boolean kohlRadioStatus) { + this.kohlRadioStatus = kohlRadioStatus; + } + + public boolean getDscoRadioStatus() { + return this.dscoRadioStatus; + } + + public void setDscoRadioStatus(boolean dscoRadioStatus) { + this.dscoRadioStatus = dscoRadioStatus; + } + + public File getEdiFile() { + return ediFile; + } + + public void setEdiFile(File data) { + this.ediFile = data; + } + + + public String getTransactionType() { + return this.transactionType; + } + + public void setTransactionType(String type) { + this.transactionType = type; + } + + public String getSegmentTerminator() { + return this.segmentTerminator; + } + + public void setSegmentTerminator(String terminator) { + this.segmentTerminator = terminator; + } + + public void setSegments(String[] segments) { + this.segments = segments; + } + + public String[] getSegments() { + return this.segments; + } + + public void setEDIData(ArrayList Data) { + this.EDI_Data = Data; + } + + public ArrayList getEDIData() { + return this.EDI_Data; + } + + + public void setFileWriteLocation(String location) { + this.fileWriteLocation = location; + } + + public String getFileWriteLocation() { + return this.fileWriteLocation; + } + + + + public void setFileWriteFlag(boolean flag) { + this.fileWriteFlag = flag; + } + public boolean getFileWriteFlag() { + + return this.fileWriteFlag; + } +} diff --git a/EDI_Filter.java b/EDI_Filter.java index e73e8c4..913ef53 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -11,7 +11,7 @@ import java.util.ArrayList; import java.util.Date; -public class EDI_Filter implements ActionListener { +public class EDI_Filter extends EDI implements ActionListener { //Creating all of the components of the application JFileChooser fileChooser; @@ -19,8 +19,15 @@ public class EDI_Filter implements ActionListener { JScrollPane jsp; JButton fileSelectorButton, clearContents; JLabel ediLab, buttonLab; - JRadioButton dscoRadio, nordRadio, kohlRadio; + JRadioButton dscoRadio, nordRadio, kohlRadio, dsco3Radio; ButtonGroup filterGroup; + + Printer printer = new Printer(formattedEDI); + Dsco dsco = new Dsco(printer); + Nord nord = new Nord(printer); + Kohl kohl = new Kohl(printer); + FileIO fileIO = new FileIO(printer); + EDI edi = new EDI(); //This method is one I found that centers the application window to the bounds of your screen public static void centreWindow(Window frame) { @@ -45,12 +52,13 @@ public static void centreWindow(Window frame) { ediLab = new JLabel("EDI Filter 1.0"); buttonLab = new JLabel("Press a button to select a file to filter or clear the text"); - dscoRadio = new JRadioButton("DSCO EDI (846 READY)"); + dscoRadio = new JRadioButton("DSCO old EDI (846, 856 READY)"); // dscoRadio.setActionCommand("Dsco Filter"); nordRadio = new JRadioButton("NORDSTORM EDI(UNDER DEV)"); // nordRadio.setActionCommand("Nordstrom Filter"); kohlRadio = new JRadioButton("KOHLS EDI (UNDER DEV)"); // kohlRadio.setActionCommand("Kohl Filter"); + dsco3Radio = new JRadioButton("DSCO Current EDI (Under Dev)"); filterGroup = new ButtonGroup(); @@ -69,6 +77,7 @@ public static void centreWindow(Window frame) { //isntantiating the text area (i.e the form where the data is going to show) formattedEDI = new JTextArea(30, 60); formattedEDI.setEditable(false); + printer.setForm(formattedEDI); //instantiating the scroll panel and adding it to the TextArea jsp = new JScrollPane(formattedEDI); @@ -83,6 +92,7 @@ public static void centreWindow(Window frame) { frm.add(dscoRadio); frm.add(nordRadio); frm.add(kohlRadio); + frm.add(dsco3Radio); frm.add(jsp); frm.add(buttonLab); frm.add(fileSelectorButton); @@ -99,27 +109,31 @@ public void actionPerformed(ActionEvent ae) { // start the switch statement using the action command switch (ae.getActionCommand()) { case "selectFile": + setDscoRadioStatus(dscoRadio.isSelected()); + setNordRadioStatus(nordRadio.isSelected()); + setKohlRadioStatus(kohlRadio.isSelected()); + setDsco3RadioStatus(dsco3Radio.isSelected()); // If radio button is selected get the file and start the error checker for - if (dscoRadio.isSelected()) { + if (getDscoRadioStatus() || getNordRadioStatus() || getKohlRadioStatus() || getDsco3RadioStatus()) { //try catch block to catch possible errors finding the files try { //calling the File Selector Method which returns a File object and storing it in the variable selectedFile - File selectedFile = fileSelector(); + fileSelector(); //call the formatter method which takes the data from the file object and formats it as well as sending the data to the error checking method - formatter(fileReader(selectedFile), selectedFile, true, false, false); + formatter(fileIO.fileReader(getEdiFile())); } catch (IOException e) { - formattedEDI.append("\n" + e.getMessage()); - // TODO Auto-generated catch block + printer.printMessageToForm("\n" + e.getMessage()); e.printStackTrace(); } // If no radio button is selected just run the formatter method without any error checking - } else { + } + else { try { //calling the File Selector Method which returns a File object and storing it in the variable selectedFile - File selectedFile = fileSelector(); + fileSelector(); //Runs the formatter method without any error checking - formatter(fileReader(selectedFile), selectedFile, false, false, false); + formatter(fileIO.fileReader(getEdiFile())); } catch (IOException e) { @@ -129,239 +143,120 @@ public void actionPerformed(ActionEvent ae) { break; // if the Clear Contents button is pushed set the value inside the TextArea to blank. case "clearContents": - formattedEDI.setText(""); + printer.clearForm(); + filterGroup.clearSelection(); + //clearEDIData(); break; } } // Selects a file based on the users input returns the file object - public File fileSelector() { + public void fileSelector() { // stores an int of 1 or 0 when the user selects a file and clicks either Open or Close int result = fileChooser.showOpenDialog(null); - File selectedFile; // if result is a 0 then store the file Object in the selectedFile variable and return it. if (result == JFileChooser.APPROVE_OPTION) { - selectedFile = fileChooser.getSelectedFile(); - return selectedFile; + setEdiFile(fileChooser.getSelectedFile()); + // if a 1 is sent for the result then write the message to the TextArea } else if (result == JFileChooser.CANCEL_OPTION) { - formattedEDI.setText("The Cancel Option was selcted"); - } - return null; - } - - // Reads the contents of the file and stores it in a string; - public String fileReader(File selectedFile) throws IOException { - String unFilteredData = ""; - String line = ""; - int value = 0; - - // instantiates a new fileReader object called unFiltered and uses the absolute path of the file selected earlier in the fileSelector method - FileReader unFiltered = new FileReader(selectedFile.getAbsolutePath()); - - // instantiates a new BufferedReader object using the unFiltered FileReader object - BufferedReader reader = new BufferedReader(unFiltered); - - // stores each line in the variable line - //line = reader.readLine(); - - // while line isn't null append the data into the unFilteredData variable and store a new set of text in the line variable - - while((value = reader.read()) != -1) { - - char c = (char)value; - unFilteredData += String.valueOf(c); + printer.printMessageToForm("The Cancel Option was selected"); } - -// while (line != null) { -// unFilteredData += line; -// line = reader.readLine(); -// } - // close the readers - reader.close(); - unFiltered.close(); - // return the populated variable - return unFilteredData; } - public void formatter(String toFilter, File selectedFile, boolean isDsco, boolean isNordstrom, boolean isKohls) { + + + public void formatter(String toFilter) { char delimeter = toFilter.charAt(105); char separate = toFilter.charAt(103); // Gets the user home folder on the computer and assigns that the the string home String home = System.getProperty("user.home"); + + File selectedFile = getEdiFile(); String segmentTerminator = ""; String elementSeparator = ""; + if (delimeter == '*' || delimeter =='|' || delimeter =='.' || delimeter =='^' || delimeter == '$' || delimeter =='?' || delimeter =='+') { + segmentTerminator = "\\" + String.valueOf(delimeter); + } else { + segmentTerminator = String.valueOf(delimeter); + } + segmentTerminator = String.valueOf(delimeter); -// if the value in separate is an '*' character we will need to add some escampe characters to the front of it so it will work this is because the regex in the split method uses the * for a different function - if (separate == '*') { - elementSeparator = "\\*"; +// if the value in separate is an '*' character we will need to add some escape characters to the front of it so it will work this is because the regex in the split method uses the * for a different function + if (separate == '*' || separate =='|' || separate =='.' || separate =='^' || separate == '$' || separate =='?' || separate =='+') { + elementSeparator = "\\" + String.valueOf(separate); } else { elementSeparator = String.valueOf(separate); } + // Splits the toFilter data and assigns it to the segments String array - String[] segments = toFilter.split(segmentTerminator); + setSegments(toFilter.split(segmentTerminator)); // checks the file-size if the file size is less than 3MB we can print to the form if (selectedFile.length() <= 3000000) { - if (isDsco) { + if (getDscoRadioStatus()) { // starts the error checking process for Dsco EDI spec (846 basically done, other documents not done) - dscoErrorCheck(segments, selectedFile, elementSeparator); - } else if (isNordstrom) { + dsco.dscoErrorCheck(getSegments(), selectedFile, elementSeparator); + } else if (getNordRadioStatus()) { // starts the error checking process for Nordstrom EDI spec (Not Done) - nordErrorCheck(segments, selectedFile, elementSeparator); - } else if (isKohls) { + nordErrorCheck(getSegments(), selectedFile, elementSeparator); + } else if (getKohlRadioStatus()) { // starts the error checking process for Dsco EDI spec (Not Done) - kohlErrorCheck(segments, selectedFile, elementSeparator); - } else { - for (int i = 0; i < segments.length; i++) { - //prints the data from the segments array and - formattedEDI.append(segments[i] + segmentTerminator + "\n"); - } + kohlErrorCheck(getSegments(), selectedFile, elementSeparator); + } else if(getDsco3RadioStatus()){ + dsco3ErrorCheck(); + }else { + printer.printDataToForm(getSegments(),segmentTerminator); } // if the size is greater than 3MB we can't print to the form so we print to a file } else { try { + boolean flag = true; + + setFileWriteFlag(flag); + //print message to the TextArea - formattedEDI.setText( + printer.printMessageToForm( "The file was too big to process quickly. It is being processed in a seperate file in your Downloads Folder"); + String fileName = selectedFile.getName() + "_Filtered.txt"; //Creates a new file at the destination - File newFile = new File(home + "/Downloads/" + fileName); + setFileWriteLocation(home + "/Downloads/" + fileName); + + File newFile = new File(getFileWriteLocation()); //checks if the file exists, if it does exist it doesn't write and stops. if (newFile.exists()) { - formattedEDI.append("The file: " + fileName + " already exists"); + printer.printMessageToForm("The file: " + fileName + " already exists"); } else { // this is where the error checking part is going to come in for large files - if (isDsco) { - dscoErrorCheck(segments, selectedFile, elementSeparator); - } else if (isNordstrom) { - nordErrorCheck(segments, selectedFile, elementSeparator); - } else if (isKohls) { - kohlErrorCheck(segments, selectedFile, elementSeparator); - } else { + if (getDscoRadioStatus()) { + dsco.dscoErrorCheck(getSegments(), selectedFile, elementSeparator); + } else if (getNordRadioStatus()) { + nordErrorCheck(getSegments(), selectedFile, elementSeparator); + } else if (getKohlRadioStatus()) { + kohlErrorCheck(getSegments(), selectedFile, elementSeparator); + } else if(getDsco3RadioStatus()){ + dsco3ErrorCheck(); + + }else { // if there is no error checking involved write the file to the Downloads folder on the machine - FileWriter fileWrite = new FileWriter(home + "/Downloads/" + fileName); - - for (int i = 0; i < segments.length; i++) { - if (segments[i] != "" && segments[i] != null) { - fileWrite.write(segments[i] + segmentTerminator + "\n"); - } - } - //close the writer - fileWrite.close(); - //inform the user that the document was created - formattedEDI.append("/n The Document" + fileName + " has been created."); + fileIO.writeToFile(getSegments()); } } - } catch (IOException e) { - formattedEDI.append("/n There was an error writing the file: " + e.getMessage()); + } catch (Exception e) { + printer.logError("/n There was an error writing the file: " + e.getMessage()); } } } - // Error checking section based off of the EDI Specs - public void dscoErrorCheck(String[] fileData, File selectedFile, String elementSeparator) { - // temporary holder for each line of the document - String holder = ""; - String[] element; - Error error = new Error(); - - boolean go = true; - int stop = 0; - - // key for the document type will be 846, 855, 810, 870 or 856 - String transactionType = ""; - - // List containing the segment data from ST to SE, which is where the transactions specific data is - ArrayList transactionData = new ArrayList(); - - // List containing the segments ISA, GS, GE, and IEA. (not sure if I need this) - ArrayList documentHeaderData = new ArrayList(); - - // while the variable is true continue the loop - while (go == true) { - for (int i = 0; i < fileData.length; i++) { - if (stop == 1) { - stop = 0; - break; - } else { - // sets the contents of the array into a String where it can be split later - holder = fileData[i]; - - // split the holder string into elements using the elementSeparator variable - element = holder.split(elementSeparator); - - //filter through the element looking at position 0 - for (int x = 0; x < element.length; x++) { - if (stop == 1) { - break; - } else { - // - if (element[0].equals("ST")) { - transactionData.add(fileData[i]); - if (element[1].isEmpty()) { - formattedEDI.append(" " + error.getErrorMessage("General", "ST01 Empty")); - stop = 1; - // stop filter because we don't know what the document is going to be doing. - go = false; - break; - } - // if the ST01 isn't empty store it in the variable this is what we are going to Switch on later - transactionType = element[1]; - break; - // if any of the 0 position elements are these values add them, but don't filter them - } else if (element[0].equals("ISA") || element[0].equals("GS") || element[0].equals("GE") - || element[0].equals("IEA")) { - documentHeaderData.add(fileData[i]); - break; - // if the 0 element is "SE" that is the end of the transaction and the data in the transactionData array list is what we are going to do the bulk of the error checking - } else if (element[0].equals("SE")) { - transactionData.add(fileData[i]); - - // take the variable in the transactionType and do a switch based on that value to error check the correct document - switch (transactionType) { - case "846": - //start the error checking process for the Dsco 846 passing the Array List of the data and the elementSeparator variable - dsco846(transactionData, elementSeparator); - break; - case "856": - System.out.println(transactionData); - formattedEDI.append("\n You got to the 856 Switch statement"); - // dsco856(transactionData); - break; - case "870": - System.out.println(transactionData); - formattedEDI.append("\n You got to the 870 Switch statement"); - // dsco870(transactionData); - break; - case "810": - System.out.println(transactionData); - formattedEDI.append("\n You got to the 810 Switch statement"); - // dsco810(transactionData); - break; - } - go = false; - stop = 1; - break; - } else { - // formattedEDI.setText(element[0]); - transactionData.add(fileData[i]); - break; - } - } - } - } - } - } - } //possible class for each spec type? public void nordErrorCheck(String[] fileData, File selectedFile, String elementSeparator) { @@ -370,448 +265,14 @@ public void nordErrorCheck(String[] fileData, File selectedFile, String elementS public void kohlErrorCheck(String[] fileData, File selectedFile, String elementSeparator) { } + public void dsco3ErrorCheck() { + + } // In-depth Error checking for Dsco 846: - public void dsco846(ArrayList transactionData, String elementSeparator) { - - String holder = ""; - String[] element; - String message = ""; - String dateFormat = "yyyyMMdd"; - String timeFormat = "HHmmss"; - Error error = new Error(); - - - boolean stop = false; - String transactionSetControlHeader = ""; - - // this will be the array that contains what we are going to print to the field--- had to do it this way becuase the error messages weren't getting added to the original ArrayList - ArrayList errorInformation = new ArrayList(); - - // Start the loop through the passed transaction data - for (int i = 0; i < transactionData.size(); i++) { - if (stop != false) { - stop = false; - } - // assign the array element to holder - holder = transactionData.get(i); - //split holder into the element array. So we can evaluate each segment of the EDI - element = holder.split(elementSeparator); - for (int x = 0; x < element.length; x++) { - if (stop != false) { - break; - } - switch (element[0]) { - - // Error Checking for the ST segment - case "ST": - //checking the length of the array - if (element.length != 3) { - message += error.getErrorMessage("General", "ST Size"); - break; - } - //if the ST02 element isn't empty check the length of the data in that element. - if (!element[2].isEmpty()) { - if (element[2].length() > 9) { - message += error.getErrorMessage("846", "ST02 Size"); - } - } - //check to see if ST02 is empty if it is pull an error - if (element[2].isEmpty()) { - message += error.getErrorMessage("General", "ST02 empty"); - } - // if it isn't empty store the value in the ST02 in the transactionSetControlHeader variable for later comparisson - else { - transactionSetControlHeader += element[2]; - } - // add the data with any errors to the errorInformation ArrayList - errorInformation.add(holder + message); - //set message to blank to be ready for the next set of errors - message = ""; - // get out of the loop so we can move on to the next segement in the EDI - stop = true; - break; - - - - // Error Checking of the BIA segment - case "BIA": - //Try catch to look out for segments that are out of bounds. Most segments in the EDI are optional and don't get checked for formatting errors. So sometimes we run into a segment that isn't as long as it should be - //which means that the elements array is shorter than expected. - try { - // most of the logic for the rest of the method is specific to the 846 spec. - if (!element[1].equals("00")) { - message += error.getErrorMessage("846", "BIA01 Value"); - }if (!element[2].equals("MM")) { - message += error.getErrorMessage("846", "BIA02 Value"); - }if (element[3].isEmpty()) { - message += error.getErrorMessage("846", "BIA03 Empty"); - }if (dateChecker(element[4], dateFormat) == false) { - message += error.getErrorMessage("846", "BIA04 Date"); - }if (dateChecker(element[5], timeFormat) == false) { - message += error.getErrorMessage("846", "BIA05 Time"); - }if (element.length < 6 || element.length > 6) { - message += error.getErrorMessage("846", "BIA Size"); - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - // Error Checking of the CUR segment - case "CUR": - try { - if (element.length > 3 || element.length < 3) { - message += error.getErrorMessage("846", "CUR Size"); - break; - } else if (!element[1].equals("SE")) { - message += error.getErrorMessage("846", "CUR01 Value"); - } else if (!element[2].equals("USD")) { - message += error.getErrorMessage("846", "CUR02 Value"); - } - - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - - // Error Checking of the REF segment - case "REF": - try { - // REF segment can be either 2 or 3 segments long. - if (element.length > 4 || element.length < 3) { - message += error.getErrorMessage("846", "REF Size"); - break; - } - //check value of the REF01 - if (element[1].equals("IA")) { - if (element[2].isEmpty()) { - message += error.getErrorMessage("846", "REF02 Empty"); - } - } - //check value of the REF01 - if (element[1].equals("ZZ")) { - if (element[3].equals("status")) { - //checks for all of the possible values that the REF02 can be - if (!element[2].equals("in-stock") && !element[2].equals("out-of-stock") - && !element[2].equals("discontinued") && !element[2].equals("hidden") - && !element[2].equals("pending")) { - message += error.getErrorMessage("846", "REF02ZZ Status Value"); - } - } - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - // Error checking of the LIN segment - - // This is the big segment where all the item information is populated and updated. - case "LIN": - try { - // Check the length for the max and min values - if (element.length > 32 || element.length < 4) { - message += error.getErrorMessage("846", "LIN Size"); - } - //if the LIN02 segment is empty throw error since that field is required - if (element[2].isEmpty()) { - message += error.getErrorMessage("846", "LIN02 Req"); - } - //Check the value of the LIN02, which has to be equal to 'SK' - if (!element[2].equals("SK")) { - message += error.getErrorMessage("846", "LIN02 Value"); - }// LIN03 can't be empty - if (element[3].isEmpty()) { - message += error.getErrorMessage("846", "LIN03 Req"); - } - // Check the length of the element because suppliers can send less than 5 segments - if (element.length >= 6) { - if (!element[4].isEmpty()) { - //LIN04 has to be "UP" - if (!element[4].equals("UP")) { - message += error.getErrorMessage("846", "LIN04 Value"); - } - // UPCs have to be either 8 or 12 digits long. They cannot be anything else (most common error I see with EDI) - if (element[5].length() != 12 && element[5].length() != 8) { - message += error.getErrorMessage("846", "LIN05 Size"); - }//LIN05 can't be empty when LIN04 has data - if (element[5].isEmpty()) { - message = message + error.getErrorMessage("846", "LIN05 Empty"); - } - } - } - if (element.length >= 7) { - if (!element[6].equals("EN")) { - message += error.getErrorMessage("846", "LIN06 Value"); - } - if (!element[6].isEmpty()) { - if (element[7].isEmpty()) { - message += error.getErrorMessage("846", "LIN07 Empty"); - } else { - //EAN's can only have 13 digits. No more no less. - if (element[7].length() != 13) { - message += error.getErrorMessage("846", "LIN07 Size"); - } - } - } - } - if (element.length >= 9) { - if (!element[8].isEmpty()) { - if (!element[8].equals("MG")) { - message += error.getErrorMessage("846", "LIN08 Value"); - } - if (element[9].isEmpty()) { - message += error.getErrorMessage("846", "LIN09 Empty"); - } - - } - } - if (element.length >= 11) { - if (!element[10].isEmpty()) { - if (!element[10].equals("IB")) { - message += error.getErrorMessage("846", "LIN10 Value"); - } else if (element[11].isEmpty()) { - message += error.getErrorMessage("846", "LIN11 Empty"); - } - } - } - if (element.length >= 13) { - if (!element[12].isEmpty()) { - if (!element[12].equals("UK")) { - message += error.getErrorMessage("846", "LIN12 Value"); - } - if (element[13].isEmpty()) { - message += error.getErrorMessage("846", "LIN13 Empty"); - } - } - } - if (element.length >= 15) { - if (!element[14].isEmpty()) { - if (!element[14].equals("BL")) { - message += error.getErrorMessage("846", "LIN14 Value"); - } - if (element[15].isEmpty()) { - message += error.getErrorMessage("846", "LIN15 Empty"); - } - } - } - if (element.length >= 17) { - if (!element[16].isEmpty()) { - } - if (!element[16].equals("SK")) { - message += error.getErrorMessage("846", "LIN16 Value"); - } - if (element[17].isEmpty()) { - message += error.getErrorMessage("846", "LIN17 Empty"); - } - } - if (element.length >= 19) { - if (!element[18].isEmpty()) { - } - if (!element[18].equals("SK")) { - message += error.getErrorMessage("846", "LIN18 Value"); - } - if (element[19].isEmpty()) { - message += error.getErrorMessage("846", "LIN19 Empty"); - } - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - // Error checking for the PID segment - - case "PID": - try { - //size if this segment must be 5. - if (element.length != 6) { - message += error.getErrorMessage("846", "PID Size"); - break; - } - if (!element[1].equals("F")) { - message += error.getErrorMessage("846", "PID01 Value"); - } - if (!element[2].equals("08")) { - message += error.getErrorMessage("846", "PID02 Value"); - } - if (!element[1].isEmpty() && !element[2].isEmpty() && element[5].isEmpty()) { - message += error.getErrorMessage("846", "PID05 Empty"); - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - // Error Checking for the CTP Segment - case "CTP": - try { - if (element.length != 4) { - message += error.getErrorMessage("846", "CTP Size"); - } - if (!element[1].equals("AS")) { - message += error.getErrorMessage("846", "CTP01 Value"); - } - if (!element[2].equals("WHL")) { - message += error.getErrorMessage("846", "CTP02 Value"); - } - if (!element[3].matches("\\d*\\.?\\d+")) { - message += error.getErrorMessage("846", "CTP03 Value"); - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - // Error check for the QTY segment - case "QTY": - try { - if (element.length != 4) { - message += error.getErrorMessage("846", "QTY Size"); - } - if (element[1].isEmpty() || element[2].isEmpty() || element[3].isEmpty()) { - message += error.getErrorMessage("846", "QTY Empty"); - break; - } - if (!element[1].isEmpty()) { - if (!element[1].equals("33")) { - message += error.getErrorMessage("846", "QTY01 Value"); - } - if (!element[3].equals("EA")) { - message += error.getErrorMessage("846", "QTY03 Vlaue"); - } - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - // Error checking for the SCH01 segment - case "SCH": - try { - if (element.length != 7) { - message += error.getErrorMessage("846", "SCH Size"); - break; - } else if (!element[1].isEmpty()) { - if (!element[2].equals("EA")) { - message += error.getErrorMessage("846", "SCH02 Value"); - } - if (!element[5].equals("018")) { - message += error.getErrorMessage("846", "SCHO5 Value"); - } - if (!element[5].isEmpty()) { - if (element[6].isEmpty()) { - message += error.getErrorMessage("846", "SCH06 Empty"); - } - if (!element[6].equals("20391231")) { - if (!dateChecker(element[6], dateFormat)) { - message += error.getErrorMessage("846", "SCH06 Value"); - } - } - - } - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - // Error Checking for the N1 segment - case "N1": - try { - if (element.length != 5) { - message += error.getErrorMessage("846", "N1 Size"); - } else if (!element[1].isEmpty()) { - if (!element[1].equals("SE")) { - message += error.getErrorMessage("846", "N101 Value"); - } - if (element[2].isEmpty() || element[3].isEmpty() || element[4].isEmpty()) { - message += error.getErrorMessage("846", "N1 Empty"); - } - if (!element[3].equals("ZZ")) { - message += error.getErrorMessage("846", "N103 Value"); - } - if (element[4].isEmpty()) { - message += error.getErrorMessage("846", "N104 Empty"); - } - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - - // Error Checking for the SE segment - - case "SE": - try { - int result; - String count = ""; - count += element[1]; - result = Integer.parseInt(count); - if (element.length != 3) { - message += error.getErrorMessage("General", "SE Size"); - } - if (element[1].isEmpty()) { - message += error.getErrorMessage("General", "SE01 Empty"); - break; - } - if (result != transactionData.size()) { - message += error.getErrorMessage("General", "SE01 Value"); - } - if (!element[2].equals(transactionSetControlHeader)) { - message += error.getErrorMessage("General", "SE02 Value"); - } - } catch (ArrayIndexOutOfBoundsException e) { - message += error.getErrorMessage("General", "ArrayBoundsError"); - } - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - default: - message = "Check this segment: " + element[0] - + " there may be whitespace that the filter isn't catching."; - errorInformation.add(holder + message); - message = ""; - stop = true; - break; - } - } - - } - for (int y = 0; y < errorInformation.size(); y++) { - formattedEDI.append("\n" + errorInformation.get(y)); - } - } + - public boolean dateChecker(String date, String dateFormat) { + public static boolean dateChecker(String date, String dateFormat) { SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); formatter.setLenient(false); // Date dateValue = null; @@ -829,6 +290,6 @@ public void run() { new EDI_Filter(); } }); + } - } diff --git a/Error.java b/Error.java index 57d8084..339b263 100644 --- a/Error.java +++ b/Error.java @@ -1,14 +1,297 @@ package ediFilterTutorial; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + public class Error { public String getErrorMessage(String transactionType, String errorParams) { - if (transactionType.equals("846")) { + switch (transactionType) { + case "846": return InvErrors(errorParams); - } else if (transactionType.equals("General")) { + case "856": + return ShipErrors(errorParams); + case "810": + return InvoiceErrors(errorParams); + case "870": + return CancelErrors(errorParams); + case "General": return GenErrors(errorParams); + default: + return ""; + } + } + + private String InvoiceErrors(String errorParams) { + switch (errorParams) { + // Messages for BIG + case "BIG Size": + return "-- The length of this segment is incorrect it should be 4 elements long--"; + case "BIG Req Empty": + return "-- One or more of the following elements are empty: BIG01, BIG02, BIG04 --"; + case "BIG01 Format": + return "-- The date format for BIG01 is incorrect it must be in the CCYYMMDD format --"; + case "BIG03 Format": + return "-- The date format for BIG03 is incorrect it must be in the CCYYMMDD format --"; + + // Messages for CUR + case "CUR Size": + return "-- The length of this segment is incorrect it should be 2 elements long --"; + case "CUR01 Value": + return "-- The value of the CUR01 segment is incorrect it should be 'BY' --"; + case "CUR02 Vlaue": + return "-- The value of hte CUR02 segment is incorrect it should be 'USD' --"; + + // Messages for REF + case "REF Size": + return "-- The length of this segment is incorrect it should be 2 or 3 elements long --"; + case "REF01 Value": + return "-- The value in the REFO1 element is incorrect " + + "it should be one of the following: ZZ, IA, IV, CO, CN --"; + case "REF ZZTransportation Code": + return "-- The value in the REF02 is incorrect. When the REF03 is 'ship_transportation_method_code' the REF02 should " + + "be one of the following: A, J, R, or S --"; + case "REF03 ZZValues": + return "-- The value in the REF03 is incorrect. When the REF01 is ZZ the REF03 should be one of the following: " + + "ship_carrier, ship_method, shipping_service_level_code, ship_transportation_method_code, ship_reference_number_equals," + + "invoice_subtotal_excluding_line_items, invoice_line_items_subtotal --"; + case "REF Ship_reference Value": + return "-- The value in the REF02 is incorrect it must be either 'BM' or 'CN' when the REF03 is ship_reference_number_qualifier --"; + case "REF Decimal": + return "-- The value in the REF02 is incorrect it should be a decimal number --"; + + // Messages for N1 + case "N101 Value": + return " -- The value of the N101 element is incorrect, it should be 'ST' or 'SF' --"; + case "N1 Size": + return "-- The length of the N1 segment is incorrect it hsould be 2 elements long --"; + + // Messages for N3 + case "N3 Size": + return "-- The length of the N3 segment is incorrect it should be 2 elements long --"; + + // Messages for N4 + case "N4 Size": + return "-- The length of the N4 segment is incorrect it should be 4 elements long --"; + + // Messages for ITD + case "ITD Size": + return "-- The length of the ITD segment is incorrect it should be 13 elements long --"; + case "ITD01 Value": + return "-- The value in the ITD01 element is incorrect it should be one of the following: 01, 02, 05, 08, or 12 --"; + case "ITD02 Value": + return "-- The value in the ITD02 element is incorrect it should be '3' --"; + case "ITD Req Empty": + return "-- One of the following element are empty: ITD04, ITD05, ITD06, ITD07, or ITD13 --"; + case "ITD08 Value": + return "-- The value in the ITD08 is incorrect it must be a decimal number --"; + case "ITD09-12 Populated": + return "-- One of the elements in the range ITD09-12 is populated when they are supposed to be empty --"; + + // Messages for DTM + case "DTM Size": + return "-- The length of the DTM segment is incorrect it should be 3 elements long --"; + case "DTM02 Format": + return "-- The format of the data in the DTM02 element is incorrect it should match CCYYMMDD --"; + case "DTM03 Format": + return "-- The format of the data in the DTM03 element is incorrect it should match HHMM --"; + + // Messages for IT1 + case "IT1 Size": + return "-- The length of the IT1 segment is incorrect it needs to be between 7 and 19 elements long --"; + case "IT1 Req Empty": + return "-- One or both of the following fields are empty and cannot be: IT102 and IT107 --"; + case "IT103 Value": + return "-- The value in the IT103 element is incorrect, it should be 'EA' --"; + case "IT104 Value": + return "-- The value in the IT104 element is incorrect, it should be a decimal number --"; + case "IT105 Value": + return "-- The value in the IT105 element is incorrect, it should be either 'QT' or 'LE' --"; + case "IT106 Value": + return "-- The value in the IT106 element is incorrect, it should be 'SK' --"; + case "IT107 SKU Length": + return "-- The value in the IT106 element is too long, it needs to be under 70 characters --"; + case "IT108 Value": + return "-- The value in the IT108 element is incorrect it should be 'UP' --"; + case "IT109 UPC Length": + return "-- The UPC value in the IT109 has the incorrect length, UPC's need to be 6 or 12 characters --"; + case "IT109 Empty": + return "-- When the IT108 is provided the IT109 cannot be empty --"; + case "IT110 Value": + return "-- The value in the IT110 element is incorrect it should be 'EN' --"; + case "IT111 EAN Length": + return "-- The EAN value in the IT111 element has the incorrect length, EAN's are 13 characters --"; + case "IT111 Empty": + return " -- When the IT110 is provided the IT111 cannot be empty --"; + case "IT112 Value": + return "-- The value in the IT112 element is incorrect it should be 'MG' --"; + case "IT113 Empty": + return "-- When the IT112 is provided the IT113 cannot be empty"; + case "IT114 Value": + return "-- The value in the IT114 element is incorrect it should be 'ZZ' --"; + case "IT115 Empty": + return "-- When the IT114 is provided the IT115 cannot be empty"; + case "IT116 Value": + return "-- The value in the IT116 element is incorrect it should be 'ZZ' --"; + case "IT117 Empty": + return "-- When the IT116 is provided the IT117 cannot be empty"; + case "IT118 Value": + return "-- The value in the IT118 element is incorrect it should be 'ZZ' --"; + case "IT119 Empty": + return "-- When the IT116 is provided the IT117 cannot be empty"; + + // Messages for TDS + case "TDS01 Empty": + return "-- TDS01 is a required field and cannot be empty --"; + case "TDS Size": + return "-- The length of the TDS segment is incorrect, it must be 2 elements long --"; + case "TDS01 Value": + return "-- The TDS01 value is incorrect it must be a decimal value --"; + case "TDS02 Value": + return "-- The TDS02 value is incorrect it must be a decimal value --"; + + // Messages for AMT + case "AMT01 Value": + return "-- The AMT01 value is incorrect it should be either 'OH' or 'F7' --"; + case "AMT02 Value": + return "-- The AMT02 Value is incorrect it should be a decimal value --"; + + // Messages for SAC + case "SAC Size": + return "-- The length of the SAC segment is incorrect it should be 5 elements long --"; + case "SAC01 Value": + return "-- The value of the SAC01 element is incorrect it should be 'C' --"; + case "SAC02 Value": + return "-- The value of hte SAC02 element is incorrect it should be 'D240' --"; + case "SAC Req Populated": + return "-- Elements SAC03 and SAC04 are required to be empty --"; + case "SAC05 Value": + return "-- The value of SAC05 is incorrect it should be a decimal character --"; + + // Messages for ISS + case "ISS Size": + return "-- The length of the ISS segment is incorrect it should be 4 elements long --"; + case "ISS01 Empty": + return "-- The ISS01 is empty, when the ISS segment is included the ISS01 is needed --"; + case "ISS02 Value": + return "-- The value of hte ISS02 is incorrect it needs to be one of the following: 'CA', 'BX', 'PK' --"; + case "ISS03 Empty": + return "-- The ISS03 is empty, when the ISS segment is included the ISS03 is needed --"; + case "ISS04 Value": + return "-- The ISS04 value is incorrect it should be one of the following: 'LB', 'OZ', '50' --"; + + // Messages for CTT + case "CTT Size": + return "-- The length of the CTT segment is incorrect it needs to be 1 element long --"; + case "CTT01 Value": + return " -- The value of the CTT01 segment is incorrect it should be equal to the number of lin-items in the transaction --"; + + default: + return ""; + + } + } + + public String evaluateReqFields(HashMap reqFields) { + String Message = ""; + Iterator> entries = reqFields.entrySet().iterator(); + while (entries.hasNext()) { + Map.Entry entry = entries.next(); + if (entry.getValue() == false) { + Message += "Required Segment " + entry.getKey() + " was not provided."; + } + } + return Message; + + } + + private String ShipErrors(String errorParams) { + switch (errorParams) { + case "BSN01 Value": + return " --BSN01 must be equal to '00' --"; + case "BSN02": + return "--BSN02 cannot be empty --"; + case "BSN03 Format": + return "-- the date format for BSN03 must be equal to CCYYMMDD --"; + case "BSN04 Format": + return "-- The time format for BSN04 must match HHMM --"; + case "BSN05 Value": + return "-- BSN05 must equal '004' --"; + case "BSN Size": + return "-- The BSN segment length is incorrect it must be 5 elments long --"; + case "BSN Segments Empty": + return "-- One or more elements are empty. All elements in the BSN are required and cannot be empty--"; + case "CUR Size": + return "-- The CUR segment length is incorrect it must be 3 elements long --"; + case "CUR01 Value": + return "-- The CUR01 segment must have 'BY' as its value --"; + case "CUR02 Value": + return "-- The CUR02 segment must have 'USD' as its value --"; + case "HL Size": + return "-- The HL segment length is incorrect it must be 3 elements long --"; + case "HL Empty": + return "-- One or more elements are empty. All elements in the HL are required and cannot be empty --"; + case "HL03 Value": + return "-- The HL03 is incorrect it must be one of the following: 'O', 'I', or 'S' --"; + case "TD5 Size": + return "-- The TD5 segment length is incorrect it must be 8 elements long -- "; + case "TDF Segments Empty": + return "-- One or more elements are empty. All elements except TD506 in the TD5 are required and cannot be empty --"; + case "TD501 Value": + return "-- The value in the TD501 element is incorrect, it should be 'Z' --"; + case "TD502 Value": + return "-- The value in the TD502 element is incorrect, it should be 'ZZ' --"; + case "TD504 Value": + return "-- The value in the TD504 element is incorrect, it should be 'ZZ' --"; + case "TD507 Value": + return "-- The value in the TD507 element is incorrect, it should be 'ZZ' --"; + case "REF Size": + return "--The REF segment length is incorrect it must be 2 or 3 elements long -- "; + case "REF01 Value": + return "-- The REF01 is incorrect it mus equal one of the following values: 'ZZ', 'IA', 'CO', 'VN' or 'CN' --"; + case "REF01 Empty": + return "-- The REF01 cannot be empty --"; + case "REF02 Empty": + return "-- The REF02 cannot be empty --"; + case "LIN02 Empty": + return "-- The LIN02 and LIN03 elements are required and cannot be empty --"; + case "SN101 Value": + return "-- The SN101 can only be empty --"; + case "SN1 Empty": + return "-- The SN102 or SN103 elements can't be empty --"; + case "SN103 Value": + return "-- The SN103 element value is incorrect it must equal 'EA' --"; + case "DTM Size": + return "-- The DTM segment length is incorrect it must be 3 elements long --"; + case "DTM Empty": + return "-- The DTM segment is required and none of the elements can be empty --"; + case "DTM01 Value": + return "-- The DTM01 value is incorrect it must equal '011' --"; + case "DTM02 Format": + return "-- The DTM02 value doesn't match teh Date format of CCYYMMDD (YYYYMMDD) --"; + case "DTM03 Format": + return "-- The DTOM03 Value doesn't match the Time format of HHMM --"; + case "SAC Size": + return "-- The SAC segment length is incorrect it must be 5 elements long --"; + case "SAC Empty": + return "-- The elements SAC01, SAC02, SAC05 cannot be empty when the SAC segment is provided --"; + case "SAC01 Value": + return "-- The SAC01 value is incorrect it must be 'C' --"; + case "SAC02 Value": + return "-- The SAC02 Value is incorrect it must be 'G821' --"; + case "SAC05 Decimal": + return "-- The SAC05 Value has a decimal missing, the decimal is required --"; + case "SAC04 Value": + return "-- The SAC03 and SAC04 values must be empty and cannot be populated --"; + case "PRF Size": + return "-- The segment length of the PRF value is incorrect it should be 1 element long --"; + case "PRF01 Empty": + return "-- The PRF01 segment is empty, the PRF01 segment is a required segment and cannot be missing --"; + + default: + return ""; } - return ""; } private String GenErrors(String errorParams) { @@ -27,6 +310,10 @@ private String GenErrors(String errorParams) { return " -- The SE01 must be the same size as the number of lines in the transaction set --"; case "SE02 Value": return " -- This value must be the same as the value in ST02 -- "; + case "ST Size": + return " --ST Segment size is incorrect it should be 2--"; + case "ST02 Size": + return " --ST02 segment is greater than the maximum allowed size (9)--"; case "ArrayBoundsError": return ""; default: @@ -37,12 +324,6 @@ private String GenErrors(String errorParams) { private String InvErrors(String errorParams) { switch (errorParams) { - // errors for ST segment - case "ST Size": - return " --ST Segment size is incorrect it should be 2--"; - case "ST02 Size": - return " --ST02 segment is greater than the maximum allowed size (9)--"; - // errors for BIA segment case "BIA01 Value": return " --The BIA01 value must equal '00'--"; @@ -84,14 +365,14 @@ private String InvErrors(String errorParams) { return " -- The LIN02 segment has to be 'SK'--- "; case "LIN03 Size": return " -- The LIN03 segment cannot be longer than 70 characters--- "; - case "LIN04 Value": - return " -- LIN04 segment has to be 'UP--- "; - case "LIN05 Size": - return " --The UPC needs to be 6 or 12 characters long--- "; case "LIN02 Req": return " --LIN02 is required and cannot be empty--- "; case "LIN03 Req": return " --LIN03 is required and cannot be empty--- "; + case "LIN04 Value": + return " -- LIN04 segment has to be 'UP--- "; + case "LIN05 Size": + return " --The UPC needs to be 6 or 12 characters long--- "; case "LIN06 Value": return " --LIN06 must be 'EN'--- "; case "LIN07 Size": @@ -145,7 +426,7 @@ private String InvErrors(String errorParams) { // Params for QTY error messages case "QTY Size": - return " ---The QTY segment size is incorrect it must be 3 segments long --- "; + return " --- The QTY segment size is incorrect it must be 3 elements long --- "; case "QTY Empty": return "-- The QTY segment is required. None of the segments can be blank --- "; case "QTY01 Value": @@ -182,5 +463,104 @@ private String InvErrors(String errorParams) { return ""; } + + } + + private String CancelErrors(String errorParams) { + switch (errorParams) { + + //Params for BSR segment Errors + case "BSR Size": + return "-- The length of the BSR segment is incorrect it should be 4 elements long --"; + case "BSR01 Value": + return "-- The value in the BSR01 element is incorrect it should be '2' --"; + case "BSR02 Value": + return "-- The value in the BSR02 element is incorrect is should be 'PP' --"; + case "BSR03 Empty": + return "-- The BSR03 element is a required field and cannot be empty --"; + case "BSR04 Format": + return "-- The BSR04 element is in the incorrect format it needs to be in the CCYYMMDD format --"; + + case "HL Size": + return "-- The length of the HL segment is incorrect it needs to be 3 elements long --"; + case "HL01 Empty": + return "-- The HL01 element is empty--"; + case "HL02 Empty": + return "-- The HL02 element is empty--"; + case "HL03 Value": + return "-- The value in the HL03 element is incorrect it should be: 'I' or 'O' --"; + + + //Params for PRF segment Errors + case "PRF Size": + return "-- The length of the PRF segment is incorrect it shoudl be 1 element long--"; + case "PRF01 Empty": + return "-- The PRF01 element is Empty --"; + + //Params for REF segment Errors + case "REF Size": + return "-- The length of the REF segment is incorrect it should be either 2 or 3 elements long--"; + case "REF01 Value": + return "-- The value in the REF01 is incorrect it needs to be one of the following: 'VN', 'CO', 'IA'--"; + case "REF02 Empty": + return "-- The REF02 segment is empty --"; + + //Params for PO1 segment + case "PO1 Req Empty": + return "-- One of the following fields are empty and cannot be: PO101, PO102, PO103, PO104, PO106, PO107 --"; + case "PO101 Value": + return "-- The value in the PO101 is incorrect it needs to be greater than 0 --"; + case "PO102 Value": + return "-- The value in the PO102 is incorrect it needs to be greater than 0 --"; + case "PO103 Value": + return "-- The value in the PO103 is incorrect it needs to be 'EN' --"; + case "PO104 Value": + return "-- The value in the PO104 didn't have a decimal, a decimal place has to be included in the PO104 --"; + case "PO105 Not Empty": + return "-- The PO105 is not empty. The PO105 has to be empty --"; + case "PO106 Value": + return "-- The PO106 is incorrect, it needs to be 'SK' --"; + case "PO107 Length": + return "-- The PO107 value is too long, it needs to be under 70 characters long --"; + case "PO108 Value": + return "-- The value in the PO108 is incorrect it needs to be 'UP' --"; + case "PO109 Length": + return "-- The length of the UPC in the PO109 is incorrect it needs to be 6 or 12 characters long --"; + case "PO109 Number": + return "-- The value in the PO109 is incorrect it cannot contain any letters --"; + case "PO109 Empty": + return "-- The PO109 element is empty. The PO109 element cannot be empty when the PO108 element is provided --"; + case "PO110 Value": + return "-- The value in the PO110 is incorrect it needs to be 'EN' --"; + case "PO111 Empty": + return "-- The PO111 element is empty. The PO111 element cannot be empty when the PO110 element is provided --"; + case "PO111 Length": + return "-- the length of the EAN in the PO111 element is incorrect it needs to be 13 characeters long --"; + case "PO111 Number": + return "-- The value in the PO111 is incorrect it cannot contain any letters --"; + case "PO112 Value": + return "-- The value in the PO112 element is incorrect it needs to be 'MG' --"; + case "PO113 Value": + return "-- The PO113 element is empty. The PO113 element cannot be empty when the PO112 element is provided --"; + case "PO114 Value": + return" -- The value in the PO114 element is incorrect it needs to be 'ZZ' --"; + case "PO115 Value": + return "-- The value in the PO115 element is incorrect it needs to be 'dsco_item_id' --"; + case "PO116 Value": + return" -- The value in the PO116 element is incorrect it needs to be 'ZZ' --"; + case "PO118 Value": + return "-- The value in the PO118 element is incorrect it needs to be 'ZZ' --"; + + // Params for the ISR segment + case "ISR Size": + return "-- The length of the ISR is incorrect it needs to be one element long --"; + case "ISR01 Value": + return"-- The value of the ISR01 element is incorrect it needs to be 'IC' --"; + + default: + return ""; + + // + } } } \ No newline at end of file diff --git a/FileIO.java b/FileIO.java new file mode 100644 index 0000000..23e1ab7 --- /dev/null +++ b/FileIO.java @@ -0,0 +1,62 @@ +package ediFilterTutorial; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class FileIO extends EDI{ + Printer printer; + + + public FileIO(Printer printer) { + this.printer = printer; + } + + // Reads the contents of the file and stores it in a string; + public String fileReader(File selectedFile) throws IOException { + + String unFilteredData = ""; + int value = 0; + + // instantiates a new fileReader object called unFiltered and uses the absolute path of the file selected earlier in the fileSelector method + FileReader unFiltered = new FileReader(selectedFile.getAbsolutePath()); + + // instantiates a new BufferedReader object using the unFiltered FileReader object + BufferedReader reader = new BufferedReader(unFiltered); + + // while the character isn't blank append the data into the unFilteredData variable and store a new set of text in the line variable + + while((value = reader.read()) != -1) { + + // assign the int value of the char to value + char c = (char)value; + //store the converted value into unFilteredData + unFilteredData += String.valueOf(c); + } + // close the readers + reader.close(); + unFiltered.close(); + // return the populated variable + setUnfilteredEDI(unFilteredData); + return getUnfilteredEDI(); + } + + public void writeToFile(String[] data) { + try (FileWriter fileWrite = new FileWriter(getFileWriteLocation())){ + + for (int i = 0; i < data.length; i++) { + if (data[i] != "" && data != null) { + fileWrite.write(data + getSegmentTerminator() + "\n"); + } + } + //inform the user that the document was created + printer.printMessageToForm("/n The Document" + getFileWriteLocation() + " has been created."); + + }catch(IOException io) { + io.printStackTrace(); + } + } +} diff --git a/Kohl.java b/Kohl.java new file mode 100644 index 0000000..8d82d27 --- /dev/null +++ b/Kohl.java @@ -0,0 +1,11 @@ +package ediFilterTutorial; + +public class Kohl{ + +Printer printer; + + public Kohl(Printer printer) { + this.printer = printer; + } + +} diff --git a/Nord.java b/Nord.java new file mode 100644 index 0000000..e6e185d --- /dev/null +++ b/Nord.java @@ -0,0 +1,10 @@ +package ediFilterTutorial; + +public class Nord { + Printer printer; + + public Nord(Printer printer) { + this.printer = printer; + } + +} diff --git a/Printer.java b/Printer.java new file mode 100644 index 0000000..456267a --- /dev/null +++ b/Printer.java @@ -0,0 +1,39 @@ +package ediFilterTutorial; +import java.util.ArrayList; +import javax.swing.JTextArea; + +public class Printer { + + JTextArea form; + + public Printer(JTextArea form) { + this.form = form; + } + public void printToForm(ArrayList printData) { + for (int y = 0; y < printData.size(); y++) { + form.append("\n" + printData.get(y)); + } + } + public void logError(String Error) { + System.out.println(Error); + } + + public void printMessageToForm(String message) { + form.append("\n" + message); + } + + public void printDataToForm(String[] data, String segmentTerminator) { + + for (int i = 0; i < data.length; i++) { + //prints the data from the segments array and + form.append(data[i] + segmentTerminator + "\n"); + } + } + public void clearForm() { + form.setText(""); + } + public void setForm(JTextArea form) { + this.form = form; + } + +}