Search in sources :

Example 21 with StringPlus

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

the class TermHelper method updateTermTraduction.

/**
 * Cette fonction permet de mettre à jour un Terme à la table Term, en
 * paramètre un objet Classe Term
 *
 * @param ds
 * @param term
 * @param idUser
 * @return
 */
// Deprecated by Miled
/*  public boolean updateTermTraduction(HikariDataSource ds,
            Term term, int idUser) {
        if (isTermExist(ds, term.getLexical_value(), term.getId_thesaurus(), term.getLang())){//isExitsTraduction(ds, term)) {
            // terme existe, il faut créer une relation
            return false;
        }
        if (!updateTermIntoTable(ds, term, idUser)) {
            return false;
        }
        return true;
    }*/
/**
 * fonction qui permet de mettre à jour une traduction
 * @param ds
 * @param term
 * @param idUser
 * @return
 */
public boolean updateTermTraduction(HikariDataSource ds, Term term, int idUser) {
    Connection conn;
    Statement stmt;
    boolean status = false;
    term.setLexical_value(new StringPlus().convertString(term.getLexical_value()));
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "UPDATE term set" + " lexical_value = '" + term.getLexical_value() + "'," + " modified = current_date ," + " contributor = " + idUser + " WHERE lang ='" + term.getLang() + "'" + " AND id_term = '" + term.getId_term() + "'" + " AND id_thesaurus = '" + term.getId_thesaurus() + "'";
                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 Term Traduction : " + 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 22 with StringPlus

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

the class ThesaurusHelper method deleteThesaurus.

/**
 * Permet de supprimer un thésaurus
 *
 * @param ds
 * @param idThesaurus
 * @return
 */
public boolean deleteThesaurus(HikariDataSource ds, String idThesaurus) {
    StringPlus text = new StringPlus();
    idThesaurus = text.convertString(idThesaurus);
    Statement stmt;
    Connection conn;
    boolean state = false;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "delete from thesaurus where id_thesaurus = '" + idThesaurus + "';" + "delete from thesaurus_label where id_thesaurus = '" + idThesaurus + "';" + "delete from thesaurus_array where id_thesaurus = '" + idThesaurus + "';" + "delete from node_label where id_thesaurus = '" + idThesaurus + "';" + "delete from thesaurus_array_concept where id_thesaurus = '" + idThesaurus + "';" + "delete from concept where id_thesaurus = '" + idThesaurus + "';" + "delete from concept_historique where id_thesaurus = '" + idThesaurus + "';" + "delete from images where id_thesaurus = '" + idThesaurus + "';" + "delete from preferred_term where id_thesaurus = '" + idThesaurus + "';" + "delete from non_preferred_term where id_thesaurus = '" + idThesaurus + "';" + "delete from non_preferred_term_historique where id_thesaurus = '" + idThesaurus + "';" + "delete from term where id_thesaurus = '" + idThesaurus + "';" + "delete from term_historique where id_thesaurus = '" + idThesaurus + "';" + "delete from concept_group where idthesaurus = '" + idThesaurus + "';" + "delete from concept_group_historique where idthesaurus = '" + idThesaurus + "';" + "delete from concept_group_label where idthesaurus = '" + idThesaurus + "';" + "delete from concept_group_label_historique where idthesaurus = '" + idThesaurus + "';" + "delete from note where id_thesaurus = '" + idThesaurus + "';" + "delete from note_historique where id_thesaurus = '" + idThesaurus + "';" + "delete from permuted where id_thesaurus = '" + idThesaurus + "';" + "delete from hierarchical_relationship where id_thesaurus = '" + idThesaurus + "';" + "delete from hierarchical_relationship_historique where id_thesaurus = '" + idThesaurus + "';" + "delete from concept_candidat where id_thesaurus = '" + idThesaurus + "';" + "delete from concept_term_candidat where id_thesaurus = '" + idThesaurus + "';" + "delete from term_candidat where id_thesaurus = '" + idThesaurus + "';" + "delete from alignement where internal_id_thesaurus = '" + idThesaurus + "';" + "delete from concept_orphan where id_thesaurus = '" + idThesaurus + "';" + "delete from proposition where id_thesaurus = '" + idThesaurus + "';" + "delete from concept_fusion where id_thesaurus = '" + idThesaurus + "';" + "delete from gps where id_theso = '" + idThesaurus + "';" + "delete from thesaurus_alignement_source where id_thesaurus = '" + idThesaurus + "';" + "delete from concept_group_concept where idthesaurus = '" + idThesaurus + "';" + "delete from relation_group where id_thesaurus = '" + idThesaurus + "';" + "delete from preferences where id_thesaurus = '" + idThesaurus + "';" + "delete from user_role where id_thesaurus = '" + idThesaurus + "';";
                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)

Example 23 with StringPlus

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

the class CandidateHelper method addTermCandidatTraduction.

/**
 * Cette fonction permet de rajouter une traduction pour un term_candidat
 *
 * @param ds
 * @param idConcept
 * @param lexical_value
 * @param idLang
 * @param idThesaurus
 * @param contributor
 * @return idConceptCandidat
 */
public boolean addTermCandidatTraduction(HikariDataSource ds, String idConcept, String lexical_value, String idLang, String idThesaurus, int contributor) {
    Connection conn;
    Statement stmt;
    boolean status = false;
    String idTermCandidat = null;
    lexical_value = new StringPlus().convertString(lexical_value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                idTermCandidat = getIdTermOfConceptCandidat(ds, idConcept, idThesaurus);
                if (idTermCandidat == null) {
                    return false;
                }
                String query = "Insert into term_candidat " + "(id_term, lexical_value, lang, " + "id_thesaurus, contributor)" + " values (" + "'" + idTermCandidat + "'" + ",'" + lexical_value + "'" + ",'" + idLang + "'" + ",'" + idThesaurus + "'" + "," + contributor + ")";
                stmt.executeUpdate(query);
                status = true;
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while adding Traduction of Term_candidat  : " + idTermCandidat, sqle);
    }
    return status;
}
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)

Example 24 with StringPlus

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

the class SearchHelper method searchPreferredTerm.

/**
 * Cette fonction permet de faire une recherche par value en filtran par
 * Group pour les termes préférés uniquement
 *
 * @param ds
 * @param value
 * @param idLang
 * @param idThesaurus
 * @param idGroup
 * @return
 */
public ArrayList<NodeSearch> searchPreferredTerm(HikariDataSource ds, String value, String idLang, String idThesaurus, String idGroup) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeSearch> nodeSearchList = null;
    value = new StringPlus().convertString(value);
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT term.lexical_value, preferred_term.id_concept," + " preferred_term.id_term, term.lang, term.id_thesaurus," + " idgroup, concept.top_concept" + " FROM term, preferred_term, concept, concept_group_concept WHERE " + "concept_group_concept.idthesaurus = term.id_thesaurus AND " + "concept_group_concept.idconcept = preferred_term.id_concept AND " + " concept.id_concept = preferred_term.id_concept AND" + " concept.id_thesaurus = preferred_term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = term.id_thesaurus" + " and" + " unaccent_string(term.lexical_value) ilike" + " unaccent_string('" + value + "%')" + " and term.id_thesaurus = '" + idThesaurus + "'" + " and term.lang = '" + idLang + "'" + " and idgroup = '" + idGroup + "'" + " order by lexical_value ASC LIMIT 100";
                resultSet = stmt.executeQuery(query);
                nodeSearchList = new ArrayList<>();
                while (resultSet.next()) {
                    NodeSearch nodeSearch = new NodeSearch();
                    nodeSearch.setLexical_value(resultSet.getString("lexical_value"));
                    nodeSearch.setIdConcept(resultSet.getString("id_concept"));
                    nodeSearch.setIdTerm(resultSet.getString("id_term"));
                    nodeSearch.setIdGroup(resultSet.getString("idgroup"));
                    nodeSearch.setIdLang(idLang);
                    nodeSearch.setIdThesaurus(idThesaurus);
                    nodeSearch.setTopConcept(resultSet.getBoolean("top_concept"));
                    // cas où le terme recherché est égal au terme retrouvé, on le place en premier
                    if (value.trim().equalsIgnoreCase(nodeSearch.getLexical_value().trim())) {
                        nodeSearchList.add(0, nodeSearch);
                    } else {
                        nodeSearchList.add(nodeSearch);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(SearchHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nodeSearchList;
}
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) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)

Example 25 with StringPlus

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

the class TermHelper method splitConceptForPermute.

/**
 * Cette fonction permet de découper les mots d'un concept (phrase) pour
 * remplir la table permutée
 *
 * @param ds
 * @param idConcept
 * @param idGroup
 * @param lexicalValue
 * @param idLang
 * @param idThesaurus
 */
public void splitConceptForPermute(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 + "'" + "," + true + ",'" + lexicalValue + "')";
                    stmt.executeUpdate(query);
                }
            } 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 values in Permuted table : " + idConcept, sqle);
        }
    }
}
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