Search in sources :

Example 21 with RelationsHelper

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

the class SelectedTerme method creerTermeAsso.

/**
 * Ajoute une relation terme associé au concept courant
 *
 * @param idC2 le concept associé
 */
public void creerTermeAsso(String idC2) {
    HierarchicalRelationship hr = new HierarchicalRelationship();
    hr.setIdConcept1(idC);
    hr.setIdConcept2(idC2);
    hr.setIdThesaurus(idTheso);
    hr.setRole("RT");
    new ConceptHelper().addAssociativeRelation(connect.getPoolConnexion(), hr, user.getUser().getId());
    ArrayList<NodeRT> tempRT = new RelationsHelper().getListRT(connect.getPoolConnexion(), idC, idTheso, idlangue);
    termesAssocies = new ArrayList<>();
    HashMap<String, String> tempMap = new HashMap<>();
    for (NodeRT nrt : tempRT) {
        tempMap.put(nrt.getIdConcept(), nrt.getTitle() + " (" + nrt.getRole() + ")");
    }
    termesAssocies.addAll(tempMap.entrySet());
    vue.setAddTAsso(0);
}
Also used : NodeRT(mom.trd.opentheso.bdd.helper.nodes.NodeRT) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) HashMap(java.util.HashMap) PrefixString(com.k_int.IR.QueryModels.PrefixString) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper)

Example 22 with RelationsHelper

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

Example 23 with RelationsHelper

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

the class WriteBranchSkosBDD method writeFirstConceptAfterGroup.

private boolean writeFirstConceptAfterGroup(SKOSResource resource, String idGroup, String idThesaurus, String id_langueSource, String dateFormat, String adressSite, boolean useArk, int idUser) {
    RelationsHelper relationsHelper = new RelationsHelper();
    // ajout du concept dans la base
    Concept concept = new Concept();
    ConceptHelper conceptHelper = new ConceptHelper();
    if (idGroup.trim().isEmpty())
        return false;
    String idC = getId(resource.getUri());
    concept.setIdConcept(idC);
    // concept.setCreated(null);
    concept.setIdThesaurus(idThesaurus);
    concept.setNotation("");
    concept.setStatus("");
    concept.setTopConcept(true);
    concept.setIdGroup(idGroup);
    concept = addDates(resource.getDateList(), concept, dateFormat);
    conceptHelper.insertConceptInTable(ds, concept, idUser);
    // ajout des termes et traductions
    NodeTerm nodeTerm = new NodeTerm();
    nodeTerm.setNodeTermTraduction(getTraductionConcept(resource.getLabelsList()));
    nodeTerm.setIdTerm(idC);
    nodeTerm.setIdConcept(idC);
    nodeTerm.setIdThesaurus(idThesaurus);
    nodeTerm.setSource("");
    nodeTerm.setStatus("");
    nodeTerm = addDatesTerm(resource.getDateList(), nodeTerm, dateFormat);
    TermHelper termHelper = new TermHelper();
    termHelper.insertTerm(ds, nodeTerm, idUser);
    // ajouter les notes
    ArrayList<NodeNote> nodeNoteList = addNotes(resource.getDocumentationsList());
    NoteHelper noteHelper = new NoteHelper();
    for (NodeNote nodeNoteList1 : nodeNoteList) {
        if (nodeNoteList1.getNotetypecode().contains("scopeNote")) {
            noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
        if (nodeNoteList1.getNotetypecode().contains("historyNote")) {
            noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
        if (nodeNoteList1.getNotetypecode().contains("definition")) {
            noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
        if (nodeNoteList1.getNotetypecode().contains("editorialNote")) {
            noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
    }
    // Enregistrer les relations sans les BT
    writeRelationsList(resource.getRelationsList(), concept.getIdConcept(), idThesaurus, idUser);
    ArrayList<SKOSMapping> sKOSMappings = resource.getMappings();
    // Enregistrer les Mappings (alignements)
    AlignmentHelper alignmentHelper = new AlignmentHelper();
    for (SKOSMapping sKOSMapping : sKOSMappings) {
        if (sKOSMapping.getProperty() == SKOSProperty.exactMatch) {
            alignmentHelper.addNewAlignment(ds, // user
            1, // concept target
            "", // thesaurus target
            "", // URI
            sKOSMapping.getTargetUri(), 1, concept.getIdConcept(), idThesaurus, 0);
        }
        if (sKOSMapping.getProperty() == SKOSProperty.closeMatch) {
            alignmentHelper.addNewAlignment(ds, // user
            1, // concept target
            "", // thesaurus target
            "", // URI
            sKOSMapping.getTargetUri(), 2, concept.getIdConcept(), idThesaurus, 0);
        }
    }
    // Ajouter l'id du concept importé pour l'aligner avec le thésaurus source
    alignmentHelper.addNewAlignment(ds, // user
    1, // concept target
    "", // thesaurus target
    "", // URI de la source
    resource.getUri(), // sKOSMapping.getTargetUri(), // URI
    1, concept.getIdConcept(), idThesaurus, 0);
    // Enregister les synonymes et traductions
    ArrayList<NodeEM> nodeEMs = writeLabelsList(ds, resource.getLabelsList());
    Term term = new Term();
    for (int i = 0; i < nodeEMs.size(); i++) {
        term.setId_concept(concept.getIdConcept());
        term.setId_term(nodeTerm.getIdTerm());
        term.setLexical_value(nodeEMs.get(i).getLexical_value());
        term.setLang(nodeEMs.get(i).getLang());
        term.setId_thesaurus(idThesaurus);
        term.setSource(nodeEMs.get(i).getSource());
        term.setStatus(nodeEMs.get(i).getStatus());
        termHelper.addNonPreferredTerm(ds, term, idUser);
    }
    return true;
}
Also used : SKOSTopConcept(skos.SKOSTopConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) AlignmentHelper(mom.trd.opentheso.bdd.helper.AlignmentHelper) Term(mom.trd.opentheso.bdd.datas.Term) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) SKOSMapping(skos.SKOSMapping) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 24 with RelationsHelper

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

the class ExportTxtHelper method countIndentation.

/**
 * permet de compter le nombre de décalalge pour chaque type de données
 * concept : pour l'hiérarchie NT : pour le nombre maxi de NT existant dans
 * le thésaurus ou le domaine choisi RT ... UF ....
 *
 * @param idConcept
 * @param indentation
 */
private void countIndentation(String idConcept, String indentation) {
    ArrayList<NodeNT> childList = new RelationsHelper().getListNT(ds, idConcept, idTheso, selectedLang);
    if (childList == null) {
        return;
    }
    // indentation des concepts par hiérarchie
    indentation += "\t";
    int tot = StringUtils.countMatches(indentation, "\t");
    if (tot > indentationConcept) {
        indentationConcept = tot;
    }
    // indentation des NT nombre maxi
    if (selectedOptions.contains("nt")) {
        int totNT = new RelationsHelper().getCountOfNT(ds, idConcept, idTheso);
        if (totNT > indentationNT) {
            indentationNT = totNT;
        }
    }
    // indentation des BT nombre maxi
    if (selectedOptions.contains("bt")) {
        int totBT = new RelationsHelper().getCountOfBT(ds, idConcept, idTheso);
        if (totBT > indentationBT) {
            indentationBT = totBT;
        }
    }
    // indentation des RT nombre maxi
    if (selectedOptions.contains("rt")) {
        int totRT = new RelationsHelper().getCountOfRT(ds, idConcept, idTheso);
        if (totRT > indentationRT) {
            indentationRT = totRT;
        }
    }
    // indentation des UF nombre maxi
    if (selectedOptions.contains("uf")) {
        int totUF = new RelationsHelper().getCountOfUF(ds, idConcept, idTheso, selectedLang);
        if (totUF > indentationUF) {
            indentationUF = totUF;
        }
    }
    // indentation des Groups nombre maxi
    if (selectedOptions.contains("groups")) {
        int totGroup = new GroupHelper().getCountOfGroups(ds, idConcept, idTheso);
        if (totGroup > indentationGroups) {
            indentationGroups = totGroup;
        }
    }
    // indentation traductions
    if (selectedOptions.contains("traductions")) {
        int totTraductions = new TermHelper().getCountOfTraductions(ds, idConcept, idTheso, selectedLang);
        if (totTraductions > indentationTraductions) {
            indentationTraductions = totTraductions;
        }
    }
    // indentation notes
    if (selectedOptions.contains("notes")) {
        int totNotes = new NoteHelper().getCountOfNotes(ds, idConcept, idTheso, selectedLang);
        if (totNotes > indentationNotes) {
            indentationNotes = totNotes;
        }
    }
    for (NodeNT nodeNT : childList) {
        countIndentation(nodeNT.getIdConcept(), indentation);
    }
}
Also used : NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 25 with RelationsHelper

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

the class ExportTxtHelper method writeConceptRecursive.

/**
 * fonction recursive qui sert a ecrire tout les fils des term
 *
 * @param id
 * @param indentation
 * @param paragraphs
 * @param idToDoc
 */
private void writeConceptRecursive(String idConcept, String indentation) {
    ArrayList<NodeNT> childList = new RelationsHelper().getListNT(ds, idConcept, idTheso, selectedLang);
    if (childList == null) {
        return;
    }
    indentation += "\t";
    for (NodeNT nodeNT : childList) {
        writeConceptsInfo(nodeNT.getIdConcept(), indentation);
        writeConceptRecursive(nodeNT.getIdConcept(), indentation);
    }
}
Also used : NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) 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