Regalamiunsorriso/decompiled-libs/www/cli-rus-2.1.9/it/acxent/pg/Foto.java

1534 lines
69 KiB
Java

package it.acxent.pg;
import it.acxent.common.StatusMsg;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.dm.FaceDetectionMethod;
import it.acxent.face.FotoI;
import it.acxent.util.ScaleImage;
import it.acxent.util.SimpleDateFormat;
import it.acxent.util.Timer;
import it.acxent.util.UploadFile;
import it.acxent.util.UploadFileBeanInterface;
import it.acxent.util.UploadFileCallable;
import it.acxent.util.Vectumerator;
import java.io.File;
import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class Foto extends _PgAdapter implements Serializable, UploadFileBeanInterface, FotoI {
private String thFotoRidotta;
private String thFotoRidottaTN;
private String thPercorsoRemoto;
public static final String SEP_PETTORALE = ",";
private long id_foto;
private String file;
private long impression;
private Date dataUltimaVisual;
private long id_gara;
private long id_puntoFoto;
private PuntoFoto puntoFoto;
private String pettorali;
private long flgFotoInviata;
private long flgPettoraleInviato;
private long id_fotoExport;
private String pettoraliOld;
class ThreadCreaPreview extends Thread {
private PuntoFoto puntoFoto;
public ThreadCreaPreview(PuntoFoto puntoFoto) {
this.puntoFoto = puntoFoto;
if (!Foto.isThreadAttivo()) {
Foto.threadInvioFotoWww = true;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "CREAZIONE PREVIEW";
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
int i = 0;
int se1 = 10;
int se2 = 100;
int fotoInviate = 0, fotoErrate = 0;
try {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "...inizio ...");
Foto.threadInvioFotoWwwMsg = "Attenzione! Thread CREAZIONE PREVIEW in esecuzione!!! ";
if (debug)
System.out.println("CREAZIONE PREVIEW " + Foto.threadInvioFotoWwwMsg);
if (this.puntoFoto.getId_puntoFoto() > 0L) {
Foto foto = new Foto(this.puntoFoto.getApFull());
FotoCR fotoCR = new FotoCR();
fotoCR.setId_puntoFoto(this.puntoFoto.getId_puntoFoto());
Vectumerator<Foto> vec = foto.findByCR(fotoCR, 0, 0);
while (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
String fotoRidotta = row.getFileNameRidottaPercorsoCompleto();
String fileNameRidotta = row.getFileNameReale();
String dirRidotte = row.getDirRidottaPercorsoCompleto();
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW",
row.getFileNamePercorsoCompleto() + " --> " + row.getFileNamePercorsoCompleto() + "#" + dirRidotte);
Foto.creaRiduzioniPerWeb(this.puntoFoto.getGara(), row.getFileNamePercorsoCompleto(), dirRidotte, false);
i++;
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "create " + i + " riduzioni su " + vec.getTotNumberOfRecords());
if (se1 > 0 && i % se1 == 0)
System.out.print(".");
if (se2 > 0 && i % se2 == 0)
System.out.println("" + i + " su " + i);
}
} else {
err.append("ERRORE!! punto foto INESISTENTE");
err.append("\n");
}
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
}
rp.setMsg("craete " + i + " preview");
timer.stop();
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
System.out.println("CREAZIONE PREVIEW DURATA: " + timer.getDurataHourMin() + "Risultato import:\n" + rp.getMsg() + "\n\nCREAZIONE PREVIEW WWW concluso\n****************");
System.out.println("CREAZIONE PREVIEW **************************************** ERRORI EXPORT FOTO SU WWW ****************************************");
Foto.threadInvioFotoWwwMsg = "DURATA: " + timer.getDurataHourMin() + " Risultato invio:\n" + rp.getMsg() + "\n\nCREAZIONE PREVIEW WWW concluso\n****************";
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "CREAZIONE PREVIEW concluso: DURATA: " +
timer.getDurataHourMin() + " Risultato invio:\n" + rp.getMsg());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW");
Foto.threadInvioFotoWww = false;
}
}
class ThreadInvioFotoDa3PianoAWww extends Thread {
private long id_gara;
private boolean soloFoto;
public ThreadInvioFotoDa3PianoAWww(long l_id_gara, boolean l_soloFoto) {
this.id_gara = l_id_gara;
this.soloFoto = l_soloFoto;
if (!Foto.isThreadAttivo()) {
Foto.threadInvioFotoWww = true;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww";
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i = 0;
int se1 = 10;
int se2 = 100;
int fotoInviate = 0, fotoErrate = 0;
int fotoTrovata = 0, fotoNuova = 0;
try {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww", "...invio foto ...");
Foto.threadInvioFotoWwwMsg = "Attenzione! Thread INVIO FOTO 3piano-->www in esecuzione!!! ";
if (debug)
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww " + Foto.threadInvioFotoWwwMsg);
Gara gara = new Gara(Foto.this.getApFull());
gara.findByPrimaryKey(this.id_gara);
if (gara.getId_gara() > 0L) {
Gara garaR = new Gara(Foto.this.getApRemoto());
garaR.findByPrimaryKey(gara.getCodGara());
if (garaR.getId_gara() > 0L) {
UploadFile uf = new UploadFile();
String urlServletRicevente = Foto.this.getApFull().getParm("RECEIVE_FILE_SERVLET").getTesto();
Foto foto = new Foto(Foto.this.getApFull());
Vectumerator<Foto> vec = foto.findFotoOPettoraleNonInviatoByGara(this.id_gara);
i = 0;
while (vec.hasMoreElements()) {
rp = new ResParm(true);
Foto currentFoto = (Foto)vec.nextElement();
Foto fotoR = null;
if (currentFoto.getFlgPettoraleInviato() == 0L || currentFoto.getId_fotoExport() == 0L) {
if (debug)
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww Invio PETTORALE foto " + i + " su " + vec.getTotNumberOfRecords());
if (currentFoto.getId_fotoExport() > 0L) {
fotoR = new Foto(_PgAdapter.apRemoto);
fotoR.findByPrimaryKey(currentFoto.getId_fotoExport());
fotoR.setPettorali(currentFoto.getPettorali());
rp = fotoR.save();
if (rp.getStatus())
Foto.syncAggiornaPettoraleInviato(currentFoto, 0L, 1L, null, 3L);
fotoTrovata++;
} else {
fotoR = (Foto)currentFoto.clone();
fotoR.setFlgFotoInviata(0L);
fotoR.setFlgPettoraleInviato(0L);
fotoR.setDBState(0);
fotoR.setApFull(_PgAdapter.apRemoto);
fotoR.setId_gara(garaR.getId_gara());
fotoR.setId_puntoFoto(currentFoto.getPuntoFoto().getId_puntoFotoExport());
fotoR.setId_foto(0L);
rp = fotoR.save();
if (rp.getStatus())
Foto.syncAggiornaPettoraleInviato(currentFoto, fotoR.getId_foto(), 1L, null, 1L);
fotoNuova++;
}
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww", "aggiorno foto puntofoto " +
currentFoto.getPuntoFoto().getDescrizione() + " " + i + " su " +
vec.getTotNumberOfRecords() + " - Nuove foto:" + fotoNuova + " Foto aggiornata (pettorali): " + fotoTrovata);
Foto.threadInvioFotoWwwMsg = "Aggiornamento foto del puntofoto " + currentFoto.getPuntoFoto().getDescrizione() + " " + i + " su " + vec.getTotNumberOfRecords() + " - Nuove foto:" + fotoNuova + " Foto aggiornata (pettorali): " + fotoTrovata;
if (debug)
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww " + Foto.threadInvioFotoWwwMsg);
} else {
fotoR = new Foto(_PgAdapter.apRemoto);
fotoR.findByPrimaryKey(currentFoto.getId_fotoExport());
}
String fotoSorgente = currentFoto.getFileNamePercorsoCompleto();
if (currentFoto.getId_fotoExport() > 0L) {
PuntoFoto puntoFotoR = new PuntoFoto(Foto.this.getApRemoto());
puntoFotoR.findByPrimaryKey(fotoR.getId_puntoFoto());
i++;
if (currentFoto.getFlgFotoInviata() == 0L) {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww", "Invio foto " + i + " su " +
vec.getTotNumberOfRecords() + ": " + currentFoto.getFileName());
if (debug)
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww Invio foto " + i + " su " + vec.getTotNumberOfRecords() + ": " +
currentFoto.getFileName());
if (currentFoto.getPuntoFoto().getId_puntoFoto() > 0L) {
String fotoRidotta = currentFoto.getFileNameRidottaPercorsoCompleto();
String fileName = currentFoto.getFileNameReale();
String dirRidotte = currentFoto.getDirRidottaPercorsoCompleto();
File dirRidotteF = new File(dirRidotte);
if (!dirRidotteF.exists())
dirRidotteF.mkdirs();
String fotoRidottaTN = dirRidotte + "tn_" + dirRidotte;
System.out.println("threadInvioFotoWwwMsg fotoridotta: " + fotoRidotta + " foto ridotta tn: " + fotoRidottaTN);
String percorsoRemoto = puntoFotoR.getPathCompletoFoto() + puntoFotoR.getPathCompletoFoto();
if (new File(fotoRidotta).exists() && new File(fotoRidottaTN).exists()) {
rp.setStatus(true);
} else {
rp = Foto.creaRiduzioniPerWeb(currentFoto.getPuntoFoto().getGara(), fotoSorgente, dirRidotte, false);
}
if (rp.getStatus()) {
Foto.threadInvioFotoWwwMsg = "Invio foto " + i + " su " + vec.getTotNumberOfRecords() + ": " + fotoRidotta + " su percorso remoto" + percorsoRemoto;
if (debug)
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww " + Foto.threadInvioFotoWwwMsg);
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww TEST FTP Transferimento di " + fotoRidotta + "-->" + percorsoRemoto + fileName + " via ftp in corso..");
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww TEST TN FTP Transferimento di " + fotoRidottaTN + "-->" + percorsoRemoto + fileName + " via ftp in corso..");
rp.append(uf.transferFile(urlServletRicevente, fotoRidotta, percorsoRemoto));
rp.append(uf.transferFile(urlServletRicevente, fotoRidottaTN, percorsoRemoto));
if (rp.getStatus()) {
currentFoto.setFlgFotoInviata(1L);
currentFoto.save();
fotoInviate++;
continue;
}
fotoErrate++;
if (debug)
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww ERRORE!! Foto " + fotoSorgente + " NON TRASFERITA: " +
rp.getMsg());
err.append("ERRORE!! Foto " + fotoSorgente + " NON TRASFERITA: " + rp.getMsg());
err.append("\n");
continue;
}
fotoErrate++;
err.append("ERRORE!! Foto " + fotoSorgente + " NON RIDOTTA: (" + fotoRidotta + ") " +
rp.getMsg());
err.append("\n");
continue;
}
err.append("ERRORE!! Foto " + fotoSorgente + " SENZA PUNTO FOTO CON ID " +
currentFoto.getId_puntoFoto() + "!! HAI CANCELLATO UN PUNTOFOTO SENZA RESETTARE L'INDICIZZAZIONE!");
err.append("\n");
}
continue;
}
err.append("ERRORE!! Foto " + fotoSorgente + " con il suo punto foto non e' stato esporato. id_fotoExport=0 ");
err.append("\n");
}
} else {
err.append("ERRORE!! GARA remota " + gara.getCodGara() + " NON TROVATA");
err.append("\n");
}
} else {
err.append("ERRORE!! GARA " + this.id_gara + " INESISTENTE");
err.append("\n");
}
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
}
rp.setMsg("INVIATE " + fotoInviate + "- FOTO ERRATE: " + fotoErrate);
Timestamp stop = new Timestamp(Calendar.getInstance().getTimeInMillis());
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww DURATA: " + dfMS.format(new Time(stop.getTime() - start.getTime() - 3600000L)) + "Risultato import:\n" +
rp.getMsg() + "\n\nINVIO FOTO WWW concluso\n****************");
System.out.println("INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww **************************************** ERRORI EXPORT FOTO SU WWW ****************************************");
Foto.threadInvioFotoWwwMsg = "DURATA: " + dfMS.format(new Time(stop.getTime() - start.getTime() - 3600000L)) + "Risultato invio:\n" + rp.getMsg() + "\n\nINVIO FOTO WWW concluso\n****************";
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww", "Invio foto concluso: DURATA: " +
dfMS.format(new Time(stop.getTime() - start.getTime() - 3600000L)) + "Risultato invio:\n" + rp.getMsg());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Foto.this.getApFull(), "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWww");
Foto.threadInvioFotoWww = false;
}
}
class ThreadCreaPreviewMT extends Thread {
private PuntoFoto puntoFoto;
public ThreadCreaPreviewMT(PuntoFoto puntoFoto) {
this.puntoFoto = puntoFoto;
if (!Foto.isThreadAttivo()) {
Foto.threadInvioFotoWww = true;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "CREAZIONE PREVIEW";
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
int i = 0;
int se1 = 10;
int se2 = 100;
int maxNumberOfThread = Foto.this.getParm("MAX_CONCURRENT_THREAD").getNumeroInt();
if (maxNumberOfThread <= 1)
maxNumberOfThread = 10;
try {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "...inizio ...");
Foto.threadInvioFotoWwwMsg = "Attenzione! Thread CREAZIONE PREVIEW in esecuzione!!! ";
if (debug)
System.out.println("CREAZIONE PREVIEW " + Foto.threadInvioFotoWwwMsg);
if (this.puntoFoto.getId_puntoFoto() > 0L) {
Foto foto = new Foto(this.puntoFoto.getApFull());
FotoCR fotoCR = new FotoCR();
fotoCR.setId_puntoFoto(this.puntoFoto.getId_puntoFoto());
Vectumerator<Foto> vec = foto.findByCR(fotoCR, 0, 0);
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
while (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
String fotoRidotta = row.getFileNameRidottaPercorsoCompleto();
String fileNameRidotta = row.getFileNameReale();
String dirRidotte = row.getDirRidottaPercorsoCompleto();
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW",
row.getFileNamePercorsoCompleto() + " --> " + row.getFileNamePercorsoCompleto() + "#" + dirRidotte);
CreaFotoPgCallable cfp = new CreaFotoPgCallable(this.puntoFoto.getGara(), row.getFileNamePercorsoCompleto(), dirRidotte, false);
vecF.add(pool.submit(cfp));
i++;
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "max thread: " + maxNumberOfThread + " - submit " + i + " riduzioni su " +
vec.getTotNumberOfRecords());
if (se1 > 0 && i % se1 == 0)
System.out.print(".");
if (se2 > 0 && i % se2 == 0)
System.out.println("" + i + " su " + i);
}
for (int j = 0; j < vecF.getTotNumberOfRecords(); j++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
try {
System.out.println(currentFuture.get().getMsg() + " ended");
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "max thread: " + maxNumberOfThread + " - create " + j + " riduzioni su " +
vec.getTotNumberOfRecords());
} catch (Exception ex) {
ex.printStackTrace();
}
}
} else {
err.append("ERRORE!! punto foto INESISTENTE");
err.append("\n");
}
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
}
rp.setMsg("craete " + i + " preview");
timer.stop();
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
System.out.println("CREAZIONE PREVIEW DURATA: " + timer.getDurataHourMin() + "Risultato import:\n" + rp.getMsg() + "\n\nCREAZIONE PREVIEW WWW concluso\n****************");
System.out.println("CREAZIONE PREVIEW **************************************** ERRORI EXPORT FOTO SU WWW ****************************************");
Foto.threadInvioFotoWwwMsg = "DURATA: " + timer.getDurataHourMin() + "Risultato invio:\n" + rp.getMsg() + "\n\nCREAZIONE PREVIEW WWW concluso\n****************";
StatusMsg.updateMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW", "CREAZIONE PREVIEW concluso: max thread: " + maxNumberOfThread + " - DURATA: " +
timer.getDurataHourMin() + " Risultato invio:\n" + rp.getMsg());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Foto.this.getApFull(), "CREAZIONE PREVIEW");
Foto.threadInvioFotoWww = false;
}
}
class ThreadInvioFotoDa3PianoAWwwMT extends Thread {
private long id_gara;
private boolean soloFoto;
public ThreadInvioFotoDa3PianoAWwwMT(long l_id_gara, boolean l_soloFoto) {
this.id_gara = l_id_gara;
this.soloFoto = l_soloFoto;
if (!Foto.isThreadAttivo()) {
Foto.threadInvioFotoWww = true;
start();
}
}
public void run() {
boolean debug = false;
int maxNumberOfThread = Foto.this.getParm("MAX_CONCURRENT_THREAD").getNumeroInt();
int maxNumberOfUploadThread = Foto.this.getParm("MAX_CONCURRENT_THREAD").getNumeroInt();
if (maxNumberOfThread <= 1)
maxNumberOfThread = 10;
if (maxNumberOfUploadThread <= 1)
maxNumberOfUploadThread = 10;
String TAG_THREAD_MSG = "INVIO FOTO DA CASA A WWW ThreadInvioFotoDa3PianoAWwwMT " + maxNumberOfThread + "-" + maxNumberOfUploadThread;
Timer timer = new Timer();
timer.start();
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "...invio foto ...");
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i = 0;
int se1 = 10;
int se2 = 100;
int fotoInviate = 0, fotoErrate = 0;
int fotoTrovata = 0, fotoNuova = 0;
if (debug)
System.out.println("OCR #######****### THREAD " + TAG_THREAD_MSG + " ######" + String.valueOf(DBAdapter.getNow()));
Gara gara = new Gara(Foto.this.getApFull());
gara.writeLog("\n\n\n----------------------\n" + TAG_THREAD_MSG + " INIZIO INVIO FOTO MULTITHREAD\n");
try {
Foto.threadInvioFotoWwwMsg = "Attenzione! Thread INVIO FOTO 3piano-->www in esecuzione!!! ";
if (debug)
System.out.println(TAG_THREAD_MSG + " " + TAG_THREAD_MSG);
gara.findByPrimaryKey(this.id_gara);
if (gara.getId_gara() > 0L) {
Gara garaR = new Gara(Foto.this.getApRemoto());
garaR.findByPrimaryKey(gara.getCodGara());
if (garaR.getId_gara() > 0L) {
UploadFile uf = new UploadFile();
String urlServletRicevente = Foto.this.getApFull().getParm("RECEIVE_FILE_SERVLET").getTesto();
Foto foto = new Foto(Foto.this.getApFull());
long totNumeroFoto = foto.findFotoOPettoraleNonInviatoByGaraTotale(this.id_gara);
i = 1;
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
ExecutorService poolInvio = Executors.newFixedThreadPool(maxNumberOfUploadThread);
PuntoFoto pf = new PuntoFoto(Foto.this.getApFull());
Vectumerator<PuntoFoto> vecPF = pf.findPuntiFotoConFotoOPettoraleNonInviatoByGara(this.id_gara);
Timer timerPF = new Timer();
while (vecPF.hasMoreElements()) {
PuntoFoto currentPF = (PuntoFoto)vecPF.nextElement();
Vectumerator<Future<ResParm>> vecFInvio = new Vectumerator();
int ipf = 1;
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
Vectumerator<Foto> vec = foto.findFotoOPettoraleNonInviatoByGaraPuntoFoto(this.id_gara,
currentPF.getId_puntoFoto());
while (vec.hasMoreElements()) {
rp = new ResParm(true);
Foto foto1 = (Foto)vec.nextElement();
foto1.findByPrimaryKey(foto1.getId_foto());
Foto fotoR = null;
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo principale pf:" + TAG_THREAD_MSG + " Invio PETTORALE foto " + currentPF.getDescrizionePuntoFoto() + " su " + ipf + " (tot:" +
vec.getTotNumberOfRecords() + " su " + i + ")..... ");
if (foto1.getFlgPettoraleInviato() == 0L || foto1.getId_fotoExport() == 0L) {
if (debug)
System.out.println(TAG_THREAD_MSG + " foto " + TAG_THREAD_MSG + " da registrare in remoto!");
if (foto1.getId_fotoExport() > 0L) {
fotoR = new Foto(_PgAdapter.apRemoto);
fotoR.findByPrimaryKey(foto1.getId_fotoExport());
fotoR.setPettorali(foto1.getPettorali());
rp = fotoR.save();
if (rp.getStatus())
Foto.syncAggiornaPettoraleInviato(foto1, 0L, 1L, null, 3L);
fotoTrovata++;
} else {
fotoR = (Foto)foto1.clone();
fotoR.setFlgFotoInviata(0L);
fotoR.setFlgPettoraleInviato(0L);
fotoR.setDBState(0);
fotoR.setApFull(_PgAdapter.apRemoto);
fotoR.setId_gara(garaR.getId_gara());
fotoR.setId_puntoFoto(foto1.getPuntoFoto().getId_puntoFotoExport());
fotoR.setId_foto(0L);
rp = fotoR.save();
if (rp.getStatus())
Foto.syncAggiornaPettoraleInviato(foto1, fotoR.getId_foto(), 1L, null, 1L);
fotoNuova++;
}
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "aggiorno foto puntofoto " +
foto1.getPuntoFoto().getDescrizionePuntoFoto() + " " + ipf + " su " +
vec.getTotNumberOfRecords() + " (tot:" + i + " su " + totNumeroFoto + ") - Nuove foto:" + fotoNuova + " Foto aggiornata (pettorali): " + fotoTrovata);
Foto.threadInvioFotoWwwMsg = "Aggiornamento foto del puntofoto " + foto1.getPuntoFoto().getDescrizionePuntoFoto() + " " + ipf + " su " + vec.getTotNumberOfRecords() + " (tot:" + i + " su " + totNumeroFoto + ") - Nuove foto:" + fotoNuova + " Foto aggiornata (pettorali): " + fotoTrovata;
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo principale INSERITO NOVO RECORD FOTO- " + TAG_THREAD_MSG);
} else {
fotoR = new Foto(_PgAdapter.apRemoto);
fotoR.findByPrimaryKey(foto1.getId_fotoExport());
if (debug)
System.out.println(TAG_THREAD_MSG + " FOTO TROVATA\n ciclo principale: RECORD FOTO REMOTA TROVATA - pf:" + TAG_THREAD_MSG + " " +
foto1.getPuntoFoto().getDescrizionePuntoFoto() + " su " + ipf + " (tot:" +
vec.getTotNumberOfRecords() + " su " + i + ")");
}
String fotoSorgente = foto1.getFileNamePercorsoCompleto();
DBAdapter.printDebug(" ====******==> apremoto catalog.:" + Foto.this.getApRemoto().getCatalog() + " database: " +
Foto.this.getApRemoto().getDatabase());
DBAdapter.printDebug(" ===******===> currentFoto. id:" + foto1.getId_foto() + " currentFoto.getId_fotoExport(): " +
foto1.getId_fotoExport() + " fotoR id: " +
fotoR.getId_foto() + " fotoR.getId_puntoFoto() " + fotoR.getId_puntoFoto());
if (foto1.getId_fotoExport() > 0L) {
PuntoFoto puntoFotoR = new PuntoFoto(Foto.this.getApRemoto());
puntoFotoR.findByPrimaryKey(fotoR.getId_puntoFoto());
i++;
ipf++;
if (foto1.getFlgFotoInviata() == 0L) {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, " pf:" +
currentPF.getDescrizionePuntoFoto() + " - Ciclo foto " + ipf + " su " +
vec.getTotNumberOfRecords() + " (tot:" + i + " su " + totNumeroFoto + "): " +
foto1.getFileName());
if (debug) {
System.out.println(TAG_THREAD_MSG + " pf:" + TAG_THREAD_MSG + " - Ciclo foto " + currentPF.getDescrizionePuntoFoto() + " su " + ipf + " (tot:" +
vec.getTotNumberOfRecords() + " su " + i + "): " + totNumeroFoto);
foto1.writeLog(TAG_THREAD_MSG + " pf:" + TAG_THREAD_MSG + " - Ciclo foto " + currentPF.getDescrizionePuntoFoto() + " su " + ipf + " (tot:" +
vec.getTotNumberOfRecords() + " su " + i + "): " + totNumeroFoto);
}
if (foto1.getPuntoFoto().getId_puntoFoto() > 0L) {
String fotoRidotta = foto1.getFileNameRidottaPercorsoCompleto();
String fileName = foto1.getFileNameReale();
String dirRidotte = foto1.getDirRidottaPercorsoCompleto();
File dirRidotteF = new File(dirRidotte);
if (!dirRidotteF.exists())
dirRidotteF.mkdirs();
String fotoRidottaTN = dirRidotte + "tn_" + dirRidotte;
DBAdapter.printDebug(" ======> puntoFotoR. id:" + puntoFotoR.getId_puntoFoto() + " id_gara: " +
puntoFotoR.getId_gara() + " percorso: " +
puntoFotoR.getPathCompletoFoto());
String percorsoRemoto = puntoFotoR.getPathCompletoFoto();
if (new File(fotoRidotta).exists() && new File(fotoRidottaTN).exists()) {
rp.setStatus(true);
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "foto ridotta esistente. Invio foto tramite thread invio di " +
foto1.getFileName() + " ...");
if (debug) {
System.out.println(TAG_THREAD_MSG + " foto ridotta esistente. Invio foto tramite thread invio di " + TAG_THREAD_MSG + " ...");
foto1.writeLog(TAG_THREAD_MSG + " foto ridotta esistente. Invio foto tramite thread invio di " + TAG_THREAD_MSG + " ...");
}
UploadFileCallable ufc = new UploadFileCallable(urlServletRicevente, fotoRidotta, percorsoRemoto, true);
ufc.setObj(foto1);
vecFInvio.add(poolInvio.submit((Callable<?>)ufc));
UploadFileCallable ufcTN = new UploadFileCallable(urlServletRicevente, fotoRidottaTN, percorsoRemoto, true);
ufcTN.setObj(foto1);
vecFInvio.add(poolInvio.submit((Callable<?>)ufcTN));
foto1.writeLog(TAG_THREAD_MSG + " foto " + TAG_THREAD_MSG + " in invio .....");
} else {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "Riduzione foto tramite thread riduzione di " +
foto1.getFileName() + " ...");
if (debug) {
System.out.println(TAG_THREAD_MSG + " Riduzione foto tramite thread riduzione di " + TAG_THREAD_MSG + " ...");
foto1.writeLog(TAG_THREAD_MSG + " Riduzione foto tramite thread riduzione di " + TAG_THREAD_MSG + " ...");
}
CreaFotoPgCallable cfp = new CreaFotoPgCallable(foto1.getPuntoFoto().getGara(), fotoSorgente, dirRidotte, false);
foto1.setThFotoRidotta(fotoRidotta);
foto1.setThFotoRidottaTN(fotoRidottaTN);
foto1.setThPercorsoRemoto(percorsoRemoto);
cfp.setFoto(foto1);
vecF.add(pool.submit(cfp));
}
if (!rp.getStatus()) {
fotoErrate++;
err.append("ERRORE!! Foto " + fotoSorgente + " NON RIDOTTA: (" + fotoRidotta + ") " +
rp.getMsg());
err.append("\n");
}
continue;
}
err.append("ERRORE!! Foto " + fotoSorgente + " SENZA PUNTO FOTO CON ID " +
foto1.getId_puntoFoto() + "!! HAI CANCELLATO UN PUNTOFOTO SENZA RESETTARE L'INDICIZZAZIONE!");
err.append("\n");
}
continue;
}
err.append("ERRORE!! Foto " + fotoSorgente + " con il suo punto foto non e' stato esporato. id_fotoExport=0 ");
err.append("\n");
}
if (debug) {
gara.writeLog(TAG_THREAD_MSG + "\n\nciclo CREAZIONE FOTO / INVIO COLCLUSO\n\nINIZIO ciclo RISULTATI RIDUZIONE, record: " + TAG_THREAD_MSG);
System.out.println(TAG_THREAD_MSG + " ###1### ciclo CREAZIONE FOTO / INVIO COLCLUSO: INIZIO ciclo RISULTATI RIDUZIONE, record PUNTOFOTO: " + TAG_THREAD_MSG + " ###1###");
}
Foto currentFoto = null;
for (int k = 0; k < vecF.getTotNumberOfRecords(); k++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
try {
if (debug) {
gara.writeLog(TAG_THREAD_MSG + " ciclo risultato thread riduzioni: currentFuture.get...");
System.out.println(TAG_THREAD_MSG + " ciclo risultato thread riduzioni: currentFuter.get ...");
}
rp = currentFuture.get();
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo risultato thread riduzioni: currentFuter.get ... GET OK!");
currentFoto = (Foto)rp.getReturnObj();
if (debug)
gara.writeLog(TAG_THREAD_MSG + " risultato: " + TAG_THREAD_MSG + " " + rp.getStatus());
if (rp.getStatus()) {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "ciclo risultato thread riduzioni: create " + k + " riduzioni su " +
vecF.getTotNumberOfRecords() + ". Invio foto tramite thread invio di " +
currentFoto.getFileName() + " ...");
if (debug) {
gara.writeLog(TAG_THREAD_MSG + " ciclo thread riduzioni: create " + TAG_THREAD_MSG + " riduzioni su " + k + ". Invio foto tramite thread invio di " +
vecF.getTotNumberOfRecords() + " ...");
System.out.println(TAG_THREAD_MSG + " ciclo risultato thread riduzioni: create " + TAG_THREAD_MSG + " riduzioni su " + k + ". Invio foto tramite thread invio di " +
vecF.getTotNumberOfRecords() + " ...");
}
UploadFileCallable ufc = new UploadFileCallable(urlServletRicevente,
currentFoto.getThFotoRidotta(), currentFoto.getThPercorsoRemoto(), true);
ufc.setObj(currentFoto);
vecFInvio.add(poolInvio.submit((Callable<?>)ufc));
UploadFileCallable ufcTN = new UploadFileCallable(urlServletRicevente,
currentFoto.getThFotoRidottaTN(), currentFoto.getThPercorsoRemoto(), true);
ufcTN.setObj(currentFoto);
vecFInvio.add(poolInvio.submit((Callable<?>)ufcTN));
currentFoto.writeLog(TAG_THREAD_MSG + " foto " + TAG_THREAD_MSG + " in invio .....");
}
} catch (Exception ex) {
ex.printStackTrace();
gara.writeLog(TAG_THREAD_MSG + " eccezione:" + TAG_THREAD_MSG);
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo risultato thread riduzioni: ECCEZIONE SU ciclo thread riduzioni n. " + TAG_THREAD_MSG + " riduzioni su " + k + ": " +
vecF.getTotNumberOfRecords() + " - " + currentFoto.getFileName());
}
}
if (debug) {
gara.writeLog(TAG_THREAD_MSG + " ciclo RISULTATI CREAZIONE FOTO CONCLUSO <br>INIZIO ciclo RISULTATI INVIO: record:s " + TAG_THREAD_MSG);
System.out.println(TAG_THREAD_MSG + " ###2### ciclo RISULTATI CREAZIONE FOTO CONCLUSO <br>INIZIO ciclo RISULTATI INVIO: record:s " + TAG_THREAD_MSG + " ###2###");
}
for (int j = 0; j < vecFInvio.getTotNumberOfRecords(); j++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecFInvio.nextElement();
try {
if (debug) {
gara.writeLog(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: currentFuture.get...");
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: currentFuter.get 8secs ...\n");
}
try {
rp = currentFuture.get(8L, TimeUnit.SECONDS);
} catch (Exception e) {
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: currentFuter.get 8secs ... TIMEOUT!!!!");
System.out.println(TAG_THREAD_MSG + " ECCEZIONE SU ciclo RISULTATI INVIO FOTO TIMEOUT!! n. " + TAG_THREAD_MSG + " su " + j + ": " +
vecF.getTotNumberOfRecords() + " " + currentFoto.getFileName());
err.append(TAG_THREAD_MSG + " ECCEZIONE SU ciclo RISULTATI INVIO FOTO TIMEOUT!! n. " + TAG_THREAD_MSG + " su " + j + ": " +
vecF.getTotNumberOfRecords() + " " + currentFoto.getFileName());
err.append("\n");
}
if (currentFuture.isCancelled()) {
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: currentFuter.get 8secs ... GET KOOOOOOOOOO!");
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, " ERRORE!! Upload cancellato! Foto " +
currentFoto.getFile() + ": " + rp.getMsg());
currentFoto.writeLog(TAG_THREAD_MSG + " ERRORE!! Upload cancellato! Foto " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile());
if (debug) {
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: ERRORE!! Upload cancellato! FOTO " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile() + " - " + rp.getMsg() + " su " + j);
err.append(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: ERRORE!! Upload cancellato! FOTO " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile() + " - " + rp.getMsg() + " su " + j);
err.append("\n");
}
} else if (currentFuture.isDone()) {
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: currentFuter.get 8secs ... GET OK!");
currentFoto = (Foto)rp.getReturnObj();
if (rp.getStatus()) {
fotoInviate++;
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "Foto " +
currentFoto.getFile() + ": " + rp.getMsg());
currentFoto.writeLog(TAG_THREAD_MSG + " Foto " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile());
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: FOTO " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile() + " - " + rp.getMsg() + " su " + j);
} else {
fotoErrate++;
if (debug)
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: ERRORE!! Foto " + TAG_THREAD_MSG + " NON TRASFERITA: " +
currentFoto.getFileName() + " - " + rp.getMsg() + " su " + j);
currentFoto.writeLog(TAG_THREAD_MSG + " ERRORE!! Foto " + TAG_THREAD_MSG + " NON TRASFERITA: " + currentFoto.getFileName());
err.append("ERRORE!! Foto " +
currentFoto.getFileName() + " NON TRASFERITA: " + rp.getMsg());
err.append("\n");
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "ERRORE !! Foto " +
currentFoto.getFileName() + " NON TRASFERITA: " + rp.getMsg());
}
} else {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, " ATTENZIONE!! Upload non completato! Foto " +
currentFoto.getFile() + ": " + rp.getMsg());
currentFoto.writeLog(TAG_THREAD_MSG + " ERRORE!! Upload cancellato! Foto " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile());
if (debug) {
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: currentFuter.get 8secs ... GET KOOOOOOOOO11!");
System.out.println(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: ATTENZIONE!! Upload non completato! FOTO " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile() + " - " + rp.getMsg() + " su " + j);
err.append(TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO: ATTENZIONE!! Upload non completato! FOTO " + TAG_THREAD_MSG + " inviata: " +
currentFoto.getFile() + " - " + rp.getMsg() + " su " + j);
err.append("\n");
}
}
} catch (Exception ex) {
ex.printStackTrace();
if (debug) {
System.out.println(TAG_THREAD_MSG + " ECCEZIONE SU ciclo RISULTATI INVIO FOTO n. " + TAG_THREAD_MSG + " su " + j + ": " +
vecF.getTotNumberOfRecords() + " " + currentFoto.getFileName());
err.append(TAG_THREAD_MSG + " ECCEZIONE SU ciclo RISULTATI INVIO FOTO n. " + TAG_THREAD_MSG + " su " + j + ": " +
vecF.getTotNumberOfRecords() + " " + currentFoto.getFileName());
err.append("\n");
}
}
}
if (debug) {
gara.writeLog(TAG_THREAD_MSG + " pf:" + TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO CONCLUSO <br> record:s " + currentPF.getDescrizionePuntoFoto());
System.out.println(TAG_THREAD_MSG + " ###3### pf:" + TAG_THREAD_MSG + " ciclo RISULTATI INVIO FOTO CONCLUSO record:s " + currentPF.getDescrizionePuntoFoto() + " ###3###");
}
}
if (debug) {
gara.writeLog(TAG_THREAD_MSG + " ###### FINE DI TUTTI I CICLI DI TUTTI I PUNTIFOTO!!!");
System.out.println(TAG_THREAD_MSG + " FINE DI TUTTI I CICLI DI TUTTI I PUNTIFOTO!!! ######");
}
} else {
err.append("ERRORE!! GARA remota " + gara.getCodGara() + " NON TROVATA");
err.append("\n");
}
} else {
err.append("ERRORE!! GARA " + this.id_gara + " INESISTENTE");
err.append("\n");
}
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
}
rp.setMsg("INVIATE " + fotoInviate + "- FOTO ERRATE: " + fotoErrate);
timer.stop();
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
System.out.println(TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + "Risultato import:\n" + timer.getDurataHourMin() + "\n\nINVIO FOTO WWW concluso\n###############*");
System.out.println(TAG_THREAD_MSG + " #######################################* ERRORI EXPORT FOTO SU WWW #######################################*");
System.out.println(err.toString());
System.out.println(TAG_THREAD_MSG + " #######################################* FINE EXPORT FOTO SU WWW #######################################*");
Foto.threadInvioFotoWwwMsg = "DURATA: " + timer.getDurataHourMin() + " Risultato invio:\n" + rp.getMsg() + "\n\nINVIO FOTO WWW concluso\n###############*";
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "Invio foto concluso: DURATA: " +
timer.getDurataHourMin() + " Risultato invio:\n" + rp.getMsg());
gara.writeLog("\n\n\n----------------------\n" + TAG_THREAD_MSG + "Invio foto concluso: DURATA: " + timer.getDurataHourMin() + "\nINVIATE " + fotoInviate + "- FOTO ERRATE: " + fotoErrate + "\nRisultato invio:\n" +
rp.getMsg() + "\n");
if (debug)
System.out.println("OCR #######****### FINE THREAD " + TAG_THREAD_MSG + " ######" + String.valueOf(DBAdapter.getNow()));
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG);
Foto.threadInvioFotoWww = false;
}
}
public static boolean threadInvioFotoWww = false;
public static String threadInvioFotoWwwMsg = "";
public Foto(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public Foto() {}
public void setId_foto(long newId_foto) {
this.id_foto = newId_foto;
}
public void setFile(String newFile) {
String temp = newFile;
temp.replace('/', '_');
this.file = temp;
}
public void setImpression(long newNVisual) {
this.impression = newNVisual;
}
public void setDataUltimaVisual(Date newDataUltimaVisual) {
this.dataUltimaVisual = newDataUltimaVisual;
}
public long getId_foto() {
return this.id_foto;
}
public String getFile() {
return (this.file == null) ? "" : this.file.trim();
}
public long getImpression() {
return this.impression;
}
public Date getDataUltimaVisual() {
return this.dataUltimaVisual;
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {}
public Vectumerator<Foto> findByCR(FotoCR CR, int pageNumber, int pageRows) {
StringBuilder s_Sql_Find = new StringBuilder("select A.* from FOTO AS A");
String s_Sql_Order = " order by A.file";
WcString wc = new WcString();
if (CR.getId_gara() != 0L)
wc.addWc("A.id_gara=" + CR.getId_gara());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getFile().isEmpty())
wc.addWc("A.file like '%" + CR.getFile() + "%'");
if (!CR.getTipoPuntoFoto().isEmpty()) {
s_Sql_Find.append(", PUNTO_FOTO AS B");
wc.addWc("A.id_puntoFoto=B.id_puntoFoto");
wc.addWc("B.tipoPuntoFoto ='" + CR.getTipoPuntoFoto() + "'");
}
if (!CR.getPettorale().isEmpty())
wc.addWc("A.pettorali like'%," + CR.getPettorale() + ",%'");
if (CR.getFlgConPettorali() == 1L)
wc.addWc("A.pettorali is not null");
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) {
removeCPConnection();
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public static final synchronized ResParm addImpression(String foto, ApplParmFull ap) {
Foto bean = new Foto(ap);
bean.findByFoto(foto);
if (bean.getDBState() == 1) {
bean.setImpression(bean.getImpression() + 1L);
} else {
bean.setFile(foto);
bean.setImpression(1L);
}
bean.setDataUltimaVisual(getToday());
return bean.save();
}
public static final synchronized ResParm addImpression(Foto bean, ApplParmFull ap) {
ResParm rp;
if (bean.getDBState() == 1) {
bean.setImpression(bean.getImpression() + 1L);
bean.setDataUltimaVisual(getToday());
rp = bean.save();
} else {
rp = new ResParm(false, "Errore! Tentativo di incrementare un impression su una foto non valida. Id_foto: " + bean.getId_foto());
}
return rp;
}
public void findByFoto(String foto) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("file = '" + fotoToFile(foto) + "'");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
}
}
public long getNextId_foto(FotoCR CR) {
long l_id_foto = getId_foto();
StringBuilder s_Sql_Find = new StringBuilder("select A.* from FOTO AS A");
String s_Sql_Order = " order by A.file";
WcString wc = new WcString();
if (CR.getId_gara() != 0L)
wc.addWc("A.id_gara=" + CR.getId_gara());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
wc.addWc("A.file >'" + getFile() + "'");
if (!CR.getTipoPuntoFoto().isEmpty()) {
s_Sql_Find.append(", PUNTO_FOTO AS B");
wc.addWc("A.id_puntoFoto=B.id_puntoFoto");
wc.addWc("B.tipoPuntoFoto ='" + CR.getTipoPuntoFoto() + "'");
}
if (!CR.getPettorale().isEmpty())
wc.addWc("A.pettorali like'%," + CR.getPettorale() + ",%'");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
Vectumerator vec = findRows(stmt, 1, 1);
while (vec.hasMoreElements()) {
if (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
l_id_foto = row.getId_foto();
break;
}
}
} catch (SQLException e) {
handleDebug(e);
}
return l_id_foto;
}
public long getPrevId_foto(FotoCR CR) {
long l_id_foto = getId_foto();
StringBuilder s_Sql_Find = new StringBuilder("select A.* from FOTO AS A");
String s_Sql_Order = " order by A.file desc";
WcString wc = new WcString();
if (CR.getId_gara() != 0L)
wc.addWc("A.id_gara=" + CR.getId_gara());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
wc.addWc("A.file <'" + getFile() + "'");
if (!CR.getTipoPuntoFoto().isEmpty()) {
s_Sql_Find.append(", PUNTO_FOTO AS B");
wc.addWc("A.id_puntoFoto=B.id_puntoFoto");
wc.addWc("B.tipoPuntoFoto ='" + CR.getTipoPuntoFoto() + "'");
}
if (!CR.getPettorale().isEmpty())
wc.addWc("A.pettorali like'%," + CR.getPettorale() + ",%'");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
Vectumerator vec = findRows(stmt, 1, 1);
while (vec.hasMoreElements()) {
if (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
l_id_foto = row.getId_foto();
break;
}
}
} catch (SQLException e) {
handleDebug(e);
}
return l_id_foto;
}
public long getImpression(String foto) {
findByFoto(foto);
if (getDBState() == 1)
return getImpression();
return 0L;
}
private String fotoToFile(String foto) {
String temp = foto;
temp = temp.replace('/', '_');
temp = temp.replace(':', '_');
return temp;
}
public String getDataUltimaVisual(String foto) {
findByFoto(foto);
if (getDBState() == 1)
return getDataFormat().format(getDataUltimaVisual());
return "";
}
protected void prepareSave(PreparedStatement ps) throws SQLException {
setFile(fotoToFile(getFile()));
synchronized (this) {
String temp = getPettorali().trim();
if (!temp.isEmpty()) {
if (!temp.startsWith(","))
temp = "," + temp;
if (!temp.endsWith(","))
temp = temp + ",";
}
while (temp.indexOf(",,") >= 0)
temp = temp.replaceAll(",,", ",");
setPettorali(temp);
}
super.prepareSave(ps);
}
public void findByFilenamePuntoFoto(String l_filename, long l_id_puntoFoto) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.file='" + l_filename + "'");
wc.addWc("A.id_puntoFoto=" + l_id_puntoFoto);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findByFilenameGara(String l_filename, long l_id_gara) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.file='" + l_filename + "'");
wc.addWc("A.id_gara=" + l_id_gara);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public long getId_gara() {
return this.id_gara;
}
public void setId_gara(long id_gara) {
this.id_gara = id_gara;
}
public long getId_puntoFoto() {
return this.id_puntoFoto;
}
public void setId_puntoFoto(long id_puntoFoto) {
this.id_puntoFoto = id_puntoFoto;
setPuntoFoto(null);
}
public ResParm deleteFotoByPuntoFoto(long l_id_puntoFoto) {
ResParm rp;
if (l_id_puntoFoto > 0L) {
rp = delete("delete from FOTO where (impression is null or impression=0 ) and id_puntoFoto=" + l_id_puntoFoto);
} else {
rp = new ResParm(false, "ERRORE! punto foto non valido");
}
return rp;
}
public String getPathCompletoFile() {
return DBAdapter.convertPathToCurrentFileSystemSeparator(getPuntoFoto().getPathCompletoFoto() + getPuntoFoto().getPathCompletoFoto());
}
public String getPathCompletoFileTn() {
return getPuntoFoto().getPathCompletoFoto() + "tn_" + getPuntoFoto().getPathCompletoFoto();
}
public PuntoFoto getPuntoFoto() {
this.puntoFoto = (PuntoFoto)getSecondaryObject(this.puntoFoto, PuntoFoto.class, getId_puntoFoto());
return this.puntoFoto;
}
public void setPuntoFoto(PuntoFoto newPuntoFoto) {
this.puntoFoto = newPuntoFoto;
}
public long getTotFoto() {
StringBuilder s_Sql_Find = new StringBuilder("select count(*) as _cnt from FOTO AS A");
WcString wc = new WcString();
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
return getCount(stmt, "_cnt");
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return 0L;
}
}
public String getFileURI() {
if (getFile().isEmpty())
return getFile();
int idxDot = getFile().lastIndexOf(".");
return getFile().substring(0, idxDot) + "-" + getFile().substring(0, idxDot) + getId_foto();
}
public String getPettorali() {
if (this.pettorali != null)
this.pettorali = this.pettorali.replace('.', ',');
return (this.pettorali == null) ? "" : this.pettorali;
}
public void setPettorali(String pettorali) {
this.pettorali = pettorali;
}
public Vectumerator<Foto> findByPettoraliCR(FotoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = " order by A.fileName ";
if ((pageNumber == 0 && pageRows == 0) || pageRows == 999)
s_Sql_Order = " order by rand() ";
WcString wc = new WcString();
if (CR.getId_puntoFoto() == 0L || !CR.getTipoPuntoFoto().isEmpty()) {
s_Sql_Find = s_Sql_Find + ", PUNTO_FOTO AS B";
wc.addWc("A.id_puntoFoto=B.id_puntoFoto");
}
if (CR.getId_gara() != 0L)
wc.addWc("A.id_gara=" + CR.getId_gara());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getTipoPuntoFoto().isEmpty())
wc.addWc("B.tipoPuntoFoto='" + CR.getTipoPuntoFoto() + "'");
if (CR.getId_puntoFoto() != 0L || CR.getTipoPuntoFoto().isEmpty());
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
if (!CR.getPettorale().isEmpty())
wc.addWc("A.pettorali like'%," + CR.getPettorale() + ",%'");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public final ResParm startInvioFotoDa3PianoAWww(long l_id_gara, boolean l_soloFoto) {
if (!isThreadAttivo()) {
new ThreadInvioFotoDa3PianoAWww(l_id_gara, l_soloFoto);
return new ResParm(true, "Thread Invio Foto Www avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread Invio Foto Www gia' in esecuzione!!!");
}
public Vectumerator findFotoOPettoraleNonInviatoByGara(long l_id_gara) {
return findFotoOPettoraleNonInviatoByGaraPuntoFoto(l_id_gara, 0L);
}
public Vectumerator findFotoOPettoraleNonInviatoByGaraPuntoFoto(long l_id_gara, long l_id_puntofoto) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = " order by A.id_puntoFoto";
WcString wc = new WcString();
wc.addWc("A.id_gara=" + l_id_gara);
if (l_id_puntofoto > 0L)
wc.addWc("A.id_puntoFoto=" + l_id_puntofoto);
wc.addWc("(A.flgFotoInviata is null or A.flgFotoInviata=0 or A.flgPettoraleInviato is null or flgPettoraleInviato=0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
System.out.println("findFotoOPettoraleNonInviatoByGara: " + s_Sql_Find + wc.toString() + s_Sql_Order);
return findRows(stmt);
} catch (SQLException e) {
return AB_EMPTY_VECTUMERATOR;
}
}
public long findFotoOPettoraleNonInviatoByGaraTotale(long l_id_gara) {
String s_Sql_Find = "select count(*) as tot from FOTO AS A";
String s_Sql_Order = " ";
WcString wc = new WcString();
wc.addWc("A.id_gara=" + l_id_gara);
wc.addWc("(A.flgFotoInviata is null or A.flgFotoInviata=0 or A.flgPettoraleInviato is null or flgPettoraleInviato=0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
System.out.println("findFotoOPettoraleNonInviatoByGaraTotale: " + s_Sql_Find + wc.toString() + s_Sql_Order);
return (long)getTots(stmt);
} catch (SQLException e) {
return 0L;
}
}
public static boolean isThreadAttivo() {
return threadInvioFotoWww;
}
public long getFlgFotoInviata() {
return this.flgFotoInviata;
}
public void setFlgFotoInviata(long flgFotoInviata) {
this.flgFotoInviata = flgFotoInviata;
}
public String getFileName() {
return (this.file == null) ? "" : this.file.trim();
}
public String getFileNamePercorsoCompleto() {
return getPuntoFoto().getPathCompletoFoto() + getPuntoFoto().getPathCompletoFoto() + DBAdapter.SEPARATOR;
}
public String getFileNameRidottaPercorsoCompleto() {
return getDirRidottaPercorsoCompleto() + getDirRidottaPercorsoCompleto();
}
public String getDirRidottaPercorsoCompleto() {
return getPuntoFoto().getPathCompletoFotoRidotta();
}
public String getFileNameReale() {
return getFileName();
}
public long getFlgPettoraleInviato() {
return this.flgPettoraleInviato;
}
public void setFlgPettoraleInviato(long flgPettoraleInviato) {
this.flgPettoraleInviato = flgPettoraleInviato;
}
public long getId_fotoExport() {
return this.id_fotoExport;
}
public void setId_fotoExport(long id_fotoExport) {
this.id_fotoExport = id_fotoExport;
}
public final ResParm startCreaPreview(PuntoFoto puntoFoto) {
if (!isThreadAttivo()) {
new ThreadCreaPreview(puntoFoto);
return new ResParm(true, "Thread Crea Preview Www avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread Crea Preview Www gia' in esecuzione!!!");
}
public String getPathCompletoRidottaFile() {
return getPuntoFoto().getPathCompletoFotoRidotta() + getPuntoFoto().getPathCompletoFotoRidotta();
}
public static final ResParm creaRiduzioniPerWeb(Gara gara, String fileSorgente, String dirRidotte, boolean creaNuovamente) {
boolean debug = false;
ResParm rp = new ResParm(true);
StringBuilder sb = new StringBuilder();
if (gara.getId_gara() > 0L) {
if (debug)
System.err.println("creaRiduzioniPerWeb " + fileSorgente);
String fotoSorgente = fileSorgente;
if (new File(fotoSorgente).exists()) {
int idxNomeFile = fileSorgente.lastIndexOf(DBAdapter.SEPARATOR);
String ultimaDirPercorso = fileSorgente.substring(0, idxNomeFile) + fileSorgente.substring(0, idxNomeFile);
String fileName = fileSorgente.substring(idxNomeFile + 1);
if (dirRidotte == null || dirRidotte.isEmpty())
dirRidotte = ultimaDirPercorso + "RIDOTTA/";
File dirRidotteF = new File(dirRidotte);
if (!dirRidotteF.exists())
boolean bool = dirRidotteF.mkdirs();
String fotoRidotta = dirRidotte + dirRidotte;
if (creaNuovamente) {
File fileRidottaF = new File(fotoRidotta);
if (fileRidottaF.exists())
fileRidottaF.delete();
}
String fotoRidottaTN = dirRidotte + "tn_" + dirRidotte;
if (creaNuovamente) {
File fotoRidottaTNF = new File(fotoRidottaTN);
if (fotoRidottaTNF.exists())
fotoRidottaTNF.delete();
}
int scaledWidth = 2240;
if (!new File(fotoRidotta).exists()) {
if (!gara.getImgLogoFileName().isEmpty()) {
ScaleImage si = new ScaleImage(fotoSorgente, dirRidotte, 0L, scaledWidth, 0, false, false);
si.setAutoRotate(true);
si.setBrandFileName(gara.getImgLogoFileName());
si.setFullManualScaledImageName(fotoRidotta);
si.setBrandFileX(1900);
si.setBrandFileY(170);
if (!gara.getTestoO().isEmpty()) {
si.setWatermarkText(gara.getTestoO());
si.setWatermarkSize((int)gara.getTestoSize());
if (!gara.getTestoFont().isEmpty())
si.setWatermarkFont(gara.getTestoFont());
if (!gara.getTestoColore().isEmpty())
si.setWatermarkColor(Gara.getColorFromHex(gara.getTestoColore()));
si.setWmY(1400);
}
rp = si.scaleIt();
} else {
ScaleImage si = new ScaleImage(fotoSorgente, ultimaDirPercorso, 0L, scaledWidth, 0, false, false);
si.setAutoRotate(true);
si.setFullManualScaledImageName(fotoRidotta);
rp = si.scaleIt();
}
if (!new File(fotoRidotta).exists()) {
rp.setStatus(false);
rp.setMsg("Errore! Impossibile creare foto ridotta");
} else {
rp.setStatus(true);
sb.append(fileName);
}
} else {
rp.setStatus(true);
sb.append(fileName);
}
scaledWidth = 350;
if (!new File(fotoRidottaTN).exists()) {
ScaleImage si = new ScaleImage(fotoSorgente, dirRidotte, 0L, scaledWidth, 0, false, false);
si.setAutoRotate(true);
si.setFullManualScaledImageName(fotoRidottaTN);
si.setWatermarkText(fileName);
int tnFontSize = (int)(gara.getTestoSize() / 4L);
si.setWatermarkSize(tnFontSize);
if (!gara.getTestoFont().isEmpty())
si.setWatermarkFont(gara.getTestoFont());
if (!gara.getTestoColore().isEmpty())
si.setWatermarkColor(Gara.getColorFromHex(gara.getTestoColore()));
si.setWmY(210);
rp = si.scaleIt();
if (!new File(fotoRidottaTN).exists()) {
rp.setStatus(false);
rp.setMsg("Errore! Impossibile creare foto ridotta");
} else {
rp.setStatus(true);
if (sb.length() > 0)
sb.append(",");
sb.append("tn_" + fileName);
}
} else {
rp.setStatus(true);
if (sb.length() > 0)
sb.append(",");
sb.append("tn_" + fileName);
}
} else {
rp.setMsg("ERRORE!! Foto " + fotoSorgente + " non esiste. Non è possibile creare la ridotta");
rp.setStatus(false);
}
}
rp.setInfoMsg(sb.toString());
return rp;
}
public ResParm save() {
if (!getPettoraliOld().equals(getPettorali()))
setFlgPettoraleInviato(0L);
return super.save();
}
public String getPettoraliOld() {
return (this.pettoraliOld == null) ? "" : this.pettoraliOld.trim();
}
public void setPettoraliOld(String pettoraleOld) {
this.pettoraliOld = pettoraleOld;
}
protected void initFields() {
super.initFields();
setPettoraliOld(null);
}
protected void fillFields(ResultSet rst) {
super.fillFields(rst);
setPettoraliOld(getPettorali());
}
public final ResParm startCreaPreviewMT(PuntoFoto puntoFoto) {
if (!isThreadAttivo()) {
new ThreadCreaPreviewMT(puntoFoto);
return new ResParm(true, "Thread Crea Preview MT Www avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread gia' in esecuzione!!!");
}
public String getThFotoRidotta() {
return this.thFotoRidotta;
}
public void setThFotoRidotta(String thFotoRidotta) {
this.thFotoRidotta = thFotoRidotta;
}
public String getThFotoRidottaTN() {
return this.thFotoRidottaTN;
}
public void setThFotoRidottaTN(String thFotoRidottaTN) {
this.thFotoRidottaTN = thFotoRidottaTN;
}
public String getThPercorsoRemoto() {
return this.thPercorsoRemoto;
}
public void setThPercorsoRemoto(String thPercorsoRemoto) {
this.thPercorsoRemoto = thPercorsoRemoto;
}
public final ResParm startInvioFotoDa3PianoAWwwMT(long l_id_gara, boolean l_soloFoto) {
if (!isThreadAttivo()) {
new ThreadInvioFotoDa3PianoAWwwMT(l_id_gara, l_soloFoto);
System.out.println("startInvioFotoDa3PianoAWwwMT: Invio Foto MT Www avviato!!!");
return new ResParm(true, "Thread Invio Foto MT Www avviato");
}
System.out.println("startInvioFotoDa3PianoAWwwMT: ATTENZIONE!! Thread Invio Foto MT Www gia' in esecuzione!!!");
return new ResParm(false, "ATTENZIONE!! Thread Invio Foto MT Www gia' in esecuzione!!!");
}
public ResParm impostaFileInviato() {
ResParm rp = new ResParm();
if (getId_foto() > 0L) {
rp = update("update FOTO set flgFotoInviata=1 where id_foto=" + getId_foto());
if (rp.getStatus())
setFlgFotoInviata(1L);
}
return rp;
}
private static final synchronized ResParm syncAggiornaFotoExportPettoraleInviato_1(Foto bean, long l_id_fotoExport, long l_flgPettoraleInviato) {
String s_sql = "update FOTO SET id_fotoExport=" + l_id_fotoExport + " ,flgPettoraleInviato = " + l_flgPettoraleInviato + " where id_foto=" +
bean.getId_foto();
ResParm rp = bean.update(s_sql);
if (rp.getStatus()) {
bean.setId_fotoExport(l_id_fotoExport);
bean.setFlgPettoraleInviato(l_flgPettoraleInviato);
}
return rp;
}
public static final synchronized ResParm syncAggiornaPettoraleInviato(Foto bean, long l_id_fotoExport, long l_flgPettoraleInviato, String l_pettorali, long l_flgTipo) {
if (l_flgTipo == 1L)
return syncAggiornaFotoExportPettoraleInviato_1(bean, l_id_fotoExport, l_flgPettoraleInviato);
if (l_flgTipo == 2L)
return syncAggiornaPettorale_2(bean, l_pettorali);
if (l_flgTipo == 3L)
return syncAggiornaPettoraleInviato_3(bean, l_flgPettoraleInviato);
return new ResParm(false);
}
private static final synchronized ResParm syncAggiornaPettoraleInviato_3(Foto bean, long l_flgPettoraleInviato) {
String s_sql = "update FOTO SET flgPettoraleInviato =" + l_flgPettoraleInviato + " where id_foto=" + bean.getId_foto();
ResParm rp = bean.update(s_sql);
if (rp.getStatus())
bean.setFlgPettoraleInviato(l_flgPettoraleInviato);
return rp;
}
private static final synchronized ResParm syncAggiornaPettorale_2(Foto bean, String l_pettorali) {
String temp = l_pettorali.trim();
if (!temp.isEmpty()) {
if (!temp.startsWith(","))
temp = "," + temp;
if (!temp.endsWith(","))
temp = temp + ",";
while (temp.indexOf(",,") >= 0)
temp = temp.replaceAll(",,", ",");
}
String s_sql = "update FOTO SET pettorali='" + temp + "' ,flgPettoraleInviato = null where id_foto=" + bean.getId_foto();
ResParm rp = bean.update(s_sql);
if (rp.getStatus()) {
bean.setFlgPettoraleInviato(0L);
bean.setPettorali(temp);
}
return rp;
}
public String getFileNameFaceRecognition() {
return getFileNamePercorsoCompleto();
}
public boolean hasFotoFaces() {
return false;
}
public ResParm _ricalcolaFotoFaces() {
return null;
}
public long getFlgFotoSearch() {
return 0L;
}
public Timestamp getTsInserimento() {
return null;
}
public String getMd5() {
return "";
}
public void setMd5(String newMd5) {}
public String getFileName(String ext) {
if (ext.isEmpty())
return getFileName().replaceAll("_", "+");
return getFileName().toLowerCase().replace(ext.toLowerCase(), "").replaceAll("_", "+");
}
public long getNumOfFaces() {
return 0L;
}
public long getHeight() {
return 0L;
}
public long getWidth() {
return 0L;
}
public long getMargineFotoBottom() {
return 0L;
}
public long getMargineFotoTop() {
return 0L;
}
public long getMargineFotoSx() {
return 0L;
}
public long getMargineFotoDx() {
return 0L;
}
public long getDimMinFotoFaceReal() {
return 0L;
}
public FaceDetectionMethod getFaceDetectionMethodReal() {
return null;
}
public double getDetectFaceConfidentThresold() {
return 0.0D;
}
public void setId_faceDetectionMethod(long l_id_faceDetectionMethod) {}
public long getId_faceDetectionMethod() {
return 0L;
}
public long getFaceSize() {
return 0L;
}
}