111 lines
4.7 KiB
Java
111 lines
4.7 KiB
Java
package it.valueteam.gnpsim.client;
|
|
|
|
import it.valueteam.gnpsim.generator.ib.*;
|
|
import it.valueteam.gnpsim.obj.SystemMap;
|
|
import it.valueteam.gnpsim.sender.IBSender;
|
|
import it.valueteam.gnpsim.utility.IOUtility;
|
|
import it.valueteam.gnpsim.utility.SimConfFile;
|
|
|
|
import java.util.Properties;
|
|
|
|
public class ClientIBGenerator extends BaseClient {
|
|
private static XMLGeneratorIF generator;
|
|
private static Properties propIB = SimConfFile.getInstance().ReadSection("InfobusIN");
|
|
|
|
// Numero minimo di parametri
|
|
private static int MIN_PARAM_NUMBER = 3;
|
|
// Indice del parametro per l'invio automatico
|
|
private static int IDX_INVIO_AUTOMATICO = 0;
|
|
// Indice del parametro Tipo Sistema
|
|
private static int IDX_TIPO_SISTEMA = 1;
|
|
// Indice del parametro Numero Richieste
|
|
private static int IDX_NUMERO_RICHIESTE = 2;
|
|
// Indice del parametro Infobus service name
|
|
private static int IDX_IB_SERVICE_NAME = 3;
|
|
|
|
public ClientIBGenerator() {
|
|
}
|
|
|
|
/**
|
|
* tipi sistema:
|
|
* CRMR,1
|
|
* CRMB,2
|
|
*/
|
|
|
|
|
|
public static final void main(String[] args) {
|
|
printInfo("ClientIBGenerator", args);
|
|
|
|
if (args.length < MIN_PARAM_NUMBER)
|
|
throw new IllegalArgumentException("Numero parametri insufficienti!");
|
|
|
|
try {
|
|
int invioAutomatico = Integer.parseInt(args[IDX_INVIO_AUTOMATICO]);
|
|
int tipoSistema = getTipoSistema(args[IDX_TIPO_SISTEMA]);
|
|
String[] argument = new String[args.length - MIN_PARAM_NUMBER];
|
|
System.arraycopy(args, MIN_PARAM_NUMBER, argument, 0, args.length - MIN_PARAM_NUMBER);
|
|
int numeroRichieste = Integer.parseInt(args[IDX_NUMERO_RICHIESTE]);
|
|
IBSender ibSender = new IBSender();
|
|
String ibServiceName = args[IDX_IB_SERVICE_NAME];
|
|
|
|
System.out.println("Invio Automatico = " + invioAutomatico);
|
|
System.out.println("Tipo Sistema = " + tipoSistema);
|
|
System.out.println("Numero Richieste = " + numeroRichieste);
|
|
System.out.println("Infobus Service Name = " + ibServiceName);
|
|
|
|
switch (tipoSistema) {
|
|
case SystemMap.SISTEMA_CRMR: {
|
|
for (int i = 0; i < numeroRichieste; i++) {
|
|
generator = new XMLCrmGenerator();
|
|
String xml = generator.generateXml(argument, SystemMap.SISTEMA_CRMR);
|
|
if (invioAutomatico == 1) {
|
|
System.out.println(xml);
|
|
ibSender.sendRequest(xml, SystemMap.SISTEMA_CRMR);
|
|
} else {
|
|
String[] content = {xml};
|
|
String file = propIB.getProperty("GEN_PATH_CRMR") + "NOTIFICA_CRMR_" + i + ".xml";
|
|
IOUtility.writeFile(file, content);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case SystemMap.SISTEMA_CRMB: {
|
|
for (int i = 0; i < numeroRichieste; i++) {
|
|
generator = new XMLCrmGenerator();
|
|
String xml = generator.generateXml(argument, SystemMap.SISTEMA_CRMB);
|
|
if (invioAutomatico == 1) {
|
|
System.out.println(xml);
|
|
ibSender.sendRequest(xml, SystemMap.SISTEMA_CRMB);
|
|
} else {
|
|
String[] content = {xml};
|
|
String file = propIB.getProperty("GEN_PATH_CRMB") + "NOTIFICA_CRMB_" + i + ".xml";
|
|
IOUtility.writeFile(file, content);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case SystemMap.SISTEMA_CRMR_HZ:
|
|
generator = new XMLHZCrmrGenerator();
|
|
for (int i = 0; i < numeroRichieste; i++) {
|
|
String xml = generator.generateXml(argument, SystemMap.SISTEMA_CRMR_HZ);
|
|
if (invioAutomatico == 1) {
|
|
System.out.println(xml);
|
|
ibSender.sendHZRequest(xml, SystemMap.SISTEMA_CRMR_HZ);
|
|
} else {
|
|
String[] content = {xml};
|
|
String file = propIB.getProperty("GEN_PATH_CRMB_HZ") + "NOTIFICA_CRMR_HZ_" + i + ".xml";
|
|
IOUtility.writeFile(file, content);
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
throw new IllegalArgumentException("sistema sconociuto!\n Sistema inserito : " + args[IDX_TIPO_SISTEMA]);
|
|
}
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
} |