package it.acxent.cc; import it.acxent.art.Articolo; import it.acxent.art.ArticoloCR; import it.acxent.common.CrontabInterface; import it.acxent.common.StatusMsg; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; import it.acxent.db.ResParm; import it.acxent.util.Timer; import it.acxent.util.Vectumerator; public class CCCronIcecatAutomatorGoogle implements CrontabInterface { public ResParm crontabJob(ApplParmFull ap) { Timer timer = new Timer(); timer.start(); String TAG_THREAD_MSG = "ICECAT+AUTOMATOR+SITEMAP+GOOGLE "; System.out.println("CCCrontIcecatAuto start..."); StringBuffer msg = new StringBuffer("\n################# Inizio crontab " + TAG_THREAD_MSG + " (" + DBAdapter.getNow().toString() + ")\n#################"); StatusMsg.updateMsgByTag(ap, TAG_THREAD_MSG, " THREAD ICECAT IN ESECUZIONE ......"); msg.append("************* THREAD ICECAT ***************+\n"); ResParm rp = new ResParm(true); Articolo art = new Articolo(ap); ArticoloCR ACR = new ArticoloCR(ap); ACR.setFlgReadyForWeb(0L); ACR.setFlgEscludiWeb(-1L); ACR.setFlgQta(1L); ACR.setQtaDa(1L); ACR.setQtaA(9999L); rp = art.startThreadIcecatAuto(ap, ACR); msg.append(rp.getMsg()); msg.append("\n"); while (Articolo.isThreadIcecatAuto()) { try { Thread.sleep(3000L); } catch (Exception e) {} } msg.append("\nfine ICECAT. Lap time:" + timer.getDurataHourMin()); StatusMsg.updateMsgByTag(ap, TAG_THREAD_MSG, " THREAD AUTOMATOR IN ESECUZIONE ......"); msg.append("\n\n************* THREAD AUTOMATOR ***************+\n"); rp = new ResParm(true); WwwAutomator automator = new WwwAutomator(ap); WwwAutomatorCR CRWA = new WwwAutomatorCR(); CRWA.setFlgAbilita(1L); rp = automator.startAutomator(ap, CRWA, true); msg.append(rp.getMsg()); msg.append("\n"); while (WwwAutomator.isThreadAttivo()) { try { Thread.sleep(3000L); } catch (Exception e) {} } msg.append("\nfine AUTOMATOR. Lap time:" + timer.getDurataHourMin()); StatusMsg.updateMsgByTag(ap, TAG_THREAD_MSG, " THREAD SITEMAP IN ESECUZIONE ......"); msg.append("\n\n************* THREAD SITEMAP ***************+\n"); rp = art.startThreadCreaSitemaps(ap, ACR); if (rp.getStatus()) { Thread t = (Thread)rp.getExtraInfo("thread", null); if (t != null) try { t.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } msg.append("\nfine SITEMAP. Lap time:" + timer.getDurataHourMin()); } else { msg.append("\nErrore nella generazione delle sitemap: " + rp.getMsg() + "\n"); } StatusMsg.updateMsgByTag(ap, TAG_THREAD_MSG, " THREAD GOOGLE MERCHANT IN ESECUZIONE ......"); msg.append("\n\n************* THREAD GOOGLE MERCHANT ***************+\n"); rp = new ResParm(true); ACR = new ArticoloCR(ap); ACR.setFlgQta(1L); ACR.setFlgGoogle(1L); ACR.setGoogleFeedFileName("offerte"); ACR.setFileNameGoogle("offerte.xml"); art = new Articolo(ap); Vectumerator vec = art.findByCR(ACR, 0, 0); CCImport bean = new CCImport(); if (!art.isLocalhost()) { if (ap.getParmValue("GOOGLE_FTP_USER", "").equals("") || ap.getParmValue("GOOGLE_FTP_PASSWORD", "").equals("")) { msg.append("parametri ftp google non impostati. impossibile inviare il feed via ftp a google\n"); } else { rp = bean.startGoogleFtp(ap, ACR); msg.append("Numero record inviati a google via ftp feed " + ACR.getGoogleFeedFileName() + ": " + vec.getTotNumberOfRecords() + "\n"); msg.append(rp.getMsg()); } } else { msg.append("thread google xml non avviato sulla crontab perché localhost!!\n"); msg.append(rp.getMsg()); } while (CCImport.isThreadGoogleMerchant()) { try { Thread.sleep(3000L); } catch (Exception e) {} } msg.append("\nfine GOOGLE MERCHANT. Lap time:" + timer.getDurataHourMin()); StatusMsg.deleteMsgByTag(ap, TAG_THREAD_MSG); msg.append("\n################# Fine crontab " + TAG_THREAD_MSG + "(" + DBAdapter.getNow().toString() + ")\n#################"); timer.stop(); msg.append("Durata aggiornamento: " + timer.getDurataHourMin() + "\n"); rp.setMsg(msg.toString()); System.out.println(msg.toString()); return rp; } }