Search in sources :

Example 6 with Table

use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.

the class TestExportPrivatesDatas method testWriteUsersIntoXML1.

@Test
public void testWriteUsersIntoXML1() {
    HikariDataSource conn = openConnexionPool();
    ExportPrivatesDatas exportPrivatesDatas = new ExportPrivatesDatas();
    ArrayList<Table> usersList = exportPrivatesDatas.getDatasOfTable(conn, "alignement_type");
    // ArrayList <Proposition> listPropo = exportPrivatesDatas.getProposition(conn);
    // ArrayList <Concept_Candidat> listConceptC = exportPrivatesDatas.getconceptCandidat(conn);
    // ArrayList <Term_Candidat> listTermC = exportPrivatesDatas.getTermeCandidat(conn);
    // ArrayList <Concept_orphan> list_userRol = exportPrivatesDatas.getConceptOrphelin(conn);
    // ArrayList <Concept_Fusion> list_userRol = exportPrivatesDatas.getconceptFusion(conn);
    // ArrayList <Images> list_userRol = exportPrivatesDatas.getImages(conn);
    // ArrayList <Preferences> list_userRol = exportPrivatesDatas.getPreferences(conn);
    // ArrayList <Concept_Group_Historique> list_userRol = exportPrivatesDatas.getConceptGroupHist(conn);
    // ArrayList <Concept_Group_Label_Historique> list_userRol = exportPrivatesDatas.getconceptGroupLabelH(conn);
    // ArrayList <Concept_Historique> list_userRol = exportPrivatesDatas.getConceptHistorique(conn);
    // ArrayList <Hierarchical_Relationship_Historique> list_userRol = exportPrivatesDatas.getHierarchicalRelationshipH(conn);
    // ArrayList <Non_Preferred_Term> list_userRol = exportPrivatesDatas.getNonPreferredTerm(conn);
    // ArrayList <Note_Historique> list_userRol = exportPrivatesDatas.getNoteHistorique(conn);
    // ArrayList <Term_Historique> list_userRol = exportPrivatesDatas.getTermHistorique(conn);
    conn.close();
    writeHead();
    startTable("users");
    for (Table user : usersList) {
        startLine();
        for (LineOfData lineOfData : user.getLineOfDatas()) {
            writeLine(lineOfData.getColomne(), lineOfData.getValue());
        }
        endLine();
    }
    endTable("users");
    System.out.println(xml);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ExportPrivatesDatas(mom.trd.opentheso.core.exports.helper.ExportPrivatesDatas) Test(org.junit.Test)

Example 7 with Table

use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.

the class testcreationconexionBD method avoirContent.

@Test
public void avoirContent(HikariDataSource ds) {
    String sCadena = "";
    String retorno = "";
    Statement stmt;
    Connection conn;
    File fichier = new File("C:\\Users\\antonio.perez\\Documents\\NetBeansProjects\\opentheso\\src\\main\\resources\\install\\opentheso_dist_4.0.9.sql");
    if (fichier.exists()) {
        try {
            BufferedReader bf = new BufferedReader(new FileReader(fichier));
            while ((sCadena = bf.readLine()) != null) {
                retorno += sCadena;
            }
        } catch (FileNotFoundException fnfe) {
        } catch (IOException ioe) {
        }
        try {
            Connection connection = ds.getConnection();
            stmt = connection.createStatement();
            try {
                // récupération des noms des colonnes de la table
                String query = "create Database prueba with owner opentheso";
                System.out.println(query);
                stmt.executeUpdate(query);
            } finally {
                stmt.close();
                connection.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 8 with Table

use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.

the class testimportxml method ouvreFichier.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void ouvreFichier() {
    HikariDataSource conn = openConnexionPool();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();
    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    File xmlFile = new File("C:/Users/antonio.perez/Desktop/testbon.xml");
    try {
        // Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xmlFile);
        // Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();
        // Se obtiene la lista de hijos de la raiz 'tables'
        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");
        // Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            // Se obtiene el elemento 'tabla'
            // ici on a la première table
            Element tabla = (Element) list.get(i);
            // Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            // ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            System.out.println("Nom de la table : " + nombreTabla);
            // Se obtiene la lista de hijos del tag 'tabla'
            // 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++) {
                // Se obtiene el elemento 'campo'
                // ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                // System.out.println("nouvelle ligne table "+ nombreTabla);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    // System.out.println("Nom de la colonne = " + colonne.getName());
                    // System.out.println("valeur de la colonne = " + colonne.getText());
                    lineOfData.setColomne(colonne.getName());
                    lineOfData.setValue(colonne.getText());
                    lineOfDatas.add(lineOfData);
                }
                insertLine(conn, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
        // / mettre à jour la table dans la BDD
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) HikariDataSource(com.zaxxer.hikari.HikariDataSource) 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) File(java.io.File) Test(org.junit.Test)

Example 9 with Table

use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.

the class testimportxml method insertLine.

private void insertLine(HikariDataSource ds, ArrayList<LineOfData> table, String nomtable) {
    Statement stmt;
    String nomcolun = "";
    String values = "";
    boolean first = true;
    for (LineOfData lineOfData : table) {
        if (!first) {
            nomcolun += ",";
            values += ",";
        }
        nomcolun += lineOfData.getColomne();
        if (lineOfData.getValue() == null)
            values += "";
        else
            values += "'" + lineOfData.getValue() + "'";
        first = false;
    }
    values += ");";
    System.out.println(nomcolun);
    System.out.println(values);
    try {
        Connection connection = ds.getConnection();
        stmt = connection.createStatement();
        try {
            System.out.println(nomtable);
            // récupération des noms des colonnes de la table
            String query = "INSERT INTO " + nomtable + " ( " + nomcolun + ") VALUES (" + values;
            System.out.println(query);
            stmt.executeUpdate(query);
        } finally {
            stmt.close();
            connection.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
    }
}
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 10 with Table

use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.

the class testoublie method vide.

private void vide(HikariDataSource ds, String email) throws SQLException {
    String nouvellePass = "";
    Statement stmt;
    ResultSet resultSet;
    try {
        Connection conn = ds.getConnection();
        stmt = conn.createStatement();
        try {
            String query = "Select username from users where mail ='" + email + "'";
            resultSet = stmt.executeQuery(query);
            if (resultSet != null) {
                nouvellePass = MD5Password.getEncodedPassword(genererNouvellePass());
                String queryAjoute = "alter table users add motpasstemp varchar(100)";
                stmt.executeQuery(queryAjoute);
            }
        } finally {
            stmt.close();
            conn.close();
            insertNP(ds, nouvellePass, email);
        }
    } catch (SQLException ex) {
        Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection)

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