Search in sources :

Example 1 with NodeStatConcept

use of mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept in project opentheso by miledrousset.

the class StatisticHelper method getStatConceptByGroupAndDate.

/**
 * #JM
 * méthode pour récupérer les concepts selon un groupe et des dates
 * la colonne modified ou created et intérrogée selon le paramètre column
 * @param ds
 * @param begin
 * @param end
 * @param column
 * @param idThesaurus
 * @param langue
 * @param selectedGroup
 * @param limit
 * @return
 */
public ArrayList<NodeStatConcept> getStatConceptByGroupAndDate(HikariDataSource ds, String begin, String end, String column, String idThesaurus, String langue, String selectedGroup, int limit) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeStatConcept> list = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT term.lexical_value," + " concept_group_concept.idgroup," + " concept_group_concept.idconcept, term.created, term.modified" + " FROM concept_group_concept," + " preferred_term, term WHERE" + " preferred_term.id_thesaurus = term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = concept_group_concept.idthesaurus AND" + " preferred_term.id_concept = concept_group_concept.idconcept AND" + " term.id_thesaurus = '" + idThesaurus + "' AND" + " idgroup = '" + selectedGroup + "' AND" + " term.created <= '" + end + "'" + " AND term.created >= '" + begin + "'" + " AND term.lang = '" + langue + "'" + " order by term.created DESC" + " LIMIT " + limit;
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeStatConcept nsc = new NodeStatConcept();
                    nsc.setDateCreat(resultSet.getDate("created"));
                    nsc.setDateEdit(resultSet.getDate("modified"));
                    String temp = new GroupHelper().getThisConceptGroup(ds, resultSet.getString("idgroup"), idThesaurus, langue).getLexicalValue();
                    nsc.setGroup(temp + "(" + resultSet.getString("idgroup") + ")");
                    nsc.setIdConcept(resultSet.getString("idconcept"));
                    nsc.setValue(resultSet.getString("lexical_value"));
                    list.add(nsc);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List statistic of Concept in thesaurus : " + idThesaurus, sqle);
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 2 with NodeStatConcept

use of mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept in project opentheso by miledrousset.

the class StatBean method creatCSVFile.

/**
 * #JM
 * Méthode pour créer un fichier télécharger
 * soit un fichier pour les statistiques du thesaurus soit pour les
 * statistiques concepts
 * @param idTheso
 * @return
 */
public StreamedContent creatCSVFile(String idTheso) {
    StringBuffer sbr = new StringBuffer();
    try {
        // ajou du titre au documen CSV
        ArrayList<String> line = new ArrayList<>();
        line.add("thesaurus : " + idTheso);
        line.add(lang.toUpperCase());
        line.add(new Date().toString());
        if (this.typeStat == 1)
            line.add(lb.getMsg("stat.forTheso"));
        if (this.typeStat == 2) {
            line.add(lb.getMsg("stat.forConcept"));
            if (searchFromDate) {
                line.add(lb.getMsg("stat.opt3") + " : " + begin);
                line.add(lb.getMsg("stat.opt4") + " : " + end);
                line.add((typeDate == 1) ? lb.getMsg("stat.opt2.1") : lb.getMsg("stat.opt2.2"));
            }
            if (searchFromGroup)
                line.add(lb.getMsg("stat.group") + " : " + this.selectedGroup);
        }
        writeLine(sbr, line);
        line = new ArrayList<>();
        // ajout entête du tableau
        if (this.typeStat == 1) {
            line.add(lb.getMsg("stat.statTheso1"));
            line.add(lb.getMsg("stat.statTheso2"));
            line.add(lb.getMsg("stat.statTheso3"));
            line.add(lb.getMsg("stat.statTheso4"));
            line.add(lb.getMsg("stat.statTheso5"));
        }
        if (this.typeStat == 2) {
            line.add(lb.getMsg("stat.statCpt1"));
            line.add(lb.getMsg("stat.idC"));
            line.add(lb.getMsg("stat.statCpt2"));
            line.add(lb.getMsg("stat.statCpt3"));
            line.add(lb.getMsg("stat.statCpt4"));
        }
        writeLine(sbr, line);
        if (this.typeStat == 1) {
            for (NodeStatTheso nst : this.statTheso) {
                line = new ArrayList<>();
                line.add(nst.getGroup());
                line.add("" + nst.getNbDescripteur());
                line.add("" + nst.getNbNonDescripteur());
                line.add("" + nst.getNbNoTrad());
                line.add("" + nst.getNbNotes());
                writeLine(sbr, line);
            }
        }
        if (this.typeStat == 2) {
            for (NodeStatConcept nsc : this.statConcept) {
                line = new ArrayList<>();
                line.add(nsc.getValue());
                line.add(nsc.getIdConcept());
                line.add("" + nsc.getDateCreat());
                line.add("" + nsc.getDateEdit());
                line.add(nsc.getGroup());
                writeLine(sbr, line);
            }
        }
    } catch (IOException e) {
        System.out.println("erreur pendant l'écriture du fichier" + e);
        return null;
    }
    InputStream stream;
    StreamedContent file = null;
    try {
        stream = new ByteArrayInputStream(sbr.toString().getBytes("UTF-8"));
        String name_file = (typeStat == 1) ? "downloadedCsv_Thesaurus_stat.csv" : "downloadedCsv_concept_stat.csv";
        file = new DefaultStreamedContent(stream, "text/csv", name_file);
    } catch (UnsupportedEncodingException e) {
        System.out.println("erreur création inputStream " + e);
        return null;
    }
    return file;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Date(java.util.Date) NodeStatTheso(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatTheso) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamedContent(org.primefaces.model.StreamedContent) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent)

Example 3 with NodeStatConcept

use of mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept in project opentheso by miledrousset.

the class StatisticHelper method getStatConceptEdit.

public ArrayList<NodeStatConcept> getStatConceptEdit(HikariDataSource ds, String begin, String end, String idThesaurus, String langue, int limit) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeStatConcept> list = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT term.lexical_value," + " concept_group_concept.idgroup," + " concept_group_concept.idconcept, term.created, term.modified" + " FROM concept_group_concept," + " preferred_term, term WHERE" + " preferred_term.id_thesaurus = term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = concept_group_concept.idthesaurus AND" + " preferred_term.id_concept = concept_group_concept.idconcept AND" + " term.id_thesaurus = '" + idThesaurus + "' AND" + " term.modified <= '" + end + "'" + " AND term.modified >= '" + begin + "'" + " AND term.lang = '" + langue + "'" + " order by term.created DESC" + " LIMIT " + limit;
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeStatConcept nsc = new NodeStatConcept();
                    nsc.setDateCreat(resultSet.getDate("created"));
                    nsc.setDateEdit(resultSet.getDate("modified"));
                    String temp = new GroupHelper().getThisConceptGroup(ds, resultSet.getString("idgroup"), idThesaurus, langue).getLexicalValue();
                    nsc.setGroup(temp + "(" + resultSet.getString("idgroup") + ")");
                    nsc.setIdConcept(resultSet.getString("idconcept"));
                    nsc.setValue(resultSet.getString("lexical_value"));
                    list.add(nsc);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List statistic of Concept in thesaurus : " + idThesaurus, sqle);
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 4 with NodeStatConcept

use of mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept in project opentheso by miledrousset.

the class StatisticHelper method getStatConcept.

/**
 * permet de retourner les stats d'un thésaurus pour les concepts modifiés
 * pas de définition de dates mais une limite de nombre de résultat
 * @param ds
 * @param idThesaurus
 * @param langue
 * @param limit
 * @return
 * #MR
 */
public ArrayList<NodeStatConcept> getStatConcept(HikariDataSource ds, String idThesaurus, String langue, int limit) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeStatConcept> list = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT term.lexical_value," + " concept_group_concept.idgroup," + " concept_group_concept.idconcept, term.created, term.modified" + " FROM concept_group_concept," + " preferred_term, term WHERE" + " preferred_term.id_thesaurus = term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = concept_group_concept.idthesaurus AND" + " preferred_term.id_concept = concept_group_concept.idconcept AND" + " term.id_thesaurus = '" + idThesaurus + "' AND" + " term.lang = '" + langue + "'" + " order by term.created DESC" + " LIMIT " + limit;
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeStatConcept nsc = new NodeStatConcept();
                    nsc.setDateCreat(resultSet.getDate("created"));
                    nsc.setDateEdit(resultSet.getDate("modified"));
                    String temp = new GroupHelper().getThisConceptGroup(ds, resultSet.getString("idgroup"), idThesaurus, langue).getLexicalValue();
                    nsc.setGroup(temp + "(" + resultSet.getString("idgroup") + ")");
                    nsc.setIdConcept(resultSet.getString("idconcept"));
                    nsc.setValue(resultSet.getString("lexical_value"));
                    list.add(nsc);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List statistic of Concept in thesaurus : " + idThesaurus, sqle);
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 5 with NodeStatConcept

use of mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept in project opentheso by miledrousset.

the class StatisticHelper method getStatConceptCreat.

public ArrayList<NodeStatConcept> getStatConceptCreat(HikariDataSource ds, String begin, String end, String idThesaurus, String langue, int limit) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeStatConcept> list = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT term.lexical_value," + " concept_group_concept.idgroup," + " concept_group_concept.idconcept, term.created, term.modified" + " FROM concept_group_concept," + " preferred_term, term WHERE" + " preferred_term.id_thesaurus = term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = concept_group_concept.idthesaurus AND" + " preferred_term.id_concept = concept_group_concept.idconcept AND" + " term.id_thesaurus = '" + idThesaurus + "' AND" + " term.created <= '" + end + "'" + " AND term.created >= '" + begin + "'" + " AND term.lang = '" + langue + "'" + " order by term.created DESC" + " LIMIT " + limit;
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeStatConcept nsc = new NodeStatConcept();
                    nsc.setDateCreat(resultSet.getDate("created"));
                    nsc.setDateEdit(resultSet.getDate("modified"));
                    String temp = new GroupHelper().getThisConceptGroup(ds, resultSet.getString("idgroup"), idThesaurus, langue).getLexicalValue();
                    nsc.setGroup(temp + "(" + resultSet.getString("idgroup") + ")");
                    nsc.setIdConcept(resultSet.getString("idconcept"));
                    nsc.setValue(resultSet.getString("lexical_value"));
                    list.add(nsc);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List statistic of Concept in thesaurus : " + idThesaurus, sqle);
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)5 NodeStatConcept (mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 NodeStatTheso (mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatTheso)1 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)1 StreamedContent (org.primefaces.model.StreamedContent)1