Search in sources :

Example 16 with SKOSResource

use of mom.trd.opentheso.skosapi.SKOSResource in project opentheso by miledrousset.

the class ExportRdf4jHelper method addFilsGroupRcursif.

private void addFilsGroupRcursif(String idThesaurus, String idPere, SKOSResource sKOSResource, List<NodeLang> selectedLanguages) {
    GroupHelper groupHelper = new GroupHelper();
    ArrayList<String> listIdsOfGroupChildren = groupHelper.getListGroupChildIdOfGroup(ds, idPere, idThesaurus);
    writeGroupInfo(sKOSResource, idThesaurus, idPere, selectedLanguages);
    for (String idOfGroupChildren : listIdsOfGroupChildren) {
        sKOSResource = new SKOSResource();
        // writeGroupInfo(groupHelper, group, idThesaurus, idOfGroupChildren, selectedLanguages);
        // if (!groupHelper.getListGroupChildIdOfGroup(ds, idOfGroupChildren, idThesaurus).isEmpty()) {
        addFilsGroupRcursif(idThesaurus, idOfGroupChildren, sKOSResource, selectedLanguages);
    // }
    }
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 17 with SKOSResource

use of mom.trd.opentheso.skosapi.SKOSResource in project opentheso by miledrousset.

the class ImportRdf4jHelper method addBranch.

/**
 * ajoute une brache en choisissant un concept père
 *
 * @param selectedTerme
 * @throws java.text.ParseException
 * @throws java.sql.SQLException
 */
public void addBranch(SelectedTerme selectedTerme) throws ParseException, SQLException {
    String idGroup = selectedTerme.getIdDomaine();
    String idConceptPere = selectedTerme.getIdC();
    idTheso = selectedTerme.getIdTheso();
    SKOSResource root = detectRootOfBranch();
    // on ajoute la racine de la branche
    AddConceptsStruct acs;
    acs = new AddConceptsStruct();
    acs.conceptHelper = new ConceptHelper();
    initAddConceptsStruct(acs, root);
    addRelationNoBTHiera(acs);
    acs.concept.setTopConcept(false);
    acs.concept.setIdGroup(idGroup);
    acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
    // on lie le nouveau concept au concept père
    HierarchicalRelationship hierarchicalRelationship1 = new HierarchicalRelationship(acs.concept.getIdConcept(), idConceptPere, idTheso, "BT");
    HierarchicalRelationship hierarchicalRelationship2 = new HierarchicalRelationship(idConceptPere, acs.concept.getIdConcept(), idTheso, "NT");
    acs.hierarchicalRelationships.add(hierarchicalRelationship1);
    acs.hierarchicalRelationships.add(hierarchicalRelationship2);
    new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
    finalizeAddConceptStruct(acs);
    // on ajoute le reste
    skosXmlDocument.getConceptList().remove(root);
    for (SKOSResource resource : skosXmlDocument.getConceptList()) {
        acs = new AddConceptsStruct();
        acs.conceptHelper = new ConceptHelper();
        initAddConceptsStruct(acs, resource);
        addRelation(acs);
        acs.concept.setTopConcept(false);
        acs.concept.setIdGroup(idGroup);
        acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
        new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
        finalizeAddConceptStruct(acs);
    }
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 18 with SKOSResource

use of mom.trd.opentheso.skosapi.SKOSResource in project opentheso by miledrousset.

the class ImportRdf4jHelper method addGroups.

public void addGroups(rdf4jFileBean fileBean) {
    // récupération des groups ou domaine
    GroupHelper groupHelper = new GroupHelper();
    String idGroup;
    for (SKOSResource group : skosXmlDocument.getGroupList()) {
        fileBean.setAbs_progress(fileBean.getAbs_progress() + 1);
        fileBean.setProgress(fileBean.getAbs_progress() / fileBean.getTotal() * 100);
        idGroup = getIdFromUri(group.getUri());
        ArrayList<SKOSNotation> notationList = group.getNotationList();
        SKOSNotation notation = null;
        if (notationList != null && !notationList.isEmpty()) {
            notation = notationList.get(0);
        }
        String notationValue;
        if (notation == null) {
            notationValue = "";
        } else {
            notationValue = notation.getNotation();
        }
        String type;
        switch(group.getProperty()) {
            case SKOSProperty.Collection:
                type = "C";
                break;
            case SKOSProperty.ConceptGroup:
                type = "G";
                break;
            case SKOSProperty.MicroThesaurus:
            default:
                type = "MT";
                break;
            case SKOSProperty.Theme:
                type = "T";
                break;
        }
        groupHelper.insertGroup(ds, idGroup, thesaurus.getId_thesaurus(), type, notationValue, adressSite, useArk, idUser);
        // sub group
        String idSubGroup;
        // concept group concept
        String idSubConcept;
        for (SKOSRelation relation : group.getRelationsList()) {
            int prop = relation.getProperty();
            switch(prop) {
                case SKOSProperty.subGroup:
                    idSubGroup = getIdFromUri(relation.getTargetUri());
                    groupHelper.addSubGroup(ds, idGroup, idSubGroup, thesaurus.getId_thesaurus());
                    break;
                case SKOSProperty.member:
                    // option cochée
                    /*   if(identifierType.equalsIgnoreCase("sans")){
                            idSubConcept = getIdFromUri(relation.getTargetUri());
                        } else {*/
                    // Récupération de l'Id d'origine sauvegardé à l'import (idArk -> identifier)
                    idSubConcept = getOriginalId(relation.getTargetUri());
                    // }
                    groupHelper.addConceptGroupConcept(ds, idGroup, idSubConcept, thesaurus.getId_thesaurus());
                    memberHashMap.put(relation.getTargetUri(), idGroup);
                    break;
                case SKOSProperty.hasTopConcept:
                    hasTopConcceptList.add(relation.getTargetUri());
                    break;
                default:
                    break;
            }
        }
        for (SKOSLabel label : group.getLabelsList()) {
            // ajouter les traductions des Groupes
            ConceptGroupLabel conceptGroupLabel = new ConceptGroupLabel();
            conceptGroupLabel.setIdgroup(idGroup);
            conceptGroupLabel.setIdthesaurus(thesaurus.getId_thesaurus());
            conceptGroupLabel.setLang(label.getLanguage());
            conceptGroupLabel.setLexicalvalue(label.getLabel());
            groupHelper.addGroupTraduction(ds, conceptGroupLabel, idUser);
        }
    }
/*
        groupHelper.insertGroup(ds,
                idGroupDefault,
                thesaurus.getId_thesaurus(),
                "MT",
                "", //notation
                adressSite,
                useArk,
                idUser);
*/
// Création du domaine par défaut
// ajouter les traductions des Groupes
/*ConceptGroupLabel conceptGroupLabel = new ConceptGroupLabel();
        conceptGroupLabel.setIdgroup(idGroupDefault);
        conceptGroupLabel.setIdthesaurus(thesaurus.getId_thesaurus());
        
        conceptGroupLabel.setLang(langueSource);
        conceptGroupLabel.setLexicalvalue("groupDefault");
        groupHelper.addGroupTraduction(ds, conceptGroupLabel, idUser);*/
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) ConceptGroupLabel(mom.trd.opentheso.bdd.datas.ConceptGroupLabel) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) SKOSNotation(mom.trd.opentheso.skosapi.SKOSNotation)

Example 19 with SKOSResource

use of mom.trd.opentheso.skosapi.SKOSResource in project opentheso by miledrousset.

the class ImportRdf4jHelper method addThesaurus.

/**
 * Cette fonction permet de créer un thésaurus avec ses traductions (Import)
 * elle retourne l'identifiant du thésaurus, sinon Null
 *
 * @return
 * @throws java.sql.SQLException
 */
public String addThesaurus() throws SQLException {
    thesaurus = new Thesaurus();
    SKOSResource conceptScheme = skosXmlDocument.getConceptScheme();
    String creator = null;
    String contributor = null;
    for (SKOSCreator c : conceptScheme.getCreatorList()) {
        if (c.getProperty() == SKOSProperty.creator) {
            creator = c.getCreator();
        } else if (c.getProperty() == SKOSProperty.contributor) {
            contributor = c.getCreator();
        }
    }
    thesaurus.setCreator(creator);
    thesaurus.setContributor(contributor);
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    thesaurusHelper.setIdentifierType("2");
    Connection conn = ds.getConnection();
    conn.setAutoCommit(false);
    String idTheso1;
    if (thesaurus.getLanguage() == null) {
        thesaurus.setLanguage(langueSource);
    }
    if ((idTheso1 = thesaurusHelper.addThesaurusRollBack(conn, adressSite, useArk)) == null) {
        conn.rollback();
        conn.close();
        return null;
    }
    // Si le Titre du thésaurus n'est pas detecter, on donne un nom par defaut
    if (skosXmlDocument.getConceptScheme().getLabelsList().isEmpty()) {
        if (thesaurus.getTitle().isEmpty()) {
            thesaurus.setTitle("theso_" + idTheso1);
        // thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
        }
    }
    thesaurus.setId_thesaurus(idTheso1);
    this.idTheso = idTheso1;
    // boucler pour les traductions
    for (SKOSLabel label : skosXmlDocument.getConceptScheme().getLabelsList()) {
        if (thesaurus.getLanguage() == null) {
            // test
            String workLanguage = "fr";
            thesaurus.setLanguage(workLanguage);
        }
        thesaurus.setTitle(label.getLabel());
        thesaurus.setLanguage(label.getLanguage());
        if (!thesaurusHelper.addThesaurusTraductionRollBack(conn, thesaurus)) {
            conn.rollback();
            conn.close();
            return null;
        }
    }
    UserHelper userHelper = new UserHelper();
    if (!userHelper.addRole(conn, idUser, idRole, idTheso1, "")) {
        conn.rollback();
        conn.close();
        return null;
    }
    conn.commit();
    conn.close();
    idGroupDefault = getNewGroupId();
    for (SKOSRelation relation : skosXmlDocument.getConceptScheme().getRelationsList()) {
        hasTopConcceptList.add(relation.getTargetUri());
    }
    return null;
}
Also used : SKOSCreator(mom.trd.opentheso.skosapi.SKOSCreator) SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) Connection(java.sql.Connection) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel)

Example 20 with SKOSResource

use of mom.trd.opentheso.skosapi.SKOSResource in project opentheso by miledrousset.

the class WritePdf method writeHieraPDF.

/**
 * ecri un thésaurus en PDF par ordre hiérarchique
 */
private void writeHieraPDF(ArrayList<Paragraph> paragraphs, String langue, String langue2, boolean isTrad, HashMap<String, ArrayList<String>> idToDoc) {
    ArrayList<SKOSResource> conceptList = xmlDocument.getConceptList();
    System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
    Collections.sort(conceptList, sortForHiera(isTrad, langue, langue2, idToNameHashMap, idToChildId, idToDoc, idToMatch, idToGPS, resourceChecked, idToIsTradDiff));
    for (SKOSResource concept : conceptList) {
        boolean isAtRoot = true;
        String conceptID = getIdFromUri(concept.getUri());
        Iterator i = idToChildId.keySet().iterator();
        String clef;
        ArrayList<String> valeur;
        while (i.hasNext()) {
            clef = (String) i.next();
            valeur = (ArrayList<String>) idToChildId.get(clef);
            for (String id : valeur) {
                if (id.equals(conceptID)) {
                    isAtRoot = false;
                }
            }
        }
        if (isAtRoot) {
            String name = idToNameHashMap.get(conceptID);
            if (name == null) {
                name = "";
            }
            paragraphs.add(new Paragraph(name + " (" + conceptID + ")", termFont));
            String indentation = "";
            writeHieraTermInfo(conceptID, indentation, paragraphs, idToDoc);
            writeHieraTermRecursif(conceptID, indentation, paragraphs, idToDoc);
        }
    }
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) Iterator(java.util.Iterator) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

SKOSResource (mom.trd.opentheso.skosapi.SKOSResource)20 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)5 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)5 SKOSLabel (mom.trd.opentheso.skosapi.SKOSLabel)3 SKOSRelation (mom.trd.opentheso.skosapi.SKOSRelation)3 Paragraph (com.itextpdf.text.Paragraph)2 ArrayList (java.util.ArrayList)2 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)2 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)2 DocumentException (com.itextpdf.text.DocumentException)1 PdfPCell (com.itextpdf.text.pdf.PdfPCell)1 PdfPTable (com.itextpdf.text.pdf.PdfPTable)1 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 ConceptGroupLabel (mom.trd.opentheso.bdd.datas.ConceptGroupLabel)1 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)1 UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)1 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)1 NodeLang (mom.trd.opentheso.bdd.helper.nodes.NodeLang)1