Search in sources :

Example 76 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class TermHelper method updateTermSynonyme.

public boolean updateTermSynonyme(HikariDataSource ds, String oldValue, Term term, int idUser) {
    Connection conn;
    Statement stmt;
    boolean status = false;
    term.setLexical_value(new StringPlus().convertString(term.getLexical_value()));
    oldValue = (new StringPlus().convertString(oldValue));
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "UPDATE non_preferred_term set" + " lexical_value = '" + term.getLexical_value() + "'," + " modified = current_date " + " WHERE lang ='" + term.getLang() + "'" + " AND id_thesaurus = '" + term.getId_thesaurus() + "'" + " AND id_term = '" + term.getId_term() + "'" + " AND lexical_value = '" + oldValue + "'";
                stmt.executeUpdate(query);
                status = true;
                addNewTermHistorique(conn, term, idUser);
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while updating Synonym Modification : " + term.getId_term(), sqle);
    }
    return status;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection)

Example 77 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class TermHelper method getAutoCompletionTermOfOtherGroup.

/**
 * Cette fonction permet de récupérer une liste des terms pour
 * l'autocomplétion en se évitant le Group actuel et en ignorant le terme
 * lui même
 *
 * @param ds
 * @param idSelectedConcept
 * @param idThesaurus
 * @param text
 * @param idGroup
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionTermOfOtherGroup(HikariDataSource ds, // le concept à ignorer
String idSelectedConcept, String idThesaurus, String idLang, String idGroup, String text) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    List<NodeAutoCompletion> nodeAutoCompletionList = new ArrayList<>();
    text = new StringPlus().convertString(text);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT term.lexical_value, concept.id_concept, idgroup " + "FROM preferred_term, term, concept,concept_group_concept WHERE " + "preferred_term.id_term = term.id_term AND " + "concept_group_concept.idconcept = concept.id_concept AND " + "concept_group_concept.idthesaurus = term.id_thesaurus AND " + "preferred_term.id_thesaurus = term.id_thesaurus AND " + "concept.id_concept = preferred_term.id_concept AND " + "concept.id_thesaurus = preferred_term.id_thesaurus AND " + "term.id_thesaurus = '" + idThesaurus + "' AND " + "term.lang = '" + idLang + "' AND " + "concept_group_concept.idgroup != '" + idGroup + "' AND " + "concept.id_concept != '" + idSelectedConcept + "' AND " + "concept.status != 'hidden' AND " + "unaccent_string(term.lexical_value) ILIKE unaccent_string('" + text + "%')" + " ORDER BY term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        if (resultSet.getRow() != 0) {
                            NodeAutoCompletion nodeAutoCompletion = new NodeAutoCompletion();
                            nodeAutoCompletion.setIdConcept(resultSet.getString("id_concept"));
                            nodeAutoCompletion.setTermLexicalValue(resultSet.getString("lexical_value"));
                            nodeAutoCompletion.setGroupLexicalValue(new GroupHelper().getLexicalValueOfGroup(ds, resultSet.getString("idgroup"), idThesaurus, idLang));
                            nodeAutoCompletion.setIdGroup(resultSet.getString("idgroup"));
                            // if(!nodeAutoCompletionList.contains(nodeAutoCompletion))
                            nodeAutoCompletionList.add(nodeAutoCompletion);
                        }
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List of autocompletion of Text : " + text, sqle);
    }
    return nodeAutoCompletionList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) NodeAutoCompletion(mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)

Example 78 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class TermHelper method isTermExistForEdit.

/**
 * Cette fonction permet de savoir si le terme existe ou non dans le
 * thésaurus mais il faut ignorer le terme lui même; ceci nous permet de
 * faire la modification dans le cas suivant : helene -> en Hélène
 *
 * @param ds
 * @param title
 * @param idThesaurus
 * @param idTerm
 * @param idLang
 * @return boolean
 */
public boolean isTermExistForEdit(HikariDataSource ds, String title, String idThesaurus, String idTerm, String idLang) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;
    title = new StringPlus().convertString(title);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_term from term where " + "unaccent_string(lexical_value) ilike " + "unaccent_string('" + title + "')  and lang = '" + idLang + "' and id_thesaurus = '" + idThesaurus + "'" + " and id_term != '" + idTerm + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = true;
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if Title of Term exist : " + title, sqle);
    }
    return existe;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 79 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class TermHelper method addNewTerm.

/**
 * @param conn
 * @param term
 * @param idUser
 * @return idTerm
 */
public String addNewTerm(Connection conn, Term term, int idUser) {
    String idTerm = null;
    // Connection conn;
    Statement stmt;
    ResultSet resultSet;
    term.setLexical_value(new StringPlus().convertString(term.getLexical_value()));
    try {
        // conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select max(id) from term";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                int idTermNum = resultSet.getInt(1);
                idTermNum++;
                idTerm = "" + (idTermNum);
                // si le nouveau Id existe, on l'incrémente
                while (isIdOfTermExist(conn, idTerm, term.getId_thesaurus())) {
                    idTerm = "" + (++idTermNum);
                }
                term.setId_term(idTerm);
                /**
                 * Ajout des informations dans la table Concept
                 */
                query = "Insert into term " + "(id_term, lexical_value, lang, " + "id_thesaurus, source, status, contributor, creator)" + " values (" + "'" + term.getId_term() + "'" + ",'" + term.getLexical_value() + "'" + ",'" + term.getLang() + "'" + ",'" + term.getId_thesaurus() + "'" + ",'" + term.getSource() + "'" + ",'" + term.getStatus() + "'" + ", " + idUser + "" + ", " + idUser + ")";
                stmt.executeUpdate(query);
                addNewTermHistorique(conn, term, idUser);
            } finally {
                stmt.close();
            }
        } finally {
        // conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        if (!sqle.getSQLState().equalsIgnoreCase("23505")) {
            idTerm = null;
        }
    }
    return idTerm;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) ResultSet(java.sql.ResultSet)

Example 80 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class ThesaurusHelper method deleteThesaurusTraduction.

/**
 * Permet de supprimer une traduction d'un thésaurus
 *
 * @param ds
 * @param idThesaurus
 * @param id_lang
 * @return
 */
public boolean deleteThesaurusTraduction(HikariDataSource ds, String idThesaurus, String id_lang) {
    StringPlus text = new StringPlus();
    idThesaurus = text.convertString(idThesaurus);
    Statement stmt = null;
    Connection conn = null;
    boolean state = false;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "delete from thesaurus_label where id_thesaurus = '" + idThesaurus + "'" + " and lang = '" + id_lang + "'";
                stmt.executeUpdate(query);
                state = true;
            } catch (SQLException e) {
                Logger.getLogger(ThesaurusHelper.class.getName()).log(Level.SEVERE, null, e);
            } finally {
                stmt.close();
            }
        } catch (SQLException e) {
            Logger.getLogger(ThesaurusHelper.class.getName()).log(Level.SEVERE, null, e);
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(ThesaurusHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return state;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection)

Aggregations

StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)80 SQLException (java.sql.SQLException)63 Statement (java.sql.Statement)63 Connection (java.sql.Connection)56 ResultSet (java.sql.ResultSet)30 PreparedStatement (java.sql.PreparedStatement)19 ArrayList (java.util.ArrayList)12 NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)6 NodeSearch (mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)6 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)4 FacesMessage (javax.faces.application.FacesMessage)2 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)2 NodeBT (mom.trd.opentheso.bdd.helper.nodes.NodeBT)2 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)2 NodePermute (mom.trd.opentheso.bdd.helper.nodes.NodePermute)2 NodeConcept (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept)2 PrefixString (com.k_int.IR.QueryModels.PrefixString)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 ConnexionTest (connexion.ConnexionTest)1 DcElement (fr.mom.arkeo.soap.DcElement)1