Search in sources :

Example 71 with StringPlus

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

the class TermHelper method splitConceptForNonPermuted.

/**
 * Cette fonction permet de découper les mots Synonymes d'un concept
 * (phrase) pour remplir la table Non permutée
 *
 * @param ds
 * @param idConcept
 * @param idGroup
 * @param lexicalValue
 * @param idLang
 * @param idThesaurus
 */
public void splitConceptForNonPermuted(HikariDataSource ds, String idConcept, String idGroup, String idThesaurus, String idLang, String lexicalValue) {
    Connection conn;
    Statement stmt;
    // ici c'est la fonction qui découpe la phrase en mots séparé pour la recherche permutée
    lexicalValue = lexicalValue.replaceAll("-", " ");
    lexicalValue = lexicalValue.replaceAll("\\(", " ");
    lexicalValue = lexicalValue.replaceAll("\\)", " ");
    lexicalValue = lexicalValue.replaceAll("\\/", " ");
    // lexicalValue = lexicalValue.replaceAll("'", " ");
    lexicalValue = new StringPlus().convertString(lexicalValue.trim());
    String[] tabMots = lexicalValue.split(" ");
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                int index = 1;
                for (String value : tabMots) {
                    String query = "Insert into permuted" + " (ord, id_concept, id_group, id_thesaurus," + " id_lang, lexical_value, ispreferredterm, original_value)" + " values (" + "" + index++ + "" + ",'" + idConcept + "'" + ",'" + idGroup + "'" + ",'" + idThesaurus + "'" + ",'" + idLang + "'" + ",'" + value + "'" + "," + false + ",'" + lexicalValue + "')";
                    stmt.executeUpdate(query);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        if (!sqle.getSQLState().equalsIgnoreCase("23505")) {
            // if (!sqle.getMessage().contains("duplicate key value violates unique constraint")) {
            log.error("Error while adding values in table Permuted for Non_Preferred_term : " + idConcept, sqle);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection)

Example 72 with StringPlus

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

the class TermHelper method getAutoCompletionTerm.

/**
 * Cette fonction permet de récupérer une liste des terms pour
 * l'autocomplétion en se limitant à un Group et en ignorant le terme lui
 * même et ses BT
 *
 * @param ds
 * @param idSelectedConcept
 * @param idBTs
 * @param idThesaurus
 * @param text
 * @param idGroup
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionTerm(HikariDataSource ds, // le concept à ignorer
String idSelectedConcept, // le concept à ignorer
ArrayList<String> idBTs, String idThesaurus, String idLang, String idGroup, String text) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    List<NodeAutoCompletion> nodeAutoCompletionList = new ArrayList<>();
    text = new StringPlus().convertString(text);
    String BT = "";
    for (String idBt : idBTs) {
        if (!BT.isEmpty()) {
            BT = BT + ",'" + idBt + "'";
        } else {
            BT = "'" + idBt + "'";
        }
    }
    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" + "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.id_concept not in (" + BT + ") 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 73 with StringPlus

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

the class TermHelper method insertTermTraduction.

/**
 * Cette fonction permet d'ajouter une traduction à un Terme cette fonction
 * est utilisée pour les imports
 *
 * @param ds
 * @param idTerm
 * @param idConcept
 * @param lexicalValue
 * @param lang
 * @param idThesaurus
 * @param created
 * @param modified
 * @param status
 * @param source
 * @param idUser
 * @return
 */
public boolean insertTermTraduction(HikariDataSource ds, String idTerm, String idConcept, String lexicalValue, String lang, String idThesaurus, Date created, Date modified, String source, String status, int idUser) {
    Connection conn;
    Statement stmt;
    boolean etat = false;
    // cette fonction permet de remplir la table Permutée
    splitConceptForPermute(ds, idConcept, new ConceptHelper().getGroupIdOfConcept(ds, idTerm, idThesaurus), idThesaurus, lang, lexicalValue);
    lexicalValue = new StringPlus().convertString(lexicalValue);
    String query;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                if (modified == null || created == null) {
                    query = "Insert into term " + "(id_term, lexical_value, lang, " + "id_thesaurus, source, status)" + " values (" + "'" + idTerm + "'" + ",'" + lexicalValue + "'" + ",'" + lang + "'" + ",'" + idThesaurus + "'" + ",'" + source + "'" + ",'" + status + "')";
                } else {
                    query = "Insert into term " + "(id_term, lexical_value, lang, " + "id_thesaurus, created, modified, source, status, contributor)" + " values (" + "'" + idTerm + "'" + ",'" + lexicalValue + "'" + ",'" + lang + "'" + ",'" + idThesaurus + "'" + ",'" + created + "'" + ",'" + modified + "'" + ",'" + source + "'" + ",'" + status + "'" + ", " + idUser + ")";
                }
                stmt.executeUpdate(query);
                etat = true;
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        if (!sqle.getMessage().contains("duplicate key value violates unique constraint")) {
            log.error("Error while adding Term Traduction : " + idTerm, sqle);
        }
    }
    return etat;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection)

Example 74 with StringPlus

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

the class TermHelper method isTermExist.

/**
 * Cette fonction permet de savoir si le terme existe ou non
 *
 * @param ds
 * @param title
 * @param idThesaurus
 * @param idLang
 * @return boolean
 */
public boolean isTermExist(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 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 75 with StringPlus

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

the class TermHelper method insertNewTerm.

/**
 * Cette fonction permet d'insérrer un Term par import avec un identifiant
 * existant
 *
 * @param ds
 * @param term
 * @param idTerm_import
 * @param idUser
 * @return idTerm
 */
public boolean insertNewTerm(HikariDataSource ds, Term term, String idTerm_import, int idUser) {
    idTerm_import = "" + idTerm_import;
    term.setId_term(idTerm_import);
    Connection conn;
    Statement stmt;
    term.setLexical_value(new StringPlus().convertString(term.getLexical_value()));
    boolean resultat = false;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                /**
                 * Ajout des informations dans la table Concept
                 */
                String query = "Insert into term " + "(id_term, lexical_value, lang, " + "id_thesaurus, source, status)" + " values (" + "'" + term.getId_term() + "'" + ",'" + term.getLexical_value() + "'" + ",'" + term.getLang() + "'" + ",'" + term.getId_thesaurus() + "'" + ",'" + term.getSource() + "'" + ",'" + term.getStatus() + "')";
                stmt.executeUpdate(query);
                resultat = true;
                addNewTermHistorique(conn, term, idUser);
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        if (!sqle.getMessage().contains("duplicate key value violates unique constraint")) {
            log.error("Error while adding Term Import : " + idTerm_import, sqle);
        }
    }
    return resultat;
}
Also used : SQLException(java.sql.SQLException) 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