Search in sources :

Example 11 with NodeAutoCompletion

use of mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion in project opentheso by miledrousset.

the class AutoCompletBean method moveBrancheFromOrphinToGroup.

// ///////
// // Other Group
// ///////
/**
 * Déplace la branche vers la racine d'un autre Group
 * (Groupe/Domaine/Collection), la tete de la branche devient un TT
 * (TopTerme)
 *
 * @return
 */
public boolean moveBrancheFromOrphinToGroup() {
    // terme.getIdC = le concept sélectionné
    try {
        Connection conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        /*    if (selectedAtt == null || selectedAtt.getIdGroup().equals("")) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("autoComp.error1")));
                return false;
            }*/
        ConceptHelper conceptHelper = new ConceptHelper();
        GroupHelper groupHelper = new GroupHelper();
        // au concept la relation TT
        if (!conceptHelper.moveBranchToAnotherMT(conn, terme.getIdC(), // ancien Group
        idOld, // ancien Group
        terme.getIdDomaine(), // nouveau Group
        selectedAtt.getIdGroup(), terme.getIdTheso(), terme.getUser().getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
            conn.rollback();
            conn.close();
            return false;
        }
        // on récupère les Ids des concepts à modifier
        ArrayList<String> lisIds = new ArrayList<>();
        lisIds = conceptHelper.getIdsOfBranch(connect.getPoolConnexion(), terme.getIdC(), terme.getIdTheso(), lisIds);
        // on supprime l'ancien Groupe de la branche
        if (!groupHelper.deleteAllDomainOfBranch(conn, lisIds, terme.getIdDomaine(), terme.getIdTheso())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
            conn.rollback();
            conn.close();
            return false;
        }
        // on ajoute le nouveau domaine à la branche
        if (!groupHelper.setDomainToBranch(conn, lisIds, selectedAtt.getIdGroup(), terme.getIdTheso())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
            conn.rollback();
            conn.close();
            return false;
        }
        OrphanHelper orphanHelper = new OrphanHelper();
        if (!orphanHelper.deleteOrphanBranch2(conn, terme.getIdC(), terme.getIdTheso(), terme.getUser().getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
            conn.rollback();
            conn.close();
            return false;
        }
        conn.commit();
        conn.close();
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("autoComp.info2")));
        tree.reInit();
        tree.reExpand();
        selectedAtt = new NodeAutoCompletion();
        return true;
    } catch (SQLException ex) {
        Logger.getLogger(AutoCompletBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}
Also used : OrphanHelper(mom.trd.opentheso.bdd.helper.OrphanHelper) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) FacesMessage(javax.faces.application.FacesMessage) NodeAutoCompletion(mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)

Example 12 with NodeAutoCompletion

use of mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion in project opentheso by miledrousset.

the class GroupConverter method getAsObject.

@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
    if (value != null && value.trim().length() > 0) {
        NodeAutoCompletion nac = new NodeAutoCompletion();
        nac.setIdGroup(value);
        return nac;
    } else {
        return null;
    }
}
Also used : NodeAutoCompletion(mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)

Example 13 with NodeAutoCompletion

use of mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion in project opentheso by miledrousset.

the class NewTreeBean method fusionConcept.

/**
 * Fusionne les concepts avec mise à  jour dans l'abre
 */
public void fusionConcept() {
    if (selectedTerme.getConceptFusionId().equals(selectedTerme.getIdC())) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error"), langueBean.getMsg("error")));
        selectedTerme.setConceptFusionId(null);
        selectedTerme.setConceptFusionAlign(null);
        selectedTerme.setConceptFusionNodeRT(null);
    } else {
        int idUser = selectedTerme.getUser().getUser().getId();
        for (NodeRT rt : selectedTerme.getConceptFusionNodeRT()) {
            HierarchicalRelationship hr = new HierarchicalRelationship(rt.getIdConcept(), selectedTerme.getConceptFusionId(), selectedTerme.getIdTheso(), "RT");
            new ConceptHelper().addAssociativeRelation(connect.getPoolConnexion(), hr, idUser);
        }
        for (NodeAlignment na : selectedTerme.getConceptFusionAlign()) {
            new AlignmentHelper().addNewAlignment(connect.getPoolConnexion(), idUser, na.getConcept_target(), na.getThesaurus_target(), na.getUri_target(), na.getAlignement_id_type(), selectedTerme.getConceptFusionId(), selectedTerme.getIdTheso(), 0);
        }
        new ConceptHelper().addConceptFusion(connect.getPoolConnexion(), selectedTerme.getConceptFusionId(), selectedTerme.getIdC(), selectedTerme.getIdTheso(), idUser);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("tree.info6")));
        reInit();
        reExpand();
    }
    selectedTerme.setSelectedTermComp(new NodeAutoCompletion());
    vue.setAddTInfo(0);
}
Also used : NodeRT(mom.trd.opentheso.bdd.helper.nodes.NodeRT) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) AlignmentHelper(mom.trd.opentheso.bdd.helper.AlignmentHelper) FacesMessage(javax.faces.application.FacesMessage) NodeAutoCompletion(mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)

Example 14 with NodeAutoCompletion

use of mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion in project opentheso by miledrousset.

the class TermHelper method getAutoCompletionTerm.

/**
 * Cette fonction permet de récupérer une liste de termes pour
 * l'autocomplétion avec les synonymes
 *
 * @param ds
 * @param idThesaurus
 * @param text
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionTerm(HikariDataSource ds, String idThesaurus, String idLang, 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 {
                // cette partie permettait de se placer directement sur un terme, mais quand on tappe le temre exacte, on a le resultat avec le teme en double
                /*       String query = 
                            "SELECT DISTINCT term.lexical_value, concept.id_concept, concept.id_group " +
                            "FROM preferred_term, term, concept WHERE " +
                            "preferred_term.id_term = term.id_term 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.lexical_value iLIKE '" + text + "' AND " +
                            "term.lang = '" + idLang + "' AND " +
                            "concept.status != 'hidden'";
                    
                    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("id_group"), idThesaurus, idLang));
                                        //resultSet.getString("lexicalvalue"));
                                nodeAutoCompletion.setIdGroup(resultSet.getString("id_group"));
                                nodeAutoCompletionList.add(nodeAutoCompletion);
                            }
                        }
                    }*/
                String query = "SELECT DISTINCT term.lexical_value, concept.id_concept, concept_group_concept.idgroup " + "FROM preferred_term, term, concept,concept_group_concept " + "WHERE " + "idThesaurus = concept.id_thesaurus AND " + "concept_group_concept.idconcept = concept.id_concept AND " + "preferred_term.id_term = term.id_term 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.status != 'hidden' AND " + "unaccent_string(term.lexical_value) ILIKE unaccent_string('" + text + "%')" + " ORDER BY term.lexical_value ASC LIMIT 20";
                /*
                    query = "SELECT DISTINCT term.lexical_value, concept.id_concept,"
                            + " concept_group_label.lexicalvalue, concept_group_label.idgroup FROM"
                            + " concept, preferred_term, term, concept_group_label"
                            + " WHERE concept.id_concept = preferred_term.id_concept"
                            + " AND concept.id_group = concept_group_label.idgroup"
                            + " AND preferred_term.id_term = term.id_term"
                            + " AND term.id_thesaurus = concept.id_thesaurus"
                            + " AND concept.status != 'hidden'"
                            + " AND term.id_thesaurus = '" + idThesaurus + "'"
                            + " AND term.lang = '" + idLang + "'"
                            + " AND concept_group_label.lang = '" + idLang + "'"
                            + " 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))
                            nodeAutoCompletion.setIsAltLabel(false);
                            nodeAutoCompletionList.add(nodeAutoCompletion);
                        }
                    }
                }
                query = "SELECT DISTINCT " + "non_preferred_term.lexical_value," + "concept.id_concept," + "concept_group_concept.idgroup" + " FROM preferred_term, non_preferred_term, concept,concept_group_concept" + "  WHERE" + "  concept_group_concept.idthesaurus = concept.id_thesaurus " + "  AND" + "   concept_group_concept.idconcept = concept.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 non_preferred_term.id_thesaurus = '" + idThesaurus + "'" + " AND non_preferred_term.lang = '" + idLang + "'" + " AND concept.status != 'hidden' " + " AND unaccent_string(non_preferred_term.lexical_value) ILIKE unaccent_string('" + text + "%') ORDER BY non_preferred_term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    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))
                    nodeAutoCompletion.setIsAltLabel(true);
                    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 15 with NodeAutoCompletion

use of mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion in project opentheso by miledrousset.

the class TermHelper method getAutoCompletForRelationNT.

/**
 * permet de retourner la liste des concepts possibles
 * pour ajouter une relation NT
 * (en ignorant les relations interdites)
 * on ignore les concepts de type TT
 * on ignore les concepts de type RT
 *
 * On recherche aussi dans les Synonymes
 *
 * @param ds
 * @param idThesaurus
 * @param text
 * @param idLang
 * @return Objet class NodeAutoCompletion
 * #MR
 */
public List<NodeAutoCompletion> getAutoCompletForRelationNT(HikariDataSource ds, String idThesaurus, String idLang, 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, concept_group_concept.idgroup " + "FROM preferred_term, term, concept,concept_group_concept " + "WHERE " + "idThesaurus = concept.id_thesaurus AND " + "concept_group_concept.idconcept = concept.id_concept AND " + "preferred_term.id_term = term.id_term 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.status != 'hidden' AND " + "concept.top_concept != 'true' 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))
                            nodeAutoCompletion.setIsAltLabel(false);
                            nodeAutoCompletionList.add(nodeAutoCompletion);
                        }
                    }
                }
                query = "SELECT DISTINCT " + "non_preferred_term.lexical_value," + "concept.id_concept," + "concept_group_concept.idgroup" + " FROM preferred_term, non_preferred_term, concept,concept_group_concept" + "  WHERE" + "  concept_group_concept.idthesaurus = concept.id_thesaurus " + "  AND" + "   concept_group_concept.idconcept = concept.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 non_preferred_term.id_thesaurus = '" + idThesaurus + "'" + " AND non_preferred_term.lang = '" + idLang + "'" + " AND concept.status != 'hidden'" + " AND concept.top_concept != 'true'" + " AND unaccent_string(non_preferred_term.lexical_value) ILIKE unaccent_string('" + text + "%') ORDER BY non_preferred_term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    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))
                    nodeAutoCompletion.setIsAltLabel(true);
                    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)

Aggregations

NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)41 FacesMessage (javax.faces.application.FacesMessage)17 ArrayList (java.util.ArrayList)16 Connection (java.sql.Connection)11 SQLException (java.sql.SQLException)11 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)8 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)7 ResultSet (java.sql.ResultSet)6 Statement (java.sql.Statement)6 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)6 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)6 PreparedStatement (java.sql.PreparedStatement)2 Term (mom.trd.opentheso.bdd.datas.Term)2 MyTreeNode (mom.trd.opentheso.bdd.helper.nodes.MyTreeNode)2 NodeCandidat (mom.trd.opentheso.bdd.helper.nodes.candidat.NodeCandidat)2 NodeCandidatValue (mom.trd.opentheso.bdd.helper.nodes.candidat.NodeCandidatValue)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1