Skip to content

Commit

Permalink
cron method mod for edi entries
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughnte committed Aug 17, 2022
1 parent 2ac2fd1 commit d0226ff
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 37 deletions.
60 changes: 60 additions & 0 deletions src/com/blueseer/adm/admData.java
Expand Up @@ -1680,6 +1680,66 @@ public static ArrayList<cron_mstr> getCronMstrMod() {
return list;
}

public static void updateCronJobID(String jobid, String modflag) {
DateFormat dfdate = new SimpleDateFormat("yyyy-MM-dd");
try{
Connection con = null;
if (ds != null) {
con = ds.getConnection();
} else {
con = DriverManager.getConnection(url + db, user, pass);
}
Statement st = con.createStatement();
try{
st.executeUpdate("update cron_mstr set cron_modflag = " + "'" + modflag + "'" +
" where cron_jobid = " + "'" + jobid + "'" + ";" );
}
catch (SQLException s){
MainFrame.bslog(s);
} finally {
if (st != null) {
st.close();
}
con.close();
}
}
catch (Exception e){
MainFrame.bslog(e);
}

}

public static void updateCronJobIDMulti(ArrayList<String> list, String modflag) {

try{
Connection con = null;
if (ds != null) {
con = ds.getConnection();
} else {
con = DriverManager.getConnection(url + db, user, pass);
}
Statement st = con.createStatement();
try{
for (String x : list) {
st.executeUpdate("update cron_mstr set cron_modflag = " + "'" + modflag + "'" +
" where cron_jobid = " + "'" + x + "'" + ";" );
}
}
catch (SQLException s){
MainFrame.bslog(s);
} finally {
if (st != null) {
st.close();
}
con.close();
}
}
catch (Exception e){
MainFrame.bslog(e);
}

}


public static void updateDefaultCurrency(String x) {
DateFormat dfdate = new SimpleDateFormat("yyyy-MM-dd");
Expand Down
62 changes: 53 additions & 9 deletions src/com/blueseer/crn/jobSys.java
Expand Up @@ -26,16 +26,23 @@ of this software and associated documentation files (the "Software"), to deal
package com.blueseer.crn;

import static bsmf.MainFrame.bslog;
import com.blueseer.edi.EDI;
import static com.blueseer.edi.EDI.packageEnvelopes;
import com.blueseer.edi.apiUtils;
import static com.blueseer.edi.ediData.isValidAS2id;
import com.blueseer.fgl.fglData;
import com.blueseer.utl.BlueSeerUtils;
import com.blueseer.utl.EDData;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -52,28 +59,65 @@ of this software and associated documentation files (the "Software"), to deal
* @author terryva
*/
public class jobSys implements Job {
public void execute(JobExecutionContext context)
throws JobExecutionException {
public void execute(JobExecutionContext context) throws JobExecutionException {

// The as2ID must be passed to this job in order to schedule push AS2 comm of this id.
// must be passed in 'param' key with 'value' = as2id of as2_mstr table

// NOTE: this job only 'pushes' AS2 transmissions from source directory of as2id
// inbounds are pushed from partner...and must be collected/processed via another mechanism

String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));

JobDataMap dataMap = context.getJobDetail().getJobDataMap();
String param = dataMap.getString("param");

switch (param.toLowerCase()) {
case "postgl" :
System.out.println("jobSys parameter used: " + param + " time: " + now);

switch (param) {
case "postgl": {
fglData.PostGL();
break;
default:
System.out.println("Unkown paramter: " + param);
}
}

case "edi810o": {
ArrayList<String> invoices = EDData.getEDIInvoicesAutoExport();
exportInvoices(invoices);
break;
}

case "edi856o": {
ArrayList<String> asns = EDData.getEDIASNsAutoExport();
exportASNs(asns);
break;
}

default:
System.out.println("Unkown paramter: " + param + " time: " + now);
}



}

public void exportInvoices(ArrayList<String> list) {
int l_error;
for (String x : list) {
l_error = EDI.Create810(x);
if (l_error == 0) { // success
EDData.updateEDIInvoiceStatus(x); // set export success
}
}
packageEnvelopes();
}

public void exportASNs(ArrayList<String> list) {
int l_error;
for (String x : list) {
l_error = EDI.Create856(x);
if (l_error == 0) { // success
EDData.updateEDIASNStatus(x); // set export success
}
}
packageEnvelopes();
}

}
12 changes: 9 additions & 3 deletions src/com/blueseer/crn/jobWD.java
Expand Up @@ -33,6 +33,8 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -62,7 +64,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {

Scheduler myscheduler = context.getScheduler();

String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
/*
JobKey key = context.getJobDetail().getKey();
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
Expand All @@ -80,6 +82,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
if (! myscheduler.checkExists(jk)) {
continue;
}
System.out.println("cron job has been modified: " + jk.getName() + " time: " + now);
myscheduler.deleteJob(jk);
Class cls = Class.forName(cm.cron_prog());
JobDetail job = JobBuilder.newJob(cls)
Expand All @@ -90,6 +93,9 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
trigger.setName(cm.cron_jobid());
trigger.setCronExpression(cm.cron_expression());
myscheduler.scheduleJob(job, trigger);

admData.updateCronJobID(cm.cron_jobid(), "0");

} catch (SchedulerException ex) {
bslog(ex);
} catch (ParseException ex) {
Expand All @@ -99,10 +105,10 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
}
}

System.out.println("List of current Jobs and Triggers: ");
System.out.println("List of current Jobs and Triggers: " + " time: " + now);

try {
System.out.println("List of current Jobs and Triggers: ");

for (String groupName : myscheduler.getJobGroupNames()) {
for (JobKey jobKey : myscheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
String jobName = jobKey.getName();
Expand Down
3 changes: 3 additions & 0 deletions src/com/blueseer/edi/EDI.java
Expand Up @@ -2179,6 +2179,9 @@ public static int Create856(String shipper) {
int idxnbr = EDData.writeEDIIDX(c);
c[16] = String.valueOf(idxnbr);




messages.add(new String[]{"info","searching for map with: " + c[1] + "/" + defaults[2] + "/" + defaults[5]});
map = EDData.getEDIMap(c[1], defaults[2], defaults[5]);

Expand Down
87 changes: 84 additions & 3 deletions src/com/blueseer/utl/EDData.java
Expand Up @@ -1031,6 +1031,48 @@ public static ArrayList<String> getEDIInvoices(String fromnbr, String tonbr, Str

}

public static ArrayList<String> getEDIInvoicesAutoExport() {
ArrayList mylist = new ArrayList();
try{
Class.forName(driver);
Connection con = null;
if (ds != null) {
con = ds.getConnection();
} else {
con = DriverManager.getConnection(url + db, user, pass);
}
Statement st = con.createStatement();
ResultSet res = null;
try{


res = st.executeQuery("select sh_id from ship_mstr " +
" inner join cm_mstr on cm_code = sh_cust " +
" where sh_export_810 = '0' and " +
" sh_status = '1' and " +
" cm_is810export = '1' ;");


while (res.next()) {
mylist.add(res.getString("sh_id"));
}
}
catch (SQLException s) {
MainFrame.bslog(s);
} finally {
if (res != null) res.close();
if (st != null) st.close();
if (con != null) con.close();
}
}
catch (Exception e){
MainFrame.bslog(e);
}
return mylist;

}


public static ArrayList<String> getEDIASNs(String fromnbr, String tonbr, String fromdate, String todate, boolean override) {
ArrayList mylist = new ArrayList();
try{
Expand Down Expand Up @@ -1083,6 +1125,48 @@ public static ArrayList<String> getEDIASNs(String fromnbr, String tonbr, String

}

public static ArrayList<String> getEDIASNsAutoExport() {
ArrayList mylist = new ArrayList();
try{
Class.forName(driver);
Connection con = null;
if (ds != null) {
con = ds.getConnection();
} else {
con = DriverManager.getConnection(url + db, user, pass);
}
Statement st = con.createStatement();
ResultSet res = null;
try{


res = st.executeQuery("select sh_id from ship_mstr " +
" inner join cm_mstr on cm_code = sh_cust " +
" where sh_export_856 = '0' " +
" and sh_status = '1' and cm_is856export = '1' " +
";");


while (res.next()) {
mylist.add(res.getString("sh_id"));
}
}
catch (SQLException s) {
MainFrame.bslog(s);
} finally {
if (res != null) res.close();
if (st != null) st.close();
if (con != null) con.close();
}
}
catch (Exception e){
MainFrame.bslog(e);
}
return mylist;

}


public static ArrayList<String> getEDIPOs(String fromnbr, String tonbr, String fromdate, String todate, boolean override) {
ArrayList mylist = new ArrayList();
try{
Expand Down Expand Up @@ -2987,9 +3071,6 @@ public static void updateEDIIDX(int key, String[] c) {
}
Statement st = con.createStatement();
try {



st.executeUpdate("update edi_idx set " +
" edx_sender = " + "'" + c[0] + "'" + "," +
" edx_receiver = " + "'" + c[21] + "'" + "," +
Expand Down
6 changes: 6 additions & 0 deletions src/com/blueseer/utl/OVData.java
Expand Up @@ -362,7 +362,10 @@ public static int getNextNbr(String countername) {
ResultSet res = null;
try{

// if (! dbtype.equals("sqlite")) {
con.setAutoCommit(false);
// }

if (dbtype.equals("sqlite")) {
res = st.executeQuery("select max(counter_id) as 'num' from counter where " +
" counter_name = " + "'" + countername + "'" + ";");
Expand All @@ -376,7 +379,10 @@ public static int getNextNbr(String countername) {
st.executeUpdate(
" update counter set counter_id = " + "'" + nbr + "'" +
" where counter_name = " + "'" + countername + "'" + ";" );

// if (! dbtype.equals("sqlite")) {
con.setAutoCommit(true);
// }

}
catch (SQLException s){
Expand Down

0 comments on commit d0226ff

Please sign in to comment.