Search in sources :

Example 36 with StringPlus

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

the class SearchHelper method searchNote.

/**
 * Cette fonction permet de faire une recherche par value sur les notes
 *
 * @param ds
 * @param value
 * @param idLang
 * @param idThesaurus
 * @param idGroup
 * @param startByOrContain //1=contient 2=commence par
 * @return
 */
public ArrayList<NodeSearch> searchNote(HikariDataSource ds, String value, String idLang, String idThesaurus, String idGroup, int startByOrContain) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeSearch> nodeSearchList = new ArrayList<>();
    value = new StringPlus().convertString(value);
    String[] values = value.trim().split(" ");
    String query;
    String langNote;
    String group;
    String multivaluesNote = "";
    // préparation de la valeur à rechercher
    if (startByOrContain == 1) {
        // contient
        for (String value1 : values) {
            multivaluesNote += " and unaccent_string(note.lexicalvalue) ilike" + " unaccent_string('%" + value1 + "%')";
        }
    }
    if (startByOrContain == 2) {
        // commence par
        multivaluesNote += " and (unaccent_string(note.lexicalvalue) ilike" + " unaccent_string('" + value + "%')" + " OR unaccent_string(note.lexicalvalue) ilike" + " unaccent_string('% " + value + "%'))";
    }
    // préparation de la requête en focntion du choix (toutes les langues ou langue donnée)
    if (idLang.isEmpty()) {
        langNote = "";
    } else {
        langNote = " and note.lang ='" + idLang + "'";
    }
    // cas du choix d'un group
    if (idGroup.isEmpty()) {
        group = "";
    } else {
        group = " and idgroup = '" + idGroup + "'";
    }
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                // notes des terms
                query = "SELECT concept.id_concept, concept.id_thesaurus," + " concept.top_concept, idgroup," + " note.lang, note.lexicalvalue," + " note.id_term " + " FROM preferred_term, note, concept,concept_group_concept" + " WHERE " + "concept_group_concept.idthesaurus = concept.id_thesaurus AND " + "concept.id_concept = concept_group_concept.idconcept AND " + " preferred_term.id_term = note.id_term" + " AND" + " preferred_term.id_thesaurus = note.id_thesaurus" + " AND" + " concept.id_concept = preferred_term.id_concept" + " AND" + " concept.id_thesaurus = preferred_term.id_thesaurus" + " AND" + " note.id_thesaurus = '" + idThesaurus + "'" + multivaluesNote + langNote + group + " order by lexicalvalue ASC LIMIT 200";
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeSearch nodeSearch = new NodeSearch();
                    nodeSearch.setLexical_value(resultSet.getString("lexicalvalue"));
                    nodeSearch.setIdConcept(resultSet.getString("id_concept"));
                    nodeSearch.setIdTerm(resultSet.getString("id_term"));
                    nodeSearch.setIdGroup(resultSet.getString("idgroup"));
                    nodeSearch.setIdLang(resultSet.getString("lang"));
                    nodeSearch.setIdThesaurus(idThesaurus);
                    nodeSearch.setTopConcept(resultSet.getBoolean("top_concept"));
                    nodeSearch.setPreferredLabel(true);
                    nodeSearchList.add(nodeSearch);
                }
                // notes des concepts
                query = "SELECT concept.id_concept, concept.id_thesaurus," + " concept.top_concept, idgroup," + " note.lang, note.lexicalvalue," + " preferred_term.id_term " + " FROM preferred_term, note, concept, concept_group_concept" + " WHERE " + "concept_group_concept.idconcept = concept.id_concept AND " + "concept_group_concept.idthesaurus = concept.id_thesaurus AND " + " preferred_term.id_concept = note.id_concept" + " AND" + " preferred_term.id_thesaurus = note.id_thesaurus" + " AND" + " concept.id_concept = preferred_term.id_concept" + " AND" + " concept.id_thesaurus = preferred_term.id_thesaurus" + " AND" + " note.id_thesaurus = '" + idThesaurus + "'" + multivaluesNote + langNote + group + " order by lexicalvalue ASC LIMIT 200";
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeSearch nodeSearch = new NodeSearch();
                    nodeSearch.setLexical_value(resultSet.getString("lexicalvalue"));
                    nodeSearch.setIdConcept(resultSet.getString("id_concept"));
                    nodeSearch.setIdTerm(resultSet.getString("id_term"));
                    nodeSearch.setIdGroup(resultSet.getString("idgroup"));
                    nodeSearch.setIdLang(resultSet.getString("lang"));
                    nodeSearch.setIdThesaurus(idThesaurus);
                    nodeSearch.setTopConcept(resultSet.getBoolean("top_concept"));
                    nodeSearch.setPreferredLabel(true);
                    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) ArrayList(java.util.ArrayList) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)

Example 37 with StringPlus

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

the class AlignmentHelper method addNewAlignment.

/**
 * Cette fonction permet d'ajouter un nouvel alignement sur un thésaurus
 * distant pour ce concept
 *
 * @param ds
 * @param nodeAlignment
 *
 * @return
 */
public boolean addNewAlignment(HikariDataSource ds, NodeAlignment nodeAlignment) {
    Connection conn;
    Statement stmt;
    nodeAlignment.setConcept_target(new StringPlus().convertString(nodeAlignment.getConcept_target()));
    nodeAlignment.setUri_target(new StringPlus().convertString(nodeAlignment.getUri_target()));
    boolean status = false;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "Insert into alignement " + "(author, concept_target, thesaurus_target," + " uri_target, alignement_id_type," + " internal_id_thesaurus, internal_id_concept)" + " values (" + nodeAlignment.getId_author() + ",'" + nodeAlignment.getConcept_target() + "'" + ",'" + nodeAlignment.getThesaurus_target() + "'" + ",'" + nodeAlignment.getUri_target() + "'" + "," + nodeAlignment.getAlignement_id_type() + ",'" + nodeAlignment.getInternal_id_thesaurus() + "'" + ",'" + nodeAlignment.getInternal_id_concept() + "')";
                stmt.executeUpdate(query);
                status = true;
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while adding external alignement with target : " + nodeAlignment.getUri_target(), 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 38 with StringPlus

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

the class AlignmentHelper method updateAlignment.

/**
 * Cette fonction permet de mettre à jour un Terme à la table Term, en
 * paramètre un objet Classe Term
 *
 * @param ds
 * @param idAlignment
 * @param conceptTarget
 * @param thesaurusTarget
 * @param idConcept
 * @param idTypeAlignment
 * @param uriTarget
 * @param idThesaurus
 * @param id_alignement_source parametre que on prende de la BDD, si c'est 0
 * c'est alignement manuel
 * @return
 */
public boolean updateAlignment(HikariDataSource ds, int idAlignment, String conceptTarget, String thesaurusTarget, String uriTarget, int idTypeAlignment, String idConcept, String idThesaurus, int id_alignement_source) {
    Connection conn;
    Statement stmt;
    boolean status = false;
    uriTarget = new StringPlus().convertString(uriTarget);
    conceptTarget = new StringPlus().convertString(conceptTarget);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "UPDATE alignement set" + " concept_target = '" + conceptTarget + "'," + " modified = current_date," + " thesaurus_target = '" + thesaurusTarget + "'," + " uri_target = '" + uriTarget + "'," + " alignement_id_type = " + idTypeAlignment + " WHERE internal_id_thesaurus = '" + idThesaurus + "'" + " AND internal_id_concept = '" + idConcept + "'" + " AND id_alignement_source = " + id_alignement_source + " AND alignement_id_type = " + idTypeAlignment;
                stmt.executeUpdate(query);
                status = true;
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while updating Alignment : " + idAlignment, 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 39 with StringPlus

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

the class CandidateHelper method addAdminMessage.

/**
 * Cette fonction permet d'ajouter un message de justification sur un
 * candidat refusé
 *
 * @param ds
 * @param idConceptCandidat
 * @param message
 * @param adminId
 * @param idThesaurus
 * @return boolean
 */
public boolean addAdminMessage(HikariDataSource ds, String idConceptCandidat, String idThesaurus, int adminId, String message) {
    Connection conn;
    Statement stmt;
    boolean status = false;
    message = new StringPlus().convertString(message);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "Update concept_candidat set" + " modified = current_date," + " admin_id = " + adminId + "," + " admin_message = '" + message + "'" + " where id_concept = '" + idConceptCandidat + "'" + " and id_thesaurus = '" + idThesaurus + "'";
                stmt.executeUpdate(query);
                status = true;
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while adding Admin Message of candidat  : " + idConceptCandidat, 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 40 with StringPlus

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

the class CandidateHelper method addTermCandidat.

/**
 * Cette fonction permet de rajouter un term_candidat
 *
 * @param ds
 * @param lexical_value
 * @param idLang
 * @param idThesaurus
 * @param contributor
 * @return idConceptCandidat
 */
public String addTermCandidat(HikariDataSource ds, String lexical_value, String idLang, String idThesaurus, int contributor) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String idTerm = null;
    lexical_value = new StringPlus().convertString(lexical_value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select max(id) from term_candidat";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                int idNumerique = resultSet.getInt(1);
                idTerm = "TC_" + (++idNumerique);
                /**
                 * Ajout des informations dans la table Concept
                 */
                query = "Insert into term_candidat " + "(id_term, lexical_value, lang, " + "id_thesaurus, contributor)" + " values (" + "'" + idTerm + "'" + ",'" + lexical_value + "'" + ",'" + idLang + "'" + ",'" + idThesaurus + "'" + "," + contributor + ")";
                stmt.executeUpdate(query);
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while adding Term_candidat  : " + idTerm, sqle);
    }
    return idTerm;
}
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) ResultSet(java.sql.ResultSet)

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