use of mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion in project opentheso by miledrousset.
the class TermHelper method getAutoCompletionTermOfOtherGroup.
/**
* Cette fonction permet de récupérer une liste des terms pour
* l'autocomplétion en se évitant le Group actuel et en ignorant le terme
* lui même
*
* @param ds
* @param idSelectedConcept
* @param idThesaurus
* @param text
* @param idGroup
* @param idLang
* @return Objet class Concept
*/
public List<NodeAutoCompletion> getAutoCompletionTermOfOtherGroup(HikariDataSource ds, // le concept à ignorer
String idSelectedConcept, String idThesaurus, String idLang, String idGroup, 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, 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 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_group_concept.idgroup != '" + idGroup + "' AND " + "concept.id_concept != '" + idSelectedConcept + "' 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;
}
Aggregations