Search in sources :

Example 31 with StringPlus

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

the class WriteFileSKOS method prepareUriTohtml.

// fonction qui permet de structurer une URL pour HTML
private String prepareUriTohtml(String url) {
    StringPlus stringPlus = new StringPlus();
    url = stringPlus.normalizeStringForXml(url);
    // StringEscapeUtils.escapeHtml4(url.trim());
    return url;
}
Also used : StringPlus(mom.trd.opentheso.bdd.tools.StringPlus)

Example 32 with StringPlus

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

the class SearchHelper method searchNonPreferedTerm.

/**
 * Cette fonction permet de faire une recherche par value en filtran par
 * Group
 *
 * @param ds
 * @param value
 * @param idLang
 * @param idThesaurus
 * @return
 */
public ArrayList<NodeSearch> searchNonPreferedTerm(HikariDataSource ds, String value, String idLang, String idThesaurus) {
    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 non_preferred_term.id_term, " + " non_preferred_term.lexical_value, " + " idgroup, preferred_term.id_concept," + " concept.top_concept" + " FROM non_preferred_term, preferred_term," + " concept,concept_group_concept WHERE " + " concept_group_concept.idthesaurus = non_preferred_term.id_thesaurus AND" + " concept_group_concept.idconcept = preferred_term.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" + " unaccent_string(non_preferred_term.lexical_value) ilike" + " unaccent_string('" + value + "%')" + " and non_preferred_term.id_thesaurus = '" + idThesaurus + "'" + " and non_preferred_term.lang = '" + idLang + "'" + " 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"));
                    nodeSearch.setPreferredLabel(false);
                    // 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 33 with StringPlus

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

the class SearchHelper method getListPermute.

/**
 * Cette fonction permet de récupérer une liste des concepts sous forme
 * permutée par domaine
 *
 * renvoie les synonymes aussi
 *
 * @param ds
 * @param idThesaurus
 * @param idLang
 * @param value
 * @param idGroup
 * @return ArrayList de NodePermute
 */
public ArrayList<NodePermute> getListPermute(HikariDataSource ds, String idThesaurus, String idLang, String value, String idGroup) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodePermute> nodePermuteList = null;
    value = new StringPlus().convertString(value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT ord, id_concept, " + " id_lang, lexical_value, ispreferredterm, original_value" + " FROM permuted WHERE" + " id_lang = '" + idLang + "'" + " and id_group = '" + idGroup + "'" + " and id_thesaurus = '" + idThesaurus + "'" + " and unaccent_string(lexical_value) ilike" + " unaccent_string('" + value + "%')" + " order by lexical_value ASC LIMIT 200";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                nodePermuteList = new ArrayList<>();
                while (resultSet.next()) {
                    NodePermute nodePermute = new NodePermute();
                    nodePermute.setIdThesaurus(idThesaurus);
                    nodePermute.setIdConcept(resultSet.getString("id_concept"));
                    nodePermute.setIdLang(resultSet.getString("id_lang"));
                    nodePermute.setIdGroup(idGroup);
                    nodePermute.setSearchedValue(resultSet.getString("lexical_value"));
                    nodePermute.setIndexOfValue(resultSet.getInt("ord"));
                    nodePermute.setIsPreferredTerm(resultSet.getBoolean("ispreferredterm"));
                    // cas où le terme recherché est égal au terme retrouvé, on le place en premier
                    if (value.trim().equalsIgnoreCase(resultSet.getString("original_value").trim())) {
                        nodePermuteList.add(0, nodePermute);
                    } else {
                        nodePermuteList.add(nodePermute);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List Permute of Value by Group : " + value, sqle);
    }
    if (nodePermuteList != null) {
        nodePermuteList = addColumnsToPermute(ds, idThesaurus, nodePermuteList);
    }
    return nodePermuteList;
}
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) NodePermute(mom.trd.opentheso.bdd.helper.nodes.NodePermute)

Example 34 with StringPlus

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

the class SearchHelper method simpleSearchNonPreferredTerm.

/**
 * Cette fonction permet de faire une recherche par valeur sur les synonymes
 * (la recherche est stricte, pas de troncature mais on ignore les majuscules
 * et les accents)
 *
 * @param ds
 * @param value
 * @param idLang
 * @param idThesaurus
 * @param idGroup
 * @return
 */
public HashMap simpleSearchNonPreferredTerm(HikariDataSource ds, String value, String idLang, String idThesaurus, String idGroup) {
    HashMap<String, String> hmap = new HashMap<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    value = new StringPlus().convertString(value);
    String query;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                query = "SELECT   term.lexical_value AS pref, non_preferred_term.lexical_value AS alt" + " FROM term, non_preferred_term, concept_group_concept," + " preferred_term" + " WHERE " + " term.id_term = non_preferred_term.id_term AND" + " term.lang = non_preferred_term.lang AND" + " term.id_thesaurus = non_preferred_term.id_thesaurus AND" + " preferred_term.id_concept = concept_group_concept.idconcept AND" + " preferred_term.id_thesaurus = concept_group_concept.idthesaurus AND" + " non_preferred_term.id_term = preferred_term.id_term AND" + " non_preferred_term.id_thesaurus = preferred_term.id_thesaurus AND" + " non_preferred_term.id_thesaurus = '" + idThesaurus + "' AND" + " non_preferred_term.lang = '" + idLang + "' AND" + " concept_group_concept.idgroup = '" + idGroup + "'" + " and unaccent_string(non_preferred_term.lexical_value) ilike" + " unaccent_string('" + value + "')";
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    hmap.put(resultSet.getString("pref"), resultSet.getString("alt"));
                // listTerms.add(resultSet.getString("lexical_value"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(SearchHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return hmap;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 35 with StringPlus

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

the class SearchHelper method simpleSearchPreferredTerm.

/**
 * Cette fonction permet de faire une recherche par valeur sur les termes
 * Préférés (la recherche est stricte, pas de troncature mais on ignore les majuscules
 * et les accents)
 *
 * @param ds
 * @param value
 * @param idLang
 * @param idThesaurus
 * @param idGroup
 * @return
 */
public ArrayList<String> simpleSearchPreferredTerm(HikariDataSource ds, String value, String idLang, String idThesaurus, String idGroup) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<String> listTerms = new ArrayList<>();
    value = new StringPlus().convertString(value);
    String query;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                query = "SELECT term.lexical_value" + " FROM term, concept_group_concept," + " preferred_term" + " WHERE " + " term.id_term = preferred_term.id_term AND" + " term.id_thesaurus = preferred_term.id_thesaurus AND" + " preferred_term.id_concept = concept_group_concept.idconcept AND" + " preferred_term.id_thesaurus = concept_group_concept.idthesaurus AND" + " term.id_thesaurus = '" + idThesaurus + "' AND" + " term.lang = '" + idLang + "' AND" + " concept_group_concept.idgroup = '" + idGroup + "'" + " and unaccent_string(term.lexical_value) ilike" + " unaccent_string('" + value + "')";
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    listTerms.add(resultSet.getString("lexical_value"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(SearchHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return listTerms;
}
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)

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