Search in sources :

Example 6 with OrphanHelper

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

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

the class AutoCompletBean method moveBranchFromOrphinToConcept.

// ////////////////////////////////////
// ////////////////////////////////////
// / partie pour les orphelins ////////
// ////////////////////////////////////
// ////////////////////////////////////
/**
 * Permet de déplacer une branche des orphelins vers un vers un concept
 * uniquement
 *
 * @return
 */
public boolean moveBranchFromOrphinToConcept() {
    // List selectedNode (c'est le noeud complet sélectionné)
    if (selectedAtt == null || selectedAtt.getIdConcept().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();
    try {
        Connection conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        // permet de déplacer une branche simplement, en cas d'erreur, rien n'est écrit
        if (!conceptHelper.moveBranchToConceptOtherGroup(conn, terme.getIdC(), idOld, selectedAtt.getIdConcept(), terme.getIdTheso(), terme.getUser().getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
            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
        ArrayList<String> domsOld = conceptHelper.getListGroupIdOfConcept(connect.getPoolConnexion(), terme.getIdC(), terme.getIdTheso());
        for (String domsOld1 : domsOld) {
            if (!groupHelper.deleteAllDomainOfBranch(conn, lisIds, domsOld1, 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
        ArrayList<String> domsNew = conceptHelper.getListGroupIdOfConcept(connect.getPoolConnexion(), selectedAtt.getIdConcept(), terme.getIdTheso());
        for (String domsNew1 : domsNew) {
            if (!groupHelper.setDomainToBranch(conn, lisIds, domsNew1, 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();
        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) FacesMessage(javax.faces.application.FacesMessage) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 8 with OrphanHelper

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

the class SelectedTerme method creerTermeSpe.

/**
 * Corrigé par M.R. Ajoute une relation terme spécifique au concept courant
 *
 * @param idCNT
 * @return true or false
 */
public boolean creerTermeSpe(String idCNT) {
    ConceptHelper conceptHelper = new ConceptHelper();
    if (new OrphanHelper().isOrphan(connect.getPoolConnexion(), idCNT, idTheso)) {
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            ArrayList<String> newGroup = conceptHelper.getListGroupIdOfConcept(connect.getPoolConnexion(), idC, idTheso);
            for (String s : newGroup) {
                Concept c = new Concept();
                c.setIdConcept(idCNT);
                c.setIdGroup(s);
                c.setIdThesaurus(idTheso);
                c.setStatus("D");
                String idConcept = conceptHelper.addConceptInTable(conn, c, user.getUser().getId());
                // si ça se passe mal, on ajoute rien;
                if (idConcept == null) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
            }
            if (!new OrphanHelper().deleteOrphan(conn, idCNT, idTheso)) {
                conn.rollback();
                conn.close();
                return false;
            }
            // On crée les relations
            if (!new RelationsHelper().addRelationBT(conn, idCNT, idTheso, idC, 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;
        }
    } else if (type == 1) {
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            if (new ConceptHelper().haveThisGroup(connect.getPoolConnexion(), idCNT, idC, idTheso)) {
                if (!new RelationsHelper().setRelationTopConcept(conn, idCNT, idTheso, idC, true, user.getUser().getId())) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
            } else {
                ArrayList<String> newGroup = new ArrayList<>();
                newGroup.add(idC);
                if (!addBranchGroup(newGroup, idCNT)) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
                if (!new RelationsHelper().setRelationTopConcept(conn, idCNT, idTheso, idC, true, 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);
        }
    } else {
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            // On ajoute les nouveaux domaines s'il y en a
            ArrayList<String> groupNT = conceptHelper.getListGroupIdOfConcept(connect.getPoolConnexion(), idCNT, idTheso);
            ArrayList<String> groupCurrent = conceptHelper.getListGroupIdOfConcept(connect.getPoolConnexion(), idC, idTheso);
            ArrayList<String> newGroup = new ArrayList<>();
            for (String s : groupCurrent) {
                if (!groupNT.contains(s)) {
                    newGroup.add(s);
                }
            }
            if (!addBranchGroup(newGroup, idCNT)) {
                conn.rollback();
                conn.close();
                return false;
            }
            // On crée les relations
            if (!new RelationsHelper().addRelationBT(conn, idCNT, idTheso, idC, 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;
        }
    }
    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);
    return true;
}
Also used : OrphanHelper(mom.trd.opentheso.bdd.helper.OrphanHelper) Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PrefixString(com.k_int.IR.QueryModels.PrefixString) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Aggregations

OrphanHelper (mom.trd.opentheso.bdd.helper.OrphanHelper)8 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)6 ArrayList (java.util.ArrayList)5 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)5 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)5 PrefixString (com.k_int.IR.QueryModels.PrefixString)3 FacesMessage (javax.faces.application.FacesMessage)3 HashMap (java.util.HashMap)2 Concept (mom.trd.opentheso.bdd.datas.Concept)2 NodeNT (mom.trd.opentheso.bdd.helper.nodes.NodeNT)2 Entry (java.util.Map.Entry)1 Term (mom.trd.opentheso.bdd.datas.Term)1 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)1 MyTreeNode (mom.trd.opentheso.bdd.helper.nodes.MyTreeNode)1 NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)1 NodeBT (mom.trd.opentheso.bdd.helper.nodes.NodeBT)1 StructIdBroaderTerm (mom.trd.opentheso.dragdrop.StructIdBroaderTerm)1 DefaultTreeNode (org.primefaces.model.DefaultTreeNode)1