First Commit from Source Code Reply

This commit is contained in:
vincenzofariello
2024-05-09 17:40:24 +02:00
parent 11e3b57c5b
commit 107a016cb9
35225 changed files with 1111346 additions and 1 deletions

View File

@@ -0,0 +1,354 @@
package it.valueteam.gnpsim.base;
import it.valueteam.gnpsim.database.SimDAO;
import it.valueteam.gnpsim.obj.CausaliRifiutoOloDTO;
import it.valueteam.gnpsim.obj.OloReplyDto;
import it.valueteam.gnpsim.utility.*;
import java.lang.reflect.Method;
import java.util.*;
/**
* @author Giovanni
*/
public class SimGenerator {
public SimGenerator() {
dao = new SimDAO();
}
protected Random rand = new Random();
protected static Properties propGeneral = SimConfFile.getInstance().ReadSection("General");
protected static Properties propUpdating = SimConfFile.getInstance().ReadSection("Updating");
protected String prefisso = propUpdating.getProperty("PREFISSO");
// protected int telefono = Integer.parseInt(propUpdating.getProperty("SEED_TEL"));
private static String DEFAULT_OLO = "AMB";
private static String DEFAULT_COS = "001";
private static String DEFAULT_MARCAGGIO = "01";
private static String DEFAULT_CANALE_VENDITA = "VB78";
protected static final int DEFAULT_KO = -1;
protected SimDAO dao;
protected String listaNomi[] = {
"ANDREA", "GIOVANNI", "AMBRA", "CLAUDIO", "IVAN", "SARA", "ELENA",
"GIORGIO", "DIEGO", "ANTONELLA"};
protected String listaCognomi[] = {
"UNGARO", "AMICI", "PARATI", "GARBELLI", "PIZZOLANTE", "SCARPELLINI",
"FIORE", "TAGLIENTE", "NUNNERI", "RENDE"};
protected String[] listaCodiciErroriXdsl = {"C07", "C10", "C11", "C15"};
/**
* Aggiunge tanti zeri come prefisso fino a maxLen
*
* @param number String
* @param maxLen int
* @return String
*/
protected String addZero(String number, int maxLen) {
int len = number.length();
while (len < maxLen) {
number = "0" + number;
len++;
}
return number;
}
protected String removeZero(String number) {
String result = null;
result = number.replaceAll("[0]", "");
return result;
}
/**
* Aggiunge tanti spazi fino a maxLen
*
* @param text String
* @param maxLen int
* @return String
*/
protected String addBlank(String text, int maxLen) {
int len = text.length();
while (len < maxLen) {
text = " " + text;
len++;
}
return text;
}
/**
* Resituisce un canale di provenienza tra quelli permessi
*
* @return String
*/
protected String randomCanaleProvenienzaDBSS() {
String[] canaliProvenienza = {"CCARE", "DMS", "CC", "IVR", "WEB", "SALES WEB", "SMS CARING", "SALES APP", "AS", "TS", "FV"};
int i = rand.nextInt(11);
return canaliProvenienza[i];
}
/**
* Resituisce un canale di provenienza tra quelli permessi
*
* @return String
*/
protected String randomCanaleProvenienzaCRM() {
String[] canaliProvenienza = {"CCARE", "DMS"};
int i = rand.nextInt(2);
return canaliProvenienza[i];
}
/**
* Resituisce il valore random di un flag nel dominio [Y,N]
*
* @return String
*/
protected String getRandomFlag() {
Random random = new Random();
return random.nextBoolean() ? "Y" : "N";
}
protected String getTelefono(int length) {
int numeroNum = (Integer.parseInt(SimConfFile.getInstance().ReadSection("Updating").getProperty("SEED_TEL"))) + 1;
saveSeedTel(numeroNum + "");
String numero = prefisso + numeroNum;
return addZero(numero, length);
}
protected String getCodiceFiscalePartitaIVA() {
return "SRTMCC75C52A345Q";
}
protected String getIdEsigenzaSolution() {
int idEsigenzaSolution = Integer.parseInt(SimConfFile.getInstance().ReadSection("Updating").getProperty("ID_ESIGENZA_SOLUTION")) + 1;
String result = addZero(Integer.toString(idEsigenzaSolution), 11);
saveIdEsigenzaSolution(idEsigenzaSolution + "");
return result;
}
protected String randomNomeCliente() {
int i = rand.nextInt(10);
return listaNomi[i];
}
protected String randomCognomeCliente() {
int i = rand.nextInt(10);
return listaCognomi[i];
}
protected String randomCodiceErroreXdsl() {
int i = rand.nextInt(3);
return listaCodiciErroriXdsl[i];
}
protected String getCodiceSessione() {
return propGeneral.getProperty("CODICE_SESSIONE");
}
public void saveSeedTel(String telefono) {
SimConfFile.getInstance().WriteString("Updating", "SEED_TEL", telefono);
SimConfFile.getInstance().UpdateFile();
}
public void saveIdEsigenzaSolution(String idEsigenza) {
SimConfFile.getInstance().WriteString("Updating", "ID_ESIGENZA_SOLUTION", idEsigenza);
SimConfFile.getInstance().UpdateFile();
}
public void saveIdEsigenzaManuale(String idEsigenzaManu) {
SimConfFile.getInstance().WriteString("Updating", "ID_ESIGENZA_MANUALE", idEsigenzaManu);
SimConfFile.getInstance().UpdateFile();
}
public void saveIdFileOLO(String idFileOLO) {
SimConfFile.getInstance().WriteString("Updating", "ID_FILE_OLO", idFileOLO);
SimConfFile.getInstance().UpdateFile();
}
protected String getWait() {
return propGeneral.getProperty("WAIT");
}
protected String getSla() {
return propGeneral.getProperty("SLA");
}
protected String getDacCrm() throws Exception {
int calc_dac = Integer.parseInt(propGeneral.getProperty("CALC_DAC"));
String dac = DateUtils.aggiungiGiorniLavorativiCrm(new Date(), calc_dac, propGeneral.getProperty("PATTERN_DATE_DAC"));
return dac;
}
protected String getDetCrm() throws Exception {
int calc_det = Integer.parseInt(propGeneral.getProperty("CALC_DET"));
String det = DateUtils.aggiungiGiorniLavorativiCrm(new Date(), calc_det, propGeneral.getProperty("PATTERN_DATE_DET"));
return det;
}
protected String getIdEsigenzaManuale() {
int idEsigenzaSolution = Integer.parseInt(SimConfFile.getInstance().ReadSection("Updating").getProperty("ID_ESIGENZA_MANUALE"));
String result = addZero(Integer.toString(idEsigenzaSolution), 15);
saveIdEsigenzaManuale((idEsigenzaSolution + 1) + "");
return result;
}
public String getIdFileOLO() {
int idFileOLO = Integer.parseInt(SimConfFile.getInstance().ReadSection("Updating").getProperty("ID_FILE_OLO"));
String result = addZero(Integer.toString(idFileOLO), 5);
saveIdFileOLO((idFileOLO + 1) + "");
return result;
}
public String randomCodiceOlo() {
String result = null;
try {
String[] olo = dao.getAllOlo();
int i = rand.nextInt(olo.length);
result = olo[i];
} catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex.getMessage());
System.out.println("Errore durante la select per gli OLO. Verr<72> inserito l'OLO di default AMB ");
result = DEFAULT_OLO;
}
return result;
}
protected Date toDate(String date, String pattern) {
Date data = null;
try {
data = DateUtils.toDate(date, pattern);
} catch (Exception ex) {
// Nothing to do
}
return data;
}
protected OloReplyDto[] getRequestToReply(String olo, int stato, int tipoRichieste) throws Exception {
return dao.getRequestToReply(olo, stato, tipoRichieste);
}
protected String toString(Date date, String pattern) {
return DateUtils.toString(date, pattern);
}
protected String getXmlFromCastorObject(Object bean, boolean validate) throws Exception {
return XmlUtility.getXmlStringFromCastorXmlObject(bean, validate);
}
protected CausaliRifiutoOloDTO getInfoOloKO(int tipoComunicazione, int tipoKO) {
CausaliRifiutoOloDTO result = null;
try {
CausaliRifiutoOloDTO[] causali = dao.getCausaliRifiutoOloByTipoComunicazione(tipoComunicazione);
if (tipoKO == DEFAULT_KO) {
result = causali[rand.nextInt(causali.length)];
} else {
int i = 0;
while (!causali[i].getCodiceMotivo_rifiuto().equals("" + tipoKO) && i < causali.length - 1) {
i++;
}
result = causali[i];
if (result == null) {
result = causali[rand.nextInt(causali.length)];
}
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex.getMessage());
}
return result;
}
protected String getRandomCos() {
String result;
try {
String[] cos = dao.getValidCos();
int i = rand.nextInt(cos.length);
result = cos[i];
} catch (Exception ex) {
System.out.println(ex.getMessage());
System.out.println("Errore durante la select per gli COS. Verrà inserito il COS di default 001 ");
result = DEFAULT_COS;
}
return result;
}
protected boolean isNull(String string) {
return string == null || string.trim().length() == 0;
}
protected void populateBeanWithUnicValue(Object o, String value) throws Exception {
Method[] methods = null;
if (o == null)
throw new Exception("l'oggetto da popolare risulta nullo");
methods = o.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
String name = method.getName();
try {
if (name.startsWith("set")) {
Object[] argument = {value};
method.invoke(o, argument);
}
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
}
protected String getCodiceCorrelazioneCRM() throws Exception {
return propGeneral.getProperty("COD_CORRELAZIONE");
}
protected String getRandomMarcaggio() {
String result = null;
try {
String[] marcaggio = dao.getValidMarcaggio();
int i = rand.nextInt(marcaggio.length);
result = marcaggio[i];
} catch (Exception ex) {
System.out.println(ex.getMessage());
System.out.println("Errore durante la select per i marcaggi. Verrà inserito il marcaggio di default 01 ");
result = DEFAULT_MARCAGGIO;
}
return result;
}
protected String getRandomCanaleVendita() {
String result = null;
try {
String[] canaleVendita = dao.getValidCanaleVendita();
int i = rand.nextInt(canaleVendita.length);
result = canaleVendita[i];
} catch (Exception ex) {
System.out.println(ex.getMessage());
System.out.println("Errore durante la select per i canaleVendita. Verrà inserito il canaleVendita di default VB78 ");
result = DEFAULT_CANALE_VENDITA;
}
return result;
}
/**
* Restituisce una stringa casuale di 18 caratteri alfanumerici
*
* @return la stringa da usare come codice progetto
*/
protected String getRandomCodiceProgetto() {
int length = 18;
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random rng = new Random();
String st = "";
for (int i = 0; i < length; i++)
{
st += chars.charAt(rng.nextInt(chars.length()));
}
return st;
}
}