Regalamiunsorriso/decompiled-libs/www/acxent-common-1.0.1/it/acxent/newsletter/CodaMessaggi.java

1361 lines
49 KiB
Java

package it.acxent.newsletter;
import it.acxent.cloudmsg.MsgJson;
import it.acxent.cloudmsg.PushNotificationService;
import it.acxent.common.Parm;
import it.acxent.common.StatusMsg;
import it.acxent.contab._ContabAdapter;
import it.acxent.db.AddImgInterface;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.mail.MailEmbededImages;
import it.acxent.mail.MailMessage;
import it.acxent.mail.MailProperties;
import it.acxent.rd.RemoteDevice;
import it.acxent.skebby.api.SmsSkebbyApi;
import it.acxent.skebby.api.SmsSkebbyApiResult;
import it.acxent.skebby.api.SmsSkebbyMessage;
import it.acxent.util.StringTokenizer;
import it.acxent.util.Timer;
import it.acxent.util.Vectumerator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Serializable;
import java.net.URLEncoder;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
public class CodaMessaggi extends _ContabAdapter implements AddImgInterface, Serializable {
private static final long serialVersionUID = -2936105636659716818L;
private String campiMail;
private long id_codaMessaggi;
private long flgTipo = 2L;
private long flgStatoInvio;
private Date dataCreazione;
private String testoMessaggio;
private String cellulare;
private String mailTo;
private String mailCc;
private String mailBcc;
private Date dataInvio;
private String result;
private String riferimento;
private String destinatario;
private String oggettoEmail;
private String imgTmst;
private String campagna;
private long id_templateMsg;
private TemplateMsg templateMsg;
private String tmstPrimaLettura;
private String tmstUltimaLettura;
private long nLetture;
private String ipPrimaLettura;
private String ipUltimaLettura;
private long id_remoteDevice;
private RemoteDevice remoteDevice;
public static boolean threadInvioCodaMessaggi = false;
public static String threadInvioCodaMessaggiMsg = "";
public static boolean threadCancellaCodaMessaggi = false;
public static String threadCancellaCodaMessaggiMsg = "";
public static boolean threadCreaCodaMessaggi = false;
public static String threadCreaCodaMessaggiMsg = "";
public static final int STATO_CODA_INVIATO = 1;
public static final int STATO_CODA_IN_CODA = 0;
public static final int STATO_CODA_ERRORE = 2;
public static final int STATO_CODA_IN_CODA_REMOTE_DEVICE = 3;
public static final int STATO_CODA_REMOTE_DEVICE_INVIATO_AL_GATEWAY = 4;
public static final int STATO_CODA_ANNULLATO = 9;
public static final int STATO_CODA_TUTTI = -1;
public static final int TIPO_MESSAGGIO_EMAIL = 1;
public static final int TIPO_MESSAGGIO_TUTTI = -1;
public static final int TIPO_MESSAGGIO_RD_SMS = 2;
public static final int TIPO_MESSAGGIO_RD_WHATSAPP = 3;
public static final int TIPO_MESSAGGIO_SKEBBY_SMS = 4;
public static final int TIPO_MESSAGGIO_REMOTE_DEVICE = 99;
class ThreadSendMsgs extends Thread {
private final CodaMessaggiCR CR;
public ThreadSendMsgs(CodaMessaggiCR l_CR) {
this.CR = l_CR;
if (this.CR.getFlgStatoInvio() != 2L)
this.CR.setFlgStatoInvio(0L);
if (!CodaMessaggi.isThreadAttivo())
if (this.CR.getFlgStatoInvio() < 0L || this.CR.getFlgStatoInvio() == 1L) {
CodaMessaggi.threadInvioCodaMessaggiMsg = "ATTENZIONE! TENTATIVO DI INVIARE TUTTI I MESSAGGI OPPURE QUELLI GIA' INVIATI<BR>Selezionare solo messaggi in coda, annullati o errati.";
} else {
CodaMessaggi.threadInvioCodaMessaggi = true;
CodaMessaggi.threadInvioCodaMessaggiMsg = "";
start();
}
}
public void run() {
HashMap<String, Long> mailInviateHM = new HashMap<>();
HashMap<String, Long> mailDoppioniHM = new HashMap<>();
long mailDoppione = 0L;
long mailInviate = 0L, numSms = 0L;
String TAG_THREAD_MSG = "INVIO MESSAGGI";
Timer timer = new Timer();
timer.start();
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "INVIO MESSAGGI", "...inizio ...");
try {
List<String> listRemoteDeviceToken = new ArrayList<>();
long numRecord = 0L;
long l_delayMsgEmail = CodaMessaggi.this.getParm("CODA_MESSAGGI_EMAIL_DELAY").getNumeroLong() * 1000L;
long l_delayMsgSms = 0L;
RemoteDevice rd = new RemoteDevice(CodaMessaggi.this.getApFull());
CodaMessaggi cm = new CodaMessaggi(CodaMessaggi.this.getApFull());
ResParm rp = new ResParm(true);
rd.findFirstAvailable();
listRemoteDeviceToken.add(rd.getFcmToken());
Vectumerator<CodaMessaggi> vec;
while ((vec = cm.findByCR(this.CR, 1, 500)).hasMoreElements()) {
while (vec.hasMoreElements()) {
numRecord++;
CodaMessaggi row = (CodaMessaggi)vec.nextElement();
if (row.getFlgTipo() == 4L) {
rp = CodaMessaggi.inviaSmsSkebby(row);
numSms++;
} else if (row.getFlgTipo() == 2L) {
if (rd.getId_remoteDevice() > 0L) {
row.setId_remoteDevice(rd.getId_remoteDevice());
row.setFlgStatoInvio(3L);
row.save();
numSms++;
} else {
row.setFlgStatoInvio(2L);
row.save();
}
} else if (row.getFlgTipo() == 3L) {
if (rd.getId_remoteDevice() > 0L) {
row.setId_remoteDevice(rd.getId_remoteDevice());
row.setFlgStatoInvio(3L);
row.save();
numSms++;
} else {
row.setFlgStatoInvio(2L);
row.save();
}
} else if (mailInviateHM.containsKey(row.getMailTo())) {
mailDoppione++;
System.out.println("MAILING LIST ERROR!! INVIO A MAIL GIA' PRESENTE: " + row.getId_codaMessaggi() + " " +
row.getMailTo() + " tot doppioni:" + mailDoppione);
mailDoppioniHM.put(row.getMailTo(), Long.valueOf(row.getId_codaMessaggi()));
row.setFlgStatoInvio(2L);
row.save();
} else {
mailInviate++;
mailInviateHM.put(row.getMailTo(), Long.valueOf(row.getId_codaMessaggi()));
rp = CodaMessaggi.inviaMessaggioMail(row);
}
CodaMessaggi.threadInvioCodaMessaggiMsg = "Attenzione! Thread invio coda messaggi esecuzione!!! Record processati: " + numRecord;
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "INVIO MESSAGGI", "Mail inviate: " + mailInviate + " Sms in coda: " + numSms + " ...");
if (vec.hasMoreElements()) {
if (row.getFlgTipo() == 2L) {
if (l_delayMsgSms > 0L) {
System.out.print("sleep....");
sleep(l_delayMsgSms);
}
continue;
}
if (l_delayMsgEmail != 0L) {
System.out.print("sleep....");
sleep(l_delayMsgEmail);
}
}
}
}
if (numSms <= 0L);
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "INVIO MESSAGGI", "Mail inviate: " + mailInviate + " Sms in coda: " + numSms + " ... chiamate al dispositivo remoto...");
String fileJsonAuth = CodaMessaggi.this.getParm("FIREBASE_JSON_AUTH_PRIVATE_KEY").getTesto();
PushNotificationService pns = new PushNotificationService(fileJsonAuth);
MsgJson notifica = new MsgJson("notification", "Sms Gateway: invio sms", "Ci sono sms da inviare...!");
MsgJson data = new MsgJson("notification", "Sms", "Ci sono " + numSms + " sms da inviare..");
pns.sendPushNotification(listRemoteDeviceToken, null, data, "smsgateway-f05ec");
} catch (Exception e) {
e.printStackTrace();
CodaMessaggi.this.handleDebug(e);
}
CodaMessaggi.threadInvioCodaMessaggi = false;
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Long> entry : mailDoppioniHM.entrySet()) {
sb.append("Key : " + (String)entry.getKey() + " Value : " + String.valueOf(entry.getValue()));
sb.append("\n");
System.out.println("Key : " + (String)entry.getKey() + " Value : " + String.valueOf(entry.getValue()));
}
if (sb.length() > 0)
CodaMessaggi.this.handleDebug("MAILING LIST ERROR!! INVIO A MAIL GIA' PRESENTI: tot doppioni:" + mailDoppione + "\n" + sb.toString(), 0);
timer.stop();
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "INVIO MESSAGGI", "FINE INVIO MESSAGGI! DURATA: " + timer.getDurataHourMin() + "<br>Mail inviate: " + mailInviate + " mail doppioni: " + mailDoppione + " Sms in coda: " + numSms);
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(CodaMessaggi.this.getApFull(), "INVIO MESSAGGI");
}
}
class ThreadCreaCodaMsgFile extends Thread {
private TemplateMsg templateMsg;
private String filename;
private ApplParmFull ap;
public ThreadCreaCodaMsgFile(TemplateMsg l_templateMsg, String l_filename, ApplParmFull l_ap) {
this.templateMsg = l_templateMsg;
this.filename = l_filename;
this.ap = l_ap;
if (!CodaMessaggi.isThreadAttivo()) {
CodaMessaggi.threadCreaCodaMessaggi = true;
start();
}
}
public void run() {
int numRecord = 0;
BufferedReader reader = null;
String currentLine = null;
String TAG_THREAD_MSG = "CREA CODA MESSAGGI DA FILE";
Timer timer = new Timer();
timer.start();
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA FILE", "...inizio ...");
System.out.println("##############\nCrea coda messaggi da file\nSTART: " + String.valueOf(timer.getTStart()));
try {
reader = new BufferedReader(new FileReader(this.filename));
while ((currentLine = reader.readLine()) != null) {
numRecord++;
CodaMessaggi cm = new CodaMessaggi(CodaMessaggi.this.getApFull());
cm.setFlgTipo(1L);
cm.setCampagna(this.templateMsg.getDescrizione());
cm.setMailTo(currentLine.trim());
cm.setOggettoEmail(this.templateMsg.getOggettoEmail());
cm.save();
cm.useTemplate(this.templateMsg, true);
CodaMessaggi.threadCreaCodaMessaggiMsg = "Attenzione! Thread creazione coda messaggi da file in esecuzione!!! Record processati: " + numRecord;
}
} catch (Exception e) {
e.printStackTrace();
CodaMessaggi.this.handleDebug(e);
}
timer.stop();
CodaMessaggi.this.handleDebug("Crea coda messaggi da file. Creati " + numRecord + " messaggi.", 4);
System.out.println("DURATA: " + timer.getDurataHourMin() + "\nCrea coda messaggi da file concluso\n****************");
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA FILE", "Crea coda messaggi da file. Creati " + numRecord + " messaggi. DURATA: " +
timer.getDurataHourMin());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA FILE");
CodaMessaggi.threadCreaCodaMessaggi = false;
}
}
class ThreadCreaCodaMessaggiByMailNewsletter extends Thread {
private MailNewsletterCR CR;
private long id_templateMsg;
public ThreadCreaCodaMessaggiByMailNewsletter(MailNewsletterCR CR, long id_templateMsg) {
synchronized (this) {
if (!CodaMessaggi.isThreadAttivo()) {
this.CR = CR;
this.id_templateMsg = id_templateMsg;
if (id_templateMsg > 0L) {
CodaMessaggi.threadCreaCodaMessaggi = true;
start();
}
}
}
}
public void run() {
long togliDuplicatiOgni = 1000L;
long numRecord = 0L;
String TAG_THREAD_MSG = "CREA CODA MESSAGGI DA Mail Newsletter";
Timer timer = new Timer();
timer.start();
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA Mail Newsletter", "...inizio ...");
System.out.println("##############\nCrea coda messaggi da MailNewsletter\nSTART: " + String.valueOf(timer.getTStart()));
ResParm rp = new ResParm(true);
MailNewsletter ml = new MailNewsletter(CodaMessaggi.this.getApFull());
int j = 0;
if (this.CR.getInizio() == 0L)
this.CR.setInizio(1L);
long tot = this.CR.getFine() - this.CR.getInizio();
int pagerow = 1000;
TemplateMsg ts = new TemplateMsg(CodaMessaggi.this.getApFull());
ts.findByPrimaryKey(this.id_templateMsg);
String campagna = ts.getDescrizione() + " " + ts.getDescrizione();
while ((long)j < tot / (long)pagerow + 1L) {
long inizio = (long)(j * pagerow) + this.CR.getInizio();
long fine = inizio + (long)pagerow - 1L;
if (fine > this.CR.getFine())
fine = this.CR.getFine();
if (fine <= inizio)
break;
System.out.println("da " + inizio + " a " + fine);
Vectumerator<MailNewsletter> vec = ml.findCodaByCR(this.CR, inizio, fine);
while (vec.hasMoreElements()) {
ml = (MailNewsletter)vec.nextElement();
if (!ml.getEMail().trim().isEmpty()) {
CodaMessaggi cm = new CodaMessaggi(CodaMessaggi.this.getApFull());
cm.setFlgTipo(1L);
cm.setCampagna(campagna);
cm.setMailTo(ml.getEMail().trim());
cm.setOggettoEmail(ts.getOggettoEmail());
cm.save();
cm.useTemplate(ts, true);
ml.setId_templateMsg(this.id_templateMsg);
ml.setDataTemplate(DBAdapter.getToday());
ml.save();
numRecord++;
CodaMessaggi.threadCreaCodaMessaggiMsg = "Attenzione! Thread creazione coda messaggi in esecuzione!!! Record processati: " + numRecord;
if (numRecord % 100L == 0L)
System.out.print(".");
if (numRecord % 1000L == 0L)
System.out.println(numRecord);
}
}
j++;
}
timer.stop();
CodaMessaggi.this.handleDebug("Creata coda mail per template " + this.id_templateMsg + ". Tot record creati: " + numRecord, 1);
System.out.println("DURATA: " + timer.getDurataHourMin() + "\nCrea coda messaggi da MailNewsletter concluso\n****************");
CodaMessaggi.threadCreaCodaMessaggi = false;
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA Mail Newsletter", "Crea coda messaggi da MailNewsletter concluso. DURATA: " +
timer.getDurataHourMin());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA Mail Newsletter");
}
}
class ThreadCancellaCodaMsg extends Thread {
private CodaMessaggiCR CR;
public ThreadCancellaCodaMsg(CodaMessaggiCR CR) {
this.CR = CR;
if (!CodaMessaggi.isThreadAttivo()) {
CodaMessaggi.threadCancellaCodaMessaggi = true;
start();
}
}
public void run() {
BufferedReader reader = null;
String currentLine = null;
String TAG_THREAD_MSG = "CREA CODA MESSAGGI DA Mail Newsletter";
Timer timer = new Timer();
timer.start();
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA Mail Newsletter", "...inizio ...");
System.out.println("##############\nCANCELLAZIONE coda messaggi\nSTART: " + String.valueOf(timer.getTStart()));
ResParm rp = new ResParm(true);
CodaMessaggi bean = new CodaMessaggi(CodaMessaggi.this.getApFull());
int nrighe = 100;
int msgCancellati = 0;
Vectumerator<CodaMessaggi> vec;
while ((vec = bean.findByCR(this.CR, 1, nrighe)).hasMoreElements()) {
while (vec.hasMoreElements()) {
CodaMessaggi row = (CodaMessaggi)vec.nextElement();
row.delete();
msgCancellati++;
CodaMessaggi.threadCancellaCodaMessaggiMsg = "Attenzione! Thread CANCELLAZIONE coda messaggi da file in esecuzione!!! Record processati: " + msgCancellati;
}
}
timer.stop();
CodaMessaggi.this.handleDebug("CANCELLAZIONE coda messaggi da file. CANCELLATI " + msgCancellati + " record.", 4);
System.out.println("DURATA: " + timer.getDurataHourMin() + "\nCANCELLAZIONE coda messaggi concluso\n****************");
CodaMessaggi.threadCancellaCodaMessaggi = false;
StatusMsg.updateMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA Mail Newsletter", "Cancellazione coda messaggi concluso. DURATA: " +
timer.getDurataHourMin());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(CodaMessaggi.this.getApFull(), "CREA CODA MESSAGGI DA Mail Newsletter");
}
}
public CodaMessaggi(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public CodaMessaggi() {}
public void setId_codaMessaggi(long newId_codaInvio) {
this.id_codaMessaggi = newId_codaInvio;
}
public void setFlgTipo(long newFlgTipo) {
this.flgTipo = newFlgTipo;
}
public void setFlgStatoInvio(long newFlgStatoInvio) {
this.flgStatoInvio = newFlgStatoInvio;
}
public void setDataCreazione(Date newDataCreazione) {
this.dataCreazione = newDataCreazione;
}
public void setTestoMessaggio(String newMessaggio) {
this.testoMessaggio = newMessaggio;
}
public void setCellulare(String newCellulare) {
this.cellulare = newCellulare;
}
public void setMailTo(String newMailTo) {
this.mailTo = newMailTo;
}
public void setMailCc(String newMailCc) {
this.mailCc = newMailCc;
}
public void setMailBcc(String newMailBcc) {
this.mailBcc = newMailBcc;
}
public long getId_codaMessaggi() {
return this.id_codaMessaggi;
}
public long getFlgTipo() {
return this.flgTipo;
}
public long getFlgStatoInvio() {
return this.flgStatoInvio;
}
public Date getDataCreazione() {
return this.dataCreazione;
}
public String getTestoMessaggio() {
return (this.testoMessaggio == null) ? "" : this.testoMessaggio.trim();
}
public ResParm useTemplate(TemplateMsg l_ts, boolean soloTemplate) {
ResParm rp = new ResParm(true);
if (l_ts.getId_templateMsg() > 0L && l_ts.getFlgTipo() == 1L) {
setId_templateMsg(0L);
for (int i = 1; i <= 10; i++)
new File(getDocBase() + getDocBase() + getPathImg()).delete();
setId_templateMsg(l_ts.getId_templateMsg());
if (soloTemplate) {
setOggettoEmail(l_ts.getOggettoEmail());
setTestoMessaggio("");
}
rp = save();
} else {
rp.setMsg("ERRORE! template non valido!");
rp.setStatus(false);
}
return rp;
}
public String getMailTo() {
return (this.mailTo == null) ? "" : this.mailTo.trim();
}
public String getMailCc() {
return (this.mailCc == null) ? "" : this.mailCc.trim();
}
public String getMailBcc() {
return (this.mailBcc == null) ? "" : this.mailBcc.trim();
}
public Vectumerator findByEmailTemplateMsg(String l_email, long l_id_template, int pageNumber, int pageRows) {
StringBuffer s_Sql_Find = new StringBuffer("select A.* from CODA_MESSAGGI AS A");
String s_Sql_Order = " order by dataInvio desc";
WcString wc = new WcString();
wc.addWc("A.mailTo like '%" + l_email + "%'");
wc.addWc("A.id_templateMsg=" + l_id_template);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Date getDataInvio() {
return this.dataInvio;
}
public void setDataInvio(Date dataInvio) {
this.dataInvio = dataInvio;
}
public static final String getStatoInvio(long l_flgStatoInvio) {
switch ((int)l_flgStatoInvio) {
case 0:
return "In coda";
case 3:
return "In coda per Remote Device";
case 1:
return "Inviato";
case 9:
return "Annullato";
case 2:
return "Errore";
case 4:
return "Messaggio inviato al gateway";
case -1:
return "Tutti";
}
return "??";
}
public String getStatoInvio() {
return getStatoInvio(getFlgStatoInvio());
}
public String getStatoInvioCompleto() {
StringBuilder sb = new StringBuilder(getStatoInvio(getFlgStatoInvio()));
if (getFlgStatoInvio() == 3L || getFlgStatoInvio() == 4L) {
sb.append(" --> device remoto: ");
sb.append(getRemoteDevice().getDescrizione());
}
return sb.toString();
}
public String getDestinatario() {
return (this.destinatario == null) ? "" : this.destinatario.trim();
}
public String getResult() {
return (this.result == null) ? "" : this.result;
}
public void setResult(String result) {
this.result = result;
}
public static final String getTipo(long l_flgTipo) {
switch ((int)l_flgTipo) {
case 2:
return "Sms";
case 1:
return "Email";
case 3:
return "WA TEST";
case 4:
return "SMS skebby";
case -1:
return "Tutti";
}
return "??";
}
public String getTipo() {
return getTipo(getFlgTipo());
}
public String getRiferimento() {
return this.riferimento;
}
public void setRiferimento(String riferimento) {
this.riferimento = riferimento;
}
public ResParm save() {
if (getDataCreazione() == null)
setDataCreazione(getToday());
if (getFlgStatoInvio() == 3L && getId_remoteDevice() == 0L)
setFlgStatoInvio(2L);
return super.save();
}
public static final synchronized ResParm inviaMessaggioMail(CodaMessaggi bean) {
ResParm rp = new ResParm(true);
String res = "";
boolean useOpenTag = (bean.getParm("CODA_MESSAGGI_USE_OPEN_TAG").getNumeroLong() == 1L);
boolean useEmbedded = (bean.getParm("CODA_MESSAGGI_USE_EMBEDDED_IMG").getNumeroLong() == 1L);
MailProperties mp = new MailProperties();
mp.put("TO", bean.getMailTo());
mp.put("FROM", bean.getParm("CODA_MESSAGGI_MAIL_FROM").getTesto());
mp.put("SUBJECT", bean.getOggettoEmail());
mp.put("ISHTML", "true");
if (useEmbedded) {
StringBuffer l_msg = new StringBuffer();
String l_tmp = bean.getMessaggioDaInviare();
int idxStart = 0;
int idxImg = 0;
int idxSrcRel = 0;
int idxSrcAbsStart = 0;
int idxSrcAbsStop = 0;
int idxCid = 0;
Vectumerator embed = new Vectumerator();
while ((idxImg = l_tmp.indexOf("<img")) >= 0) {
idxSrcRel = l_tmp.substring(idxImg).indexOf("src=\"");
if (idxSrcRel < 0)
return new ResParm(false, "Impossibile creare immagini embedded");
idxSrcAbsStart = idxImg + idxSrcRel;
l_msg.append(l_tmp.substring(idxStart, idxSrcAbsStart));
l_msg.append(" src=\"cid:imagePart_" + idxCid + "\"");
idxSrcRel = l_tmp.substring(idxSrcAbsStart + 5).indexOf("\"");
idxSrcAbsStop = idxSrcAbsStart + idxSrcRel;
String src = l_tmp.substring(idxSrcAbsStart + 5, idxSrcAbsStop + 5);
idxSrcRel = src.lastIndexOf("/");
String filename = src.substring(idxSrcRel + 1);
String absFilename = bean.getDocBase() + bean.getDocBase() + bean.getPathImg();
l_tmp = l_tmp.substring(idxSrcAbsStop + 5 + 1);
embed.add(new MailEmbededImages(absFilename, "imagePart_" + idxCid, filename));
idxCid++;
}
l_msg.append(l_tmp);
l_msg.insert(0, "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>Mail Message</title></head><body style=\"margin:0; padding:0\">");
l_msg.append("</body></html>");
MailMessage mmCampi = new MailMessage(bean.getApFull());
mmCampi.setTextMessage(l_msg.toString());
mmCampi.setString("email", bean.getMailTo());
try {
mmCampi.setString("emailUrl", URLEncoder.encode(bean.getMailTo(), "UTF-8"));
} catch (Exception e) {}
if (!bean.getCampiMail().isEmpty()) {
StringTokenizer st = new StringTokenizer(bean.getCampiMail(), "|");
int i = 1;
while (st.hasMoreTokens()) {
String campo = st.nextToken();
mmCampi.setString("campo" + i, campo);
i++;
}
}
mp.put("MSG", mmCampi.getMessageGtLt());
StringBuffer fileNames = new StringBuffer();
if (bean.getId_templateMsg() == 0L) {
Vectumerator vec = bean.getAllegati();
while (vec.hasMoreElements()) {
AllegatoCodaMessaggi rowCS = (AllegatoCodaMessaggi)vec.nextElement();
fileNames.append(rowCS.getNomeFileCompleto());
if (vec.hasMoreElements())
fileNames.append(",");
}
} else {
Vectumerator vec = bean.getTemplateMsg().getAllegati();
while (vec.hasMoreElements()) {
AllegatoTemplateMsg rowCS = (AllegatoTemplateMsg)vec.nextElement();
fileNames.append(rowCS.getNomeFileCompleto());
if (vec.hasMoreElements())
fileNames.append(",");
}
}
if (!fileNames.toString().trim().isEmpty())
mp.put("FILES", fileNames.toString());
MailMessage mm = new MailMessage(bean.getApFull());
if (embed.getTotNumberOfRecords() == 0) {
rp = mm.sendMailMessage(mp, false);
} else {
rp = mm.sendMailMessageEmbedded(mp, embed);
}
} else {
String l_urlImg = bean.getParm("CODA_MESSAGGI_IMG_URL_BASE").getTesto();
String l_msg = bean.getMessaggioDaInviare();
int idx;
while ((idx = l_msg.indexOf("../")) >= 0)
l_msg = l_msg.substring(0, idx) + l_msg.substring(0, idx);
l_msg = l_msg.replaceAll("\"_img/_imgMsg", "\"" + l_urlImg + "_img/_imgMsg");
l_msg = l_msg.replaceAll("\"/_img/_imgMsg", "\"" + l_urlImg + "_img/_imgMsg");
l_msg = l_msg.replaceAll("href=\"/", "href=\"" + l_urlImg);
if (useOpenTag) {
String tmpTag = "<br><img src='" + l_urlImg + "_img/_imgMsg/logo/logo_" + bean.getId_codaMessaggi() + ".png' alt='AblMlst' width='5'>";
l_msg = l_msg + l_msg;
}
l_msg = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>Mail Message</title></head><body style=\"margin:0; padding:0\">" + l_msg.toString() + "</body></html>";
MailMessage mmCampi = new MailMessage(bean.getApFull());
mmCampi.setTextMessage(l_msg.toString());
mmCampi.setString("email", bean.getMailTo());
try {
mmCampi.setString("emailUrl", URLEncoder.encode(bean.getMailTo(), "UTF-8"));
} catch (Exception e) {}
if (!bean.getCampiMail().isEmpty()) {
StringTokenizer st = new StringTokenizer(bean.getCampiMail(), "|");
mmCampi.setTextMessage(l_msg.toString());
int i = 1;
while (st.hasMoreTokens()) {
String campo = st.nextToken();
mmCampi.setString("campo" + i, campo);
i++;
}
}
mp.put("MSG", mmCampi.getMessageGtLt());
StringBuffer fileNames = new StringBuffer();
if (bean.getId_templateMsg() == 0L) {
Vectumerator vec = bean.getAllegati();
while (vec.hasMoreElements()) {
AllegatoCodaMessaggi rowCS = (AllegatoCodaMessaggi)vec.nextElement();
fileNames.append(rowCS.getNomeFileCompleto());
if (vec.hasMoreElements())
fileNames.append(",");
}
} else {
Vectumerator vec = bean.getTemplateMsg().getAllegati();
while (vec.hasMoreElements()) {
AllegatoTemplateMsg rowCS = (AllegatoTemplateMsg)vec.nextElement();
fileNames.append(rowCS.getNomeFileCompleto());
if (vec.hasMoreElements())
fileNames.append(",");
}
}
if (!fileNames.toString().trim().isEmpty())
mp.put("FILES", fileNames.toString());
MailMessage mm = new MailMessage(bean.getApFull());
Calendar cal = Calendar.getInstance();
Timestamp ts = new Timestamp(cal.getTimeInMillis());
System.out.println("#-#-#- " + ts.toString() + " invio messaggio a " + bean.getMailTo());
rp = mm.sendMailMessage(mp, false);
}
if (!rp.getStatus()) {
String msg = bean.getDataFormat().format(getToday()) + " " + bean.getDataFormat().format(getToday());
if (bean.getResult().length() > 0) {
bean.setResult(bean.getResult() + "<br>" + bean.getResult());
} else {
bean.setResult(msg);
}
bean.setFlgStatoInvio(2L);
bean.save();
} else {
bean.setFlgStatoInvio(1L);
bean.setDataInvio(getToday());
rp.append(bean.save());
}
return rp;
}
public synchronized ResParm inviaMessaggiAll(CodaMessaggiCR CR) {
if (!isThreadAttivo()) {
new ThreadSendMsgs(CR);
return new ResParm(true, "Thread invio messaggi avviato....<br>" + threadInvioCodaMessaggiMsg);
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public void setDestinatario(String destinatario) {
this.destinatario = destinatario;
}
public String getDestinatarioCompleto() {
if (isSmsMessage())
return getDestinatario() + " cell. " + getDestinatario();
return getDestinatario() + " mail. " + getDestinatario();
}
protected void initFields() {
super.initFields();
setFlgTipo(2L);
}
public String getOggettoEmail() {
return (this.oggettoEmail == null) ? "" : this.oggettoEmail.trim();
}
public void setOggettoEmail(String oggettoEmail) {
this.oggettoEmail = oggettoEmail;
}
protected int getStringValueCase(String name) {
if ((name != null && name.startsWith("mail")) || name.equals("testoMessaggio"))
return 0;
return super.getStringValueCase(name);
}
public String getImgFileName(int imgNumber) {
return getImgFileName(imgNumber, getImgTmst());
}
public String getImgFileName(int imgNumber, String oldTmst) {
if (getId_templateMsg() == 0L)
return "CM_" + getId_codaMessaggi() + "_" + oldTmst + "_" + imgNumber + ".jpg";
return getTemplateMsg().getImgFileName(imgNumber, oldTmst);
}
public String getImgTmst() {
return (this.imgTmst == null) ? "" : this.imgTmst;
}
public void setImgTmst(String imgTmst) {
this.imgTmst = imgTmst;
}
public static boolean isThreadAttivo() {
return (threadCancellaCodaMessaggi || threadCreaCodaMessaggi || threadInvioCodaMessaggi || MailNewsletter.threadAddMailsFromFile);
}
public void setCampagna(String campagna) {
this.campagna = campagna;
}
public String getCellulare() {
return (this.cellulare == null) ? "" : this.cellulare.trim();
}
public long getId_templateMsg() {
return this.id_templateMsg;
}
public void setId_templateMsg(long id_templateMsg) {
this.id_templateMsg = id_templateMsg;
setTemplateMsg(null);
}
public TemplateMsg getTemplateMsg() {
this.templateMsg = (TemplateMsg)getSecondaryObject(this.templateMsg, TemplateMsg.class, getId_templateMsg());
return this.templateMsg;
}
public void setTemplateMsg(TemplateMsg templateMsg) {
this.templateMsg = templateMsg;
}
public static synchronized void addLettura(CodaMessaggi bean, String l_ip) {
if (bean.getId_codaMessaggi() != 0L) {
Timestamp currentTmst = new Timestamp(System.currentTimeMillis());
if (bean.getTmstPrimaLettura().isEmpty()) {
bean.setTmstPrimaLettura(currentTmst.toString());
bean.setIpPrimaLettura(l_ip);
}
bean.setTmstUltimaLettura(currentTmst.toString());
bean.setIpUltimaLettura(l_ip);
bean.setNLetture(bean.getNLetture() + 1L);
bean.save();
}
}
private void findByCRCreateStmtDate(CodaMessaggiCR CR, PreparedStatement stmt) {}
private void findByCRCreateWC(CodaMessaggiCR CR, StringBuffer s_Sql_Find, WcString wc) {
if (CR.getId_codaMessaggiS() != 0L) {
wc.addWc("A.id_codaMessaggi=" + CR.getId_codaMessaggiS());
} else {
if (!CR.getSearchTxt().trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = st.nextToken();
txt.append("(A.destinatario like '%" + token + "%' or A.cellulare like '%" + token + "%' or A.mailTo like '%" + token + "%')");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
if (!CR.getCampagna().isEmpty())
wc.addWc("A.campagna like'%" + CR.getCampagna() + "%'");
if (CR.getFlgTipo() == 0L) {
wc.addWc("(A.flgTipo is null or flgTipo=0)");
} else if (CR.getFlgTipo() == 99L) {
wc.addWc("(A.flgTipo =2 OR A.flgTipo =3)");
} else if (CR.getFlgTipo() > 0L) {
wc.addWc("A.flgTipo =" + CR.getFlgTipo());
}
}
if (CR.getFlgStatoInvio() == 0L) {
wc.addWc("(A.flgStatoInvio is null or flgStatoInvio=0)");
} else if (CR.getFlgStatoInvio() > 0L) {
wc.addWc("A.flgStatoInvio =" + CR.getFlgStatoInvio());
}
}
private int findByCRTotRecord(CodaMessaggiCR CR) {
StringBuffer s_Sql_Find = new StringBuffer("select count(*) as tot from CODA_MESSAGGI AS A ");
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
findByCRCreateStmtDate(CR, stmt);
return (int)getTots(stmt);
} catch (Exception e) {
handleDebug(e);
return 0;
}
}
protected void deleteCascade() {
if (getId_templateMsg() == 0L)
for (int i = 1; i <= 4; i++)
new File(getDocBase() + getDocBase() + getPathImg()).delete();
}
public final ResParm cancellazioneMassiva(CodaMessaggiCR CR) {
if (!isThreadAttivo()) {
new ThreadCancellaCodaMsg(CR);
return new ResParm(true, "Thread CANCELLAZIONE coda messaggi avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public ResParm detachTemplate(int numImmagini) {
ResParm rp = new ResParm(true);
if (getId_templateMsg() == 0L) {
rp.setStatus(false);
rp.setMsg("Attenzione! Il presente testoMessaggio non ha template associati!");
} else {
TemplateMsg l_ts = getTemplateMsg();
if (l_ts.getId_templateMsg() > 0L && l_ts.getFlgTipo() == 1L) {
setId_templateMsg(0L);
for (int i = 1; i <= numImmagini; i++)
new File(getDocBase() + getDocBase() + getPathImg()).delete();
String temp = l_ts.getTestoMessaggio();
setImgTmst(l_ts.getImgTmst());
for (int j = 1; j <= numImmagini; j++) {
try {
copyFile(getDocBase() + getDocBase() + getPathImg(), getDocBase() + getDocBase() + getPathImg());
temp = temp.replaceAll(l_ts.getImgFileName(j), getImgFileName(j));
} catch (Exception e) {
rp.setException(e);
rp.setStatus(false);
}
}
setTestoMessaggio(temp);
rp = save();
} else {
rp.setMsg("ERRORE! template non valido!");
rp.setStatus(false);
}
}
return rp;
}
public String getTmstPrimaLettura() {
return (this.tmstPrimaLettura == null) ? "" : this.tmstPrimaLettura.trim();
}
public void setTmstPrimaLettura(String tmstPrimaLettura) {
this.tmstPrimaLettura = tmstPrimaLettura;
}
public String getTmstUltimaLettura() {
return (this.tmstUltimaLettura == null) ? "" : this.tmstUltimaLettura.trim();
}
public void setTmstUltimaLettura(String tmstUltimaLettura) {
this.tmstUltimaLettura = tmstUltimaLettura;
}
public long getNLetture() {
return this.nLetture;
}
public void setNLetture(long nLetture) {
this.nLetture = nLetture;
}
public String getIpPrimaLettura() {
return (this.ipPrimaLettura == null) ? "" : this.ipPrimaLettura.trim();
}
public void setIpPrimaLettura(String ipPrimaLettura) {
this.ipPrimaLettura = ipPrimaLettura;
}
public String getIpUltimaLettura() {
return (this.ipUltimaLettura == null) ? "" : this.ipUltimaLettura.trim();
}
public void setIpUltimaLettura(String ipUltimaLettura) {
this.ipUltimaLettura = ipUltimaLettura;
}
public final ResParm creaCodaMessaggi(TemplateMsg l_templateMsg, String l_filename) {
if (!isThreadAttivo()) {
new ThreadCreaCodaMsgFile(l_templateMsg, l_filename, getApFull());
return new ResParm(true, "Thread crea coda email tramite file e template avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public ResParm updateStatoMessaggi(long l_flgOldStato, long l_flgNewStato) {
ResParm rp = new ResParm(true);
String s_sqString = " update CODA_MESSAGGI SET flgStatoInvio=" + l_flgNewStato + " where flgStatoInvio=" + l_flgOldStato;
rp = update(s_sqString);
return rp;
}
public Vectumerator<CodaMessaggi> findByCR(CodaMessaggiCR CR, int pageNumber, int pageRows) {
StringBuffer s_Sql_Find = new StringBuffer("select A.* from CODA_MESSAGGI AS A");
String s_Sql_Order = " order by A.dataCreazione desc, A.mailTo";
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
findByCRCreateStmtDate(CR, stmt);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ResParm addAllegato(AllegatoCodaMessaggi row) {
AllegatoCodaMessaggi bean = new AllegatoCodaMessaggi(getApFull());
bean.findByCodaMessaggiNomeFile(row.getId_codaMessaggi(), 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(AllegatoCodaMessaggi row) {
AllegatoCodaMessaggi bean = new AllegatoCodaMessaggi(getApFull());
bean.findByPrimaryKey(row.getId_allegatoCodaMessaggi());
return bean.delete();
}
public static void initApplicationParms(ApplParmFull ap) {
boolean debug = false;
if (ap != null) {
DBAdapter.logDebug(debug, "Coda Messaggi initParms: start");
String l_tipoParm = "";
Parm bean = new Parm(ap);
l_tipoParm = "CODA MESSAGGI - NEWSLETTER";
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
bean.findByCodice("CODA_MESSAGGI_USE_EMBEDDED_IMG");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_USE_EMBEDDED_IMG");
bean.setDescrizione("CODA_MESSAGGI_USE_EMBEDDED_IMG");
bean.setFlgTipo(5L);
bean.setNota("0:NO<BR>1:SI");
bean.save();
bean.findByCodice("CODA_MESSAGGI_USE_OPEN_TAG");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_USE_OPEN_TAG");
bean.setDescrizione("CODA_MESSAGGI_USE_OPEN_TAG");
bean.setFlgTipo(5L);
bean.setNota("0:NO<BR>1:SI");
bean.save();
bean.findByCodice("CODA_MESSAGGI_PATH_IMG_MSG");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_PATH_IMG_MSG");
bean.setDescrizione("CODA_MESSAGGI_PATH_IMG_MSG");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("_img/_imgMsg/");
bean.setNota("Path relativo a docbase che finisce con /");
bean.save();
bean.findByCodice("CODA_MESSAGGI_EMAIL_DELAY");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_EMAIL_DELAY");
bean.setDescrizione("CODA_MESSAGGI_EMAIL_DELAY");
bean.setFlgTipo(1L);
bean.setNota("RITARDO DI INVIO IN SECONDI TRA UNA MAIL E L'ALTRA.<BR>O: NESSUN RITARDO");
bean.save();
bean.findByCodice("CODA_MESSAGGI_SMS_DELAY");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_SMS_DELAY");
bean.setDescrizione("CODA_MESSAGGI_SMS_DELAY");
bean.setFlgTipo(1L);
if (bean.getNumero() == 0.0D)
bean.setNumero(2.0D);
bean.setNota("RITARDO DI INVIO IN SECONDI TRA UN SMS E L'ALTRO.<BR>O: NESSUN RITARDO");
bean.save();
bean.findByCodice("CODA_MESSAGGI_IMG_URL_BASE");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_IMG_URL_BASE");
bean.setDescrizione("CODA_MESSAGGI_IMG_URL_BASE");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("http://www.sitoweb.com/");
bean.setNota("URL DI BASE PER IMMAGINI NELLE EMAIL.");
bean.save();
bean.findByCodice("CODA_MESSAGGI_MAIL_FROM");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_MAIL_FROM");
bean.setDescrizione("CODA_MESSAGGI_MAIL_FROM");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("newsletter@miodomini.com");
bean.setNota("MAIL FROM UTILIZZATO DA CODA MESSAGGI");
bean.save();
bean.findByCodice("MAIL_INVIO_DOC");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("MAIL_INVIO_DOC");
bean.setDescrizione("MAIL_INVIO_DOC");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("mail@dominio.com");
bean.setNota("INDIRIZZO EMAIL DIDEFAULT PER INVIO DOCUMENTI");
bean.save();
bean.findByCodice("CODA_MESSAGGI_ATTACH_PATH");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("CODA_MESSAGGI_ATTACH_PATH");
bean.setDescrizione("CODA_MESSAGGI_ATTACH_PATH");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("_attach/_codaMessaggi/");
bean.setNota("Path x attach coda messaggi relativo a docbase che finisce con /");
bean.save();
bean.findByCodice("TMPL_MSG_ATTACH_PATH");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("TMPL_MSG_ATTACH_PATH");
bean.setDescrizione("TMPL_MSG_ATTACH_PATH");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("_attach/_templateMessaggi/");
bean.setNota("Path x attach template messaggi relativo a docbase che finisce con /");
bean.save();
DBAdapter.logDebug(debug, "Coda Messaggi initParms: stop");
}
}
public String getPathAllegato() {
return getDocBase() + getDocBase();
}
public Vectumerator getAllegati() {
return new AllegatoCodaMessaggi(getApFull()).findByCodaMessaggi(getId_codaMessaggi(), 0, 0);
}
public String getCampiMail() {
return (this.campiMail == null) ? "" : this.campiMail.trim();
}
public void setCampiMail(String campiMail) {
this.campiMail = campiMail;
}
public final ResParm creaCodaMessaggi(MailNewsletterCR CR, long id_templateMsg) {
if (!isThreadAttivo()) {
new ThreadCreaCodaMessaggiByMailNewsletter(CR, id_templateMsg);
return new ResParm(true, "Thread crea coda email tramite MailNewsletter avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public String getCampagna() {
return (this.campagna == null) ? "" : this.campagna.trim();
}
public String getMessaggioDaInviare() {
if (getId_templateMsg() == 0L)
return getTestoMessaggio();
if (getTestoMessaggio().isEmpty())
return getTemplateMsg().getTestoMessaggio();
return getTestoMessaggio();
}
public String getTestoMessaggioScript() {
return DBAdapter.prepareScriptString(getTestoMessaggio(), true, false);
}
public ResParm addCodaMessaggioByTemplate(String l_email, TemplateMsg l_templateMessage) {
ResParm rp = new ResParm(true);
if (getApFull() != null) {
if (!l_email.isEmpty()) {
CodaMessaggi cm = new CodaMessaggi(getApFull());
cm.setFlgTipo(l_templateMessage.getFlgTipo());
String campagna = l_templateMessage.getDescrizione() + " " + l_templateMessage.getDescrizione();
cm.setCampagna(campagna);
cm.setMailTo(l_email.trim());
cm.setOggettoEmail(l_templateMessage.getOggettoEmail());
rp = cm.save();
if (rp.getStatus())
rp = cm.useTemplate(l_templateMessage, true);
} else {
rp.setStatus(true);
rp.setMsg("Attenzione! email vuota!");
}
} else {
rp.setStatus(false);
rp.setMsg("ERRORE! Parametri db assenti!");
}
return rp;
}
public long getId_remoteDevice() {
return this.id_remoteDevice;
}
public void setId_remoteDevice(long id_remoteDevice) {
this.id_remoteDevice = id_remoteDevice;
setRemoteDevice(null);
}
public RemoteDevice getRemoteDevice() {
this.remoteDevice = (RemoteDevice)getSecondaryObject(this.remoteDevice, RemoteDevice.class, getId_remoteDevice());
return this.remoteDevice;
}
public void setRemoteDevice(RemoteDevice remoteDevice) {
this.remoteDevice = remoteDevice;
}
public JSONObject getJsonSmsRecord() {
JSONObject jo = new JSONObject();
jo.put("id_codaMessaggi", getId_codaMessaggi());
jo.put("cellulare", getCellulare());
jo.put("testoMessaggio", getTestoMessaggio());
return jo;
}
public Vectumerator<CodaMessaggi> findByCROLD(CodaMessaggiCR CR, int pageNumber, int pageRows) {
boolean flgOttimizzo = false;
int start = 0;
int stop = 0;
if (getApFull().getDbType() == 5 || getApFull().getDbType() == 3 ||
getApFull().getDbType() == 17 ||
getApFull().getDbType() == 14 ||
getApFull().getDbType() == 13)
flgOttimizzo = true;
if (pageNumber == 0 && pageRows == 0) {
flgOttimizzo = false;
} else {
if (pageNumber == 0)
pageNumber = 1;
start = (pageNumber - 1) * pageRows;
stop = start + pageRows;
}
StringBuffer s_Sql_Find = new StringBuffer("select A.* from CODA_MESSAGGI AS A");
if (flgOttimizzo && (getApFull().getDbType() == 14 ||
getApFull().getDbType() == 13))
s_Sql_Find = new StringBuffer("select TOP " + stop + " A.* from CODA_MESSAGGI AS A");
String s_Sql_Order = " order by A.dataCreazione desc, A.mailTo";
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt;
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
} else if (getApFull().getDbType() != 14 &&
getApFull().getDbType() != 13) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + " limit " + s_Sql_Order + "," + start);
} else {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
}
findByCRCreateStmtDate(CR, stmt);
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo)
return findRows(stmt, pageNumber, pageRows);
if (getApFull().getDbType() == 14 ||
getApFull().getDbType() == 13) {
Vectumerator<CodaMessaggi> vectumerator = findRows(stmt, pageNumber, pageRows);
vectumerator.setPageNumber(pageNumber);
if (stop >= vectumerator.getTotNumberOfRecords() - 1)
vectumerator.setTotNumberOfRecords(findByCRTotRecord(CR));
return vectumerator;
}
Vectumerator<CodaMessaggi> vec = findRows(stmt, 1, pageRows);
vec.setPageNumber(pageNumber);
vec.setTotNumberOfRecords(findByCRTotRecord(CR));
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public boolean isSmsMessage() {
if (getFlgTipo() == 2L || getFlgTipo() == 3L ||
getFlgTipo() == 4L)
return true;
return false;
}
public String getPathImg() {
return getParm("CODA_MESSAGGI_PATH_IMG_MSG").getTesto();
}
public static final synchronized ResParm inviaSmsSkebby(CodaMessaggi bean) {
ResParm rp = new ResParm(true);
SmsSkebbyApi skApi = new SmsSkebbyApi(bean.getApFull());
String numero = bean.getCellulare();
if (!numero.startsWith("+39"))
numero = "+39" + numero;
SmsSkebbyMessage smsMesg = new SmsSkebbyMessage(numero, bean.getTestoMessaggio());
SmsSkebbyApiResult resF = skApi._sendMessage(smsMesg);
if (!resF.isOk()) {
String msg = bean.getDataFormat().format(getToday()) + " " + bean.getDataFormat().format(getToday());
if (bean.getResult().length() > 0) {
bean.setResult(bean.getResult() + "<br>" + bean.getResult());
} else {
bean.setResult(msg);
}
bean.setFlgStatoInvio(2L);
bean.save();
} else {
bean.setFlgStatoInvio(1L);
String msg = bean.getDataFormat().format(getToday()) + " " + bean.getDataFormat().format(getToday());
if (bean.getResult().length() > 0) {
bean.setResult(bean.getResult() + "<br>" + bean.getResult());
} else {
bean.setResult(msg);
}
bean.setDataInvio(getToday());
rp.append(bean.save());
}
return rp;
}
}