Search in sources :

Example 6 with RelationsHelper

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

the class SelectedTerme method delGene.

/**
 * Supprime la relation hiérarchique qui lie le terme courant à son père
 *
 * @param id l'identifiant du père
 * @return true or false
 */
public boolean delGene(String id) {
    // id est l'identifiant du concept à qui on doit supprimer la relation BT
    boolean TGisDomaine = false;
    if (idDomaine.equals(id)) {
        // cas où le générique est un domaine // donc le concept est un TT
        TGisDomaine = true;
    }
    // premier cas, si la branche n'a qu'un BT, alors elle devient orpheline
    if (termeGenerique.size() == 1) {
        // Le concept devient orphelin
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            /*   if (!new ConceptHelper().deleteConceptFromTable(conn, idC, idTheso, user.getUser().getId())) {
                    conn.rollback();
                    conn.close();
                    return false;
                }*/
            if (!new OrphanHelper().addNewOrphan(conn, idC, idTheso)) {
                conn.rollback();
                conn.close();
                return false;
            }
            if (new GroupHelper().isIdOfGroup(connect.getPoolConnexion(), id, idTheso)) {
                if (!new RelationsHelper().setRelationTopConcept(conn, idC, idTheso, id, false, user.getUser().getId())) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
            } else // on coupe la branche de son BT
            if (!new RelationsHelper().deleteRelationBT(conn, idC, idTheso, id, user.getUser().getId())) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
            termeGenerique = new ArrayList<>();
            vue.setAddTGen(0);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    // deuxième cas où la branche a plusieurs termes générique
    if (termeGenerique.size() > 1) {
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            if (TGisDomaine) {
                if (!new RelationsHelper().deleteRelationTT(conn, idC, idTheso, user.getUser().getId())) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
            } else if (!new RelationsHelper().deleteRelationBT(conn, idC, idTheso, id, user.getUser().getId())) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
            termeGenerique = new ArrayList<>();
            majTGen();
            vue.setAddTGen(0);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    // troisième cas, si la branche est à deplacer dans un nouveau domaine, alors il faut lui rajouter ce nouveau domaine.
    return false;
}
Also used : OrphanHelper(mom.trd.opentheso.bdd.helper.OrphanHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Example 7 with RelationsHelper

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

the class SelectedTerme method creerTermeSpe.

/**
 * *************************************** CREATION
 * ****************************************
 */
/**
 * Crée un nouveau terme spécifique au terme sélectionné
 *
 * @param selecedTerm
 * @return true or false
 */
public boolean creerTermeSpe(MyTreeNode selecedTerm) {
    ConceptHelper instance = new ConceptHelper();
    if (user.nodePreference == null)
        return false;
    instance.setNodePreference(user.getNodePreference());
    // 1 = domaine/Group, 2 = TT (top Term), 3 = Concept/term
    if (selecedTerm.isIsSubGroup() || selecedTerm.isIsGroup()) {
        // ici c'est le cas d'un Group ou Sous Group, on crée un TT Top Terme
        Concept concept = new Concept();
        concept.setIdGroup(selecedTerm.getIdConcept());
        concept.setIdThesaurus(idTheso);
        concept.setStatus("D");
        concept.setNotation("");
        Term terme = new Term();
        terme.setId_thesaurus(idTheso);
        terme.setLang(idlangue);
        terme.setLexical_value(valueEdit);
        terme.setSource("");
        terme.setStatus("");
        if (instance.addTopConcept(connect.getPoolConnexion(), idTheso, concept, terme, user.getUser().getId()) == null) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", instance.getMessage()));
            return false;
        }
        // instance.insertID_grouptoPermuted(connect.getPoolConnexion(), concept.getIdThesaurus(), concept.getIdConcept());
        ConceptHelper ch = new ConceptHelper();
        ArrayList<NodeConceptTree> tempNT = ch.getListTopConcepts(connect.getPoolConnexion(), idC, idTheso, idlangue);
        termesSpecifique = new ArrayList<>();
        HashMap<String, String> tempMap = new HashMap<>();
        for (NodeConceptTree nct : tempNT) {
            tempMap.put(nct.getIdConcept(), nct.getTitle());
        }
        termesSpecifique.addAll(tempMap.entrySet());
    } else {
        Concept concept = new Concept();
        concept.setIdGroup(selecedTerm.getIdCurrentGroup());
        concept.setIdThesaurus(idTheso);
        concept.setStatus("D");
        concept.setNotation("");
        Term terme = new Term();
        terme.setId_thesaurus(idTheso);
        terme.setLang(idlangue);
        terme.setLexical_value(valueEdit);
        terme.setSource("");
        terme.setStatus("");
        // String idTC = idTopConcept;
        String idP = idC;
        if (instance.addConcept(connect.getPoolConnexion(), idP, concept, terme, user.getUser().getId()) == null) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", instance.getMessage()));
            return false;
        }
        // instance.insertID_grouptoPermuted(connect.getPoolConnexion(), concept.getIdThesaurus(), concept.getIdConcept());
        concept.getUserName();
        ArrayList<NodeNT> tempNT = new RelationsHelper().getListNT(connect.getPoolConnexion(), idC, idTheso, idlangue);
        termesSpecifique = new ArrayList<>();
        HashMap<String, String> tempMap = new HashMap<>();
        for (NodeNT nnt : tempNT) {
            tempMap.put(nnt.getIdConcept(), nnt.getTitle() + " (" + nnt.getRole() + ")");
        }
        termesSpecifique.addAll(tempMap.entrySet());
    }
    vue.setAddTSpe(false);
    valueEdit = "";
    return true;
}
Also used : Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HashMap(java.util.HashMap) Term(mom.trd.opentheso.bdd.datas.Term) PrefixString(com.k_int.IR.QueryModels.PrefixString) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) NodeConceptTree(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree) FacesMessage(javax.faces.application.FacesMessage) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Example 8 with RelationsHelper

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

the class SelectedTerme method delBranchGroup.

/**
 * (ne marche pas encore !!! en cours) cette fonction permet de supprimer un
 * groupe d'une branche
 *
 * @param delGroup
 * @param idConcept
 * @return
 */
public boolean delBranchGroup(ArrayList<String> delGroup, String idConcept) {
    if (new ConceptHelper().haveChildren(connect.getPoolConnexion(), idTheso, idConcept)) {
        List<NodeNT> children = new RelationsHelper().getListNT(connect.getPoolConnexion(), idConcept, idTheso, "");
        for (NodeNT nnt : children) {
            delBranchGroup(delGroup, nnt.getIdConcept());
        }
    }
    List<NodeBT> parents = new RelationsHelper().getListBT(connect.getPoolConnexion(), idConcept, idTheso, "");
    int cpt = 0;
    for (String s : delGroup) {
        for (NodeBT nbt : parents) {
            if (new ConceptHelper().haveThisGroup(connect.getPoolConnexion(), nbt.getIdConcept(), s, idTheso)) {
                cpt++;
            }
        }
        if (new ConceptHelper().isTopConcept(connect.getPoolConnexion(), idConcept, idTheso, s)) {
            cpt++;
        }
        if (cpt <= 1) {
            new ConceptHelper().deleteGroupOfConcept(connect.getPoolConnexion(), idConcept, s, idTheso, user.getUser().getId());
        }
        cpt = 0;
    }
    return true;
}
Also used : NodeBT(mom.trd.opentheso.bdd.helper.nodes.NodeBT) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) PrefixString(com.k_int.IR.QueryModels.PrefixString) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Example 9 with RelationsHelper

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

the class SelectedTerme method delSpe.

// ancien code qui ne marche pas
/*   
     if(termeGenerique.size() == 1) { // Le concept devient orphelin
     new ConceptHelper().deleteConceptFromTable(connect.getPoolConnexion(), idC, idTheso);
     new OrphanHelper().addNewOrphan(connect.getPoolConnexion(), idC, idTheso);
            
     if(new GroupHelper().isIdOfGroup(connect.getPoolConnexion(), id, idTheso)) {
     new RelationsHelper().setRelationTopConcept(connect.getPoolConnexion(), idC, idTheso, id, false);
     } else {
     new RelationsHelper().deleteRelationBT(connect.getPoolConnexion(), idC, idTheso, id);
     }
            
     termeGenerique = new ArrayList<>();
     }  else {
     // On supprime l'ancien domaines si besoin
     ArrayList<String> groupBT;
     if(type == 2) {
     groupBT = new ArrayList<>();
     groupBT.add(id);
     } else {
     groupBT = new ConceptHelper().getListGroupIdOfConcept(connect.getPoolConnexion(), id, idTheso);
     }
     ArrayList<String> groupCurrent = new ConceptHelper().getListGroupIdOfConcept(connect.getPoolConnexion(), idC, idTheso);
     ArrayList<String> delGroup = new ArrayList<>();
     for(String s : groupBT) {
     if(groupCurrent.contains(s)) {
     delGroup.add(s);
     }
     }
     delBranchGroup(delGroup, idC);
            
     if(new GroupHelper().isIdOfGroup(connect.getPoolConnexion(), id, idTheso)) {
     new RelationsHelper().setRelationTopConcept(connect.getPoolConnexion(), idC, idTheso, id, false);
     } else {
     new RelationsHelper().deleteRelationBT(connect.getPoolConnexion(), idC, idTheso, id);
     }
            
     termeGenerique = new ArrayList<>();
     majTGen();
     }  
     vue.setAddTGen(false);
        
     }*/
/**
 * Supprime les relations qui lient le concept au Concept père
 *
 * @param id l'identifiant du fils
 * @return true or false
 */
public boolean delSpe(String id) {
    // On regarde si le fils devient orphelin
    ArrayList<Entry<String, String>> sonFathers = new ArrayList<>();
    // On ajoute le domaine
    ArrayList<String> listIdGroup = new ConceptHelper().getListGroupParentIdOfConcept(connect.getPoolConnexion(), id, idTheso);
    HashMap<String, String> tempMap1 = new HashMap<>();
    for (String group : listIdGroup) {
        tempMap1.put(group, new GroupHelper().getLexicalValueOfGroup(connect.getPoolConnexion(), group, idTheso, idlangue));
    }
    sonFathers.addAll(tempMap1.entrySet());
    ArrayList<NodeBT> tempBT = new RelationsHelper().getListBT(connect.getPoolConnexion(), id, idTheso, idlangue);
    HashMap<String, String> tempMap2 = new HashMap<>();
    for (NodeBT nbt : tempBT) {
        tempMap2.put(nbt.getIdConcept(), nbt.getTitle());
    }
    sonFathers.addAll(tempMap2.entrySet());
    if (sonFathers.size() <= 1) {
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            if (!new ConceptHelper().deleteConceptFromTable(conn, id, idTheso, user.getUser().getId())) {
                conn.rollback();
                conn.close();
                return false;
            }
            if (!new RelationsHelper().deleteRelationBT(conn, id, idTheso, idC, user.getUser().getId())) {
                conn.rollback();
                conn.close();
                return false;
            }
            if (!new OrphanHelper().addNewOrphan(conn, id, idTheso)) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    } else {
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            // On supprime l'ancien domaines si besoin
            ArrayList<String> groupCurrent;
            if (type == 1) {
                groupCurrent = new ArrayList<>();
                groupCurrent.add(idC);
            } else {
                groupCurrent = new ConceptHelper().getListGroupIdOfConcept(connect.getPoolConnexion(), idC, idTheso);
            }
            ArrayList<String> groupNT = new ConceptHelper().getListGroupIdOfConcept(connect.getPoolConnexion(), id, idTheso);
            ArrayList<String> delGroup = new ArrayList<>();
            for (String s : groupCurrent) {
                if (groupNT.contains(s)) {
                    delGroup.add(s);
                }
            }
            if (!delBranchGroup(delGroup, id)) {
                conn.rollback();
                conn.close();
                return false;
            }
            if (type == 1) {
                if (!new RelationsHelper().setRelationTopConcept(conn, id, idTheso, idC, false, user.getUser().getId())) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
            } else if (!new RelationsHelper().deleteRelationBT(conn, id, idTheso, idC, user.getUser().getId())) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
            ArrayList<NodeNT> tempNT = new RelationsHelper().getListNT(connect.getPoolConnexion(), idC, idTheso, idlangue);
            termesSpecifique = new ArrayList<>();
            HashMap<String, String> tempMap3 = new HashMap<>();
            for (NodeNT nnt : tempNT) {
                tempMap3.put(nnt.getIdConcept(), nnt.getTitle() + " (" + nnt.getRole() + ")");
            }
            termesSpecifique.addAll(tempMap3.entrySet());
        } catch (SQLException ex) {
            Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    return true;
}
Also used : OrphanHelper(mom.trd.opentheso.bdd.helper.OrphanHelper) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PrefixString(com.k_int.IR.QueryModels.PrefixString) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) NodeBT(mom.trd.opentheso.bdd.helper.nodes.NodeBT) Entry(java.util.Map.Entry) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Example 10 with RelationsHelper

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

the class SelectedTerme method addTermeGene.

/**
 * Ajoute une relation terme générique au concept courant
 *
 * @param idNT
 * @param idBT
 * @return true or false
 */
public boolean addTermeGene(String idNT, String idBT) {
    try {
        Connection conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        if (termeGenerique.isEmpty()) {
            // c'était un orphelin
            if (!new OrphanHelper().deleteOrphan(conn, idNT, idTheso)) {
                conn.rollback();
                conn.close();
                return false;
            }
        }
        // On ajoute la realtion BT au concept
        if (!new RelationsHelper().addRelationBT(conn, idNT, idTheso, idBT, user.getUser().getId())) {
            conn.rollback();
            conn.close();
            return false;
        }
        conn.commit();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
    termeGenerique = new ArrayList<>();
    majTGen();
    vue.setAddTGen(0);
    return true;
}
Also used : OrphanHelper(mom.trd.opentheso.bdd.helper.OrphanHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Aggregations

RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)26 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)14 PrefixString (com.k_int.IR.QueryModels.PrefixString)11 NodeNT (mom.trd.opentheso.bdd.helper.nodes.NodeNT)10 SQLException (java.sql.SQLException)8 HashMap (java.util.HashMap)8 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)8 Connection (java.sql.Connection)7 Concept (mom.trd.opentheso.bdd.datas.Concept)7 ArrayList (java.util.ArrayList)5 FacesMessage (javax.faces.application.FacesMessage)5 OrphanHelper (mom.trd.opentheso.bdd.helper.OrphanHelper)5 Term (mom.trd.opentheso.bdd.datas.Term)4 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)4 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)4 NodeBT (mom.trd.opentheso.bdd.helper.nodes.NodeBT)4 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)3 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)3 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)3 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)2