From 89910d9a348659dee958084ce02e3a9018324075 Mon Sep 17 00:00:00 2001 From: Lynn Mecham Date: Tue, 12 Jun 2018 22:31:15 -0600 Subject: [PATCH 01/24] Lots of organization changes Added a few classes and started moving the methods and such. --- Dsco.java | 547 ++++++++++++++++++++++++++++++++++++++++++++++ EDI_Filter.java | 564 ++---------------------------------------------- Kohl.java | 11 + Nord.java | 10 + Printer.java | 36 ++++ 5 files changed, 622 insertions(+), 546 deletions(-) create mode 100644 Dsco.java create mode 100644 Kohl.java create mode 100644 Nord.java create mode 100644 Printer.java diff --git a/Dsco.java b/Dsco.java new file mode 100644 index 0000000..c1737ae --- /dev/null +++ b/Dsco.java @@ -0,0 +1,547 @@ +package ediFilterTutorial; + +import java.io.File; +import java.util.ArrayList; + +public class Dsco { + Error error = new Error(); + Printer printer; + + 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; + 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()) { + + // call printer class here + printer.logError(" " + 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; + } + } + } + } + } + } + } + + + private void dsco846(ArrayList transactionData, String elementSeparator) { + + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmmss"; + + + 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 because 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 (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 = ""; + 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 (!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 = ""; + 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; + } + } + + } + printer.printToForm(errorInformation); + } + } diff --git a/EDI_Filter.java b/EDI_Filter.java index e73e8c4..e71a86d 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -21,6 +21,11 @@ public class EDI_Filter implements ActionListener { JLabel ediLab, buttonLab; JRadioButton dscoRadio, nordRadio, kohlRadio; ButtonGroup filterGroup; + + Printer printer = new Printer(formattedEDI); + Dsco dsco = new Dsco(printer); + Nord nord = new Nord(printer); + Kohl kohl = new Kohl(printer); //This method is one I found that centers the application window to the bounds of your screen public static void centreWindow(Window frame) { @@ -69,6 +74,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); @@ -110,7 +116,6 @@ public void actionPerformed(ActionEvent ae) { formatter(fileReader(selectedFile), selectedFile, true, false, false); } catch (IOException e) { formattedEDI.append("\n" + e.getMessage()); - // TODO Auto-generated catch block e.printStackTrace(); } // If no radio button is selected just run the formatter method without any error checking @@ -157,6 +162,9 @@ public String fileReader(File selectedFile) throws IOException { String unFilteredData = ""; String line = ""; int value = 0; + + //error check variable + String path = selectedFile.getAbsolutePath(); // 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()); @@ -210,7 +218,7 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea if (selectedFile.length() <= 3000000) { if (isDsco) { // starts the error checking process for Dsco EDI spec (846 basically done, other documents not done) - dscoErrorCheck(segments, selectedFile, elementSeparator); + dsco.dscoErrorCheck(segments, selectedFile, elementSeparator); } else if (isNordstrom) { // starts the error checking process for Nordstrom EDI spec (Not Done) nordErrorCheck(segments, selectedFile, elementSeparator); @@ -218,17 +226,14 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea // 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"); - } + printer.printDataToForm(segments,segmentTerminator); } // if the size is greater than 3MB we can't print to the form so we print to a file } else { try { //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"; @@ -237,11 +242,11 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea //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); + dsco.dscoErrorCheck(segments, selectedFile, elementSeparator); } else if (isNordstrom) { nordErrorCheck(segments, selectedFile, elementSeparator); } else if (isKohls) { @@ -258,110 +263,15 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea //close the writer fileWrite.close(); //inform the user that the document was created - formattedEDI.append("/n The Document" + fileName + " has been created."); + printer.printMessageToForm("/n The Document" + fileName + " has been created."); } } } catch (IOException e) { - formattedEDI.append("/n There was an error writing the file: " + e.getMessage()); + 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) { @@ -372,446 +282,9 @@ public void kohlErrorCheck(String[] fileData, File selectedFile, String elementS } // 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; @@ -830,5 +303,4 @@ public void run() { } }); } - } 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..8cce75a --- /dev/null +++ b/Printer.java @@ -0,0 +1,36 @@ +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.setText(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 setForm(JTextArea form) { + this.form = form; + } + +} From ae70a308c6a106e5fcbbcf29a9b90dad3943d3d7 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 14 Jun 2018 18:15:28 -0600 Subject: [PATCH 02/24] Format Changes Got rid of an un needed for loop and some un needed variables. Also reformatted the code. --- Dsco.java | 256 +++++++++++++++++++++++++++--------------------------- 1 file changed, 127 insertions(+), 129 deletions(-) diff --git a/Dsco.java b/Dsco.java index c1737ae..41b7c23 100644 --- a/Dsco.java +++ b/Dsco.java @@ -6,122 +6,111 @@ public class Dsco { Error error = new Error(); Printer printer; - + 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; - 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; + String holder = ""; + String[] element; + + boolean go = true; + + // 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++) { + // 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 + // + 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 + transactionType = element[1]; + + // 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]); + // 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); + 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; - } 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()) { - - // call printer class here - printer.logError(" " + 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; - } - } - } } + go = false; + break; + } else { + // 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"; - 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 because the error messages weren't getting added to the original ArrayList + + // 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(); // Start the loop through the passed transaction data @@ -129,64 +118,71 @@ private void dsco846(ArrayList transactionData, String elementSeparator) if (stop != false) { stop = false; } - // assign the array element to holder + // 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 + // 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 + // 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 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 + // 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 + // 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 + // 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 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")) { + } + if (!element[2].equals("MM")) { message += error.getErrorMessage("846", "BIA02 Value"); - }if (element[3].isEmpty()) { + } + if (element[3].isEmpty()) { message += error.getErrorMessage("846", "BIA03 Empty"); - }if (EDI_Filter.dateChecker(element[4], dateFormat) == false) { + } + if (EDI_Filter.dateChecker(element[4], dateFormat) == false) { message += error.getErrorMessage("846", "BIA04 Date"); - }if (EDI_Filter.dateChecker(element[5], timeFormat) == false) { + } + if (EDI_Filter.dateChecker(element[5], timeFormat) == false) { message += error.getErrorMessage("846", "BIA05 Time"); - }if (element.length < 6 || element.length > 6) { + } + if (element.length < 6 || element.length > 6) { message += error.getErrorMessage("846", "BIA Size"); } } catch (ArrayIndexOutOfBoundsException e) { @@ -216,8 +212,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) message = ""; stop = true; break; - - + // Error Checking of the REF segment case "REF": try { @@ -226,16 +221,16 @@ private void dsco846(ArrayList transactionData, String elementSeparator) message += error.getErrorMessage("846", "REF Size"); break; } - //check value of the REF01 + // 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 + // 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 + // 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")) { @@ -252,35 +247,38 @@ private void dsco846(ArrayList transactionData, String elementSeparator) break; // Error checking of the LIN segment - // This is the big segment where all the item information is populated and updated. + // 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 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' + // 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 + } // 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 + // 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" + // 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) + // 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 + } // LIN05 can't be empty when LIN04 has data if (element[5].isEmpty()) { message = message + error.getErrorMessage("846", "LIN05 Empty"); } @@ -294,7 +292,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) if (element[7].isEmpty()) { message += error.getErrorMessage("846", "LIN07 Empty"); } else { - //EAN's can only have 13 digits. No more no less. + // EAN's can only have 13 digits. No more no less. if (element[7].length() != 13) { message += error.getErrorMessage("846", "LIN07 Size"); } @@ -372,7 +370,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) case "PID": try { - //size if this segment must be 5. + // size if this segment must be 5. if (element.length != 6) { message += error.getErrorMessage("846", "PID Size"); break; @@ -544,4 +542,4 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } printer.printToForm(errorInformation); } - } +} From 4e540d3c00c964d9a31ca42d9bf2994db82d5386 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 15 Jun 2018 22:10:51 -0600 Subject: [PATCH 03/24] Updates to format Added new classes and got rid of un needed code. --- Dsco.java | 26 +++++++++++------------ EDI.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ EDI_Filter.java | 43 ++++++++++++++++++------------------- FileIO.java | 29 +++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 36 deletions(-) create mode 100644 EDI.java create mode 100644 FileIO.java diff --git a/Dsco.java b/Dsco.java index 41b7c23..707ece9 100644 --- a/Dsco.java +++ b/Dsco.java @@ -3,13 +3,17 @@ import java.io.File; import java.util.ArrayList; -public class Dsco { +public class Dsco extends EDI{ Error error = new Error(); Printer printer; + FileIO fileIO; + public Dsco(Printer printer) { this.printer = printer; } + + public void dscoErrorCheck(String[] fileData, File selectedFile, String elementSeparator) { // temporary holder for each line of the document @@ -115,18 +119,11 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // 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 @@ -147,7 +144,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) message += error.getErrorMessage("General", "ST02 empty"); } // if it isn't empty store the value in the ST02 in the - // transactionSetControlHeader variable for later comparisson + // transactionSetControlHeader variable for later comparison else { transactionSetControlHeader += element[2]; } @@ -155,8 +152,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) 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; + // get out of the loop so we can move on to the next segment in the EDI break; // Error Checking of the BIA segment @@ -538,8 +534,12 @@ private void dsco846(ArrayList transactionData, String elementSeparator) break; } } - + if (getFileWriteFlag()) { + setEDIData(errorInformation); + } printer.printToForm(errorInformation); + } + } -} + diff --git a/EDI.java b/EDI.java new file mode 100644 index 0000000..05153b2 --- /dev/null +++ b/EDI.java @@ -0,0 +1,56 @@ +package ediFilterTutorial; + +import java.util.ArrayList; + +public class EDI { + + private boolean fileWriteFlag; + private ArrayList EDI_Data; + private String fileWriteLocation; + private String[] segments; + private String segmentTerminator; + + + 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 e71a86d..b22d0d6 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; @@ -26,6 +26,7 @@ public class EDI_Filter implements ActionListener { Dsco dsco = new Dsco(printer); Nord nord = new Nord(printer); Kohl kohl = new Kohl(printer); + FileIO fileIO = new FileIO(printer); //This method is one I found that centers the application window to the bounds of your screen public static void centreWindow(Window frame) { @@ -160,7 +161,6 @@ public File fileSelector() { // 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; //error check variable @@ -205,40 +205,47 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea String elementSeparator = ""; 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 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 == '*') { elementSeparator = "\\*"; } 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) { // starts the error checking process for Dsco EDI spec (846 basically done, other documents not done) - dsco.dscoErrorCheck(segments, selectedFile, elementSeparator); + dsco.dscoErrorCheck(getSegments(), selectedFile, elementSeparator); } else if (isNordstrom) { // starts the error checking process for Nordstrom EDI spec (Not Done) - nordErrorCheck(segments, selectedFile, elementSeparator); + nordErrorCheck(getSegments(), selectedFile, elementSeparator); } else if (isKohls) { // starts the error checking process for Dsco EDI spec (Not Done) - kohlErrorCheck(segments, selectedFile, elementSeparator); + kohlErrorCheck(getSegments(), selectedFile, elementSeparator); } else { - printer.printDataToForm(segments,segmentTerminator); + 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 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()) { @@ -246,24 +253,14 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea } else { // this is where the error checking part is going to come in for large files if (isDsco) { - dsco.dscoErrorCheck(segments, selectedFile, elementSeparator); + dsco.dscoErrorCheck(getSegments(), selectedFile, elementSeparator); } else if (isNordstrom) { - nordErrorCheck(segments, selectedFile, elementSeparator); + nordErrorCheck(getSegments(), selectedFile, elementSeparator); } else if (isKohls) { - kohlErrorCheck(segments, selectedFile, elementSeparator); + kohlErrorCheck(getSegments(), selectedFile, elementSeparator); } 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 - printer.printMessageToForm("/n The Document" + fileName + " has been created."); + FileIO.writeToFile(getSegments()); } } } catch (IOException e) { diff --git a/FileIO.java b/FileIO.java new file mode 100644 index 0000000..2fb40c3 --- /dev/null +++ b/FileIO.java @@ -0,0 +1,29 @@ +package ediFilterTutorial; + +import java.io.File; +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; + } + + 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(); + } + } +} From 99010ed4a5106b6554e7294a00f3d2a3bd7e576a Mon Sep 17 00:00:00 2001 From: Lynn Date: Sat, 16 Jun 2018 14:15:27 -0600 Subject: [PATCH 04/24] simple changes added some stuff to a few classes. Trying to get the FileIO class to work --- Dsco.java | 1 + EDI_Filter.java | 6 ++++-- FileIO.java | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dsco.java b/Dsco.java index 707ece9..7bcdf60 100644 --- a/Dsco.java +++ b/Dsco.java @@ -7,6 +7,7 @@ public class Dsco extends EDI{ Error error = new Error(); Printer printer; FileIO fileIO; + //EDI_Filter filter = new EDI_Filter(); public Dsco(Printer printer) { diff --git a/EDI_Filter.java b/EDI_Filter.java index b22d0d6..f810d6a 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -27,6 +27,7 @@ public class EDI_Filter extends EDI implements ActionListener { 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) { @@ -260,10 +261,10 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea kohlErrorCheck(getSegments(), selectedFile, elementSeparator); } else { // if there is no error checking involved write the file to the Downloads folder on the machine - FileIO.writeToFile(getSegments()); + fileIO.writeToFile(getSegments()); } } - } catch (IOException e) { + } catch (Exception e) { printer.logError("/n There was an error writing the file: " + e.getMessage()); } } @@ -299,5 +300,6 @@ public void run() { new EDI_Filter(); } }); + } } diff --git a/FileIO.java b/FileIO.java index 2fb40c3..7285618 100644 --- a/FileIO.java +++ b/FileIO.java @@ -7,6 +7,8 @@ public class FileIO extends EDI{ Printer printer; + + public FileIO(Printer printer) { this.printer = printer; } From 0a9d1edb1bff81fa65abb2d9293e29db3c86d121 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 18 Jun 2018 08:57:13 -0600 Subject: [PATCH 05/24] Some Changes Working on new class and starting 810 filtering --- Dsco.java | 23 ++++++----------------- EDI.java | 8 ++++++++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Dsco.java b/Dsco.java index 7bcdf60..cdba7b7 100644 --- a/Dsco.java +++ b/Dsco.java @@ -23,8 +23,6 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS boolean go = true; - // 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 @@ -38,6 +36,9 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS 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]; + + //remove whitespace from beginning and end of the string + holder.trim(); // split the holder string into elements using the elementSeparator variable element = holder.split(elementSeparator); @@ -56,7 +57,7 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS } // if the ST01 isn't empty store it in the variable this is what we are going to // Switch on later - transactionType = element[1]; + setTransactionType(element[1]); // if any of the 0 position elements are these values add them, but don't filter // them @@ -71,7 +72,7 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS // take the variable in the transactionType and do a switch based on that value // to error check the correct document - switch (transactionType) { + switch (getTransactionType()) { case "846": // start the error checking process for the Dsco 846 passing the Array List of // the data and the elementSeparator variable @@ -110,7 +111,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) String dateFormat = "yyyyMMdd"; String timeFormat = "HHmmss"; - boolean stop = false; String transactionSetControlHeader = ""; // this will be the array that contains what we are going to print to the @@ -125,7 +125,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // split holder into the element array. So we can evaluate each segment of the // EDI element = holder.split(elementSeparator); - switch (element[0]) { + switch (element[0].trim()) { // Error Checking for the ST segment case "ST": @@ -187,7 +187,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error Checking of the CUR segment @@ -207,7 +206,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error Checking of the REF segment @@ -240,7 +238,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error checking of the LIN segment @@ -361,7 +358,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error checking for the PID segment @@ -386,7 +382,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error Checking for the CTP Segment @@ -409,7 +404,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error check for the QTY segment @@ -435,7 +429,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error checking for the SCH01 segment @@ -468,7 +461,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error Checking for the N1 segment @@ -495,7 +487,6 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } errorInformation.add(holder + message); message = ""; - stop = true; break; // Error Checking for the SE segment @@ -524,14 +515,12 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } 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; } } diff --git a/EDI.java b/EDI.java index 05153b2..f091a98 100644 --- a/EDI.java +++ b/EDI.java @@ -9,7 +9,15 @@ public class EDI { private String fileWriteLocation; private String[] segments; private String segmentTerminator; + private String transactionType; + public String getTransactionType() { + return this.transactionType; + } + + public void setTransactionType(String type) { + this.transactionType = type; + } public String getSegmentTerminator() { return this.segmentTerminator; From ff5ff88adbbbadcbe800133080f6060f88b0512c Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 18 Jun 2018 15:54:48 -0600 Subject: [PATCH 06/24] Format Changes again Adding more functionality to the buttons --- EDI.java | 22 ++++++++++++++++++++++ EDI_Filter.java | 37 +++++++++++++------------------------ FileIO.java | 4 ++++ 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/EDI.java b/EDI.java index f091a98..90251f0 100644 --- a/EDI.java +++ b/EDI.java @@ -1,5 +1,6 @@ package ediFilterTutorial; +import java.io.File; import java.util.ArrayList; public class EDI { @@ -10,6 +11,27 @@ public class EDI { private String[] segments; private String segmentTerminator; private String transactionType; + private File ediFile; + private boolean dscoRadioStatus; + + + + public boolean isDscoRadioStatus() { + return dscoRadioStatus; + } + + public void setDscoRadioStatus(boolean dscoRadioStatus) { + this.dscoRadioStatus = dscoRadioStatus; + } + + public File getEdiFile() { + return this.ediFile; + } + + public void setEdiFile(File data) { + this.ediFile = data; + } + public String getTransactionType() { return this.transactionType; diff --git a/EDI_Filter.java b/EDI_Filter.java index f810d6a..c16da0c 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -107,15 +107,15 @@ public void actionPerformed(ActionEvent ae) { // start the switch statement using the action command switch (ae.getActionCommand()) { case "selectFile": - + setDscoRadioStatus(dscoRadio.isSelected()); // If radio button is selected get the file and start the error checker for if (dscoRadio.isSelected()) { //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(fileReader(getEdiFile()), getEdiFile(), true, false, false); } catch (IOException e) { formattedEDI.append("\n" + e.getMessage()); e.printStackTrace(); @@ -124,9 +124,9 @@ public void actionPerformed(ActionEvent ae) { } 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(fileReader(getEdiFile()), getEdiFile(), false, false, false); } catch (IOException e) { @@ -142,53 +142,42 @@ public void actionPerformed(ActionEvent ae) { } // 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"); + printer.printMessageToForm("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 = ""; int value = 0; - - //error check variable - String path = selectedFile.getAbsolutePath(); // 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 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); } - - -// while (line != null) { -// unFilteredData += line; -// line = reader.readLine(); -// } // close the readers reader.close(); unFiltered.close(); diff --git a/FileIO.java b/FileIO.java index 7285618..636593c 100644 --- a/FileIO.java +++ b/FileIO.java @@ -13,6 +13,10 @@ public FileIO(Printer printer) { this.printer = printer; } + public void fileReader() { + + } + public void writeToFile(String[] data) { try (FileWriter fileWrite = new FileWriter(getFileWriteLocation())){ From 64e7bb23d7dcc7abfb8a526748a886907b0a9816 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 18 Jun 2018 20:24:05 -0600 Subject: [PATCH 07/24] More class variables and other changes --- EDI.java | 21 ++++++++++++++++++++- EDI_Filter.java | 28 +++++++++++++++++++++++++--- Printer.java | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/EDI.java b/EDI.java index 90251f0..72bde3a 100644 --- a/EDI.java +++ b/EDI.java @@ -12,11 +12,30 @@ public class EDI { private String segmentTerminator; private String transactionType; private File ediFile; + private boolean dscoRadioStatus; + private boolean nordRadioStatus; + private boolean kohlRadioStatus; - public boolean isDscoRadioStatus() { + public boolean getNordRadioStatus() { + return nordRadioStatus; + } + + public void setNordRadioStatus(boolean nordRadioStatus) { + this.nordRadioStatus = nordRadioStatus; + } + + public boolean getKohlRadioStatus() { + return kohlRadioStatus; + } + + public void setKohlRadioStatus(boolean kohlRadioStatus) { + this.kohlRadioStatus = kohlRadioStatus; + } + + public boolean getDscoRadioStatus() { return dscoRadioStatus; } diff --git a/EDI_Filter.java b/EDI_Filter.java index c16da0c..c6c5498 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -108,8 +108,11 @@ public void actionPerformed(ActionEvent ae) { switch (ae.getActionCommand()) { case "selectFile": setDscoRadioStatus(dscoRadio.isSelected()); + setNordRadioStatus(nordRadio.isSelected()); + setKohlRadioStatus(kohlRadio.isSelected()); + // If radio button is selected get the file and start the error checker for - if (dscoRadio.isSelected()) { + if (getDscoRadioStatus()) { //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 @@ -117,11 +120,30 @@ public void actionPerformed(ActionEvent ae) { //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(getEdiFile()), getEdiFile(), true, false, false); } catch (IOException e) { - formattedEDI.append("\n" + e.getMessage()); + printer.printMessageToForm("\n" + e.getMessage()); e.printStackTrace(); } // If no radio button is selected just run the formatter method without any error checking - } else { + } else if(getNordRadioStatus()) { + try { + fileSelector(); + formatter(fileReader(getEdiFile()),getEdiFile(),false, true, false); + }catch(IOException e) { + printer.printMessageToForm("\n" + e.getMessage()); + e.printStackTrace(); + } + + } else if (getKohlRadioStatus()) { + try { + fileSelector(); + formatter(fileReader(getEdiFile()),getEdiFile(),false,false,true); + }catch(IOException e) { + printer.printMessageToForm("\n" + e.getMessage()); + e.printStackTrace(); + } + + } + else { try { //calling the File Selector Method which returns a File object and storing it in the variable selectedFile fileSelector(); diff --git a/Printer.java b/Printer.java index 8cce75a..06d245a 100644 --- a/Printer.java +++ b/Printer.java @@ -19,7 +19,7 @@ public void logError(String Error) { } public void printMessageToForm(String message) { - form.setText(message); + form.append(message); } public void printDataToForm(String[] data, String segmentTerminator) { From b0849b5e499e892a56b4e2dfe092018675b4e887 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 19 Jun 2018 15:14:00 -0600 Subject: [PATCH 08/24] Format changes --- EDI.java | 28 ++++++++++++++++--- EDI_Filter.java | 72 +++++++++++-------------------------------------- FileIO.java | 33 ++++++++++++++++++++--- Printer.java | 5 +++- 4 files changed, 74 insertions(+), 64 deletions(-) diff --git a/EDI.java b/EDI.java index 72bde3a..ff47cd6 100644 --- a/EDI.java +++ b/EDI.java @@ -3,6 +3,8 @@ import java.io.File; import java.util.ArrayList; +import javax.swing.JTextArea; + public class EDI { private boolean fileWriteFlag; @@ -12,15 +14,33 @@ public class EDI { private String segmentTerminator; private String transactionType; private File ediFile; + private String unfilteredEdi; private boolean dscoRadioStatus; private boolean nordRadioStatus; private boolean kohlRadioStatus; +// private JTextArea form; +// +// public void setForm(JTextArea form) { +// this.form = form; +// } +// public JTextArea getForm() { +// return form; +// } + + public String getUnfilteredEDI() { + return this.unfilteredEdi; + } + + + public void setUnfilteredEDI(String data) { + this.unfilteredEdi = data; + } public boolean getNordRadioStatus() { - return nordRadioStatus; + return this.nordRadioStatus; } public void setNordRadioStatus(boolean nordRadioStatus) { @@ -28,7 +48,7 @@ public void setNordRadioStatus(boolean nordRadioStatus) { } public boolean getKohlRadioStatus() { - return kohlRadioStatus; + return this.kohlRadioStatus; } public void setKohlRadioStatus(boolean kohlRadioStatus) { @@ -36,7 +56,7 @@ public void setKohlRadioStatus(boolean kohlRadioStatus) { } public boolean getDscoRadioStatus() { - return dscoRadioStatus; + return this.dscoRadioStatus; } public void setDscoRadioStatus(boolean dscoRadioStatus) { @@ -44,7 +64,7 @@ public void setDscoRadioStatus(boolean dscoRadioStatus) { } public File getEdiFile() { - return this.ediFile; + return ediFile; } public void setEdiFile(File data) { diff --git a/EDI_Filter.java b/EDI_Filter.java index c6c5498..5edb28f 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -112,43 +112,25 @@ public void actionPerformed(ActionEvent ae) { setKohlRadioStatus(kohlRadio.isSelected()); // If radio button is selected get the file and start the error checker for - if (getDscoRadioStatus()) { + if (getDscoRadioStatus() || getNordRadioStatus() || getKohlRadioStatus()) { //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 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(getEdiFile()), getEdiFile(), true, false, false); + formatter(fileIO.fileReader(getEdiFile())); } catch (IOException e) { printer.printMessageToForm("\n" + e.getMessage()); e.printStackTrace(); } // If no radio button is selected just run the formatter method without any error checking - } else if(getNordRadioStatus()) { - try { - fileSelector(); - formatter(fileReader(getEdiFile()),getEdiFile(),false, true, false); - }catch(IOException e) { - printer.printMessageToForm("\n" + e.getMessage()); - e.printStackTrace(); - } - - } else if (getKohlRadioStatus()) { - try { - fileSelector(); - formatter(fileReader(getEdiFile()),getEdiFile(),false,false,true); - }catch(IOException e) { - printer.printMessageToForm("\n" + e.getMessage()); - e.printStackTrace(); - } - - } + } else { try { //calling the File Selector Method which returns a File object and storing it in the variable selectedFile fileSelector(); //Runs the formatter method without any error checking - formatter(fileReader(getEdiFile()), getEdiFile(), false, false, false); + formatter(fileIO.fileReader(getEdiFile())); } catch (IOException e) { @@ -158,7 +140,8 @@ 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(); break; } } @@ -180,38 +163,15 @@ public void fileSelector() { } - // 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 - 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 = ""; @@ -228,13 +188,13 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea // 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) dsco.dscoErrorCheck(getSegments(), selectedFile, elementSeparator); - } else if (isNordstrom) { + } else if (getNordRadioStatus()) { // starts the error checking process for Nordstrom EDI spec (Not Done) nordErrorCheck(getSegments(), selectedFile, elementSeparator); - } else if (isKohls) { + } else if (getKohlRadioStatus()) { // starts the error checking process for Dsco EDI spec (Not Done) kohlErrorCheck(getSegments(), selectedFile, elementSeparator); } else { @@ -264,11 +224,11 @@ public void formatter(String toFilter, File selectedFile, boolean isDsco, boolea 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) { + if (getDscoRadioStatus()) { dsco.dscoErrorCheck(getSegments(), selectedFile, elementSeparator); - } else if (isNordstrom) { + } else if (getNordRadioStatus()) { nordErrorCheck(getSegments(), selectedFile, elementSeparator); - } else if (isKohls) { + } else if (getKohlRadioStatus()) { kohlErrorCheck(getSegments(), selectedFile, elementSeparator); } else { // if there is no error checking involved write the file to the Downloads folder on the machine diff --git a/FileIO.java b/FileIO.java index 636593c..23e1ab7 100644 --- a/FileIO.java +++ b/FileIO.java @@ -1,6 +1,8 @@ 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; @@ -13,9 +15,34 @@ public FileIO(Printer printer) { this.printer = printer; } - public void fileReader() { - - } + // 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())){ diff --git a/Printer.java b/Printer.java index 06d245a..a8cebfe 100644 --- a/Printer.java +++ b/Printer.java @@ -19,7 +19,7 @@ public void logError(String Error) { } public void printMessageToForm(String message) { - form.append(message); + form.setText(message); } public void printDataToForm(String[] data, String segmentTerminator) { @@ -29,6 +29,9 @@ public void printDataToForm(String[] data, String segmentTerminator) { form.append(data[i] + segmentTerminator + "\n"); } } + public void clearForm() { + form.setText(""); + } public void setForm(JTextArea form) { this.form = form; } From 1699f04809eda81268c2e15db069dfa077115509 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 19 Jun 2018 15:50:02 -0600 Subject: [PATCH 09/24] Starting 856 error checking --- Dsco.java | 916 +++++++++++++++++++++++++++++------------------------ Error.java | 10 +- 2 files changed, 505 insertions(+), 421 deletions(-) diff --git a/Dsco.java b/Dsco.java index cdba7b7..d4747c4 100644 --- a/Dsco.java +++ b/Dsco.java @@ -3,18 +3,15 @@ import java.io.File; import java.util.ArrayList; -public class Dsco extends EDI{ +public class Dsco extends EDI { Error error = new Error(); Printer printer; FileIO fileIO; - //EDI_Filter filter = new EDI_Filter(); - + // EDI_Filter filter = new EDI_Filter(); public Dsco(Printer printer) { this.printer = printer; } - - public void dscoErrorCheck(String[] fileData, File selectedFile, String elementSeparator) { // temporary holder for each line of the document @@ -23,7 +20,6 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS boolean go = true; - // List containing the segment data from ST to SE, which is where the // transactions specific data is ArrayList transactionData = new ArrayList(); @@ -34,74 +30,71 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS // 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]; - - //remove whitespace from beginning and end of the string - holder.trim(); - - // split the holder string into elements using the elementSeparator variable - element = holder.split(elementSeparator); - - // filter through the element looking at position 0 - // - 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 - } else if (element[0].equals("ISA") || element[0].equals("GS") || element[0].equals("GE") - || element[0].equals("IEA")) { - 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 - } 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 (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); - 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; - } + // 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 + // + 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; - } else { - // formattedEDI.setText(element[0]); - transactionData.add(fileData[i]); } + // 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 + } else if (element[0].equals("ISA") || element[0].equals("GS") || element[0].equals("GE") + || element[0].equals("IEA")) { + 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 + } 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 (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); + 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); + break; + case "810": + System.out.println(transactionData); + // formattedEDI.append("\n You got to the 810 Switch statement"); + // dsco810(transactionData); + break; + } + go = false; + break; + } else { + // formattedEDI.setText(element[0]); + transactionData.add(fileData[i]); } } } + } private void dsco846(ArrayList transactionData, String elementSeparator) { @@ -122,414 +115,507 @@ private void dsco846(ArrayList transactionData, String elementSeparator) 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()) { + switch (element[0].trim()) { - // 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; + // 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("General", "ST02 Size"); } - // 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 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 { + // 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"); } - // 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 { - // 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"); + if (!element[2].equals("MM")) { + message += error.getErrorMessage("846", "BIA02 Value"); } - 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"); + 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"); } - 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"); + } 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; } - 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 { - // 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 + // check value of the REF01 + if (element[1].equals("IA")) { if (element[2].isEmpty()) { - message += error.getErrorMessage("846", "LIN02 Req"); + message += error.getErrorMessage("846", "REF02 Empty"); } - // 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"); - } + } + // 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"); } } - if (element.length >= 7) { - if (!element[6].equals("EN")) { - message += error.getErrorMessage("846", "LIN06 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 { + // 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"); } - 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"); - } - } + // 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 >= 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 >= 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 >= 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 >= 9) { + if (!element[8].isEmpty()) { + if (!element[8].equals("MG")) { + message += error.getErrorMessage("846", "LIN08 Value"); } - } - 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[9].isEmpty()) { + message += error.getErrorMessage("846", "LIN09 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 >= 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 >= 17) { - if (!element[16].isEmpty()) { - } - if (!element[16].equals("SK")) { - message += error.getErrorMessage("846", "LIN16 Value"); + } + if (element.length >= 13) { + if (!element[12].isEmpty()) { + if (!element[12].equals("UK")) { + message += error.getErrorMessage("846", "LIN12 Value"); } - if (element[17].isEmpty()) { - message += error.getErrorMessage("846", "LIN17 Empty"); + if (element[13].isEmpty()) { + message += error.getErrorMessage("846", "LIN13 Empty"); } } - if (element.length >= 19) { - if (!element[18].isEmpty()) { - } - if (!element[18].equals("SK")) { - message += error.getErrorMessage("846", "LIN18 Value"); + } + if (element.length >= 15) { + if (!element[14].isEmpty()) { + if (!element[14].equals("BL")) { + message += error.getErrorMessage("846", "LIN14 Value"); } - if (element[19].isEmpty()) { - message += error.getErrorMessage("846", "LIN19 Empty"); + if (element[15].isEmpty()) { + message += error.getErrorMessage("846", "LIN15 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.length >= 17) { + if (!element[16].isEmpty()) { } - if (!element[1].equals("F")) { - message += error.getErrorMessage("846", "PID01 Value"); + if (!element[16].equals("SK")) { + message += error.getErrorMessage("846", "LIN16 Value"); } - if (!element[2].equals("08")) { - message += error.getErrorMessage("846", "PID02 Value"); + if (element[17].isEmpty()) { + message += error.getErrorMessage("846", "LIN17 Empty"); } - 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.length >= 19) { + if (!element[18].isEmpty()) { } - if (!element[1].equals("AS")) { - message += error.getErrorMessage("846", "CTP01 Value"); + if (!element[18].equals("SK")) { + message += error.getErrorMessage("846", "LIN18 Value"); } - if (!element[2].equals("WHL")) { - message += error.getErrorMessage("846", "CTP02 Value"); + if (element[19].isEmpty()) { + message += error.getErrorMessage("846", "LIN19 Empty"); } - 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 { - 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; + } 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 { + 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[1].isEmpty()) { - if (!element[1].equals("33")) { - message += error.getErrorMessage("846", "QTY01 Value"); - } - if (!element[3].equals("EA")) { - message += error.getErrorMessage("846", "QTY03 Vlaue"); - } + 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"); + } 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[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"); - } + 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 + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + break; - case "SE": - try { - int result; - String count = ""; - count += element[1]; - result = Integer.parseInt(count); - if (element.length != 3) { - message += error.getErrorMessage("General", "SE Size"); + // 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[1].isEmpty()) { - message += error.getErrorMessage("General", "SE01 Empty"); - break; + if (element[2].isEmpty() || element[3].isEmpty() || element[4].isEmpty()) { + message += error.getErrorMessage("846", "N1 Empty"); } - if (result != transactionData.size()) { - message += error.getErrorMessage("General", "SE01 Value"); + if (!element[3].equals("ZZ")) { + message += error.getErrorMessage("846", "N103 Value"); } - if (!element[2].equals(transactionSetControlHeader)) { - message += error.getErrorMessage("General", "SE02 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; - default: - message = "Check this segment: " + element[0] - + " there may be whitespace that the filter isn't catching."; - errorInformation.add(holder + message); - message = ""; - break; + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + errorInformation.add(holder + message); + message = ""; + 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 = ""; + 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); + } + + public void dsco856(ArrayList transactionData, String elementSeparator) { + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmmss"; + + 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); + + // 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()) { + case "ST": + 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 "BSN": + 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"); + } + // 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": + break; + case "TD5": + break; + case "REF": + break; + case "LIN": + break; + case "SN1": + break; + case "SE": + break; + } } - } +} diff --git a/Error.java b/Error.java index 57d8084..b2edb96 100644 --- a/Error.java +++ b/Error.java @@ -27,6 +27,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 +41,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'--"; From dc813ee3b1730ae408b6d2a7446de71dcf128830 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 21 Jun 2018 11:20:27 -0600 Subject: [PATCH 10/24] Starting the 856 error checking --- Dsco.java | 208 ++++++++++++++++++++++++++++++++++++++++++++++++----- Error.java | 57 ++++++++++++++- 2 files changed, 245 insertions(+), 20 deletions(-) diff --git a/Dsco.java b/Dsco.java index d4747c4..0225b44 100644 --- a/Dsco.java +++ b/Dsco.java @@ -70,6 +70,7 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS // 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"); @@ -265,7 +266,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) 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 + // 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"); @@ -523,7 +524,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } if (getFileWriteFlag()) { setEDIData(errorInformation); - fileIO.writeCheckedToFile(getEDIData()); + // fileIO.writeCheckedToFile(getEDIData()); } printer.printToForm(errorInformation); @@ -534,7 +535,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) String[] element; String message = ""; String dateFormat = "yyyyMMdd"; - String timeFormat = "HHmmss"; + String timeFormat = "HHmm"; String transactionSetControlHeader = ""; @@ -581,20 +582,31 @@ public void dsco856(ArrayList transactionData, String elementSeparator) // get out of the loop so we can move on to the next segment in the EDI break; case "BSN": - 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"); + 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); @@ -603,14 +615,176 @@ public void dsco856(ArrayList transactionData, String elementSeparator) // get out of the loop so we can move on to the next segment in the EDI break; case "HL": + try { + 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 { + 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 { + 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 "LIN": + try { + 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 "SN1": + 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"); + } + } break; case "SE": break; diff --git a/Error.java b/Error.java index b2edb96..6ab6139 100644 --- a/Error.java +++ b/Error.java @@ -3,14 +3,65 @@ 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 "General": return GenErrors(errorParams); + default: + return ""; } - return ""; } + 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 "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 --"; + default: + return ""; + } + } + private String GenErrors(String errorParams) { switch (errorParams) { From d2b531341fed9fd91aa4833ddbae89bff3c50881 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 22 Jun 2018 09:23:03 -0600 Subject: [PATCH 11/24] Added 856 Method --- Dsco.java | 113 +++++++++++++++++++++++++++++++++++++++++++++++++---- Error.java | 30 ++++++++++++++ 2 files changed, 136 insertions(+), 7 deletions(-) diff --git a/Dsco.java b/Dsco.java index 0225b44..506931f 100644 --- a/Dsco.java +++ b/Dsco.java @@ -691,6 +691,34 @@ public void dsco856(ArrayList transactionData, String elementSeparator) message = ""; // get out of the loop so we can move on to the next segment in the EDI break; + case "DTM": + try { + 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 { if (element[2].isEmpty() || element[3].isEmpty()) { @@ -776,18 +804,89 @@ public void dsco856(ArrayList transactionData, String elementSeparator) // get out of the loop so we can move on to the next segment in the EDI break; case "SN1": - 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"); + 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("\\d*\\.?\\d+")) { + 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 { + 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; + } } } diff --git a/Error.java b/Error.java index 6ab6139..3e482d7 100644 --- a/Error.java +++ b/Error.java @@ -57,6 +57,36 @@ private String ShipErrors(String errorParams) { 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 --"; default: return ""; } From 5a5d69b3a50c4bcc5bb8f85bcccfc9cc38a28451 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 25 Jun 2018 19:02:26 -0600 Subject: [PATCH 12/24] More changes More error checking and additional reworking --- Dsco.java | 41 +++++++++++++++++++++++++++++++++++------ EDI_Filter.java | 3 ++- Error.java | 11 +++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Dsco.java b/Dsco.java index 506931f..69d4c08 100644 --- a/Dsco.java +++ b/Dsco.java @@ -32,12 +32,12 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS 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(); + - // filter through the element looking at position 0 - // if (element[0].equals("ST")) { transactionData.add(fileData[i]); if (element[1].isEmpty()) { @@ -547,14 +547,18 @@ public void dsco856(ArrayList transactionData, String elementSeparator) 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 - 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()) { + //element[0] = element[0].trim(); +// if(elementSeparator != "/n") { +// element[0] = element[0].replaceAll("/n", ""); +// } + switch (element[0]) { case "ST": if (element.length != 3) { message += error.getErrorMessage("General", "ST Size"); @@ -581,6 +585,23 @@ public void dsco856(ArrayList transactionData, String elementSeparator) 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": try { if (element.length != 6) { @@ -803,6 +824,13 @@ public void dsco856(ArrayList transactionData, String elementSeparator) message = ""; // get out of the loop so we can move on to the next segment in the EDI break; + case "PRF": + if(element.length != 2) { + error.getErrorMessage(getTransactionType(), "PRF Size"); + } + if(element[1].isEmpty()) { + error.getErrorMessage(getTransactionType(), "PRF01 Empty"); + } case "SN1": try { if (!element[1].isEmpty()) { @@ -889,6 +917,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) } } + printer.printToForm(errorInformation); } } diff --git a/EDI_Filter.java b/EDI_Filter.java index 5edb28f..10f9a46 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -158,7 +158,7 @@ public void fileSelector() { // if a 1 is sent for the result then write the message to the TextArea } else if (result == JFileChooser.CANCEL_OPTION) { - printer.printMessageToForm("The Cancel Option was selcted"); + printer.printMessageToForm("The Cancel Option was selected"); } } @@ -183,6 +183,7 @@ public void formatter(String toFilter) { } else { elementSeparator = String.valueOf(separate); } + // Splits the toFilter data and assigns it to the segments String array setSegments(toFilter.split(segmentTerminator)); diff --git a/Error.java b/Error.java index 3e482d7..6a68ead 100644 --- a/Error.java +++ b/Error.java @@ -31,6 +31,12 @@ private String ShipErrors(String errorParams) { 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": @@ -87,6 +93,11 @@ private String ShipErrors(String errorParams) { 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 ""; } From 7cc0f499b95f748c131d91f91bfc042e585b3527 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 27 Jun 2018 14:26:07 -0600 Subject: [PATCH 13/24] Changes Added format changes as well as new functionality to check if required fields exist in the document. --- Dsco.java | 30 +++++++++++++++++++++++++++++- EDI.java | 42 ++++++++++++++++++++++++++++++++++++++++++ Error.java | 18 ++++++++++++++++++ Printer.java | 2 +- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Dsco.java b/Dsco.java index 69d4c08..a56f819 100644 --- a/Dsco.java +++ b/Dsco.java @@ -2,6 +2,9 @@ import java.io.File; 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(); @@ -104,6 +107,9 @@ private void dsco846(ArrayList transactionData, String elementSeparator) String message = ""; String dateFormat = "yyyyMMdd"; String timeFormat = "HHmmss"; + createFieldsDsco846(); + + HashMap fields = getRequiredFields(); String transactionSetControlHeader = ""; @@ -127,6 +133,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // 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"); @@ -161,6 +168,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // 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"); @@ -243,6 +251,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // 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"); @@ -407,6 +416,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // Error check for the QTY segment case "QTY": try { + fields.put("QTY", true); if (element.length != 4) { message += error.getErrorMessage("846", "QTY Size"); } @@ -491,6 +501,7 @@ private void dsco846(ArrayList transactionData, String elementSeparator) case "SE": try { + fields.put("SE", true); int result; String count = ""; count += element[1]; @@ -528,14 +539,18 @@ private void dsco846(ArrayList transactionData, String elementSeparator) } printer.printToForm(errorInformation); + printer.printMessageToForm(error.evaluateReqFields(fields)); } - public void dsco856(ArrayList transactionData, String elementSeparator) { + 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 = ""; @@ -560,6 +575,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) // } switch (element[0]) { case "ST": + fields.put("ST", true); if (element.length != 3) { message += error.getErrorMessage("General", "ST Size"); break; @@ -603,6 +619,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) // 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"); @@ -637,6 +654,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) break; case "HL": try { + fields.put("HL", true); if (element.length != 4) { error.getErrorMessage(getTransactionType(), "HL Size"); } @@ -657,6 +675,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) break; case "TD5": try { + fields.put("TD5", true); if (element.length != 9) { error.getErrorMessage(getTransactionType(), "TD5 Size"); } @@ -688,6 +707,8 @@ public void dsco856(ArrayList transactionData, String elementSeparator) break; case "REF": try { + fields.put("REF", true); + if (element.length < 3 || element.length > 4) { error.getErrorMessage(getTransactionType(), "REF Size"); } @@ -714,6 +735,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) break; case "DTM": try { + fields.put("DTM", true); if (element.length != 4) { message += error.getErrorMessage(getTransactionType(), "DTM Size"); } @@ -742,6 +764,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) break; case "LIN": try { + fields.put("LIN", true); if (element[2].isEmpty() || element[3].isEmpty()) { error.getErrorMessage(getTransactionType(), "LIN Empty"); } @@ -825,6 +848,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) // 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"); } @@ -832,6 +856,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) error.getErrorMessage(getTransactionType(), "PRF01 Empty"); } case "SN1": + fields.put("SN1", true); try { if (!element[1].isEmpty()) { error.getErrorMessage(getTransactionType(), "SN101 Value"); @@ -885,6 +910,7 @@ public void dsco856(ArrayList transactionData, String elementSeparator) break; case "SE": try { + fields.put("SE", true); int result; String count = ""; count += element[1]; @@ -918,6 +944,8 @@ public void dsco856(ArrayList transactionData, String elementSeparator) } } printer.printToForm(errorInformation); + printer.printMessageToForm(error.evaluateReqFields(fields)); } + } diff --git a/EDI.java b/EDI.java index ff47cd6..8290452 100644 --- a/EDI.java +++ b/EDI.java @@ -2,6 +2,8 @@ import java.io.File; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import javax.swing.JTextArea; @@ -29,6 +31,46 @@ public class EDI { // return form; // } + private HashMap requiredFields = new HashMap(); + + + private HashMap Dsco856 = new HashMap(); + private HashMap Dsco846 = new HashMap(); + + 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; } diff --git a/Error.java b/Error.java index 6a68ead..c632dd8 100644 --- a/Error.java +++ b/Error.java @@ -1,5 +1,9 @@ package ediFilterTutorial; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + public class Error { public String getErrorMessage(String transactionType, String errorParams) { @@ -14,6 +18,20 @@ public String getErrorMessage(String transactionType, String errorParams) { 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) { diff --git a/Printer.java b/Printer.java index a8cebfe..456267a 100644 --- a/Printer.java +++ b/Printer.java @@ -19,7 +19,7 @@ public void logError(String Error) { } public void printMessageToForm(String message) { - form.setText(message); + form.append("\n" + message); } public void printDataToForm(String[] data, String segmentTerminator) { From 9e2f6ed7cd237af7ba7983fe5adc324fec774e59 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sun, 1 Jul 2018 15:22:21 -0600 Subject: [PATCH 14/24] Changes --- Dsco.java | 187 ++++++++++++++++++++++++++++++++++++++++-------- EDI.java | 18 +++++ EDI_Filter.java | 1 + Error.java | 11 +++ 4 files changed, 186 insertions(+), 31 deletions(-) diff --git a/Dsco.java b/Dsco.java index a56f819..1c08d75 100644 --- a/Dsco.java +++ b/Dsco.java @@ -11,6 +11,7 @@ public class Dsco extends EDI { Printer printer; FileIO fileIO; // EDI_Filter filter = new EDI_Filter(); + ArrayList errorInformation = new ArrayList(); public Dsco(Printer printer) { this.printer = printer; @@ -37,9 +38,8 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS holder = fileData[i]; // split the holder string into elements using the elementSeparator variable element = holder.split(elementSeparator); - - element[0] = element[0].trim(); + element[0] = element[0].trim(); if (element[0].equals("ST")) { transactionData.add(fileData[i]); @@ -57,13 +57,14 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS // 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")) { + } + 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 - } else if (element[0].equals("SE")) { + } + if (element[0].equals("SE")) { transactionData.add(fileData[i]); // take the variable in the transactionType and do a switch based on that value @@ -75,7 +76,7 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS dsco846(transactionData, elementSeparator); break; case "856": - System.out.println(transactionData); + // System.out.println(transactionData); // formattedEDI.append("\n You got to the 856 Switch statement"); dsco856(transactionData, elementSeparator); break; @@ -90,9 +91,20 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS // dsco810(transactionData); break; } + // break; + + } + if (element[0].equals("IEA")) { + documentHeaderData.add(fileData[i]); + // setEDIData(errorInformation); + + printer.printToForm(errorInformation); + errorInformation.clear(); go = false; break; - } else { + } + 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]); } @@ -107,17 +119,12 @@ private void dsco846(ArrayList transactionData, String elementSeparator) String message = ""; String dateFormat = "yyyyMMdd"; String timeFormat = "HHmmss"; - createFieldsDsco846(); - + createFieldsDsco846(); + 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(); - // Start the loop through the passed transaction data for (int i = 0; i < transactionData.size(); i++) { // assign the array element to holder @@ -538,8 +545,8 @@ private void dsco846(ArrayList transactionData, String elementSeparator) // fileIO.writeCheckedToFile(getEDIData()); } - printer.printToForm(errorInformation); - printer.printMessageToForm(error.evaluateReqFields(fields)); + // printer.printToForm(errorInformation); + errorInformation.add(error.evaluateReqFields(fields)); } private void dsco856(ArrayList transactionData, String elementSeparator) { @@ -549,7 +556,7 @@ private void dsco856(ArrayList transactionData, String elementSeparator) String dateFormat = "yyyyMMdd"; String timeFormat = "HHmm"; createFieldsDsco856(); - + HashMap fields = getRequiredFields(); String transactionSetControlHeader = ""; @@ -557,22 +564,22 @@ private void dsco856(ArrayList transactionData, String elementSeparator) // 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(); + + // 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", ""); -// } + // element[0] = element[0].trim(); + // if(elementSeparator != "/n") { + // element[0] = element[0].replaceAll("/n", ""); + // } switch (element[0]) { case "ST": fields.put("ST", true); @@ -605,10 +612,11 @@ private void dsco856(ArrayList transactionData, String elementSeparator) if (element.length != 3) { error.getErrorMessage(getTransactionType(), "CUR Size"); } - if(!element[1].isEmpty() && !element[2].isEmpty()) { - if(!element[1].equals("BY")) { + if (!element[1].isEmpty() && !element[2].isEmpty()) { + if (!element[1].equals("BY")) { error.getErrorMessage(getTransactionType(), "CUR01 Value"); - }if (!element[2].equals("USD")) { + } + if (!element[2].equals("USD")) { error.getErrorMessage(getTransactionType(), "CUR02 Value"); } } @@ -708,7 +716,7 @@ private void dsco856(ArrayList transactionData, String elementSeparator) case "REF": try { fields.put("REF", true); - + if (element.length < 3 || element.length > 4) { error.getErrorMessage(getTransactionType(), "REF Size"); } @@ -849,10 +857,10 @@ private void dsco856(ArrayList transactionData, String elementSeparator) break; case "PRF": fields.put("PRF", true); - if(element.length != 2) { + if (element.length != 2) { error.getErrorMessage(getTransactionType(), "PRF Size"); } - if(element[1].isEmpty()) { + if (element[1].isEmpty()) { error.getErrorMessage(getTransactionType(), "PRF01 Empty"); } case "SN1": @@ -943,9 +951,126 @@ private void dsco856(ArrayList transactionData, String elementSeparator) } } - printer.printToForm(errorInformation); - printer.printMessageToForm(error.evaluateReqFields(fields)); + // 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"; + 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 "BIG": + 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"); + } + // 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) { + 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"); + } + // 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": + 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")) { + error.getErrorMessage(getTransactionType(), "REF01 Value"); + } + if (!element[2].isEmpty()) { + if (element[1].equals("ZZ")) { + if (!element[2].equals("ship_carrier") && !element[2].equals("ship_method") + && !element[2].equals("A") && !element[2].equals("J") && !element[2].equals("R") + && !element[2].equals("S")) { + message += error.getErrorMessage(getTransactionType(), "REF02 ZZValue"); + } + } + } + } + + } + } } diff --git a/EDI.java b/EDI.java index 8290452..d1bc880 100644 --- a/EDI.java +++ b/EDI.java @@ -36,6 +36,24 @@ public class EDI { private HashMap Dsco856 = new HashMap(); private HashMap Dsco846 = new HashMap(); + private HashMap Dsco810 = new HashMap(); + +// public void clearEDIData() { +// EDI_Data.clear(); +// ediFile = null; +// } + + 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); diff --git a/EDI_Filter.java b/EDI_Filter.java index 10f9a46..33dc85d 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -142,6 +142,7 @@ public void actionPerformed(ActionEvent ae) { case "clearContents": printer.clearForm(); filterGroup.clearSelection(); + //clearEDIData(); break; } } diff --git a/Error.java b/Error.java index c632dd8..d2e84f5 100644 --- a/Error.java +++ b/Error.java @@ -12,6 +12,8 @@ public String getErrorMessage(String transactionType, String errorParams) { return InvErrors(errorParams); case "856": return ShipErrors(errorParams); + case "810": + return InvoiceErrors(errorParams); case "General": return GenErrors(errorParams); default: @@ -19,6 +21,15 @@ public String getErrorMessage(String transactionType, String errorParams) { } } + private String InvoiceErrors(String errorParams) { + switch(errorParams) { + case "BIG Size": + return "-- The length of this segment is incorrect it should be 5 elements long--"; + + } + return null; + } + public String evaluateReqFields(HashMap reqFields) { String Message = ""; Iterator> entries = reqFields.entrySet().iterator(); From 37823e315642ff66251e69f6b2fc6c9b5a3e175a Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 4 Jul 2018 09:04:41 -0600 Subject: [PATCH 15/24] Adding the 810 Logic and error messages --- Dsco.java | 324 +++++++++++++++++++++++++++++++++++++++++++----- Dsco3.java | 5 + EDI.java | 9 ++ EDI_Filter.java | 20 ++- Error.java | 104 +++++++++++++++- 5 files changed, 421 insertions(+), 41 deletions(-) create mode 100644 Dsco3.java diff --git a/Dsco.java b/Dsco.java index 1c08d75..67fbf9a 100644 --- a/Dsco.java +++ b/Dsco.java @@ -12,6 +12,7 @@ public class Dsco extends EDI { FileIO fileIO; // EDI_Filter filter = new EDI_Filter(); ArrayList errorInformation = new ArrayList(); + private String decimalPattern = "\\d*\\.?\\d+"; public Dsco(Printer printer) { this.printer = printer; @@ -86,9 +87,9 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS // dsco870(transactionData); break; case "810": - System.out.println(transactionData); + // System.out.println(transactionData); // formattedEDI.append("\n You got to the 810 Switch statement"); - // dsco810(transactionData); + dsco810(transactionData, elementSeparator); break; } // break; @@ -900,7 +901,7 @@ private void dsco856(ArrayList transactionData, String elementSeparator) if (!element[2].equals("G821")) { message += error.getErrorMessage(getTransactionType(), "SAC02 Value"); } - if (!element[5].matches("\\d*\\.?\\d+")) { + if (!element[5].matches(decimalPattern)) { message += error.getErrorMessage(getTransactionType(), "SAC05 Decimal"); } if (!element[3].isEmpty() || !element[4].isEmpty()) { @@ -1015,18 +1016,22 @@ private void dsco810(ArrayList transactionData, String elementSeparator) // get out of the loop so we can move on to the next segment in the EDI break; case "BIG": - 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"); + 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); @@ -1036,14 +1041,18 @@ private void dsco810(ArrayList transactionData, String elementSeparator) break; case "CUR": - 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"); + 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); @@ -1052,22 +1061,269 @@ private void dsco810(ArrayList transactionData, String elementSeparator) // get out of the loop so we can move on to the next segment in the EDI break; case "REF": - if (element.length != 3 && element.length != 4) { - error.getErrorMessage(getTransactionType(), "REF Size"); + 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")) { + error.getErrorMessage(getTransactionType(), "REF01 Value"); + } + if (!element[2].isEmpty()) { + if (element[1].equals("ZZ")) { + if (!element[2].equals("A") && !element[2].equals("J") && !element[2].equals("R") + && !element[2].equals("S") && !element[2].matches(decimalPattern)) { + if (!element[3].equals("ship_carrier") && !element[3].equals("ship_method")) { + + message += error.getErrorMessage(getTransactionType(), "REF02 ZZValue"); + } + } + } + } + if (!element[3].isEmpty()) { + if (element[1].equals("ZZ")) { + 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_equals") + && !element[3].equals("invoice_subtotal_excluding_line_items") + && !element[3].equals("invoice_line_items_subtotal")) { + + message += error.getErrorMessage(getTransactionType(), "REF03 ZZValues"); + + } + } + + } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); } - if (!element[1].equals("ZZ") && !element[1].equals("IA") && !element[1].equals("IV") - && !element[1].equals("CO") && !element[1].equals("CN")) { - error.getErrorMessage(getTransactionType(), "REF01 Value"); + + 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"); } - if (!element[2].isEmpty()) { - if (element[1].equals("ZZ")) { - if (!element[2].equals("ship_carrier") && !element[2].equals("ship_method") - && !element[2].equals("A") && !element[2].equals("J") && !element[2].equals("R") - && !element[2].equals("S")) { - message += error.getErrorMessage(getTransactionType(), "REF02 ZZValue"); + + 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[4].isEmpty() || element[5].isEmpty() || element[6].isEmpty() || element[7].isEmpty() + || element[13].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ITD Req Empty"); + } + if (!element[8].matches(decimalPattern)) { + message += error.getErrorMessage(getTransactionType(), "ITD08 Value"); + } + if (!element[9].isEmpty() || !element[10].isEmpty() || !element[11].isEmpty() + || element[12].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "ITD09-12 Populated"); + } + + } 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(dateFormat, element[2])) { + message += error.getErrorMessage(getTransactionType(), "DTM02 Format"); } + if (!EDI_Filter.dateChecker(timeFormat, element[3])) { + 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); + 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; } } 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 index d1bc880..5383c8f 100644 --- a/EDI.java +++ b/EDI.java @@ -21,6 +21,7 @@ public class EDI { private boolean dscoRadioStatus; private boolean nordRadioStatus; private boolean kohlRadioStatus; + private boolean dsco3RadioStatus; // private JTextArea form; // @@ -98,6 +99,14 @@ 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; diff --git a/EDI_Filter.java b/EDI_Filter.java index 33dc85d..a3fa1c9 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -19,7 +19,7 @@ public class EDI_Filter extends EDI 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); @@ -52,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(); @@ -110,9 +111,10 @@ public void actionPerformed(ActionEvent ae) { 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 (getDscoRadioStatus() || getNordRadioStatus() || getKohlRadioStatus()) { + 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 @@ -199,7 +201,9 @@ public void formatter(String toFilter) { } else if (getKohlRadioStatus()) { // starts the error checking process for Dsco EDI spec (Not Done) kohlErrorCheck(getSegments(), selectedFile, elementSeparator); - } else { + } else if(getDsco3RadioStatus()){ + dsco3ErrorCheck(); + }else { printer.printDataToForm(getSegments(),segmentTerminator); } @@ -232,7 +236,10 @@ public void formatter(String toFilter) { nordErrorCheck(getSegments(), selectedFile, elementSeparator); } else if (getKohlRadioStatus()) { kohlErrorCheck(getSegments(), selectedFile, elementSeparator); - } else { + } else if(getDsco3RadioStatus()){ + dsco3ErrorCheck(); + + }else { // if there is no error checking involved write the file to the Downloads folder on the machine fileIO.writeToFile(getSegments()); } @@ -251,6 +258,9 @@ 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: diff --git a/Error.java b/Error.java index d2e84f5..93e72f6 100644 --- a/Error.java +++ b/Error.java @@ -24,9 +24,109 @@ public String getErrorMessage(String transactionType, String errorParams) { private String InvoiceErrors(String errorParams) { switch(errorParams) { case "BIG Size": - return "-- The length of this segment is incorrect it should be 5 elements long--"; + 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 --"; + 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' --"; + 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 "REF02 ZZValue": + return "-- The value in the REF02 is incorrect. When the REF01 is ZZ the REF02 should " + + "be one of the following: A, J, R, S, or a decimal value --"; + 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 "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 --"; + case "N3 Size": + return "-- The length of the N3 segment is incorrect it should be 2 elements long --"; + case "N4 Size": + return "-- The length of the N4 segment is incorrect it should be 4 elements long --"; + 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 --"; + 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 --"; + 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"; + 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 --"; - } + + + } return null; } From 21ce3cbbd91cc5639845f155861c41d68f1f3462 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 6 Jul 2018 08:54:22 -0600 Subject: [PATCH 16/24] 810 Data --- Dsco.java | 221 ++++++++++++++++++++++++++++++++++++++++-------- EDI_Filter.java | 1 + Error.java | 73 +++++++++++++++- 3 files changed, 256 insertions(+), 39 deletions(-) diff --git a/Dsco.java b/Dsco.java index 67fbf9a..5376a0d 100644 --- a/Dsco.java +++ b/Dsco.java @@ -962,7 +962,9 @@ private void dsco810(ArrayList transactionData, String elementSeparator) String message = ""; String dateFormat = "yyyyMMdd"; String timeFormat = "HHmm"; - createFieldsDsco856(); + createFieldsDsco810(); + + int lineItemCount = 0; HashMap fields = getRequiredFields(); @@ -1067,33 +1069,59 @@ private void dsco810(ArrayList transactionData, String elementSeparator) } if (!element[1].equals("ZZ") && !element[1].equals("IA") && !element[1].equals("IV") && !element[1].equals("CO") && !element[1].equals("CN")) { - error.getErrorMessage(getTransactionType(), "REF01 Value"); + message += error.getErrorMessage(getTransactionType(), "REF01 Value"); } - if (!element[2].isEmpty()) { - if (element[1].equals("ZZ")) { - if (!element[2].equals("A") && !element[2].equals("J") && !element[2].equals("R") - && !element[2].equals("S") && !element[2].matches(decimalPattern)) { - if (!element[3].equals("ship_carrier") && !element[3].equals("ship_method")) { - - message += error.getErrorMessage(getTransactionType(), "REF02 ZZValue"); - } - } - } + 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_equals") + && !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("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"); @@ -1108,7 +1136,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) if (element.length != 3) { message += error.getErrorMessage(getTransactionType(), "N1 Size"); } - if (!element[1].equals("ST") || !element[1].equals("SF")) { + if (!element[1].equals("ST") && !element[1].equals("SF")) { message += error.getErrorMessage(getTransactionType(), "N101 Value"); } @@ -1162,17 +1190,19 @@ private void dsco810(ArrayList transactionData, String elementSeparator) if (!element[2].equals("3")) { message += error.getErrorMessage(getTransactionType(), "ITD02 Value"); } - 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[8].matches(decimalPattern)) { - message += error.getErrorMessage(getTransactionType(), "ITD08 Value"); - } - if (!element[9].isEmpty() || !element[10].isEmpty() || !element[11].isEmpty() - || element[12].isEmpty()) { - message += error.getErrorMessage(getTransactionType(), "ITD09-12 Populated"); - } + 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"); @@ -1209,6 +1239,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) case "IT1": fields.put("IT1", true); + lineItemCount++; try { if (element.length < 8 || element.length > 20) { @@ -1299,23 +1330,22 @@ private void dsco810(ArrayList transactionData, String elementSeparator) case "TDS": fields.put("TDS", true); try { - - if(element.length != 3) { + + if (element.length != 3) { message += error.getErrorMessage(getTransactionType(), "TDS Size"); } - if(element[1].isEmpty()) { + if (element[1].isEmpty()) { message += error.getErrorMessage(getTransactionType(), "TDS01 Empty"); - }else { - if(element[1].matches(decimalPattern)) { + } else { + if (element[1].matches(decimalPattern)) { message += error.getErrorMessage(getTransactionType(), "TDS01 Value"); } - if(!element[2].isEmpty()) { - if(!element[2].matches(decimalPattern)) { + if (!element[2].isEmpty()) { + if (!element[2].matches(decimalPattern)) { message += error.getErrorMessage(getTransactionType(), "TDS02 Value"); } } } - } catch (ArrayIndexOutOfBoundsException e) { message += error.getErrorMessage("General", "ArrayBoundsError"); @@ -1324,9 +1354,130 @@ private void dsco810(ArrayList transactionData, String elementSeparator) 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)); } } diff --git a/EDI_Filter.java b/EDI_Filter.java index a3fa1c9..b32d82e 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -92,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); diff --git a/Error.java b/Error.java index 93e72f6..7d1b735 100644 --- a/Error.java +++ b/Error.java @@ -23,6 +23,7 @@ public String getErrorMessage(String transactionType, String errorParams) { 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": @@ -31,32 +32,49 @@ private String InvoiceErrors(String errorParams) { 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 "REF02 ZZValue": - return "-- The value in the REF02 is incorrect. When the REF01 is ZZ the REF02 should " - + "be one of the following: A, J, R, S, or a decimal value --"; + 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": @@ -69,12 +87,16 @@ private String InvoiceErrors(String errorParams) { 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": @@ -117,17 +139,60 @@ private String InvoiceErrors(String errorParams) { 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 ""; } - return null; } public String evaluateReqFields(HashMap reqFields) { From dced779ddb01ea27ac4f9e70528a03d1444b6777 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 6 Jul 2018 19:22:47 -0600 Subject: [PATCH 17/24] Adjusting 810 logic --- Dsco.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dsco.java b/Dsco.java index 5376a0d..4f7def7 100644 --- a/Dsco.java +++ b/Dsco.java @@ -1220,10 +1220,10 @@ private void dsco810(ArrayList transactionData, String elementSeparator) if (!element[1].equals("011")) { message += error.getErrorMessage(getTransactionType(), "DTM01 Value"); } - if (!EDI_Filter.dateChecker(dateFormat, element[2])) { + if (!EDI_Filter.dateChecker(element[2], dateFormat)) { message += error.getErrorMessage(getTransactionType(), "DTM02 Format"); } - if (!EDI_Filter.dateChecker(timeFormat, element[3])) { + if (!EDI_Filter.dateChecker(element[3], dateFormat)) { message += error.getErrorMessage(getTransactionType(), "DTM03 Format"); } @@ -1295,7 +1295,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) } } if (!element[14].isEmpty()) { - if (element[14].equals("ZZ")) { + if (!element[14].equals("ZZ")) { message += error.getErrorMessage(getTransactionType(), "IT114 Value"); } if (element[15].isEmpty()) { @@ -1303,7 +1303,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) } } if (!element[16].isEmpty()) { - if (element[16].equals("ZZ")) { + if (!element[16].equals("ZZ")) { message += error.getErrorMessage(getTransactionType(), "IT116 Value"); } if (element[17].isEmpty()) { @@ -1311,7 +1311,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) } } if (!element[18].isEmpty()) { - if (element[18].equals("ZZ")) { + if (!element[18].equals("ZZ")) { message += error.getErrorMessage(getTransactionType(), "IT118 Value"); } if (element[19].isEmpty()) { @@ -1331,13 +1331,13 @@ private void dsco810(ArrayList transactionData, String elementSeparator) fields.put("TDS", true); try { - if (element.length != 3) { + 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)) { + if (!element[1].matches(decimalPattern)) { message += error.getErrorMessage(getTransactionType(), "TDS01 Value"); } if (!element[2].isEmpty()) { From 2a77c63ea47b1ff90b86cfc1323f2ccdbce7a4a3 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 10 Jul 2018 12:01:16 -0600 Subject: [PATCH 18/24] Adding 870 Logic --- Dsco.java | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++--- EDI.java | 14 +++++ Error.java | 135 ++++++++++++++++++++++++++++++---------------- 3 files changed, 252 insertions(+), 53 deletions(-) diff --git a/Dsco.java b/Dsco.java index 4f7def7..9c7f7e2 100644 --- a/Dsco.java +++ b/Dsco.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.Map; + public class Dsco extends EDI { Error error = new Error(); Printer printer; @@ -82,9 +83,9 @@ public void dscoErrorCheck(String[] fileData, File selectedFile, String elementS dsco856(transactionData, elementSeparator); break; case "870": - System.out.println(transactionData); + // System.out.println(transactionData); // formattedEDI.append("\n You got to the 870 Switch statement"); - // dsco870(transactionData); + dsco870(transactionData, elementSeparator); break; case "810": // System.out.println(transactionData); @@ -1071,8 +1072,8 @@ private void dsco810(ArrayList transactionData, String elementSeparator) && !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[2].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "REF02 Empty"); } if (!element[3].isEmpty()) { if (element[1].equals("ZZ")) { @@ -1190,7 +1191,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) if (!element[2].equals("3")) { message += error.getErrorMessage(getTransactionType(), "ITD02 Value"); } - if(element[1].equals("02") || element[1].equals("12")) { + 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"); @@ -1202,7 +1203,7 @@ private void dsco810(ArrayList transactionData, String elementSeparator) if (!element[8].matches(decimalPattern)) { message += error.getErrorMessage(getTransactionType(), "ITD08 Value"); } - } + } } catch (ArrayIndexOutOfBoundsException e) { message += error.getErrorMessage("General", "ArrayBoundsError"); @@ -1480,4 +1481,147 @@ private void dsco810(ArrayList transactionData, String elementSeparator) errorInformation.add(error.evaluateReqFields(fields)); } + private void dsco870(ArrayList transactionData, String elementSeparator) { + + String holder = ""; + String[] element; + String message = ""; + String dateFormat = "yyyyMMdd"; + String timeFormat = "HHmm"; + + 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(element[2].StringUtils.IsNumeric()) { + + } + } 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"); + } + } + } + + } + } diff --git a/EDI.java b/EDI.java index 5383c8f..880e56d 100644 --- a/EDI.java +++ b/EDI.java @@ -38,12 +38,26 @@ public class EDI { 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); diff --git a/Error.java b/Error.java index 7d1b735..738958d 100644 --- a/Error.java +++ b/Error.java @@ -14,16 +14,18 @@ public String getErrorMessage(String transactionType, String errorParams) { return ShipErrors(errorParams); case "810": return InvoiceErrors(errorParams); + case "870": + return CancelErrors(errorParams); case "General": return GenErrors(errorParams); - default: - return ""; + default: + return ""; } } - + private String InvoiceErrors(String errorParams) { - switch(errorParams) { - // Messages for BIG + 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": @@ -32,16 +34,16 @@ private String InvoiceErrors(String errorParams) { 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 + + // 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 + + // 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": @@ -58,23 +60,22 @@ private String InvoiceErrors(String errorParams) { 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 + + // Messages for N1 case "N101 Value": - return" -- The value of the N101 element is incorrect, it should be 'ST' or 'SF' --"; + 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 + + // 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 + + // Messages for ITD case "ITD Size": return "-- The length of the ITD segment is incorrect it should be 13 elements long --"; case "ITD01 Value": @@ -87,16 +88,16 @@ private String InvoiceErrors(String errorParams) { 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 + + // 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 + + // 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": @@ -106,7 +107,7 @@ private String InvoiceErrors(String errorParams) { 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' --"; + 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": @@ -139,8 +140,8 @@ private String InvoiceErrors(String errorParams) { 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 + + // Messages for TDS case "TDS01 Empty": return "-- TDS01 is a required field and cannot be empty --"; case "TDS Size": @@ -149,15 +150,14 @@ private String InvoiceErrors(String errorParams) { 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 + + // 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 + 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": @@ -168,9 +168,8 @@ private String InvoiceErrors(String errorParams) { 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 + + // Messages for ISS case "ISS Size": return "-- The length of the ISS segment is incorrect it should be 4 elements long --"; case "ISS01 Empty": @@ -181,32 +180,30 @@ private String InvoiceErrors(String errorParams) { 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 + + // 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()) { + while (entries.hasNext()) { Map.Entry entry = entries.next(); - if(entry.getValue() == false) { + if (entry.getValue() == false) { Message += "Required Segment " + entry.getKey() + " was not provided."; } } return Message; - - + } private String ShipErrors(String errorParams) { @@ -290,13 +287,13 @@ private String ShipErrors(String errorParams) { 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 --"; - + return "-- The PRF01 segment is empty, the PRF01 segment is a required segment and cannot be missing --"; + default: return ""; } } - + private String GenErrors(String errorParams) { switch (errorParams) { @@ -466,5 +463,49 @@ 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 element is incorrect it should be 4 elements long --"; + case "BSR01 Value": + return "-- The value in the BSR01 element is incorrect it shoudl be '2' --"; + case "BSR02 Value": + return "-- The value in the BSR02 element is incorrect is should be 'PP' --"; + case "BSR03 Empty": + return "-- The BSR03 Value is a required field and cannot be empty --"; + case "BSR04 Format": + return "-- The BSR04 Value 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 segment is empty--"; + case "HL02 Empty": + return "-- The HL02 segment 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 --"; + default: + return ""; + } } } \ No newline at end of file From 3b378f55d6b44bd5a10be173543e024696e2d010 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 20 Jul 2018 10:54:13 -0600 Subject: [PATCH 19/24] 870 Logic --- Dsco.java | 16 ++++++++++++++-- Error.java | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Dsco.java b/Dsco.java index 9c7f7e2..93f2f15 100644 --- a/Dsco.java +++ b/Dsco.java @@ -1,6 +1,8 @@ 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; @@ -1577,8 +1579,8 @@ private void dsco870(ArrayList transactionData, String elementSeparator) if (!element[3].equals("O") && !element[3].equals("I")) { message += error.getErrorMessage(getTransactionType(), "HL03 Value"); } - if(element[2].StringUtils.IsNumeric()) { - + if(!isNumber(element[2])) { + message += error.getErrorMessage(getTransactionType(), "HL02 Value"); } } catch (ArrayIndexOutOfBoundsException e) { message += error.getErrorMessage("General", "ArrayBoundsError"); @@ -1623,5 +1625,15 @@ private void dsco870(ArrayList transactionData, String elementSeparator) } } + 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/Error.java b/Error.java index 738958d..4270f4b 100644 --- a/Error.java +++ b/Error.java @@ -506,6 +506,8 @@ private String CancelErrors(String errorParams) { return "-- The REF02 segment is empty --"; default: return ""; + + // } } } \ No newline at end of file From 09ad8ae8e6a3f6a99f34ae703f3d0ef69c28aed5 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 27 Jul 2018 16:01:18 -0600 Subject: [PATCH 20/24] Troubleshooting --- EDI_Filter.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/EDI_Filter.java b/EDI_Filter.java index b32d82e..913ef53 100644 --- a/EDI_Filter.java +++ b/EDI_Filter.java @@ -180,10 +180,16 @@ public void formatter(String toFilter) { 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 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 == '*') { - elementSeparator = "\\*"; + if (separate == '*' || separate =='|' || separate =='.' || separate =='^' || separate == '$' || separate =='?' || separate =='+') { + elementSeparator = "\\" + String.valueOf(separate); } else { elementSeparator = String.valueOf(separate); } From 1fa84f80b6b3e27a22681154b5a2002867a5fd16 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 14 Aug 2018 15:55:24 -0600 Subject: [PATCH 21/24] Updates to Error Messages --- Error.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Error.java b/Error.java index 4270f4b..ae8c10f 100644 --- a/Error.java +++ b/Error.java @@ -365,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": @@ -426,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": @@ -471,9 +471,9 @@ private String CancelErrors(String errorParams) { //Params for BSR segment Errors case "BSR Size": - return "-- The length of the BSR element is incorrect it should be 4 elements long --"; + 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 shoudl be '2' --"; + 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": From 811d8ff7fe46363af76752edf27b10558640798b Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 31 Aug 2018 15:57:10 -0600 Subject: [PATCH 22/24] Finishing up Dsco 2.0 870 Added more fields to the 870 validation as well as the correct Error messages that should correspond --- Dsco.java | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Error.java | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/Dsco.java b/Dsco.java index 93f2f15..8eb3403 100644 --- a/Dsco.java +++ b/Dsco.java @@ -1618,6 +1618,62 @@ private void dsco870(ArrayList transactionData, String elementSeparator) message += error.getErrorMessage(getTransactionType(), "REF02 Empty"); } + } catch (ArrayIndexOutOfBoundsException e) { + message += error.getErrorMessage("General", "ArrayBoundsError"); + } + case "PO1": + 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].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"); + } + } + } catch (ArrayIndexOutOfBoundsException e) { message += error.getErrorMessage("General", "ArrayBoundsError"); } @@ -1625,6 +1681,12 @@ private void dsco870(ArrayList transactionData, String elementSeparator) } } + + 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); diff --git a/Error.java b/Error.java index ae8c10f..9f1e65a 100644 --- a/Error.java +++ b/Error.java @@ -504,6 +504,45 @@ private String CancelErrors(String errorParams) { 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 Nubmer": + return "-- The value in the PO113 element is incorrect it needs to be 'ZZ' --"; + default: return ""; From a77f52f980f77b7a8ad76d1f91f5596282501de1 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 5 Sep 2018 08:00:00 -0600 Subject: [PATCH 23/24] Finishing 870 Requirements --- Dsco.java | 6 +++++- Error.java | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Dsco.java b/Dsco.java index 8eb3403..f0f31ef 100644 --- a/Dsco.java +++ b/Dsco.java @@ -1648,7 +1648,7 @@ private void dsco870(ArrayList transactionData, String elementSeparator) if(element[7].length() > 70) { message += error.getErrorMessage(getTransactionType(), "PO107 Length"); } - if(!element[8].equals("UP")) { + if(!element[8].isEmpty() && !element[8].equals("UP")) { message += error.getErrorMessage(getTransactionType(), "PO108 Value"); } if(!element[8].isEmpty() && element[9].isEmpty()) { @@ -1671,6 +1671,10 @@ private void dsco870(ArrayList transactionData, String elementSeparator) 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[12].isEmpty() && !element[14].isEmpty()) { + message += error.getErrorMessage(getTransactionType(), "PO114 Value"); } } diff --git a/Error.java b/Error.java index 9f1e65a..9d87fde 100644 --- a/Error.java +++ b/Error.java @@ -540,8 +540,10 @@ private String CancelErrors(String errorParams) { 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 Nubmer": - return "-- The value in the PO113 element is incorrect it needs to be 'ZZ' --"; + 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' --"; default: return ""; From e8111714c13255e1a154688c9e8485f3580acac6 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 6 Sep 2018 16:03:31 -0600 Subject: [PATCH 24/24] Finished 870 Added more validation checks as well as started to combine duplicate code into methods. --- Dsco.java | 150 ++++++++++++++++++++++++++++++++++++++++++----------- Error.java | 20 +++++-- 2 files changed, 136 insertions(+), 34 deletions(-) diff --git a/Dsco.java b/Dsco.java index f0f31ef..a5f1493 100644 --- a/Dsco.java +++ b/Dsco.java @@ -8,7 +8,6 @@ import java.util.Iterator; import java.util.Map; - public class Dsco extends EDI { Error error = new Error(); Printer printer; @@ -1490,6 +1489,7 @@ private void dsco870(ArrayList transactionData, String elementSeparator) String message = ""; String dateFormat = "yyyyMMdd"; String timeFormat = "HHmm"; + int size = transactionData.size(); HashMap fields = getRequiredFields(); @@ -1565,7 +1565,7 @@ private void dsco870(ArrayList transactionData, String elementSeparator) case "HL": fields.put("HL", true); - + try { if (element.length != 4) { message += error.getErrorMessage(getTransactionType(), "HL Size"); @@ -1579,7 +1579,7 @@ private void dsco870(ArrayList transactionData, String elementSeparator) if (!element[3].equals("O") && !element[3].equals("I")) { message += error.getErrorMessage(getTransactionType(), "HL03 Value"); } - if(!isNumber(element[2])) { + if (!isNumber(element[2])) { message += error.getErrorMessage(getTransactionType(), "HL02 Value"); } } catch (ArrayIndexOutOfBoundsException e) { @@ -1607,33 +1607,37 @@ private void dsco870(ArrayList transactionData, String elementSeparator) 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")) { + if (!element[1].equals("IA") && !element[1].equals("CO") && !element[1].equals("VN")) { message += error.getErrorMessage(getTransactionType(), "REF01 Value"); } - if(element[2].isEmpty()) { + 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()) { + 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) { + } else { + if (convertToNumber(element[1]) < 1) { message += error.getErrorMessage(getTransactionType(), "PO101 Value"); } - if(convertToNumber(element[2]) < 1) { + if (convertToNumber(element[2]) < 1) { message += error.getErrorMessage(getTransactionType(), "PO102 Value"); } - if(!element[3].equals("EA")) { + if (!element[3].equals("EA")) { message += error.getErrorMessage(getTransactionType(), "PO103 Value"); } if (!element[4].matches(decimalPattern)) { @@ -1642,62 +1646,148 @@ private void dsco870(ArrayList transactionData, String elementSeparator) if (!element[5].isEmpty()) { message += error.getErrorMessage(getTransactionType(), "PO105 Not Empty"); } - if(!element[6].equals("SK")) { + if (!element[6].equals("SK")) { message += error.getErrorMessage(getTransactionType(), "PO106 Value"); } - if(element[7].length() > 70) { + if (element[7].length() > 70) { message += error.getErrorMessage(getTransactionType(), "PO107 Length"); } - if(!element[8].isEmpty() && !element[8].equals("UP")) { + if (!element[8].isEmpty() && !element[8].equals("UP")) { message += error.getErrorMessage(getTransactionType(), "PO108 Value"); } - if(!element[8].isEmpty() && element[9].isEmpty()) { + if (!element[8].isEmpty() && element[9].isEmpty()) { message += error.getErrorMessage(getTransactionType(), "PO109 Empty"); } - if(element[9].length() != 6 && element[9].length() != 12) { + if (element[9].length() != 6 && element[9].length() != 12) { message += error.getErrorMessage(getTransactionType(), "PO109 Length"); - }if(!isNumber(element[9])) { + } + if (!isNumber(element[9])) { message += error.getErrorMessage(getTransactionType(), "PO109 Number"); } - if(!element[10].equals("EN")) { + if (!element[10].equals("EN")) { message += error.getErrorMessage(getTransactionType(), "PO110 Value"); } - if(!element[10].isEmpty() && element[11].isEmpty()) { + if (!element[10].isEmpty() && element[11].isEmpty()) { message += error.getErrorMessage(getTransactionType(), "PO111 Empty"); } - if(element[11].length() != 13) { + if (element[11].length() != 13) { message += error.getErrorMessage(getTransactionType(), "PO111 Length"); - }if(!isNumber(element[11])) { + } + if (!isNumber(element[11])) { message += error.getErrorMessage(getTransactionType(), "PO111 Number"); - }if(!element[12].equals("MG")) { + } + if (!element[12].equals("MG")) { message += error.getErrorMessage(getTransactionType(), "PO112 Value"); - }if(!element[12].isEmpty() && !element[13].isEmpty()) { + } + if (!element[12].isEmpty() && element[13].isEmpty()) { message += error.getErrorMessage(getTransactionType(), "PO113 Value"); - }if(!element[12].isEmpty() && !element[14].isEmpty()) { + } + 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()) { + if (value.length() == pos.getIndex()) { return true; - }else { + } else { return false; } } diff --git a/Error.java b/Error.java index 9d87fde..339b263 100644 --- a/Error.java +++ b/Error.java @@ -477,16 +477,16 @@ private String CancelErrors(String errorParams) { case "BSR02 Value": return "-- The value in the BSR02 element is incorrect is should be 'PP' --"; case "BSR03 Empty": - return "-- The BSR03 Value is a required field and cannot be empty --"; + return "-- The BSR03 element is a required field and cannot be empty --"; case "BSR04 Format": - return "-- The BSR04 Value is in the incorrect format it needs to be in the CCYYMMDD 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 segment is empty--"; + return "-- The HL01 element is empty--"; case "HL02 Empty": - return "-- The HL02 segment is 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' --"; @@ -544,6 +544,18 @@ private String CancelErrors(String errorParams) { 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 "";