Search in sources :

Example 26 with StringPlus

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

the class TermHelper method addTermTraduction.

/**
 * Cette fonction permet d'ajouter une traduction à un Terme
 *
 * @param conn
 * @param term
 * @param idUser
 * @return
 */
public boolean addTermTraduction(Connection conn, Term term, int idUser) {
    Statement stmt;
    term.setLexical_value(new StringPlus().convertString(term.getLexical_value()));
    try {
        // conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String 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() + "'" + ", " + term.getContributor() + ", " + term.getCreator() + ")";
                stmt.execute(query);
                addNewTermHistorique(conn, term, idUser);
            } finally {
                stmt.close();
            }
        } finally {
        // conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        if (!sqle.getSQLState().equalsIgnoreCase("23505")) {
            return false;
        }
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus)

Example 27 with StringPlus

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

the class TermHelper method addUSE.

/**
 * @param conn
 * @param term
 * @param idUser
 * @return idTerm
 */
private boolean addUSE(Connection conn, Term term, int idUser) {
    boolean status = false;
    // Connection conn;
    Statement stmt;
    term.setLexical_value(new StringPlus().convertString(term.getLexical_value()));
    try {
        try {
            stmt = conn.createStatement();
            try {
                String query = "Insert into non_preferred_term " + "(id_term, lexical_value, lang, " + "id_thesaurus, source, status, hiden)" + " values (" + "'" + term.getId_term() + "'" + ",'" + term.getLexical_value() + "'" + ",'" + term.getLang() + "'" + ",'" + term.getId_thesaurus() + "'" + ",'" + term.getSource() + "'" + ",'" + term.getStatus() + "'" + "," + term.isHidden() + ")";
                stmt.executeUpdate(query);
                status = true;
            } finally {
                stmt.close();
            }
        } finally {
        // conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        if (!sqle.getSQLState().equalsIgnoreCase("23505")) {
            status = false;
        }
    }
    return status;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus)

Example 28 with StringPlus

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

the class TermHelper method isTermEqualTo.

/**
 * Cette fonction permet de savoir si le terme est un parfait doublon ou non
 * si oui, on retourne l'identifiant, sinon, on retourne null
 *
 * @param ds
 * @param title
 * @param idThesaurus
 * @param idLang
 * @return idTerm or null
 */
public String isTermEqualTo(HikariDataSource ds, String title, String idThesaurus, String idLang) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String idTerm = null;
    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 " + "lexical_value = '" + title + "'" + " and lang = '" + idLang + "'" + " and id_thesaurus = '" + idThesaurus + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    idTerm = resultSet.getString("id_term");
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if Term exist : " + title, sqle);
    }
    return idTerm;
}
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 29 with StringPlus

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

the class TermHelper method isAltLabelExist.

/**
 * Cette fonction permet de savoir si le altLabel existe dans le thésaurus
 *
 * @param ds
 * @param title
 * @param idThesaurus
 * @param idLang
 * @return boolean
 */
public boolean isAltLabelExist(HikariDataSource ds, String title, String idThesaurus, 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 non_preferred_term where " + "unaccent_string(lexical_value) ilike " + "unaccent_string('" + title + "')  and lang = '" + idLang + "' and id_thesaurus = '" + idThesaurus + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getRow() != 0;
                }
            } 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 30 with StringPlus

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

the class TermHelper method getAutoCompletForRelationNT.

/**
 * permet de retourner la liste des concepts possibles
 * pour ajouter une relation NT
 * (en ignorant les relations interdites)
 * on ignore les concepts de type TT
 * on ignore les concepts de type RT
 *
 * On recherche aussi dans les Synonymes
 *
 * @param ds
 * @param idThesaurus
 * @param text
 * @param idLang
 * @return Objet class NodeAutoCompletion
 * #MR
 */
public List<NodeAutoCompletion> getAutoCompletForRelationNT(HikariDataSource ds, String idThesaurus, String idLang, 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, concept_group_concept.idgroup " + "FROM preferred_term, term, concept,concept_group_concept " + "WHERE " + "idThesaurus = concept.id_thesaurus AND " + "concept_group_concept.idconcept = concept.id_concept AND " + "preferred_term.id_term = term.id_term 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.status != 'hidden' AND " + "concept.top_concept != 'true' 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))
                            nodeAutoCompletion.setIsAltLabel(false);
                            nodeAutoCompletionList.add(nodeAutoCompletion);
                        }
                    }
                }
                query = "SELECT DISTINCT " + "non_preferred_term.lexical_value," + "concept.id_concept," + "concept_group_concept.idgroup" + " FROM preferred_term, non_preferred_term, concept,concept_group_concept" + "  WHERE" + "  concept_group_concept.idthesaurus = concept.id_thesaurus " + "  AND" + "   concept_group_concept.idconcept = concept.id_concept" + " AND preferred_term.id_term = non_preferred_term.id_term " + " AND preferred_term.id_thesaurus = non_preferred_term.id_thesaurus " + " AND concept.id_concept = preferred_term.id_concept " + " AND concept.id_thesaurus = preferred_term.id_thesaurus " + " AND non_preferred_term.id_thesaurus = '" + idThesaurus + "'" + " AND non_preferred_term.lang = '" + idLang + "'" + " AND concept.status != 'hidden'" + " AND concept.top_concept != 'true'" + " AND unaccent_string(non_preferred_term.lexical_value) ILIKE unaccent_string('" + text + "%') ORDER BY non_preferred_term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    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))
                    nodeAutoCompletion.setIsAltLabel(true);
                    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)

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