Skip to content

Commit

Permalink
patch updates for issue #142
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughnte committed Sep 26, 2024
1 parent a239bda commit 7a6201b
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 64 deletions.
50 changes: 39 additions & 11 deletions src/com/blueseer/edi/EDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,28 @@ public static String[] processFile(String infile, String map, String outfile, St
GlobalDebug = true;
}

if (GlobalDebug)
if (GlobalDebug) {
System.out.println("processFile: entering function with file :" + infile);
}

// always need a site
if (site.isBlank()) {
site = OVData.getDefaultSite();
if (GlobalDebug) {
System.out.println("Site parameter blank...using default :" + site);
}
}

// lets check to see if outfile contains a directory path...as if called from EDIbs with -of qualf
Path outdirpath = null;
Path path = Paths.get(outfile);
if (path.getParent() != null) {
outdirpath = path.getParent();
outfile = path.getFileName().toString();
}




String[] m = new String[]{"0",""};
String[] c = null; // control values to pass to map and log
Expand Down Expand Up @@ -1009,6 +1029,11 @@ public static String[] processFile(String infile, String map, String outfile, St
c[13] = "";
c[16] = "0"; // initial idxnbr
c[22] = String.valueOf(comkey);

if (outdirpath != null && Files.exists(outdirpath)) {
c[27] = cleanDirString(outdirpath.toString()); // set outdir if called from EDIbs with -of
}

c[26] = file.getParent(); // indir
c[28] = editype[0];
c[30] = String.valueOf(isDebug);
Expand Down Expand Up @@ -1301,7 +1326,6 @@ public static Map<Integer, Object[]> createMAPUNE(char[] cbuf, String[] c, Strin
c[11] = String.valueOf((int) u);
c[12] = isOverride;
c[13] = String.join("+", unb);
c[15] = "0"; // inbound

}
// UNG may not be there...needs revisiting
Expand Down Expand Up @@ -1420,16 +1444,15 @@ public static Map<Integer, Object[]> createIMAP(char[] cbuf, String[] c, String

c[0] = isa[6].trim(); // senderid
c[21] = isa[8].trim(); // receiverid
c[2] = map;
c[3] = infile;
// c[2] = map;
// c[3] = infile;
c[4] = isa[13]; //isactrlnbr
c[8] = outfile;
// c[8] = outfile;
c[9] = String.valueOf((int) s);
c[10] = String.valueOf((int) e);
c[11] = String.valueOf((int) u);
c[12] = isOverride;
// c[12] = isOverride;
c[13] = new String(cbuf,i,105);
c[15] = "0"; // inbound

}
if (i > 1 && cbuf[i-1] == s && cbuf[i] == 'G' && cbuf[i+1] == 'S') {
Expand Down Expand Up @@ -2845,6 +2868,8 @@ public static void processX12(Map<Integer, Object[]> ISAmap, char[] cbuf, String

String[] c = (String[]) isa.getValue()[6];



// ArrayList d = (ArrayList) isa.getValue()[5];
Map<Integer, ArrayList> d = (HashMap<Integer, ArrayList>)isa.getValue()[5];

Expand Down Expand Up @@ -2979,12 +3004,15 @@ public static void processX12(Map<Integer, Object[]> ISAmap, char[] cbuf, String
String[] defaults = EDData.getEDITPDefaultsX(c[1], gs02, gs03, c[2]);
c[29] = defaults[15]; // defines outputfiletype

if (GlobalDebug)
if (GlobalDebug) {
System.out.println("Entering Map " + map + " with: " + c[1] + "/" + gs02 + "/" + gs03);

}

messages.add(new String[]{"info","Found Map: " + map + " with " + c[1] + "/" + gs02 + "/" + gs03});
messages.add(new String[]{"info","Using Map: " + map + " for docID: " + c[6]});



// at this point I should have a doc set (ST to SE) and a map ...now call map to operate on doc
URLClassLoader cl = null;
try {
Expand Down Expand Up @@ -3441,7 +3469,7 @@ public static String[] createVoucherFrom810i(edi810i e, String[] control) {
if (m[0].isBlank()) { // if not error
m = VoucherTransaction("receipt", list, ap, false);
}
System.out.println("HERE: " + m[0] + "/" + m[1]);

return m;
}

Expand Down Expand Up @@ -3727,7 +3755,7 @@ public static String[] createCFOFrom204(edi204 e, String[] control) {
if (m[0].isBlank()) { // if not error
m = addCFOTransaction(list, x, null, null);
}
System.out.println("HERE: " + m[0] + "/" + m[1]);

return m;
}

Expand Down
83 changes: 62 additions & 21 deletions src/com/blueseer/edi/EDIMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public void setControl(String[] c) throws UserDefinedException {
stctrl = c[6];
ref = c[7];
outfile = c[8];
outdir = c[27]; // in case edibs uses -of with embedded file/path directory
sd = delimConvertIntToStr(c[9]);
ed = delimConvertIntToStr(c[10]);
ud = delimConvertIntToStr(c[11]);
Expand All @@ -325,15 +326,24 @@ public void setControl(String[] c) throws UserDefinedException {



if (c[0].equals("MapTester")) {
if (c[0].equals("MapTester") || ! c[12].isBlank()) {
// throw new UserDefinedException("Houston...we have a problem");
// c values override lookup below for map tester

ediData.map_mstr x = getMapMstr(new String[]{c[2]});
outsender = c[0];
outreceiver = c[21];
outputdoctype = c[15];
outputfiletype = c[29];
if (! c[15].isBlank()) {
outputdoctype = c[15];
} else {
outputdoctype = x.map_outdoctype();
}
if (! c[29].isBlank()) {
outputfiletype = c[29];
} else {
outputfiletype = x.map_outfiletype();
c[29] = x.map_outfiletype();
}

if (outsender.isBlank()) {
throw new UserDefinedException("Missing outsender in c[0]");
Expand Down Expand Up @@ -405,7 +415,7 @@ public static String delimConvertIntToStr(String intdelim) {

public void setOutPutEnvelopeStrings(String[] c) {
if ( ! isOverride) { // if not override...use internal partner / doc lookup for envelope info

if (c[29].toUpperCase().equals("X12")) {
if (c[0].equals("MapTester")) {
envelope = EDI.generateEnvelope(c[1], c[13], c[21], c[14], c[2]); //override use of c[13] from mapper ddsenderenvelope
Expand All @@ -429,7 +439,9 @@ public void setOutPutEnvelopeStrings(String[] c) {
GE = envelope[2];
IEA = envelope[3];
filename = envelope[4];
outfile = filename;
if (outfile.isBlank()) { // if ran from edibs with -of...outfile will already be set as complete path
outfile = filename;
}
isactrl = envelope[5];
gsctrl = envelope[6];
stctrl = String.format("%04d", 1);
Expand Down Expand Up @@ -462,6 +474,7 @@ public void setOutPutEnvelopeStrings(String[] c) {
}



if (c[29].toUpperCase().equals("X12")) {
ST = "ST" + ed + EDData.getEDIDocTypeFromBSDoc(outputdoctype) + ed + stctrl ;
SE = "SE" + ed + String.valueOf(segcount) + ed + stctrl;
Expand Down Expand Up @@ -491,11 +504,12 @@ public void setOutPutEnvelopeStrings(String[] c) {
xsetISA(9,""); // set date to now
xsetISA(10,""); // set time to now


/*
header = "";
detail = "";
trailer = "";
content = "";
*/
}

}
Expand Down Expand Up @@ -780,14 +794,28 @@ public String[] packagePayLoad(String[] c) {
// get TP/Doc defaults
String[] tp = EDData.getEDITPDefaultsX(doctype, outsender, outreceiver, map );

// override
if (! c[12].isBlank()) {
tp = EDData.getEDITPDefaults(doctype, outsender, outreceiver );
}


if (tp == null || tp.length < 18) {
setError("tp defaults is null or empty for: " + doctype + "/" + outsender + "/" + outreceiver);
return error;
}

if (GlobalDebug) {
System.out.println("Getting tp defaults for: " + doctype + "/" + outsender + "/" + outreceiver);
System.out.println("Value of tp defaults found: " + String.join(",", tp));
int j = 0;
for (String g : c) {
System.out.println("Control c array values (packagePayLoad): " + j + " " + g);
j++;
}
if (! c[12].isBlank()) {
System.out.println("override detected in c[12]...using 3 (indoc,snd,rcv) key TP entry instead of 4 (indoc,snd,rcv,map");
}
System.out.println("Getting tp defaults for: " + doctype + "/" + outsender + "/" + outreceiver + "/" + map);
System.out.println("Value of tp defaults found: " + String.join(",", tp));
}


Expand All @@ -798,10 +826,12 @@ public String[] packagePayLoad(String[] c) {
int filenumber = OVData.getNextNbr("edifile");
String batchfile = "X" + String.format("%07d", filenumber);
String outfilemulti = "";
if (outfile.isEmpty()) {
if (outfile.isBlank()) {
outfile = tp[10] + String.format("%07d", filenumber) + "." + tp[11];
}



if (c[29].toUpperCase().equals("X12") || c[29].toUpperCase().equals("UNE")) {
setOutPutEnvelopeStrings(c);

Expand Down Expand Up @@ -858,12 +888,18 @@ public String[] packagePayLoad(String[] c) {
c[7] = ref;
c[15] = tp[14];
c[25] = batchfile;
if (tp[20].equals("0")) { // if single package
c[8] = outfile;
} else {
c[8] = outfilemulti;
if (c[8].isBlank()) { // may not be blank if ran from edibs with -of qual
if (tp[20].equals("0")) { // if single package
c[8] = outfile;
} else {
c[8] = outfilemulti;
}
}
c[27] = outdir;

if (c[27].isBlank()) { // outdir may not be blank if ran from edibs with -of qual
c[27] = outdir;
}

// c[29] ...(outboundfiletype) should be defined at first available getTPDefaults prior to mapping
c[6] = stctrl;
c[5] = gsctrl;
Expand All @@ -876,9 +912,7 @@ public String[] packagePayLoad(String[] c) {
c[36] = tp[6];
c[37] = tp[8];

if (GlobalDebug)
System.out.println("Value of c within EDIMap class: " + String.join(",", c));


// error handling
if (batchfile.isEmpty()) {
setError("batch file is empty");
Expand All @@ -888,10 +922,12 @@ public String[] packagePayLoad(String[] c) {
setError("out file is empty");
return error;
}
if (tp[15].isEmpty()) {
if (outputfiletype.isEmpty()) {
setError("out file type is unknown");
return error;
}


try {
// Write output batch file
EDI.writeFile(content, cleanDirString(EDData.getEDIBatchDir()), batchfile);
Expand Down Expand Up @@ -936,8 +972,13 @@ public void isDBWrite(String[] c) {
c[36] = "0";
c[37] = "0";

if (GlobalDebug)
System.out.println("Value of c within EDIMap class: " + String.join(",", c));
if (GlobalDebug) {
int j = 0;
for (String g : c) {
System.out.println("Control c array values (isDBWrite): " + j + " " + g);
j++;
}
}

}

Expand Down Expand Up @@ -1179,7 +1220,7 @@ public static segRecord getSegmentInISF(String rawSegmentLM, String rawGroupHead
if (x[5].equals("groupend")) {
continue;
}
// System.out.println("HERE: " + rawSegmentLM + "/" + rawGroupHeadLM + "/" + x[0] + "/" + x[1]);
if (rawSegmentLM.equals(x[0]) && rawGroupHeadLM.equals(x[1])) {
segment = x;
break;
Expand Down
33 changes: 18 additions & 15 deletions src/com/blueseer/edi/EDIbs.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ public static void main(String args[]) throws IOException {
tags = ResourceBundle.getBundle("resources.bs", Locale.getDefault());
// lets process the arguments
String[] vs = checkargs(args);
String infile = vs[0].toString();
String outfile = vs[1].toString();
String indir = vs[2].toString();
String outdir = vs[3].toString();
String map = vs[4].toString();
String isOverride = vs[5].toString();
String infile = vs[0];
String outfile = vs[1];
String indir = vs[2];
String outdir = vs[3];
String map = vs[4];
String isOverride = vs[5];
String[] doctypes = vs[6].split(",");
String prog = vs[7].toString();
String archdir = vs[8].toString();

String prog = vs[7];
String archdir = vs[8];
String site = vs[9];
String myargs = String.join(",", args);


switch (prog) {

case "single" :
processSingle(infile, outfile, map, isOverride);
processSingle(infile, outfile, map, isOverride, site);
break;
case "multiple" :
processMultiple(indir, outdir, map, isOverride);
Expand Down Expand Up @@ -130,9 +130,9 @@ public static void main(String args[]) throws IOException {


public static String[] checkargs(String[] args) {
List<String> legitargs = Arrays.asList("-if", "-of", "-id", "-od", "-m", "-x", "-ff", "-fd", "-ad", "-td", "-tf", "-e", "-debug", "-ftp", "-pd", "-pdr" );
List<String> legitargs = Arrays.asList("-if", "-of", "-id", "-od", "-m", "-x", "-ff", "-fd", "-ad", "-td", "-tf", "-e", "-debug", "-ftp", "-pd", "-pdr", "-site" );

String[] vals = new String[9]; // last element is the program type (single or mulitiple)
String[] vals = new String[10]; // last element is now 'site'
Arrays.fill(vals, "");

String myargs = String.join(",", args);
Expand Down Expand Up @@ -174,7 +174,7 @@ public static String[] checkargs(String[] args) {



if ( (args.length > i+1 && args[i+1] != null) || (args[i].toString().equals("-x")) || (args[i].toString().equals("-ff") || (args[i].toString().equals("-fd"))) ) {
if ( (args.length > i+1 && args[i+1] != null) || (args[i].toString().equals("-x")) || (args[i].toString().equals("-debug")) || (args[i].toString().equals("-ff") || (args[i].toString().equals("-fd"))) ) {

switch (args[i].toString().toLowerCase()) {

Expand Down Expand Up @@ -233,6 +233,9 @@ public static String[] checkargs(String[] args) {
case "-debug" :
isDebug = true;
break;
case "-site" :
vals[9] = args[i+1];
break;
case "-ftp" :
vals[4] = args[i+1];
vals[7] = "ftpClient";
Expand All @@ -253,11 +256,11 @@ public static String[] checkargs(String[] args) {
return vals;
}

public static void processSingle(String infile, String outfile, String map, String isOverride) {
public static void processSingle(String infile, String outfile, String map, String isOverride, String thissite) {
// case of single input and output file
if (! infile.isEmpty() && ! outfile.isEmpty() ) {
try {
EDI.processFile(infile, map, outfile, isOverride, isDebug, false, 0, 0, "");
EDI.processFile(infile, map, outfile, isOverride, isDebug, false, 0, 0, thissite);
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
Expand Down
Loading

0 comments on commit 7a6201b

Please sign in to comment.