*/
private void processClient(VariablesSecureApp vars, ProcessBundle bundle) throws ServletException {
final String processId = bundle.getProcessId();
final String pinstanceId = bundle.getPinstanceId();
final ProcessContext ctx = bundle.getContext();
isDirect = bundle.getChannel() == Channel.DIRECT;
if (log4j.isDebugEnabled()) {
log4j.debug("Processing client: " + vars.getClient());
}
String adNoteId = "";
if (isDirect) {
addLog("@DL_STARTING@", false);
} else {
addLog("Starting background process.");
}
if (vars == null) {
try {
final AcctServerProcessData[] dataOrg = AcctServerProcessData.selectUserOrg(connection,
processId);
if (dataOrg == null || dataOrg.length == 0) {
if (isDirect) {
addLog("@DL_LOAD_FAILED@");
} else {
addLog("User and Organization loading failed.");
}
return;
}
vars = new VariablesSecureApp(dataOrg[0].adUserId, ctx.getClient(), dataOrg[0].adOrgId);
} catch (final ServletException ex) {
log4j.error(ex.getMessage());
return;
}
}
try {
final AcctServerProcessData[] data = AcctServerProcessData.selectAcctTable(connection);
final ArrayList<Object> vTableIds = new ArrayList<Object>();
for (int i = 0; i < data.length; i++) {
vTableIds.add(data[i].adTableId);
}
TableIds = new String[vTableIds.size()];
vTableIds.toArray(TableIds);
} catch (final ServletException ex) {
log4j.error(ex.getMessage());
return;
}
adNoteId = saveLog(adNoteId, vars.getClient());
String[] tables = null;
String strTable = "";
// If it is the background process, we use 0
String strOrg = "0";
// if called by 'Posting by DB tables' get params from ad_pinstance
if (isDirect) {
strTable = AcctServerProcessData.selectTable(connection, pinstanceId);
strOrg = AcctServerProcessData.selectOrg(connection, pinstanceId);
}
if (!strTable.equals("")) {
tables = new String[1];
tables[0] = new String(strTable);
} else {
tables = TableIds;
}
String strTableDesc;
for (int i = 0; i < tables.length; i++) {
final AcctServer acct = AcctServer.get(tables[i], vars.getClient(), strOrg, connection);
acct.setBatchSize(BATCH_SIZE);
strTableDesc = AcctServerProcessData.selectDescription(connection, ctx.getLanguage(),
acct.AD_Table_ID);
int total = 0;
while (acct.checkDocuments()) {
if (total == 0) {
if (isDirect)
addLog("@DL_ACCOUNTING@ - " + strTableDesc, false);
else
addLog("Accounting - " + strTableDesc, false);
} else {
if (isDirect)
addLog("@DL_COUNTED@ " + total + " - " + strTableDesc, false);
else
addLog("Counted " + total + " - " + strTableDesc, false);
}
try {
acct.run(vars);
} catch (final Exception ex) {
log4j.error(ex.getMessage(), ex);
return;
}
total += Integer.valueOf(BATCH_SIZE).intValue();
}
if (isDirect) {
addLog("@DL_TABLE@ = " + strTableDesc + " - " + acct.getInfo(ctx.getLanguage()), false);
} else {
addLog("Table = " + strTableDesc + " - " + acct.getInfo(ctx.getLanguage()));
}
adNoteId = saveLog(adNoteId, vars.getClient());
}
}