use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class BaseDeDonnesBean method backUpBaseDonnees.
/**
* Cette fonction permet de télécharger les tables et les données ce qui
* permet de sauvegarder toutes les données privées pour les mise à jour
*
* @param toutTables
* @return
*/
public StreamedContent backUpBaseDonnees(ArrayList<String> toutTables) {
ArrayList<Table> sortirXml;
ExportPrivatesDatas backUp = new ExportPrivatesDatas();
Iterator<String> it1 = toutTables.iterator();
WriteXml write = new WriteXml();
write.writeHead();
write.start();
String table = "";
// date du jour
java.util.Date datetoday = new java.util.Date();
while (it1.hasNext()) {
table = it1.next();
sortirXml = backUp.getDatasOfTable(connect.getPoolConnexion(), table);
write.WriteIntoXML(sortirXml, table);
}
write.end();
InputStream stream;
try {
stream = new ByteArrayInputStream(write.getXml().toString().getBytes("UTF-8"));
file = new DefaultStreamedContent(stream, "application/xml", "backupOpentheso_" + datetoday + ".xml");
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
}
return file;
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class ForgetPasswordHelper method faireChangePass.
/**
* cette funtion c'est la funtion que realise le update dans la table et
* efface le ancien motpasstemp;
*
* @param ds
* @param Pass
* @param ConfirmPass
* @param id
* @return
* @throws SQLException
*/
public boolean faireChangePass(HikariDataSource ds, String Pass, String ConfirmPass, int id) throws SQLException {
String passwordencoding = MD5Password.getEncodedPassword(Pass);
Statement stmt, stmt1;
boolean ok = false;
// ancien = MD5Password.getEncodedPassword(ancien);//transform le pass en format encrypt pour la BDD
try {
Connection conn = ds.getConnection();
stmt = stmt1 = conn.createStatement();
try {
// System.out.println(Pass);
String queryAjouPass = "update users set password ='" + passwordencoding + "',passtomodify = false where id_user ='" + id + // on mettre a jour le nouvelle pass dans le memme colon que le motpasstemp
"'";
stmt.executeUpdate(queryAjouPass);
ok = true;
} finally {
stmt.close();
stmt1.close();
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
}
// }
return ok;
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class WriteXml method WriteIntoXML.
public void WriteIntoXML(ArrayList<Table> DataTable, String Tablename) {
startTable(Tablename);
for (Table user : DataTable) {
startLine();
for (LineOfData lineOfData : user.getLineOfDatas()) {
writeLine(lineOfData.getColomne(), lineOfData.getValue());
}
endLine();
}
endTable();
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class importxml method insertLine2.
/**
* cette funtion permet de faire la inyection a la BDD line par line de la table "nomtable"
* et le données que ils sont dans une ArrayList
* Cette funtion c'est la generique;
* @param ds
* @param table
* @param nomtable
*/
private void insertLine2(HikariDataSource ds, ArrayList<LineOfData> table, String nomtable) throws ClassNotFoundException, SQLException {
Statement stmt;
String nomcolun = "";
String values = "";
boolean first = true;
Connection con = ds.getConnection();
String temp = "";
for (LineOfData lineOfData : table) {
if (!first) {
nomcolun += ",";
values += ",";
}
// nomcolun contiens toutes les camps de la table "nomtable"
nomcolun += lineOfData.getColomne();
// contiens toutes les values de la memme ligne
values += "'" + lineOfData.getValue() + "'";
first = false;
}
values += ");";
try {
stmt = con.createStatement();
try {
// récupération des noms des colonnes de la table
String query = "INSERT INTO " + nomtable + " ( " + nomcolun + ") VALUES (" + values;
temp = query;
stmt.executeUpdate(query);
} finally {
stmt.close();
con.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(temp);
}
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class importxml method ouvreFichier.
/*
for (Table user : DataTable) {
for (LineOfData lineOfData : user.getLineOfDatas()) {
writeLine(lineOfData.getColomne(), lineOfData.getValue());
}
*/
/*
public void choisirfichier (HikariDataSource ds){
JFileChooser fileChooser = new JFileChooser();
int seleccion = fileChooser.showOpenDialog(null);
fichero = fileChooser.getSelectedFile();
//Acciones que se quieran realizar
ouvreFichier();
}*/
/**
* cette funtion permet de ouvrir un fichier pour comencée a faire une
* injection de données.
* C'est seulement pour la creation de un nouvelle BDD.
* la funtion generique est plus ba
* @param con
* @param archive
* @throws ClassNotFoundException
* @throws SQLException
*/
public void ouvreFichier(Connection con, File archive) throws ClassNotFoundException, SQLException {
LanguageBean langueBean = new LanguageBean();
SAXBuilder builder = new SAXBuilder();
ArrayList<Table> toutTables = new ArrayList<>();
ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
try {
// on crée le document a partir du fichier que on a selectioné
Document document = (Document) builder.build(archive);
// Se obtiene la raiz 'tables'
Element rootNode = document.getRootElement();
// ici on a toutes les tables (les enfants de la racine)
List list = rootNode.getChildren("table");
// ici on fait le tour pour les enfants de 'tables'
for (int i = 0; i < list.size(); i++) {
// ici on a la première table
Element tabla = (Element) list.get(i);
// ici on a le nom de la table
String nombreTabla = tabla.getAttributeValue("nom");
// ici c'est la liste des lignes de la table
List lista_campos = tabla.getChildren();
// ici on découpe la liste des lignes
for (int j = 0; j < lista_campos.size(); j++) {
// ici on a une ligne de la table
Element campo = (Element) lista_campos.get(j);
for (Element colonne : campo.getChildren()) {
LineOfData lineOfData = new LineOfData();
// le nom de la colone
lineOfData.setColomne(colonne.getName());
// le value que le correspond
lineOfData.setValue(colonne.getText());
lineOfDatas.add(lineOfData);
}
insertLine(con, lineOfDatas, nombreTabla);
lineOfDatas.clear();
}
// / mettre à jour la table dans la BDD
}
} catch (IOException | JDOMException io) {
System.out.println("error");
}
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1")));
}
Aggregations