1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
package be.proximus.cecu.ivr.thread;
import be.ivr.ejb.upload;
import be.ivr.ejb.uploadHome;
import be.eventlog.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.sql.Date;
import java.util.Vector;
import java.io.InputStream;
import java.lang.Thread;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
public class IVRPackage extends Thread {
boolean keepRunning = true;
private CECULogger logger = null;
public void run(){
while(keepRunning){
Vector dDate = new Vector();
InputStream in = null;
boolean isDeployed = false;
boolean previous = false;
boolean after = false;
int interval = 60000;
int num = 0;
int yes = 1;
String deployed = "";
String server = "";
String username = "";
String password = "";
String destinationFolder = "";
String id = "";
Context ctx = null;
try{
logger = new CECULogger(CECULogger.IVR, "");
ctx = new InitialContext();
Object ref = ctx.lookup("upload");
uploadHome uph = (uploadHome) PortableRemoteObject.narrow(ref, uploadHome.class);
upload up = uph.create();
interval = up.getTimeInterval(); //Contains the timeInterval for the thread's jobs.
System.out.println("Time interval : " + interval);
dDate = up.deployDate(); //Contains the deploy date of the IVR_PACKAGE.
num = dDate.size(); //Contains the number of IVR_PACKAGE to deploy.
System.out.println("Number of IVR_Package to deploy : " + num);
Date aujourdhui = new java.sql.Date(new java.util.Date().getTime()); //Contains the current date.
System.out.println("Date : " + aujourdhui);
DateFormat dateFormat2 = new SimpleDateFormat("yyyyMMddhhmmss"); //Set the Date format to yyyyMMddhhmmss
String fileName = dateFormat2.format(new java.util.Date()) + ".zip"; //Contains the fileName, fomated like this "yyyyMMddhhmmss.zip" .
System.out.println("File name : " + fileName);
server = up.getFTPAddress(); //Retrieve the FTP address.
System.out.println("Server name : " + server);
username = up.getFTPUser(); //Retrieve the FTP login.
System.out.println("Username : " + username);
password = up.getFTPPassword(); //Retrieve the FTP password.
System.out.println("Password : " + password);
destinationFolder = up.getDestFolder(); //Retrieve the FTP folder where the IVR_PACKAGE will be uploaded.
System.out.println("DestinationFolder : " + destinationFolder);
for (int i = 0; i < num; i++) {
------- Le problème vient d'ici ! ------
Date dateD = (Date) dDate.get(i); //Contains the deploy date of the IVR_PACKAGE.
--------------------------------------
//System.out.println("Object getClass()"+dateD.getClass());
id = (String) dDate.get(i + 1); //Contains the ID of the IVR_PACKAGE to deploy.
System.out.println("Deploy date : " + dDate.get(i)+" Id of the Blob : "+dDate.get(i+1));
System.out.println("Deploy date : " + dateD);
System.out.println("Test Dev : "+ dDate.get(i).getClass().getName() );
previous = dateD.before(aujourdhui); //Contains true if the DEPLOYDATE is < than the current date.
System.out.println("previous : " + previous);
deployed = up.IsDeployed(id); //Contains 0 if the IVR_PACKAGE is not yet deploy, and 1 if deployed.
System.out.println("deployed : " + deployed);
if ("0".equals(deployed)) { //Test if if we need to upload the IVR_PACKAGE.
if (previous) {
if (i > 0) {
i--;
} else {
i = 0;
}
in = up.getBlob(id); //Contains the InputStream of the Blob.
System.out.println("InputStream : " + in);
isDeployed = up.uploadBlob(server, username, password, fileName, in,destinationFolder); //We uplpoad the IVR_PACKAGE, and isDeployed is set to true, if the upload was successfull.
System.out.println("File uploaded 3 : " + isDeployed);
if (isDeployed) {
up.SetDeployed(yes, id); //Now that we have upload the IVR_Package we set the deployed field to true.
logger.info("File "+ fileName +" uploaded successfully.");
System.out.println("File uploaded successfully.");
}
}else {
after = dateD.after(aujourdhui);
if (after) {
i++; //To reach the next Blob's deployDate.
}
}
}
}
Thread.sleep(interval); //Time interval between the Thread tasks.
System.out.println("Time interval : " + interval);
}catch (Exception e) {
this.keepRunning = false;
e.printStackTrace();
logger.error(ErrorCode.GENERAL_JAVA_EXCEPTION, "Exception : " + e);
System.out.println("Test Dev : "+ dDate.get(0).getClass().getName() );
}
System.out.println("Keep Running value : "+keepRunning);
}
}
public void destroy() {
try{
logger = new CECULogger(CECULogger.IVR, "");
System.out.println("-- The processus IVRPackage is stopped.");
logger.info("-- The processus IVRPackage is stopped.");
this.keepRunning = false;
}catch(Exception e){
e.printStackTrace();
logger.error(ErrorCode.GENERAL_JAVA_EXCEPTION,"Exception : "+e);
}
}
} |
Partager