Search in sources :

Example 11 with Table

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WriteXml(mom.trd.opentheso.core.exports.privatesdatas.WriteXml) ByteArrayInputStream(java.io.ByteArrayInputStream) ExportPrivatesDatas(mom.trd.opentheso.core.exports.helper.ExportPrivatesDatas)

Example 12 with Table

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;
}
Also used : Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 13 with Table

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();
}
Also used : Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table)

Example 14 with Table

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);
    }
}
Also used : Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) SQLException(java.sql.SQLException) Statement(java.sql.Statement) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) Connection(java.sql.Connection)

Example 15 with Table

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")));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ArrayList(java.util.ArrayList) List(java.util.List) LanguageBean(mom.trd.opentheso.SelectedBeans.LanguageBean)

Aggregations

Table (mom.trd.opentheso.core.exports.privatesdatas.tables.Table)17 SQLException (java.sql.SQLException)11 Statement (java.sql.Statement)11 Connection (java.sql.Connection)10 ArrayList (java.util.ArrayList)8 LineOfData (mom.trd.opentheso.core.exports.privatesdatas.LineOfData)8 ResultSet (java.sql.ResultSet)6 IOException (java.io.IOException)4 List (java.util.List)3 Document (org.jdom2.Document)3 Element (org.jdom2.Element)3 JDOMException (org.jdom2.JDOMException)3 SAXBuilder (org.jdom2.input.SAXBuilder)3 Test (org.junit.Test)3 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 File (java.io.File)2 LanguageBean (mom.trd.opentheso.SelectedBeans.LanguageBean)2 ExportPrivatesDatas (mom.trd.opentheso.core.exports.helper.ExportPrivatesDatas)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1