Search in sources :

Example 21 with Term

use of mom.trd.opentheso.bdd.datas.Term in project opentheso by miledrousset.

the class SelectedTerme method creerTradterme.

/**
 * Ajoute une traduction au terme courant et met l'affichage à jour
 */
public void creerTradterme() {
    if (valueEdit == null || valueEdit.trim().equals("")) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("sTerme.error3")));
        return;
    }
    boolean tradExist = false;
    // c'est le cas ou le concept n'a pas de traduction dans la langue en cours, il faut le mettre a jour dans l'arbre
    boolean newTraduction = false;
    for (Entry<String, String> e : langues) {
        if (e.getKey().equals(langueEdit)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("sTerme.error4")));
            tradExist = true;
            break;
        }
    }
    ConceptHelper ch = new ConceptHelper();
    TermHelper termHelper = new TermHelper();
    if (idT.isEmpty()) {
        newTraduction = true;
        String tmp = termHelper.getIdTermOfConcept(connect.getPoolConnexion(), idC, idTheso);
        if (tmp != null) {
            idT = tmp;
        }
    }
    // traduction du domaine
    if (type == 1 && !tradExist) {
        ConceptGroupLabel cgl = new ConceptGroupLabel();
        cgl.setLexicalvalue(valueEdit);
        cgl.setIdgroup(idDomaine);
        cgl.setIdthesaurus(idTheso);
        cgl.setLang(langueEdit);
        GroupHelper cgh = new GroupHelper();
        if (cgh.isDomainExist(connect.getPoolConnexion(), cgl.getLexicalvalue(), cgl.getIdthesaurus(), cgl.getLang())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("sTerme.error4")));
            return;
        }
        if (!cgh.addGroupTraduction(connect.getPoolConnexion(), cgl, user.getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("Error")));
            return;
        }
        ArrayList<NodeGroupTraductions> tempNGT = new GroupHelper().getGroupTraduction(connect.getPoolConnexion(), idDomaine, idTheso, idlangue);
        langues = new ArrayList<>();
        HashMap<String, String> tempMapL = new HashMap<>();
        for (NodeGroupTraductions ngt : tempNGT) {
            tempMapL.put(ngt.getIdLang(), ngt.getTitle());
        }
        if (newTraduction) {
            nom = cgh.getLexicalValueOfGroup(connect.getPoolConnexion(), idDomaine, idTheso, idlangue);
        }
        langues.addAll(tempMapL.entrySet());
    // traduction du TT
    } else if (type == 2 && !tradExist) {
        Term terme = new Term();
        terme.setId_thesaurus(idTheso);
        terme.setLang(langueEdit);
        terme.setLexical_value(valueEdit);
        terme.setId_term(idT);
        terme.setContributor(user.getUser().getId());
        terme.setCreator(user.getUser().getId());
        terme.setSource("");
        terme.setStatus("");
        if (termHelper.isTermExist(connect.getPoolConnexion(), terme.getLexical_value(), terme.getId_thesaurus(), terme.getLang())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("sTerme.error4")));
            return;
        }
        if (!ch.addTopConceptTraduction(connect.getPoolConnexion(), terme, user.getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("Error")));
            return;
        }
        ArrayList<NodeTermTraduction> tempNTT = termHelper.getTraductionsOfConcept(connect.getPoolConnexion(), idC, idTheso, idlangue);
        langues = new ArrayList<>();
        HashMap<String, String> tempMapL = new HashMap<>();
        for (NodeTermTraduction ntt : tempNTT) {
            tempMapL.put(ntt.getLang(), ntt.getLexicalValue());
        }
        if (newTraduction) {
            nom = termHelper.getThisTerm(connect.getPoolConnexion(), idC, idTheso, idlangue).getLexical_value();
        }
        langues.addAll(tempMapL.entrySet());
    // traduction des concepts
    } else if (type == 3 && !tradExist) {
        Term terme = new Term();
        terme.setId_thesaurus(idTheso);
        terme.setLang(langueEdit);
        terme.setLexical_value(valueEdit);
        terme.setId_term(idT);
        terme.setContributor(user.getUser().getId());
        terme.setCreator(user.getUser().getId());
        terme.setSource("");
        terme.setStatus("");
        if (termHelper.isTermExist(connect.getPoolConnexion(), terme.getLexical_value(), terme.getId_thesaurus(), terme.getLang())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("sTerme.error4")));
            return;
        }
        if (!ch.addConceptTraduction(connect.getPoolConnexion(), terme, user.getUser().getId())) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("Error")));
            return;
        }
        ArrayList<NodeTermTraduction> tempNTT = termHelper.getTraductionsOfConcept(connect.getPoolConnexion(), idC, idTheso, idlangue);
        langues = new ArrayList<>();
        HashMap<String, String> tempMapL = new HashMap<>();
        for (NodeTermTraduction ntt : tempNTT) {
            tempMapL.put(ntt.getLang(), ntt.getLexicalValue());
        }
        langues.addAll(tempMapL.entrySet());
        if (newTraduction) {
            nom = termHelper.getThisTerm(connect.getPoolConnexion(), idC, idTheso, idlangue).getLexical_value();
        }
    }
    langueEdit = "";
    valueEdit = "";
    if (!tradExist) {
        vue.setAddTrad(0);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("sTerme.info2")));
    }
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HashMap(java.util.HashMap) ConceptGroupLabel(mom.trd.opentheso.bdd.datas.ConceptGroupLabel) ArrayList(java.util.ArrayList) PrefixString(com.k_int.IR.QueryModels.PrefixString) Term(mom.trd.opentheso.bdd.datas.Term) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) NodeGroupTraductions(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroupTraductions) FacesMessage(javax.faces.application.FacesMessage) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 22 with Term

use of mom.trd.opentheso.bdd.datas.Term in project opentheso by miledrousset.

the class SelectedTerme method getTerme.

public Term getTerme(String id) {
    TermHelper th = new TermHelper();
    Term t = th.getThisTerm(connect.getPoolConnexion(), id, idTheso, idlangue);
    return t;
}
Also used : Term(mom.trd.opentheso.bdd.datas.Term) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 23 with Term

use of mom.trd.opentheso.bdd.datas.Term in project opentheso by miledrousset.

the class ConceptHelper method getConcept.

/**
 * Cette fonction permet de récupérer toutes les informations concernant un
 * Concept par son id et son thésaurus et la langue
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @param idLang
 * @return Objet class NodeConcept
 */
public NodeConcept getConcept(HikariDataSource ds, String idConcept, String idThesaurus, String idLang) {
    NodeConcept nodeConcept = new NodeConcept();
    // récupération des BT
    RelationsHelper relationsHelper = new RelationsHelper();
    ArrayList<NodeBT> nodeListBT = relationsHelper.getListBT(ds, idConcept, idThesaurus, idLang);
    nodeConcept.setNodeBT(nodeListBT);
    // récupération du Concept
    Concept concept = getThisConcept(ds, idConcept, idThesaurus);
    nodeConcept.setConcept(concept);
    // récupération du Terme
    TermHelper termHelper = new TermHelper();
    Term term = termHelper.getThisTerm(ds, idConcept, idThesaurus, idLang);
    nodeConcept.setTerm(term);
    // récupération des termes spécifiques
    nodeConcept.setNodeNT(relationsHelper.getListNT(ds, idConcept, idThesaurus, idLang));
    // récupération des termes associés
    nodeConcept.setNodeRT(relationsHelper.getListRT(ds, idConcept, idThesaurus, idLang));
    // récupération des Non Prefered Term
    nodeConcept.setNodeEM(termHelper.getNonPreferredTerms(ds, term.getId_term(), idThesaurus, idLang));
    // récupération des traductions
    nodeConcept.setNodeTermTraductions(termHelper.getTraductionsOfConcept(ds, idConcept, idThesaurus, idLang));
    NoteHelper noteHelper = new NoteHelper();
    // récupération des notes du Concept
    nodeConcept.setNodeNotesConcept(noteHelper.getListNotesConcept(ds, idConcept, idThesaurus, idLang));
    // récupération des notes du term
    nodeConcept.setNodeNotesTerm(noteHelper.getListNotesTerm(ds, term.getId_term(), idThesaurus, idLang));
    GroupHelper groupHelper = new GroupHelper();
    nodeConcept.setNodeConceptGroup(groupHelper.getListGroupOfConcept(ds, idThesaurus, idConcept, idLang));
    return nodeConcept;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) NodeBT(mom.trd.opentheso.bdd.helper.nodes.NodeBT) NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Term(mom.trd.opentheso.bdd.datas.Term)

Example 24 with Term

use of mom.trd.opentheso.bdd.datas.Term in project opentheso by miledrousset.

the class ImportSkosHelper method addConcepts_progress.

/**
 * récupération des concepts
 * @param fileBean
 * @return
 */
public boolean addConcepts_progress(FileBean_progress fileBean) {
    String uri;
    Value value;
    boolean isTopConcept = true;
    Concept concept = new Concept();
    ConceptHelper conceptHelper = new ConceptHelper();
    TermHelper termHelper = new TermHelper();
    NoteHelper noteHelper = new NoteHelper();
    Term term = new Term();
    AlignmentHelper alignmentHelper = new AlignmentHelper();
    // ajout des termes et traductions
    NodeTerm nodeTerm = new NodeTerm();
    ArrayList<NodeTermTraduction> nodeTermTraductionList = new ArrayList<>();
    // Enregister les synonymes et traductions
    ArrayList<NodeEM> nodeEMList = new ArrayList<>();
    // ajout des notes
    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    // ajout des alignements
    ArrayList<NodeAlignment> nodeAlignments = new ArrayList<>();
    // ajout des relations
    ArrayList<HierarchicalRelationship> hierarchicalRelationships = new ArrayList<>();
    // ajout des relations Groups
    ArrayList<String> idGrps = new ArrayList<>();
    if (dataSet.getSKOSConcepts().isEmpty())
        return false;
    int i = 0;
    // i can get all the concepts from this scheme
    for (SKOSConcept conceptsInScheme : dataSet.getSKOSConcepts()) {
        // URI du Concept récupération automatique de l'identifiant
        String id = getIdFromUri(conceptsInScheme.getURI().toString());
        if (id == null || id.isEmpty()) {
            message = message + "identifiant null pour l'URI : " + conceptsInScheme.getURI().toString();
            continue;
        } else {
            concept.setIdConcept(id);
        }
        concept.setIdThesaurus(thesaurus.getId_thesaurus());
        // concept.setIdGroup(idGroup.get(0));
        concept.setNotation("");
        concept.setStatus("");
        concept.setIdArk(conceptsInScheme.getURI().toString());
        for (SKOSAnnotation anno : conceptsInScheme.getSKOSAnnotations(dataSet)) {
            // c'est une valeur
            if (anno.isAnnotationByConstant()) {
                // balises SKOS
                if (anno.getURI().getFragment() != null) {
                    // get altLabels
                    if (anno.getURI().getFragment().equalsIgnoreCase("prefLabel")) {
                        value = getValue(anno);
                        NodeTermTraduction nodeTermTraduction = new NodeTermTraduction();
                        nodeTermTraduction.setLexicalValue(value.getValue());
                        nodeTermTraduction.setLang(value.getLang());
                        nodeTermTraductionList.add(nodeTermTraduction);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("altLabel")) {
                        value = getValue(anno);
                        NodeEM nodeEM = new NodeEM();
                        nodeEM.setLexical_value(value.getValue());
                        nodeEM.setLang(value.getLang());
                        nodeEM.setSource("" + idUser);
                        nodeEM.setStatus("USE");
                        nodeEM.setHiden(false);
                        nodeEMList.add(nodeEM);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("hiddenLabel")) {
                        value = getValue(anno);
                        NodeEM nodeEM = new NodeEM();
                        nodeEM.setLexical_value(value.getValue());
                        nodeEM.setLang(value.getLang());
                        nodeEM.setSource("" + idUser);
                        nodeEM.setStatus("Hidden");
                        nodeEM.setHiden(true);
                        nodeEMList.add(nodeEM);
                    }
                    // get notes
                    if (anno.getURI().getFragment().equalsIgnoreCase("definition")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("definition");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("note")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("note");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("scopeNote")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("scopeNote");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("editorialNote")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("editorialNote");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("historyNote")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("historyNote");
                        nodeNotes.add(nodeNote);
                    }
                } else // balises DublinCore dc
                {
                    uri = getIdFromUri(anno.getURI().toString());
                    if (uri.equalsIgnoreCase("created") || uri.equalsIgnoreCase("date")) {
                        concept = addDates(concept, formatDate, getValue(anno).getValue(), "created");
                    }
                    if (uri.equalsIgnoreCase("modified")) {
                        concept = addDates(concept, formatDate, getValue(anno).getValue(), "modified");
                    }
                    // get the identifier from dcterms ceci peut être aussi l'identifiant ark
                    if (uri.equalsIgnoreCase("identifier")) {
                        concept.setIdArk(getValue(anno).getValue());
                    }
                }
            } else // c'est une relation
            {
                // balises SKOS
                if (anno.getURI().getFragment() != null) {
                    // get relations hiérarchiques
                    if (anno.getURI().getFragment().equalsIgnoreCase("narrower")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
                        hierarchicalRelationship.setIdConcept1(concept.getIdConcept());
                        hierarchicalRelationship.setIdConcept2(uri);
                        hierarchicalRelationship.setIdThesaurus(thesaurus.getId_thesaurus());
                        hierarchicalRelationship.setRole("NT");
                        hierarchicalRelationships.add(hierarchicalRelationship);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("broader")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
                        hierarchicalRelationship.setIdConcept1(concept.getIdConcept());
                        hierarchicalRelationship.setIdConcept2(uri);
                        hierarchicalRelationship.setIdThesaurus(thesaurus.getId_thesaurus());
                        hierarchicalRelationship.setRole("BT");
                        hierarchicalRelationships.add(hierarchicalRelationship);
                        isTopConcept = false;
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("related")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
                        hierarchicalRelationship.setIdConcept1(concept.getIdConcept());
                        hierarchicalRelationship.setIdConcept2(uri);
                        hierarchicalRelationship.setIdThesaurus(thesaurus.getId_thesaurus());
                        hierarchicalRelationship.setRole("RT");
                        hierarchicalRelationships.add(hierarchicalRelationship);
                    }
                    // get scheme
                    if (anno.getURI().getFragment().equalsIgnoreCase("inScheme")) {
                    // uri = anno.getAnnotationValue().getURI().toString();
                    }
                    // get Groups
                    if (anno.getURI().getFragment().equalsIgnoreCase("memberOf")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        idGrps.add(uri);
                        addIdGroupToVector(uri);
                    }
                    // get Alignements
                    if (anno.getURI().getFragment().equalsIgnoreCase("closeMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(2);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("exactMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(1);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("broadMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(3);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("narrowMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(5);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("relatedMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(4);
                        nodeAlignments.add(nodeAlignment);
                    }
                }
            }
        }
        // ajout des termes et traductions
        nodeTerm.setNodeTermTraduction(nodeTermTraductionList);
        nodeTerm.setIdTerm(concept.getIdConcept());
        nodeTerm.setIdConcept(concept.getIdConcept());
        nodeTerm.setIdThesaurus(thesaurus.getId_thesaurus());
        nodeTerm.setSource("");
        nodeTerm.setStatus("");
        nodeTerm.setCreated(concept.getCreated());
        nodeTerm.setModified(concept.getModified());
        // conctrole si le concept est vide aucun prefLable, on l'ignore
        if (!isConceptEmpty(nodeTermTraductionList)) {
            if (idGrps.isEmpty()) {
                concept.setTopConcept(isTopConcept);
                concept.setIdGroup(idGroupDefault);
                conceptHelper.insertConceptInTable(ds, concept, idUser);
            } else {
                for (String idGrp : idGrps) {
                    concept.setTopConcept(isTopConcept);
                    concept.setIdGroup(idGrp);
                    conceptHelper.insertConceptInTable(ds, concept, idUser);
                }
            }
            termHelper.insertTerm(ds, nodeTerm, idUser);
            try {
                Connection conn = ds.getConnection();
                conn.setAutoCommit(false);
                for (HierarchicalRelationship hierarchicalRelationship : hierarchicalRelationships) {
                    conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser);
                }
                conn.commit();
                conn.close();
            } catch (SQLException ex) {
            }
            for (NodeNote nodeNoteList1 : nodeNotes) {
                if (nodeNoteList1.getNotetypecode().contains("scopeNote")) {
                    noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("historyNote")) {
                    noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("definition")) {
                    noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("editorialNote")) {
                    noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("note")) {
                    noteHelper.addConceptNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
            }
            for (NodeAlignment nodeAlignment : nodeAlignments) {
                alignmentHelper.addNewAlignment(ds, nodeAlignment);
            }
            for (NodeEM nodeEMList1 : nodeEMList) {
                term.setId_concept(concept.getIdConcept());
                term.setId_term(nodeTerm.getIdTerm());
                term.setLexical_value(nodeEMList1.getLexical_value());
                term.setLang(nodeEMList1.getLang());
                term.setId_thesaurus(thesaurus.getId_thesaurus());
                term.setSource(nodeEMList1.getSource());
                term.setStatus(nodeEMList1.getStatus());
                termHelper.addNonPreferredTerm(ds, term, idUser);
            }
        }
        // initialisation des variables
        concept = new Concept();
        term = new Term();
        nodeTerm = new NodeTerm();
        nodeTermTraductionList = new ArrayList<>();
        nodeEMList = new ArrayList<>();
        nodeNotes = new ArrayList<>();
        nodeAlignments = new ArrayList<>();
        hierarchicalRelationships = new ArrayList<>();
        idGrps = new ArrayList<>();
        isTopConcept = true;
        if (conceptsCount < 100) {
            fileBean.setProgress(i * (100 / conceptsCount));
        } else {
            fileBean.setProgress(i / (conceptsCount / 100));
        }
        try {
            Thread.sleep(200);
            if (fileBean.getProgress() == null) {
                fileBean.setProgress(100);
                return false;
            }
        } catch (InterruptedException e) {
        }
        i++;
    }
    for (String idTopConcept1 : idTopConcept) {
        if (!conceptHelper.setTopConcept(ds, idTopConcept1, thesaurus.getId_thesaurus())) {
        // erreur;
        }
    }
    addGroups();
    addLangsToThesaurus(ds, thesaurus.getId_thesaurus());
    message = message + "\n nombre de Concepts importés : " + conceptsCount;
    fileBean.setProgress(100);
    // System.out.println("Finished Function");
    return true;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper) SKOSConcept(org.semanticweb.skos.SKOSConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) Connection(java.sql.Connection) 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) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) SKOSAnnotation(org.semanticweb.skos.SKOSAnnotation) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) SKOSConcept(org.semanticweb.skos.SKOSConcept)

Example 25 with Term

use of mom.trd.opentheso.bdd.datas.Term in project opentheso by miledrousset.

the class ImportSkosHelper method addConcepts_progress.

/**
 * récupération des concepts
 * @param fileBean
 * @return
 */
public boolean addConcepts_progress(FileBean fileBean) {
    String uri;
    Value value;
    boolean isTopConcept = true;
    Concept concept = new Concept();
    ConceptHelper conceptHelper = new ConceptHelper();
    TermHelper termHelper = new TermHelper();
    NoteHelper noteHelper = new NoteHelper();
    Term term = new Term();
    AlignmentHelper alignmentHelper = new AlignmentHelper();
    // ajout des termes et traductions
    NodeTerm nodeTerm = new NodeTerm();
    ArrayList<NodeTermTraduction> nodeTermTraductionList = new ArrayList<>();
    // Enregister les synonymes et traductions
    ArrayList<NodeEM> nodeEMList = new ArrayList<>();
    // ajout des notes
    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    // ajout des alignements
    ArrayList<NodeAlignment> nodeAlignments = new ArrayList<>();
    // ajout des relations
    ArrayList<HierarchicalRelationship> hierarchicalRelationships = new ArrayList<>();
    // ajout des relations Groups
    ArrayList<String> idGrps = new ArrayList<>();
    if (dataSet.getSKOSConcepts().isEmpty())
        return false;
    int i = 0;
    // i can get all the concepts from this scheme
    for (SKOSConcept conceptsInScheme : dataSet.getSKOSConcepts()) {
        // URI du Concept récupération automatique de l'identifiant
        String id = getIdFromUri(conceptsInScheme.getURI().toString());
        if (id == null || id.isEmpty()) {
            message = message + "identifiant null pour l'URI : " + conceptsInScheme.getURI().toString();
            continue;
        } else {
            concept.setIdConcept(id);
        }
        concept.setIdThesaurus(thesaurus.getId_thesaurus());
        // concept.setIdGroup(idGroup.get(0));
        concept.setNotation("");
        concept.setStatus("");
        concept.setIdArk(conceptsInScheme.getURI().toString());
        for (SKOSAnnotation anno : conceptsInScheme.getSKOSAnnotations(dataSet)) {
            // c'est une valeur
            if (anno.isAnnotationByConstant()) {
                // balises SKOS
                if (anno.getURI().getFragment() != null) {
                    // get altLabels
                    if (anno.getURI().getFragment().equalsIgnoreCase("prefLabel")) {
                        value = getValue(anno);
                        NodeTermTraduction nodeTermTraduction = new NodeTermTraduction();
                        nodeTermTraduction.setLexicalValue(value.getValue());
                        nodeTermTraduction.setLang(value.getLang());
                        nodeTermTraductionList.add(nodeTermTraduction);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("altLabel")) {
                        value = getValue(anno);
                        NodeEM nodeEM = new NodeEM();
                        nodeEM.setLexical_value(value.getValue());
                        nodeEM.setLang(value.getLang());
                        nodeEM.setSource("" + idUser);
                        nodeEM.setStatus("USE");
                        nodeEM.setHiden(false);
                        nodeEMList.add(nodeEM);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("hiddenLabel")) {
                        value = getValue(anno);
                        NodeEM nodeEM = new NodeEM();
                        nodeEM.setLexical_value(value.getValue());
                        nodeEM.setLang(value.getLang());
                        nodeEM.setSource("" + idUser);
                        nodeEM.setStatus("Hidden");
                        nodeEM.setHiden(true);
                        nodeEMList.add(nodeEM);
                    }
                    // get notes
                    if (anno.getURI().getFragment().equalsIgnoreCase("definition")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("definition");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("note")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("note");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("scopeNote")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("scopeNote");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("editorialNote")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("editorialNote");
                        nodeNotes.add(nodeNote);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("historyNote")) {
                        value = getValue(anno);
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setLang(value.getLang());
                        nodeNote.setLexicalvalue(value.getValue());
                        nodeNote.setNotetypecode("historyNote");
                        nodeNotes.add(nodeNote);
                    }
                } else // balises DublinCore dc
                {
                    uri = getIdFromUri(anno.getURI().toString());
                    if (uri.equalsIgnoreCase("created") || uri.equalsIgnoreCase("date")) {
                        concept = addDates(concept, formatDate, getValue(anno).getValue(), "created");
                    }
                    if (uri.equalsIgnoreCase("modified")) {
                        concept = addDates(concept, formatDate, getValue(anno).getValue(), "modified");
                    }
                    // get the identifier from dcterms ceci peut être aussi l'identifiant ark
                    if (uri.equalsIgnoreCase("identifier")) {
                        concept.setIdArk(getValue(anno).getValue());
                    }
                }
            } else // c'est une relation
            {
                // balises SKOS
                if (anno.getURI().getFragment() != null) {
                    // get relations hiérarchiques
                    if (anno.getURI().getFragment().equalsIgnoreCase("narrower")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
                        hierarchicalRelationship.setIdConcept1(concept.getIdConcept());
                        hierarchicalRelationship.setIdConcept2(uri);
                        hierarchicalRelationship.setIdThesaurus(thesaurus.getId_thesaurus());
                        hierarchicalRelationship.setRole("NT");
                        hierarchicalRelationships.add(hierarchicalRelationship);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("broader")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
                        hierarchicalRelationship.setIdConcept1(concept.getIdConcept());
                        hierarchicalRelationship.setIdConcept2(uri);
                        hierarchicalRelationship.setIdThesaurus(thesaurus.getId_thesaurus());
                        hierarchicalRelationship.setRole("BT");
                        hierarchicalRelationships.add(hierarchicalRelationship);
                        isTopConcept = false;
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("related")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
                        hierarchicalRelationship.setIdConcept1(concept.getIdConcept());
                        hierarchicalRelationship.setIdConcept2(uri);
                        hierarchicalRelationship.setIdThesaurus(thesaurus.getId_thesaurus());
                        hierarchicalRelationship.setRole("RT");
                        hierarchicalRelationships.add(hierarchicalRelationship);
                    }
                    // get scheme
                    if (anno.getURI().getFragment().equalsIgnoreCase("inScheme")) {
                    // uri = anno.getAnnotationValue().getURI().toString();
                    }
                    // get Groups
                    if (anno.getURI().getFragment().equalsIgnoreCase("memberOf")) {
                        uri = getIdFromUri(anno.getAnnotationValue().getURI().toString());
                        idGrps.add(uri);
                        addIdGroupToVector(uri);
                    }
                    // get Alignements
                    if (anno.getURI().getFragment().equalsIgnoreCase("closeMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(2);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("exactMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(1);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("broadMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(3);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("narrowMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(5);
                        nodeAlignments.add(nodeAlignment);
                    }
                    if (anno.getURI().getFragment().equalsIgnoreCase("relatedMatch")) {
                        uri = anno.getAnnotationValue().getURI().toString();
                        NodeAlignment nodeAlignment = new NodeAlignment();
                        nodeAlignment.setId_author(idUser);
                        nodeAlignment.setConcept_target("");
                        nodeAlignment.setThesaurus_target("");
                        nodeAlignment.setUri_target(uri);
                        nodeAlignment.setInternal_id_concept(concept.getIdConcept());
                        nodeAlignment.setInternal_id_thesaurus(thesaurus.getId_thesaurus());
                        nodeAlignment.setAlignement_id_type(4);
                        nodeAlignments.add(nodeAlignment);
                    }
                }
            }
        }
        // ajout des termes et traductions
        nodeTerm.setNodeTermTraduction(nodeTermTraductionList);
        nodeTerm.setIdTerm(concept.getIdConcept());
        nodeTerm.setIdConcept(concept.getIdConcept());
        nodeTerm.setIdThesaurus(thesaurus.getId_thesaurus());
        nodeTerm.setSource("");
        nodeTerm.setStatus("");
        nodeTerm.setCreated(concept.getCreated());
        nodeTerm.setModified(concept.getModified());
        // conctrole si le concept est vide aucun prefLable, on l'ignore
        if (!isConceptEmpty(nodeTermTraductionList)) {
            if (idGrps.isEmpty()) {
                concept.setTopConcept(isTopConcept);
                concept.setIdGroup(idGroupDefault);
                conceptHelper.insertConceptInTable(ds, concept, idUser);
            } else {
                for (String idGrp : idGrps) {
                    concept.setTopConcept(isTopConcept);
                    concept.setIdGroup(idGrp);
                    conceptHelper.insertConceptInTable(ds, concept, idUser);
                }
            }
            termHelper.insertTerm(ds, nodeTerm, idUser);
            try {
                Connection conn = ds.getConnection();
                conn.setAutoCommit(false);
                for (HierarchicalRelationship hierarchicalRelationship : hierarchicalRelationships) {
                    conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser);
                }
                conn.commit();
                conn.close();
            } catch (SQLException ex) {
            }
            for (NodeNote nodeNoteList1 : nodeNotes) {
                if (nodeNoteList1.getNotetypecode().contains("scopeNote")) {
                    noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("historyNote")) {
                    noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("definition")) {
                    noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("editorialNote")) {
                    noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
                if (nodeNoteList1.getNotetypecode().contains("note")) {
                    noteHelper.addConceptNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), thesaurus.getId_thesaurus(), nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
                }
            }
            for (NodeAlignment nodeAlignment : nodeAlignments) {
                alignmentHelper.addNewAlignment(ds, nodeAlignment);
            }
            for (NodeEM nodeEMList1 : nodeEMList) {
                term.setId_concept(concept.getIdConcept());
                term.setId_term(nodeTerm.getIdTerm());
                term.setLexical_value(nodeEMList1.getLexical_value());
                term.setLang(nodeEMList1.getLang());
                term.setId_thesaurus(thesaurus.getId_thesaurus());
                term.setSource(nodeEMList1.getSource());
                term.setStatus(nodeEMList1.getStatus());
                termHelper.addNonPreferredTerm(ds, term, idUser);
            }
        }
        // initialisation des variables
        concept = new Concept();
        term = new Term();
        nodeTerm = new NodeTerm();
        nodeTermTraductionList = new ArrayList<>();
        nodeEMList = new ArrayList<>();
        nodeNotes = new ArrayList<>();
        nodeAlignments = new ArrayList<>();
        hierarchicalRelationships = new ArrayList<>();
        idGrps = new ArrayList<>();
        isTopConcept = true;
        if (conceptsCount < 100) {
            fileBean.setProgress(i * (100 / conceptsCount));
        } else {
            fileBean.setProgress(i / (conceptsCount / 100));
        }
        try {
            Thread.sleep(200);
            if (fileBean.getProgress() == null) {
                fileBean.setProgress(100);
                return false;
            }
        } catch (InterruptedException e) {
        }
        i++;
    }
    for (String idTopConcept1 : idTopConcept) {
        if (!conceptHelper.setTopConcept(ds, idTopConcept1, thesaurus.getId_thesaurus())) {
        // erreur;
        }
    }
    addGroups();
    addLangsToThesaurus(ds, thesaurus.getId_thesaurus());
    message = message + "\n nombre de Concepts importés : " + conceptsCount;
    fileBean.setProgress(100);
    // System.out.println("Finished Function");
    return true;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper) SKOSConcept(org.semanticweb.skos.SKOSConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) Connection(java.sql.Connection) 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) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) SKOSAnnotation(org.semanticweb.skos.SKOSAnnotation) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) SKOSConcept(org.semanticweb.skos.SKOSConcept)

Aggregations

Term (mom.trd.opentheso.bdd.datas.Term)31 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)22 Concept (mom.trd.opentheso.bdd.datas.Concept)15 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)15 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)13 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)12 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)11 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)10 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)10 FacesMessage (javax.faces.application.FacesMessage)9 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)7 ArrayList (java.util.ArrayList)7 PrefixString (com.k_int.IR.QueryModels.PrefixString)5 HashMap (java.util.HashMap)5 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)5 SKOSMapping (skos.SKOSMapping)5 SKOSTopConcept (skos.SKOSTopConcept)5 Statement (java.sql.Statement)4 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)4