Search in sources :

Example 51 with ConceptHelper

use of mom.trd.opentheso.bdd.helper.ConceptHelper 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 52 with ConceptHelper

use of mom.trd.opentheso.bdd.helper.ConceptHelper 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 53 with ConceptHelper

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

the class SelectedTerme method majSearchPermute.

public void majSearchPermute() {
    if (new ConceptHelper().isTopConcept(connect.getPoolConnexion(), nodePe.getIdConcept(), idTheso, nodePe.getIdGroup())) {
        type = 2;
    } else {
        type = 3;
    }
    String value = (nodePe.getFirstColumn() + " " + nodePe.getSearchedValue() + " " + nodePe.getLastColumn()).trim();
    MyTreeNode mtn = new MyTreeNode(type, nodePe.getIdConcept(), nodePe.getIdThesaurus(), nodePe.getIdLang(), nodePe.getIdGroup(), "", null, null, value, null);
    majTerme(mtn);
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) PrefixString(com.k_int.IR.QueryModels.PrefixString)

Example 54 with ConceptHelper

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

the class SelectedTerme method addTermeGeneOtherGroup.

/**
 * Ajoute une relation terme générique au concept courant
 *
 * @param idConcept
 * @param idGroup
 * @param idNewConceptBT
 * @return true or false
 */
public boolean addTermeGeneOtherGroup(String idConcept, String idGroup, String idNewConceptBT) {
    ConceptHelper conceptHelper = new ConceptHelper();
    RelationsHelper relationsHelper = new RelationsHelper();
    GroupHelper groupHelper = new GroupHelper();
    String idNewGroup = conceptHelper.getGroupIdOfConcept(connect.getPoolConnexion(), idNewConceptBT, idTheso);
    if (idNewGroup == null) {
        return false;
    }
    try {
        Connection conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        if (termeGenerique.isEmpty()) {
            // c'était un orphelin
            if (!new OrphanHelper().deleteOrphan(conn, idConcept, idTheso)) {
                conn.rollback();
                conn.close();
                return false;
            }
        }
        // On ajoute la realtion BT au concept
        if (!relationsHelper.addRelationBT(conn, idConcept, idTheso, idNewConceptBT, user.getUser().getId())) {
            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(), idConcept, idTheso, lisIds);
        // on ajoute le nouveau domaine à la branche
        if (!groupHelper.addDomainToBranch(conn, lisIds, idNewGroup, idTheso, user.getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
            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();
    return true;
}
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) PrefixString(com.k_int.IR.QueryModels.PrefixString) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) FacesMessage(javax.faces.application.FacesMessage)

Example 55 with ConceptHelper

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

the class SelectedThesaurus method supprimerTheso.

/**
 * Suppréssion d'un thésaurus
 *
 * @param id
 */
public void supprimerTheso(String id) {
    ThesaurusHelper th = new ThesaurusHelper();
    // on vérifie si l'utilisateur n'a plus aucun thésaurus, on garde son dernier role sans thésaurus
    // cette action est temporaire le temps de mettre en place une gestion complète des users et des groupes
    UserHelper userHelper = new UserHelper();
    Connection conn;
    try {
        conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        if (userHelper.isLastThesoOfUser(connect.getPoolConnexion(), tree.getSelectedTerme().getUser().getUser().getId())) {
            if (!userHelper.deleteOnlyTheThesoFromRole(conn, id)) {
                conn.rollback();
                conn.close();
                return;
            }
        } else {
            if (!userHelper.deleteThisRoleForThisThesaurus(conn, tree.getSelectedTerme().getUser().getUser().getId(), id)) {
                conn.rollback();
                conn.close();
                return;
            }
        }
        conn.commit();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(SelectedThesaurus.class.getName()).log(Level.SEVERE, null, ex);
    }
    ConceptHelper conceptHelper = new ConceptHelper();
    conceptHelper.setNodePreference(nodePreference);
    conceptHelper.deleteAllIdHandle(connect.getPoolConnexion(), id);
    th.deleteThesaurus(connect.getPoolConnexion(), id);
    arrayTheso = new ArrayList<>(th.getListThesaurus(connect.getPoolConnexion(), langueSource).entrySet());
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, langueBean.getMsg("info") + " :", conceptHelper.getMessage()));
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) Connection(java.sql.Connection) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)125 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)38 SQLException (java.sql.SQLException)36 Connection (java.sql.Connection)29 ArrayList (java.util.ArrayList)28 FacesMessage (javax.faces.application.FacesMessage)23 Concept (mom.trd.opentheso.bdd.datas.Concept)18 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)16 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)16 Term (mom.trd.opentheso.bdd.datas.Term)15 PrefixString (com.k_int.IR.QueryModels.PrefixString)14 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)14 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)13 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)12 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)12 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)12 HashMap (java.util.HashMap)9 MyTreeNode (mom.trd.opentheso.bdd.helper.nodes.MyTreeNode)9 NodeConceptExport (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptExport)9 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)9