first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,683 @@
package com.ablia.log;
import com.ablia.common.Blacklist;
import com.ablia.common.CrontabInterface;
import com.ablia.common.Users;
import com.ablia.db.ApplParmFull;
import com.ablia.db.DBAdapter;
import com.ablia.db.ResParm;
import com.ablia.db.WcString;
import com.ablia.util.SimpleDateFormat;
import com.ablia.util.StringTokenizer;
import com.ablia.util.Timer;
import com.ablia.util.Vectumerator;
import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Calendar;
public class Log extends _LogAdapter implements Serializable, CrontabInterface {
public static final String CRONTAB_DAILY_JOB = "com.ablia.common.Log 0 0 * * * ";
public static final String CROBTAB_DAILY_JOB_NAME = "Pulizia Log giornaliera";
public static final long MOV_CREAZIONE_RECORD = 30L;
public static final long MOV_ALTRO = 0L;
public static final long MOV_CANCELLAZIONE_RECORD = 20L;
public static final long MOV_CANCELLAZIONE_RECORD_LOGICA = 21L;
public static final long MOV_CANCELLAZIONE_RECORD_FALLITA = 22L;
public static final long MOV_LOGIN = 1L;
public static final long MOV_LOGIN_BLACKLISTED = 10L;
public static final long MOV_LOGIN_IP_NON_CONSENTITO = 15L;
public static final long MOV_LOGIN_CANCELLATO = 5L;
public static final long MOV_LOGIN_ERRATO = 3L;
public static final long MOV_LOGIN_NON_VALIDO = 4L;
public static final long MOV_LOGOUT = 2L;
public static final long MOV_AGGIORNAMENTO_RECORD = 31L;
public static final long MOV_AGGIORNAMENTO_RECORD_FALLITO = 32L;
public static final long MOV_FATAL = 99L;
public static final long MOV_TUTTI = -1L;
public static final String LABEL_REQUEST_URL = "<B>REQUEST URL</B>";
public static final String LABEL_SQL_QUERY = "<B>SQL QUERY</B>";
public static final String LABEL_PK = "PK: ";
public static final String LABEL_PK_SEPARATOR = "-";
public static final String LABEL_DASH_SEPARATOR = "---------------------------";
public static final String LABEL_DESC_RECORD = "<B>BEAN DESCRIPTION</B>";
private Blacklist blacklist;
private Date dataLog;
private String descrizione;
private long flgMovimento;
private long id_blacklist;
private long id_log;
private long id_users;
private String ipAddress;
private Users users;
private String tabella;
private Time oraLog;
private String pk;
private String pkValue;
class ThreadCancellaLog extends Thread {
private LogCR CR;
public ThreadCancellaLog(LogCR CR) {
this.CR = CR;
if (!Log.isThreadAttivo()) {
Log.threadCancellaLog = true;
start();
}
}
public void run() {
Timer timer = new Timer();
timer.start();
System.out.println("##############\nCANCELLAZIONE LOG\nSTART: " + timer.getTStart().toString());
try {
Log bean = new Log(Log.this.getApOrig());
int nrighe = 100;
int recordCancellati = 0;
Vectumerator<Log> vec;
while ((vec = bean.findByCR(this.CR, 1, nrighe)).hasMoreElements()) {
while (vec.hasMoreElements()) {
Log row = vec.nextElement();
row.delete();
recordCancellati++;
Log.threadCancellaLogMsg = "Attenzione! Thread CANCELLAZIONE LOG in esecuzione!!! Record processati: " +
recordCancellati;
}
}
Log.this.handleDebug("CANCELLAZIONE LOG. CANCELLATI " + recordCancellati + " record.", 4);
timer.stop();
System.out.println("STOP: " + timer.getTStop().toString());
System.out.println("DURATA: " + timer.getDurataHourMin() +
"\nCANCELLAZIONE coda messaggi concluso\n****************");
} catch (Exception e) {
Log.this.handleDebug(" ERRORE! CANCELLAZIONE LOG. " + e.getMessage() + "\n" + e.getStackTrace(), 0);
} finally {
Log.threadCancellaLog = false;
}
}
}
public static final ResParm addAltro(ApplParmFull ap, String l_ip, long l_id_users, String l_descrizione) {
return addLog(ap, 0L, l_descrizione, l_ip, l_id_users, 0L);
}
public static final ResParm addCreazioneRecord(DBAdapter theBean) {
return addLog(theBean.getApFull(), 30L, theBean.getDescRecord(), theBean.getReqIpAddress(),
theBean.getLastUpdId_user(), 0L, theBean.getTableBeanName(), theBean.get_IdName(), theBean.get_Id());
}
public static final ResParm addCancellazioneRecordLogico(DBAdapter theBean) {
return addLog(theBean.getApFull(), 21L, theBean.getDescRecord(), theBean.getReqIpAddress(),
theBean.getLastUpdId_user(), 0L, theBean.getTableBeanName(), theBean.get_IdName(), theBean.get_Id());
}
private static final ResParm addLog(ApplParmFull ap, long l_flgMov, String l_descrizione, String l_ip, long l_id_users, long l_id_blacklist) {
return addLog(ap, l_flgMov, l_descrizione, l_ip, l_id_users, l_id_blacklist, "", "", "");
}
private static final ResParm addLog(ApplParmFull ap, long l_flgMov, String l_descrizione, String l_ip, long l_id_users, long l_id_blacklist, String l_tabella, String l_pk, String l_pk_value) {
if (ap != null) {
Log log = new Log(ap);
log.setFlgMovimento(l_flgMov);
log.setIpAddress(l_ip);
log.setDataLog(DBAdapter.getToday());
log.setOraLog(DBAdapter.getNow());
int maxlen = 65535;
if (l_descrizione != null)
if (l_descrizione.length() < maxlen) {
log.setDescrizione(l_descrizione);
} else {
log.setDescrizione(l_descrizione.substring(0, maxlen));
}
log.setId_users(l_id_users);
log.setId_blacklist(l_id_blacklist);
log.setTabella(l_tabella);
log.setPk(l_pk);
log.setPkValue(l_pk_value);
return log.save();
}
return new ResParm(false, "Error!. No Appl Parm defined. Could not save log");
}
public static final ResParm addLogin(ApplParmFull ap, String l_ip, long l_id_users) {
if (l_id_users == 1L)
return new ResParm(true, "Log Override!");
return addLog(ap, 1L, null, l_ip, l_id_users, 0L);
}
public static final ResParm addLoginBlacklisted(ApplParmFull ap, String l_ip, long l_id_users, long l_id_blacklist) {
if (l_id_users == 1L)
return new ResParm(true, "Log Override!");
return addLog(ap, 10L, null, l_ip, l_id_users, l_id_blacklist);
}
public static final ResParm addLoginIpNonConsentito(ApplParmFull ap, String l_ip, long l_id_users) {
if (l_id_users == 1L)
return new ResParm(true, "Log Override!");
return addLog(ap, 15L, null, l_ip, l_id_users, 0L);
}
public static final ResParm addLoginCancellato(ApplParmFull ap, String l_ip, long l_id_users, Date l_dataFineVld) {
if (l_id_users == 1L)
return new ResParm(true, "Log Override!");
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String l_descrizione = "Data cancellazione: " + df.format(l_dataFineVld);
return addLog(ap, 3L, l_descrizione, l_ip, l_id_users, 0L);
}
public static final ResParm addLoginErrato(ApplParmFull ap, String l_ip, String l_descrizione) {
return addLog(ap, 3L, l_descrizione, l_ip, 0L, 0L);
}
public static final ResParm addLoginNonValido(ApplParmFull ap, String l_ip, long l_id_users) {
if (l_id_users == 1L)
return new ResParm(true, "Log Override!");
return addLog(ap, 4L, null, l_ip, l_id_users, 0L);
}
public static final ResParm addLogout(ApplParmFull ap, String l_ip, long l_id_users) {
if (l_id_users == 1L)
return new ResParm(true, "Log Override!");
return addLog(ap, 2L, null, l_ip, l_id_users, 0L);
}
public static final String getMovimento(long l_flgIngressoUscita) {
if (l_flgIngressoUscita == 0L)
return "Altri mov.";
if (l_flgIngressoUscita == 1L)
return "Login";
if (l_flgIngressoUscita == 2L)
return "Logout";
if (l_flgIngressoUscita == 3L)
return "Login Errato";
if (l_flgIngressoUscita == 4L)
return "Login non valido";
if (l_flgIngressoUscita == 5L)
return "Login Cancellato";
if (l_flgIngressoUscita == 10L)
return "Login Blacklisted";
if (l_flgIngressoUscita == 15L)
return "Login da ip non consentito";
if (l_flgIngressoUscita == 20L)
return "Cancellazione record";
if (l_flgIngressoUscita == 22L)
return "Cancellazione record FALLITA ";
if (l_flgIngressoUscita == 21L)
return "Canc. logica record ";
if (l_flgIngressoUscita == 30L)
return "Creazione record ";
if (l_flgIngressoUscita == 31L)
return "Aggiornamento record ";
if (l_flgIngressoUscita == 32L)
return "Aggiornamento record FALLITA ";
if (l_flgIngressoUscita == 99L)
return "FATAL ERROR ";
if (l_flgIngressoUscita == -1L)
return "-- tutti --";
return "??";
}
public static boolean threadCancellaLog = false;
public static String threadCancellaLogMsg = "";
public Log() {}
public Log(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
public ResParm delete() {
if (getDBState() == 1) {
String s_sql_delete = "delete from LOG where id_log=";
return delete(String.valueOf(s_sql_delete) + getId_log());
}
return new ResParm();
}
public ResParm deleteByCR(LogCR CR) {
ResParm rp = new ResParm(true);
Log bean = new Log(getApFull());
int nrighe = 100;
int count = 0;
Vectumerator<Log> vec;
while ((vec = bean.findByCR(CR, 1, nrighe)).hasMoreElements()) {
while (vec.hasMoreElements()) {
Log row = vec.nextElement();
row.delete();
count++;
}
}
rp.setMsg("Cancellazione Massiva: n. log cancellati: " + count);
return rp;
}
protected void deleteCascade() {}
public Vectumerator findByCR(LogCR CR, int pageNumber, int pageRows) {
boolean flgOttimizzo = true;
int start = 0;
int stop = 0;
if (flgOttimizzo) {
if (pageNumber == 0)
pageNumber = 1;
start = (pageNumber - 1) * pageRows;
stop = start + pageRows;
}
StringBuffer s_Sql_Find = new StringBuffer("select DISTINCT A.* from LOG AS A");
if (flgOttimizzo && (getApFull().getDbType() == 14 ||
getApFull().getDbType() == 13))
s_Sql_Find = new StringBuffer("select TOP " + stop + " A.* from LOG AS A");
String s_Sql_Order = " order by A.lastUpdTmst desc";
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt;
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
stmt = getConn().prepareStatement(s_Sql_Find + wc.toString() + s_Sql_Order);
} else if (getApFull().getDbType() != 14 &&
getApFull().getDbType() != 13) {
stmt = getConn().prepareStatement(s_Sql_Find + wc.toString() + s_Sql_Order);
} else {
stmt = getConn().prepareStatement(s_Sql_Find + wc.toString() + s_Sql_Order);
}
findByCRCreateStmtDate(CR, stmt);
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo)
return findRows(stmt, pageNumber, pageRows);
if (getApFull().getDbType() == 14 ||
getApFull().getDbType() == 13) {
Vectumerator<? extends DBAdapter> vectumerator = findRows(stmt, pageNumber, pageRows);
vectumerator.setPageNumber(pageNumber);
if (stop >= vectumerator.getTotNumberOfRecords() - 1)
vectumerator.setTotNumberOfRecords(findByCRTotRecord(CR));
return vectumerator;
}
Vectumerator<? extends DBAdapter> vec = findRows(stmt, pageNumber, pageRows);
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
private void findByCRCreateStmtDate(LogCR CR, PreparedStatement stmt) {
try {
int dataCount = 1;
if (CR.getDataLogDa() != null) {
stmt.setDate(dataCount, CR.getDataLogDa());
dataCount++;
}
if (CR.getDataLogA() != null) {
stmt.setDate(dataCount, CR.getDataLogA());
dataCount++;
}
} catch (SQLException e) {
handleDebug(e);
}
}
private void findByCRCreateWC(LogCR CR, StringBuffer s_Sql_Find, WcString wc) {
if (CR.getId_logonUsers() != 1L)
wc.addWc("(A.flgMovimento!=3 or A.flgMovimento is null)");
if (CR.getId_users() != 0L)
wc.addWc("A.id_users=" + CR.getId_users());
if (!CR.getDescLog().trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(CR.getDescLog().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = st.nextToken();
txt.append("(A.descrizione like '%" + token + "%' or A.ipAddress like '%" + token + "%')");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
if (!CR.getDescUser().trim().isEmpty()) {
s_Sql_Find.append(", USERS AS C");
wc.addWc("A.id_users=C.id_users");
StringTokenizer st = new StringTokenizer(CR.getDescUser().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = st.nextToken();
txt.append("(C.cognome like '%" + token + "%' or C.nome like '%" + token + "%')");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
if (!CR.getDescBlacklist().trim().isEmpty()) {
s_Sql_Find.append(", BLASCKLIT AS B");
wc.addWc("A.id_blacklist=B.id_blascklist");
StringTokenizer st = new StringTokenizer(CR.getDescBlacklist().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = st.nextToken();
txt.append("(B.eMail like '%" + token + "%' or B.ipAddress like '%" + token + "%')");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getFlgMovimento() == 0L) {
wc.addWc("(A.flgMovimento is null or A.flgMovimento=0)");
} else if (CR.getFlgMovimento() > 0L) {
wc.addWc("A.flgMovimento=" + CR.getFlgMovimento());
}
if (!CR.getTabella().isEmpty())
wc.addWc("A.tabella='" + CR.getTabella() + "'");
if (!CR.getPk().isEmpty())
wc.addWc("A.pk='" + CR.getPk() + "'");
if (!CR.getPkValue().isEmpty())
wc.addWc("A.pkValue='" + CR.getPkValue() + "'");
if (CR.getDataLogDa() != null)
wc.addWc("A.dataLog>=?");
if (CR.getDataLogA() != null)
wc.addWc("A.dataLog<=?");
}
private int findByCRTotRecord(LogCR CR) {
StringBuffer s_Sql_Find = new StringBuffer("select count(*) as tot from LOG AS A ");
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + wc.toString());
findByCRCreateStmtDate(CR, stmt);
return (int)getTots(stmt);
} catch (Exception e) {
handleDebug(e);
return 0;
}
}
public Vectumerator findByUser(long l_id_users, int pageNumber, int pageRows) {
String s_Sql_Find = "select DISTINCT A.* from LOG AS A";
String s_Sql_Order = " order by lastUpdTmst desc";
WcString wc = new WcString();
wc.addWc("A.id_users=" + l_id_users);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_Order);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Blacklist getBlacklist() {
if (this.blacklist == null && getId_blacklist() > 0L) {
this.blacklist = new Blacklist(getApOrig());
this.blacklist.findByPrimaryKey(getId_blacklist());
}
return (this.blacklist == null) ? new Blacklist(getApOrig()) : this.blacklist;
}
public Date getDataLog() {
return this.dataLog;
}
public String getDescrizione() {
return (this.descrizione == null) ? "" : this.descrizione.trim();
}
public String getDescrizioneCompleta() {
StringBuilder sb = new StringBuilder();
SimpleDateFormat tf = new SimpleDateFormat("HH:mm:ss.SS");
sb.append("<b>");
sb.append(getMovimento());
sb.append("</b> <br>");
if (getFlgMovimento() == 0L)
return convertStringToHtml(getDescrizione());
if (!getDescrizione().isEmpty())
try {
String beanDescription = getDescrizione().substring(0,
getDescrizione().indexOf("---------------------------<B>REQUEST URL</B>"));
String requestUrl = getDescrizione().substring(getDescrizione().indexOf("---------------------------<B>REQUEST URL</B>"),
getDescrizione().indexOf("---------------------------<B>SQL QUERY</B>"));
String sqlQuery = getDescrizione().substring(getDescrizione().indexOf("---------------------------<B>SQL QUERY</B>"),
getDescrizione().length());
sb.append("<table width=\"100%\"><tr><td style=\"vertical-align:top\">");
sb.append(convertStringToHtml(beanDescription));
sb.append("</td><td style=\"vertical-align:top\">");
sb.append(convertStringToHtml(requestUrl));
sb.append("</td><td style=\"vertical-align:top\">");
sb.append(convertStringToHtml(sqlQuery));
sb.append("</td></tr></table>");
} catch (Exception e) {}
if (getId_blacklist() > 0L)
sb.append(getBlacklist().getDescrizioneCompleta());
return sb.toString();
}
public long getFlgMovimento() {
return this.flgMovimento;
}
public long getId_blacklist() {
return this.id_blacklist;
}
public long getId_log() {
return this.id_log;
}
public long getId_users() {
return this.id_users;
}
public String getIpAddress() {
return (this.ipAddress == null) ? "" : this.ipAddress;
}
public String getMovimento() {
return getMovimento(getFlgMovimento());
}
public Users getUsers() {
if (this.users == null && getId_users() > 0L) {
this.users = new Users(getApOrig());
this.users.findByPrimaryKey(getId_users());
}
return (this.users == null) ? new Users(getApOrig()) : this.users;
}
public void setBlacklist(Blacklist blacklist) {
this.blacklist = blacklist;
}
public void setDataLog(Date timeStampLog) {
this.dataLog = timeStampLog;
}
public void setDescrizione(String newDescrizione) {
this.descrizione = newDescrizione;
}
public void setFlgMovimento(long flgLog) {
this.flgMovimento = flgLog;
}
public void setId_blacklist(long id_blacklist) {
this.id_blacklist = id_blacklist;
setBlacklist(null);
}
public void setId_log(long newId_log) {
this.id_log = newId_log;
}
public void setId_users(long newId_users) {
this.id_users = newId_users;
setUsers(null);
}
public void setIpAddress(String newIpAddress) {
this.ipAddress = newIpAddress;
}
public void setUsers(Users newUsers) {
this.users = newUsers;
}
public ResParm deleteLogs(int days) {
String s_Sql_Delete = "delete from LOG";
WcString wc = new WcString();
wc.addWc("dataLog<=?");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Delete) + wc.toString());
if (days == 0)
days = 1;
Calendar cal = Calendar.getInstance();
cal.add(6, -days);
Date dataLimite = new Date(cal.getTimeInMillis());
stmt.setDate(1, dataLimite);
ResParm rp = delete(stmt);
if (rp.getStatus())
rp.setMsg("Cancellazione Log " + getApFull().getDatabase() + " di giorni " + days + " fino alla data " + dataLimite +
" effettuata.");
return rp;
} catch (SQLException e) {
handleDebug(e);
return new ResParm(false, e);
}
}
public static final ResParm addCancellazioneRecord(DBAdapter theBean) {
return addLog(theBean.getApFull(), 20L, theBean.getDescRecord(), theBean.getReqIpAddress(),
theBean.getLastUpdId_user(), 0L, theBean.getTableBeanName(), theBean.get_IdName(), theBean.get_Id());
}
public static final ResParm addCancellazioneRecordFallita(DBAdapter theBean, String reason) {
return addLog(theBean.getApFull(), 22L, String.valueOf(reason) + "<br>" + theBean.getDescRecord(),
theBean.getReqIpAddress(), theBean.getLastUpdId_user(), 0L, theBean.getTableBeanName(), theBean.get_IdName(),
theBean.get_Id());
}
public static final ResParm addAggiornamentoRecordFallito(DBAdapter theBean, String reason) {
return addLog(theBean.getApFull(), 32L, String.valueOf(reason) + "<br>" + theBean.getDescRecord(),
theBean.getReqIpAddress(), theBean.getLastUpdId_user(), 0L, theBean.getTableBeanName(), theBean.get_IdName(),
theBean.get_Id());
}
public static final ResParm addAggiornamentoRecord(DBAdapter theBean) {
return addLog(theBean.getApFull(), 31L, theBean.getDescRecord(), theBean.getReqIpAddress(),
theBean.getLastUpdId_user(), 0L, theBean.getTableBeanName(), theBean.get_IdName(), theBean.get_Id());
}
public ResParm crontabJob(ApplParmFull ap) {
ResParm rp = new ResParm(true);
int dayLogs = ap.getParm("LOG_GG").getNumeroInt();
int dayLogsMail = ap.getParm("LOG_MAIL_GG").getNumeroInt();
if (dayLogs > 0 || dayLogsMail > 0) {
if (dayLogs > 0) {
Log log = new Log(ap);
rp = log.deleteLogs(dayLogs);
}
dayLogsMail = 10;
if (dayLogsMail > 0) {
LogMail logMail = new LogMail(ap);
rp.append(logMail.deleteLogs(dayLogsMail));
}
return rp;
}
rp = new ResParm(false,
"Crontab LOG job not started. LOG_GG and LOG_GG set to 0 days. Shouldn't be here!");
return rp;
}
public final ResParm cancellazioneMassiva(LogCR CR) {
if (!isThreadAttivo())
return new ResParm(true, "Thread CANCELLAZIONE LOG avviato");
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public static final ResParm addFatal(ApplParmFull ap, String l_ip, long l_id_users, String l_descrizione) {
return addLog(ap, 99L, l_descrizione, l_ip, l_id_users, 0L);
}
public static boolean isThreadAttivo() {
return threadCancellaLog;
}
public String getTabella() {
return (this.tabella == null) ? "" : this.tabella.trim();
}
public void setTabella(String tabella) {
this.tabella = tabella;
}
public Time getOraLog() {
return this.oraLog;
}
public void setOraLog(Time oraLog) {
this.oraLog = oraLog;
}
public String getPk() {
return (this.pk == null) ? "" : this.pk.trim();
}
public void setPk(String pk) {
this.pk = pk;
}
public String getPkValue() {
return (this.pkValue == null) ? "" : this.pkValue.trim();
}
public void setPkValue(String pkValue) {
this.pkValue = pkValue;
}
public static final ResParm delUserLog(ApplParmFull ap, long l_id_users) {
Log log = new Log(ap);
return log.update("delete from LOG where id_users=" + l_id_users);
}
}

View file

@ -0,0 +1,210 @@
package com.ablia.log;
import com.ablia.common.Blacklist;
import com.ablia.common.Users;
import com.ablia.db.ApplParmFull;
import com.ablia.db.CRAdapter;
import java.sql.Date;
import java.sql.Time;
public class LogCR extends CRAdapter {
private long id_log;
private Date dataLogDa;
private Time oraLogDa;
private Time oraLogA;
private Date dataLogA;
private String descUser;
private String descLog;
private String descBlacklist;
private long id_users;
private long id_logonUsers;
private String ipAddress;
private Users users;
private Blacklist blacklist;
private long id_blacklist;
private long flgMovimento = -1L;
private String tabella;
private String pk;
private String pkValue;
public LogCR(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public LogCR() {}
public void setId_log(long newId_log) {
this.id_log = newId_log;
}
public void setDataLogDa(Date newDataLog) {
this.dataLogDa = newDataLog;
}
public void setDescLog(String newDescrizione) {
this.descLog = newDescrizione;
}
public void setId_users(long newId_users) {
this.id_users = newId_users;
setUsers(null);
}
public void setIpAddress(String newIpAddress) {
this.ipAddress = newIpAddress;
}
public long getId_log() {
return this.id_log;
}
public Date getDataLogDa() {
return this.dataLogDa;
}
public String getDescLog() {
return (this.descLog == null) ? "" : this.descLog.trim();
}
public long getId_users() {
return this.id_users;
}
public String getIpAddress() {
return (this.ipAddress == null) ? "" : this.ipAddress;
}
public void setUsers(Users newUsers) {
this.users = newUsers;
}
public Users getUsers() {
if (this.users == null && getId_users() > 0L) {
this.users = new Users(getApFull());
this.users.findByPrimaryKey(getId_users());
}
return (this.users == null) ? new Users(getApFull()) : this.users;
}
public Blacklist getBlacklist() {
if (this.blacklist == null && getId_blacklist() > 0L) {
this.blacklist = new Blacklist(getApFull());
this.blacklist.findByPrimaryKey(getId_blacklist());
}
return (this.blacklist == null) ? new Blacklist(getApFull()) : this.blacklist;
}
public long getId_blacklist() {
return this.id_blacklist;
}
public void setBlacklist(Blacklist blacklist) {
this.blacklist = blacklist;
}
public void setId_blacklist(long id_blacklist) {
this.id_blacklist = id_blacklist;
setBlacklist(null);
}
public String getDescBlacklist() {
return (this.descBlacklist == null) ? "" : this.descBlacklist.trim();
}
public void setDescBlacklist(String descBlacklist) {
this.descBlacklist = descBlacklist;
}
public Date getDataLogA() {
return this.dataLogA;
}
public void setDataLogA(Date dataLogA) {
this.dataLogA = dataLogA;
}
public static final String getMovimento(long l_flgIngressoUscita) {
return Log.getMovimento(l_flgIngressoUscita);
}
public long getFlgMovimento() {
return this.flgMovimento;
}
public void setFlgMovimento(long flgMovimento) {
this.flgMovimento = flgMovimento;
}
public String getDescUser() {
return (this.descUser == null) ? "" : this.descUser.trim();
}
public void setDescUser(String descUser) {
this.descUser = descUser;
}
public long getId_logonUsers() {
return this.id_logonUsers;
}
public void setId_logonUsers(long id_logonUsers) {
this.id_logonUsers = id_logonUsers;
}
public String getTabella() {
return (this.tabella == null) ? "" : this.tabella.trim();
}
public void setTabella(String tabella) {
this.tabella = tabella;
}
public Time getOraLogDa() {
return this.oraLogDa;
}
public void setOraLogDa(Time oraLogDa) {
this.oraLogDa = oraLogDa;
}
public Time getOraLogA() {
return this.oraLogA;
}
public void setOraLogA(Time oraLogA) {
this.oraLogA = oraLogA;
}
public String getPk() {
return (this.pk == null) ? "" : this.pk.trim();
}
public void setPk(String pk) {
this.pk = pk;
}
public String getPkValue() {
return (this.pkValue == null) ? "" : this.pkValue.trim();
}
public void setPkValue(String pkValue) {
this.pkValue = pkValue;
}
}

View file

@ -0,0 +1,323 @@
package com.ablia.log;
import com.ablia.common.Users;
import com.ablia.db.ApplParmFull;
import com.ablia.db.ResParm;
import com.ablia.db.WcString;
import com.ablia.mail.MailProperties;
import com.ablia.util.Debug;
import com.ablia.util.SimpleDateFormat;
import com.ablia.util.Timer;
import com.ablia.util.Vectumerator;
import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.StringTokenizer;
public class LogMail extends _LogAdapter implements Serializable {
private static final long serialVersionUID = 1448626122225L;
private long id_logMail;
private Timestamp tsInvio;
private String lmTo;
private String lmCc;
private String lmBcc;
private String testoMessaggio;
private String result;
private long id_users;
private Users users;
private String oggetto;
class ThreadCancellaLog extends Thread {
private LogMailCR CR;
public ThreadCancellaLog(LogMailCR CR) {
this.CR = CR;
if (!LogMail.isThreadAttivo()) {
LogMail.threadCancellaLog = true;
start();
}
}
public void run() {
Timer timer = new Timer();
timer.start();
System.out.println("##############\nCANCELLAZIONE LOG MAIL\nSTART: " + timer.getTStart().toString());
try {
LogMail bean = new LogMail(LogMail.this.getApOrig());
int nrighe = 100;
int recordCancellati = 0;
Vectumerator<LogMail> vec;
while ((vec = bean.findByCR(this.CR, 1, nrighe)).hasMoreElements()) {
while (vec.hasMoreElements()) {
LogMail row = vec.nextElement();
row.delete();
recordCancellati++;
LogMail.threadCancellaLogMsg = "Attenzione! Thread CANCELLAZIONE LOG MAIL in esecuzione!!! Record processati: " +
recordCancellati;
}
}
LogMail.this.handleDebug("CANCELLAZIONE LOG MAIL. CANCELLATI " + recordCancellati + " record.", 4);
timer.stop();
System.out.println("STOP: " + timer.getTStop().toString());
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
System.out.println("DURATA: " + timer.getDurataHourMin() +
"\nCANCELLAZIONE coda messaggi concluso\n****************");
} catch (Exception e) {
LogMail.this.handleDebug(" ERRORE! CANCELLAZIONE LOG MAIL. " + e.getMessage() + "\n" + e.getStackTrace(), 0);
} finally {
LogMail.threadCancellaLog = false;
}
}
}
public static boolean threadCancellaLog = false;
public static String threadCancellaLogMsg = "";
public LogMail(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public LogMail() {}
public void setId_logMail(long newId_logMail) {
this.id_logMail = newId_logMail;
}
public void setTsInvio(Timestamp newDataInvio) {
this.tsInvio = newDataInvio;
}
public void setLmTo(String newTo) {
this.lmTo = newTo;
}
public void setLmCc(String newCc) {
this.lmCc = newCc;
}
public void setLmBcc(String newBcc) {
this.lmBcc = newBcc;
}
public void setTestoMessaggio(String newTestoMessaggio) {
this.testoMessaggio = newTestoMessaggio;
}
public void setResult(String newResult) {
this.result = newResult;
}
public long getId_logMail() {
return this.id_logMail;
}
public Timestamp getTsInvio() {
return this.tsInvio;
}
public String getLmTo() {
return (this.lmTo == null) ? "" : this.lmTo.trim();
}
public String getLmCc() {
return (this.lmCc == null) ? "" : this.lmCc.trim();
}
public String getLmBcc() {
return (this.lmBcc == null) ? "" : this.lmBcc.trim();
}
public String getTestoMessaggio() {
return (this.testoMessaggio == null) ? "" : this.testoMessaggio.trim();
}
public String getResult() {
return (this.result == null) ? "" : this.result.trim();
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {
Vectumerator<LogMailAttach> vec = getAllegati();
while (vec.hasMoreElements()) {
LogMailAttach row = vec.nextElement();
row.delete();
}
}
public Vectumerator<LogMail> findByCR(LogMailCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from LOG_MAIL AS A";
String s_Sql_Order = " order by A.tsInvio desc";
WcString wc = new WcString();
if (!CR.getLmTo().isEmpty())
wc.addWc("A.lmTo like '%" + CR.getLmTo() + "%'");
if (CR.getId_users() > 0L)
wc.addWc("A.id_users=" + CR.getId_users());
if (!CR.getOggetto().isEmpty())
wc.addWc("A.oggetto like '%" + CR.getOggetto() + "%'");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_Order);
return (Vectumerator)findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return (Vectumerator)AB_EMPTY_VECTUMERATOR;
}
}
public Users getUsers() {
if (this.users == null && getId_users() > 0L) {
this.users = new Users(getApOrig());
this.users.findByPrimaryKey(getId_users());
}
return (this.users == null) ? new Users(getApOrig()) : this.users;
}
public void setId_users(long newId_users) {
this.id_users = newId_users;
setUsers(null);
}
public void setUsers(Users newUsers) {
this.users = newUsers;
}
public static final ResParm addLogMail(ApplParmFull ap, MailProperties prop, String l_oggetto, String l_msg, String result, long l_id_users) {
if (ap != null) {
LogMail logMail = new LogMail(ap);
logMail.setLmTo(prop.getProperty("TO"));
logMail.setLmCc(prop.getProperty("CC"));
logMail.setLmBcc(prop.getProperty("BCC"));
logMail.setTsInvio(getTimestamp());
logMail.setResult(result);
logMail.setTestoMessaggio(l_msg);
logMail.setOggetto(l_oggetto);
logMail.setId_users(l_id_users);
if (l_id_users == 0L)
System.out.println("ERRORE FATAL! ADD LOG. ID_USERS NON IMPOSTATO.\n" + Debug.getCallingStackTrace());
ResParm rp = logMail.save();
if (rp.getStatus()) {
String l_files = prop.getProperty("FILES");
if (l_files != null && l_files.length() > 0) {
StringTokenizer st = new StringTokenizer(l_files, ",");
while (st.hasMoreElements()) {
String currentFile = st.nextToken();
String nomeFile = currentFile.substring(currentFile.lastIndexOf('/') + 1);
LogMailAttach lma = new LogMailAttach(ap);
lma.setId_logMail(logMail.getId_logMail());
lma.setNomeFile(nomeFile);
lma.setFileCompletoDaSalvare(currentFile);
logMail.addAllegato(lma);
}
}
}
return rp;
}
return new ResParm(false, "Error!. No Appl Parm defined. Could not save log");
}
public long getId_users() {
return this.id_users;
}
public String getOggetto() {
return (this.oggetto == null) ? "" : this.oggetto.trim();
}
public void setOggetto(String oggetto) {
this.oggetto = oggetto;
}
public ResParm addAllegato(LogMailAttach row) {
LogMailAttach bean = new LogMailAttach(getApOrig());
bean.findByLogMailNomeFile(row.getId_logMail(), row.getNomeFile());
if (bean.getDBState() == 1)
return new ResParm(false, "Nome File Duplicato");
row.setDBState(0);
ResParm rp = row.save();
return rp;
}
public ResParm delAllegato(LogMailAttach row) {
LogMailAttach bean = new LogMailAttach(getApFull());
bean.findByPrimaryKey(row.getId_logMailAttach());
return bean.delete();
}
public Vectumerator<LogMailAttach> getAllegati() {
return new LogMailAttach(getApOrig()).findByLogMail(getId_logMail(), 0, 0);
}
public boolean hasAllegati() {
Vectumerator<LogMailAttach> vec = new LogMailAttach(getApOrig()).findByLogMail(getId_logMail(), 1, 1);
if (vec.hasMoreElements())
return true;
return false;
}
public ResParm deleteLogs(int days) {
ResParm rp = new ResParm(true);
Calendar cal = Calendar.getInstance();
cal.add(6, -days);
Date dataLimite = new Date(cal.getTimeInMillis());
Vectumerator<LogMail> vec = findByMailLogGG(days, 0, 0);
while (vec.hasMoreElements()) {
LogMail row = vec.nextElement();
rp = row.delete();
if (!rp.getStatus())
break;
}
if (rp.getStatus())
rp.setMsg("Cancellazione Log " + getApFull().getDatabase() + " di giorni " + days + " fino alla data " + dataLimite +
" effettuata.");
return rp;
}
public Vectumerator<LogMail> findByMailLogGG(int mailLogGg, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from LOG_MAIL AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("tsInvio<=? ");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_Order);
if (mailLogGg == 0)
mailLogGg = 1;
Calendar cal = Calendar.getInstance();
cal.add(6, -mailLogGg);
Date dataLimite = new Date(cal.getTimeInMillis());
stmt.setDate(1, dataLimite);
return (Vectumerator)findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return (Vectumerator)AB_EMPTY_VECTUMERATOR;
}
}
public final ResParm cancellazioneMassiva(LogMailCR CR) {
if (!isThreadAttivo())
return new ResParm(true, "Thread CANCELLAZIONE LOG avviato");
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public static boolean isThreadAttivo() {
return threadCancellaLog;
}
}

View file

@ -0,0 +1,150 @@
package com.ablia.log;
import com.ablia.db.ApplParmFull;
import com.ablia.db.DBAdapter;
import com.ablia.db.ResParm;
import com.ablia.db.WcString;
import com.ablia.util.Vectumerator;
import java.io.File;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class LogMailAttach extends _LogAdapter implements Serializable {
private static final long serialVersionUID = 1448626122254L;
private long id_logMailAttach;
private String nomeFile;
private long id_logMail;
private LogMail logMail;
private String fileCompletoDaSalvare;
public LogMailAttach(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public LogMailAttach() {}
public void setId_logMailAttach(long newId_logMailAttach) {
this.id_logMailAttach = newId_logMailAttach;
}
public void setNomeFile(String newNomeFile) {
this.nomeFile = newNomeFile;
}
public void setId_logMail(long newId_logMail) {
this.id_logMail = newId_logMail;
setLogMail(null);
}
public long getId_logMailAttach() {
return this.id_logMailAttach;
}
public String getNomeFile() {
return (this.nomeFile == null) ? "" : this.nomeFile.trim();
}
public long getId_logMail() {
return this.id_logMail;
}
public void setLogMail(LogMail newLogMail) {
this.logMail = newLogMail;
}
public LogMail getLogMail() {
this.logMail = (LogMail)getSecondaryObject((DBAdapter)this.logMail, LogMail.class, getId_logMail());
return this.logMail;
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
public Vectumerator<LogMailAttach> findByCR(LogMailAttachCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select DISTINCT A.* from LOG_MAIL_ATTACH AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_Order);
return (Vectumerator)findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return (Vectumerator)AB_EMPTY_VECTUMERATOR;
}
}
public String getNomeFileSuDisco() {
return getNomeFile();
}
protected void deleteCascade() {
new File(String.valueOf(getPathAllegato()) + getNomeFileSuDisco()).delete();
}
public String getPathAllegato() {
return String.valueOf(getDocBase()) + getParm("LOG_MAIL_ATTACH").getTesto() + getId_logMail() + "/";
}
public void findByLogMailNomeFile(long l_id_logMail, String l_id_nomeFile) {
String s_Sql_Find = "select DISTINCT A.* from LOG_MAIL_ATTACH AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_logMail=" + l_id_logMail);
wc.addWc("A.nomeFile='" + l_id_nomeFile + "'");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_Order);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public Vectumerator<LogMailAttach> findByLogMail(long l_id_logMail, int pageNumber, int pageRows) {
String s_Sql_Find = "select DISTINCT A.* from LOG_MAIL_ATTACH AS A";
String s_Sql_Order = " order by A.nomeFile";
WcString wc = new WcString();
wc.addWc("A.id_logMail=" + l_id_logMail);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_Order);
return (Vectumerator)findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return (Vectumerator)AB_EMPTY_VECTUMERATOR;
}
}
public String getFileCompletoDaSalvare() {
return (this.fileCompletoDaSalvare == null) ? "" : this.fileCompletoDaSalvare.trim();
}
public void setFileCompletoDaSalvare(String fileCompletoDaSalvare) {
this.fileCompletoDaSalvare = fileCompletoDaSalvare;
}
public ResParm save() {
ResParm rp = super.save();
if (rp.getStatus() &&
!getFileCompletoDaSalvare().isEmpty() &&
isFileExist(getFileCompletoDaSalvare())) {
String targetFile = String.valueOf(getPathAllegato()) + getNomeFileSuDisco();
new File(targetFile).delete();
File pathAllegato = new File(getPathAllegato());
if (!pathAllegato.exists())
pathAllegato.mkdirs();
try {
DBAdapter.copyFile(getFileCompletoDaSalvare(), targetFile);
} catch (Exception e) {
handleDebug(e, 0);
}
}
return rp;
}
}

View file

@ -0,0 +1,57 @@
package com.ablia.log;
import com.ablia.db.ApplParmFull;
import com.ablia.db.CRAdapter;
import com.ablia.db.DBAdapter;
public class LogMailAttachCR extends CRAdapter {
private long id_logMailAttach;
private String nomeFile;
private long id_logMail;
private LogMail logMail;
public LogMailAttachCR(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public LogMailAttachCR() {}
public void setId_logMailAttach(long newId_logMailAttach) {
this.id_logMailAttach = newId_logMailAttach;
}
public void setNomeFile(String newNomeFile) {
this.nomeFile = newNomeFile;
}
public void setId_logMail(long newId_logMail) {
this.id_logMail = newId_logMail;
setLogMail(null);
}
public long getId_logMailAttach() {
return this.id_logMailAttach;
}
public String getNomeFile() {
return (this.nomeFile == null) ? "" : this.nomeFile.trim();
}
public long getId_logMail() {
return this.id_logMail;
}
public void setLogMail(LogMail newLogMail) {
this.logMail = newLogMail;
}
public LogMail getLogMail() {
this.logMail = (LogMail)getSecondaryObject(
(DBAdapter)this.logMail,
LogMail.class, getId_logMail());
return this.logMail;
}
}

View file

@ -0,0 +1,129 @@
package com.ablia.log;
import com.ablia.common.Users;
import com.ablia.db.ApplParmFull;
import com.ablia.db.CRAdapter;
import java.sql.Date;
public class LogMailCR extends CRAdapter {
private long id_logMail;
private Date dataInvio;
private String testoMessaggio;
private String result;
private String lmBcc;
private String lmCc;
private String lmTo;
private long id_users;
private Users users;
private String oggetto;
private long id_logonUsers;
public LogMailCR(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public LogMailCR() {}
public void setId_logMail(long newId_logMail) {
this.id_logMail = newId_logMail;
}
public void setDataInvio(Date newDataInvio) {
this.dataInvio = newDataInvio;
}
public void setTestoMessaggio(String newTestoMessaggio) {
this.testoMessaggio = newTestoMessaggio;
}
public void setResult(String newResult) {
this.result = newResult;
}
public long getId_logMail() {
return this.id_logMail;
}
public Date getDataInvio() {
return this.dataInvio;
}
public String getTestoMessaggio() {
return (this.testoMessaggio == null) ? "" : this.testoMessaggio.trim();
}
public String getResult() {
return (this.result == null) ? "" : this.result.trim();
}
public String getLmBcc() {
return (this.lmBcc == null) ? "" : this.lmBcc.trim();
}
public String getLmCc() {
return (this.lmCc == null) ? "" : this.lmCc.trim();
}
public String getLmTo() {
return (this.lmTo == null) ? "" : this.lmTo.trim();
}
public void setLmBcc(String newBcc) {
this.lmBcc = newBcc;
}
public void setLmCc(String newCc) {
this.lmCc = newCc;
}
public void setLmTo(String newTo) {
this.lmTo = newTo;
}
public Users getUsers() {
if (this.users == null && getId_users() > 0L) {
this.users = new Users(getApFull());
this.users.findByPrimaryKey(getId_users());
}
return (this.users == null) ? new Users(getApFull()) : this.users;
}
public void setUsers(Users newUsers) {
this.users = newUsers;
}
public long getId_users() {
return this.id_users;
}
public void setId_users(long newId_users) {
this.id_users = newId_users;
setUsers(null);
}
public String getOggetto() {
return (this.oggetto == null) ? "" : this.oggetto.trim();
}
public void setOggetto(String oggetto) {
this.oggetto = oggetto;
}
public long getId_logonUsers() {
return this.id_logonUsers;
}
public void setId_logonUsers(long id_logonUsers) {
this.id_logonUsers = id_logonUsers;
}
}

View file

@ -0,0 +1,204 @@
package com.ablia.log;
import com.ablia.common.Parm;
import com.ablia.common.Users;
import com.ablia.db.ApplParm;
import com.ablia.db.ApplParmFull;
import com.ablia.db.DBAdapter;
import com.ablia.db.DBAdapterException;
import com.ablia.db.ResParm;
import com.ablia.util.Debug;
import com.ablia.util.StringTokenizer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;
public abstract class _LogAdapter extends DBAdapter {
public static final String LOG_DATABASE_SUFF = "_log";
private static final String CREATE_LOG_FILE = "createLog";
private ApplParmFull apOrig;
public _LogAdapter() {}
public _LogAdapter(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
protected ResParm checkDeleteCascade() throws DBAdapterException, SQLException {
return null;
}
protected void deleteCascade() {}
public void setApFull(ApplParmFull theAp) {
String databaseLog;
setApOrig(theAp);
if (theAp.getDbType() == 14 || theAp.getDbType() == 13) {
if (theAp.getDatabase().endsWith(";")) {
databaseLog = String.valueOf(theAp.getDatabase().substring(0, theAp.getDatabase().length() - 1)) + "_log" + ";";
} else {
databaseLog = String.valueOf(theAp.getDatabase()) + "_log";
}
} else {
databaseLog = String.valueOf(theAp.getDatabase()) + "_log";
}
ApplParm apLog = new ApplParm(theAp.getDbType(), databaseLog, theAp.getUser(), theAp.getPassword(), theAp.getInitialCons(),
theAp.getMaxCons(), theAp.getTimeout());
apLog.setLangCode(theAp.getLangCode());
super.setApFull(new ApplParmFull(apLog, theAp.getLastUpdId_user(), theAp.getReqIpAddress(), theAp.getReqUrl()));
}
public Parm getParm(String theKey) {
if (getApOrig() != null)
return getApOrig().getParm(theKey);
return new Parm();
}
public ApplParmFull getApOrig() {
return this.apOrig;
}
private void setApOrig(ApplParmFull apOrig) {
this.apOrig = apOrig;
}
protected Locale getCurrentLocale() {
return getApOrig().getLocale();
}
public boolean getDebug() {
if (getApOrig() != null)
return getApOrig().getDebug();
return super.getDebug();
}
public int getDebugLevel() {
if (getApOrig() != null)
return getApOrig().getDebugLevel();
return super.getDebugLevel();
}
public Users getLastUpdUser() {
if (this.lastUpdUser == null && getLastUpdId_user() > 0L) {
this.lastUpdUser = new Users(getApOrig());
this.lastUpdUser.findByPrimaryKey(getLastUpdId_user());
}
return (this.lastUpdUser == null) ? new Users(getApOrig()) : this.lastUpdUser;
}
public static final boolean createLogDatabase(ApplParmFull theAp) {
String databaseLogFull, databaseServer, databaseLog;
boolean result = true;
if (theAp.getDbType() == 14 || theAp.getDbType() == 13) {
if (theAp.getDatabase().endsWith(";")) {
databaseLogFull = String.valueOf(theAp.getDatabase().substring(0, theAp.getDatabase().length() - 1)) + "_log" + ";";
} else {
databaseLogFull = String.valueOf(theAp.getDatabase()) + "_log";
}
databaseServer = databaseLogFull.substring(0, databaseLogFull.toLowerCase().indexOf("databasename="));
databaseLog = databaseLogFull.substring(databaseServer.length() + 13);
} else {
databaseLogFull = String.valueOf(theAp.getDatabase()) + "_log";
databaseServer = databaseLogFull.substring(0, databaseLogFull.substring(3).indexOf('/') + 3);
databaseLog = databaseLogFull.substring(databaseServer.length() + 1);
}
Connection conn = null;
Statement s = null;
try {
Class.forName(theAp.getDriverManager()).newInstance();
if (theAp.getDbEnvironProperty() != null) {
conn = DriverManager.getConnection(String.valueOf(theAp.getConnectionString()) + ":" + databaseServer, theAp.getDbEnvironProperty());
} else {
conn = DriverManager.getConnection(String.valueOf(theAp.getConnectionString()) + ":" + databaseServer, theAp.getUser(),
theAp.getPassword());
}
s = conn.createStatement();
if (theAp.getDbType() == 14 || theAp.getDbType() == 13) {
s.executeUpdate("IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'" + databaseLog +
"') CREATE DATABASE " + databaseLog);
} else {
s.executeUpdate("CREATE DATABASE IF NOT EXISTS " + databaseLog);
}
} catch (Exception e) {
e.printStackTrace();
if (theAp.getDbType() == 14 || theAp.getDbType() == 13) {
result = true;
} else {
result = false;
}
} finally {
if (conn != null)
try {
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
if (s != null)
try {
s.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (result) {
PreparedStatement ps = null;
try {
if (theAp.getDbEnvironProperty() != null) {
conn = DriverManager.getConnection(String.valueOf(theAp.getConnectionString()) + ":" + databaseLogFull, theAp.getDbEnvironProperty());
} else {
conn = DriverManager.getConnection(String.valueOf(theAp.getConnectionString()) + ":" + databaseLogFull, theAp.getUser(),
theAp.getPassword());
}
StringTokenizer st = new StringTokenizer(getCreateLogString(theAp.getDbType()), "#");
while (st.hasMoreTokens()) {
String token = st.nextToken();
ps = conn.prepareStatement(token);
try {
ps.execute();
} catch (Exception e) {}
}
} catch (Exception e) {
e.printStackTrace();
if (theAp.getDbType() == 14 || theAp.getDbType() == 13) {
result = true;
} else {
result = false;
}
} finally {
if (conn != null)
try {
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
if (ps != null)
try {
ps.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return result;
}
private static final String getCreateLogString(int dbType) {
String packageName = "/com/ablia/log/";
StringBuilder fileName = new StringBuilder("createLog");
switch (dbType) {
case 3:
fileName.append("Mysql.sql");
break;
case 13:
case 14:
fileName.append("MSsql.sql");
break;
}
return Debug.getResourceAsString(String.valueOf(packageName) + fileName.toString());
}
}

View file

@ -0,0 +1,57 @@
CREATE TABLE [LOG_MAIL] (
[id_logMail] INTEGER IDENTITY(0,1) NOT NULL,
[id_users] INTEGER,
[tsInvio] DATETIME,
[oggetto] VARCHAR(254),
[lmTo] VARCHAR(254),
[lmCc] VARCHAR(254),
[lmBcc] VARCHAR(254),
[testoMessaggio] TEXT,
[result] VARCHAR(1000),
[lastUpdId_user] INTEGER,
[lastUpdTmst] DATETIME,
CONSTRAINT [PK_LOG_MAIL] PRIMARY KEY ([id_logMail])
)
#CREATE TABLE [LOG_MAIL_ATTACH] (
[id_logMailAttach] INTEGER IDENTITY(0,1) NOT NULL,
[nomeFile] VARCHAR(254),
[id_logMail] INTEGER,
[lastUpdId_user] INTEGER,
[lastUpdTmst] DATETIME,
CONSTRAINT [PK_LOG_MAIL_ATTACH] PRIMARY KEY ([id_logMailAttach])
)
#CREATE TABLE [LOG] (
[id_log] INTEGER IDENTITY(0,1) NOT NULL,
[id_users] INTEGER,
[id_blacklist] INTEGER,
[dataLog] DATETIME,
[descrizione] TEXT,
[ipAddress] CHAR(60),
[flgMovimento] INTEGER,
[tabella] VARCHAR(60),
[oraLog] DATETIME,
[pk] VARCHAR(40),
[pkValue] VARCHAR(40),
[lastUpdId_user] INTEGER,
[lastUpdTmst] DATETIME,
CONSTRAINT [PK_LOG] PRIMARY KEY ([id_log])
)
#CREATE INDEX [IDX_LOG_3] ON [LOG] ([tabella])
#CREATE INDEX [IDX_LOG_4] ON [LOG] ([flgMovimento])
#CREATE INDEX [IDX_LOG_5] ON [LOG] ([pkValue])
#CREATE INDEX [IDX_LOG_6] ON [LOG] ([id_users])
#CREATE INDEX [IDX_LOG_7] ON [LOG] ([id_blacklist])
#CREATE INDEX [IDX_LOG_1] ON [LOG] ([pk])
#CREATE INDEX [IDX_LOG_2] ON [LOG] ([dataLog])
#ALTER TABLE [LOG_MAIL_ATTACH] ADD CONSTRAINT [LOG_MAIL_LOG_MAIL_ATTACH]
FOREIGN KEY ([id_logMail]) REFERENCES [LOG_MAIL] ([id_logMail])

View file

@ -0,0 +1,59 @@
CREATE TABLE IF NOT EXISTS `LOG_MAIL` (
`id_logMail` INTEGER NOT NULL AUTO_INCREMENT,
`id_users` INTEGER,
`oggetto` VARCHAR(254),
`tsInvio` DATETIME,
`lmTo` VARCHAR(254),
`lmCc` VARCHAR(254),
`lmBcc` VARCHAR(254),
`testoMessaggio` TEXT,
`result` VARCHAR(1000),
`lastUpdTmst` TIMESTAMP,
`lastUpdId_user` INTEGER,
CONSTRAINT `PK_LOG_MAIL` PRIMARY KEY (`id_logMail`)
);
#
CREATE TABLE IF NOT EXISTS `LOG_MAIL_ATTACH` (
`id_logMailAttach` INTEGER NOT NULL AUTO_INCREMENT,
`nomeFile` VARCHAR(254),
`id_logMail` INTEGER,
`lastUpdTmst` TIMESTAMP,
`lastUpdId_user` INTEGER,
CONSTRAINT `PK_LOG_MAIL_ATTACH` PRIMARY KEY (`id_logMailAttach`),
CONSTRAINT `LOG_MAIL_LOG_MAIL_ATTACH`
FOREIGN KEY (`id_logMail`) REFERENCES `LOG_MAIL` (`id_logMail`)
);
#
CREATE TABLE IF NOT EXISTS `LOG` (
`id_log` INTEGER NOT NULL AUTO_INCREMENT,
`id_users` INTEGER,
`id_blacklist` INTEGER,
`dataLog` DATE,
`descrizione` text,
`ipAddress` CHAR(60),
`flgMovimento` INTEGER,
`tabella` VARCHAR(60),
`oraLog` TIME,
`pk` VARCHAR(40),
`pkValue` VARCHAR(40),
`lastUpdTmst` TIMESTAMP,
`lastUpdId_user` INTEGER,
CONSTRAINT `PK_LOG` PRIMARY KEY (`id_log`)
);
#
CREATE INDEX `IDX_LOG_1` ON `LOG` (`pk`);
#
CREATE INDEX `IDX_LOG_2` ON `LOG` (`dataLog`);
#
CREATE INDEX `IDX_LOG_3` ON `LOG` (`tabella`);
#
CREATE INDEX `IDX_LOG_4` ON `LOG` (`flgMovimento`);
#
CREATE INDEX `IDX_LOG_5` ON `LOG` (`pkValue`);
#
CREATE INDEX `IDX_LOG_6` ON `LOG` (`id_users`);
#
CREATE INDEX `IDX_LOG_7` ON `LOG` (`id_blacklist`);