Search in sources :

Example 11 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class JsonHelper method readSkosDocument.

public SKOSXmlDocument readSkosDocument(StringBuffer skosStringBuffer) {
    SKOSXmlDocument sKOSXmlDocument;
    try {
        ReadFileSKOS readFileSKOS = new ReadFileSKOS();
        sKOSXmlDocument = readFileSKOS.readStringBuffer(skosStringBuffer);
        return sKOSXmlDocument;
    } catch (Exception ex) {
        Logger.getLogger(JsonHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : SKOSXmlDocument(skos.SKOSXmlDocument) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Example 12 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class SelectedThesaurus method getMetaData.

/**
 * ************************************ GETTERS SETTERS
 * *************************************
 */
/**
 * @return
 */
public String getMetaData() {
    if (this.tree.getSelectedTerme() != null) {
        if (this.tree.getSelectedTerme().getIdC() != null) {
            if (this.tree.getSelectedTerme().getIdTheso() != null) {
                // cas d'un domaine ou  Groupe
                if (tree.getSelectedTerme().getType() == 1) {
                    ExportFromBDD exportFromBDD = new ExportFromBDD();
                    exportFromBDD.setNodePreference(nodePreference);
                    exportFromBDD.setServerArk(serverArk);
                    exportFromBDD.setServerAdress(cheminSite);
                    StringBuffer skos = exportFromBDD.exportThisGroup(connect.getPoolConnexion(), this.tree.getSelectedTerme().getIdTheso(), this.tree.getSelectedTerme().getIdC());
                    JsonHelper jsonHelper = new JsonHelper();
                    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
                    StringBuffer jsonLd = jsonHelper.getJsonLdForSchemaOrg(sKOSXmlDocument);
                    if (jsonLd != null) {
                        return jsonLd.toString();
                    } else {
                        return "";
                    }
                }
                // cas d'un concept
                if (tree.getSelectedTerme().getType() == 2 || tree.getSelectedTerme().getType() == 3) {
                    ExportFromBDD exportFromBDD = new ExportFromBDD();
                    exportFromBDD.setNodePreference(nodePreference);
                    exportFromBDD.setServerArk(serverArk);
                    exportFromBDD.setServerAdress(cheminSite);
                    StringBuffer skos = exportFromBDD.exportConcept(connect.getPoolConnexion(), this.tree.getSelectedTerme().getIdTheso(), this.tree.getSelectedTerme().getIdC());
                    if (skos == null) {
                        return "";
                    }
                    JsonHelper jsonHelper = new JsonHelper();
                    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
                    if (sKOSXmlDocument == null) {
                        return "";
                    }
                    StringBuffer jsonLd = jsonHelper.getJsonLdForSchemaOrg(sKOSXmlDocument);
                    if (jsonLd != null) {
                        return jsonLd.toString();
                    } else {
                        return "";
                    }
                }
            }
        }
    }
    // Envoye les domaines (MT)
    if (thesaurus != null && thesaurus.getId_thesaurus() != null) {
        if (!thesaurus.getId_thesaurus().trim().isEmpty()) {
            ExportFromBDD exportFromBDD = new ExportFromBDD();
            exportFromBDD.setNodePreference(nodePreference);
            exportFromBDD.setServerArk(serverArk);
            exportFromBDD.setServerAdress(cheminSite);
            StringBuffer skos = exportFromBDD.exportGroupsOfThesaurus(connect.getPoolConnexion(), thesaurus.getId_thesaurus());
            JsonHelper jsonHelper = new JsonHelper();
            SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
            StringBuffer jsonLd = jsonHelper.getJsonLdForSchemaOrgForConceptScheme(sKOSXmlDocument);
            if (jsonLd == null) {
                return "";
            }
            return jsonLd.toString();
        }
    }
    return "";
// ancienne version
/*        if(this.tree.getSelectedTerme() != null ) {
            if(this.tree.getSelectedTerme().getIdC() != null ) {
                if(this.tree.getSelectedTerme().getIdTheso() != null ) {
                    // cas d'un domaine ou  Groupe
                    if(tree.getSelectedTerme().getType() == 1) {
                        ExportFromBDD exportFromBDD = new ExportFromBDD();
                        exportFromBDD.setServerArk(serverArk);
                        exportFromBDD.setServerAdress(cheminSite);
                        StringBuffer skos = exportFromBDD.exportThisGroup(
                                connect.getPoolConnexion(), 
                                this.tree.getSelectedTerme().getIdTheso(),
                                this.tree.getSelectedTerme().getIdC());

                    JsonHelper jsonHelper = new JsonHelper();
                    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
                    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
                    return jsonLd.toString();
                }
                // cas d'un concept
                if(tree.getSelectedTerme().getType() == 2 || tree.getSelectedTerme().getType() == 3) {
                    ExportFromBDD exportFromBDD = new ExportFromBDD();
                    exportFromBDD.setServerArk(serverArk);
                    exportFromBDD.setServerAdress(cheminSite);
                    StringBuffer skos = exportFromBDD.exportConcept(
                            connect.getPoolConnexion(), 
                            this.tree.getSelectedTerme().getIdTheso(),
                            this.tree.getSelectedTerme().getIdC());

                        JsonHelper jsonHelper = new JsonHelper();
                        SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
                        StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
                        return jsonLd.toString();
                    }
                }
            }
        }
        
        // Envoye les domaines (MT)
        if(thesaurus.getId_thesaurus() != null) {
            if(!thesaurus.getId_thesaurus().trim().isEmpty()) {
                ExportFromBDD exportFromBDD = new ExportFromBDD();
                exportFromBDD.setServerArk(serverArk);
                exportFromBDD.setServerAdress(cheminSite);
                StringBuffer skos = exportFromBDD.exportGroupsOfThesaurus(
                        connect.getPoolConnexion(), 
                        thesaurus.getId_thesaurus());

                JsonHelper jsonHelper = new JsonHelper();
                SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
                StringBuffer jsonLd = jsonHelper.getJsonLdForConceptScheme(sKOSXmlDocument);
                if(jsonLd == null) return "";
                return jsonLd.toString();
            }
        }
        return ""; */
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) SKOSXmlDocument(skos.SKOSXmlDocument) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD)

Example 13 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class DownloadBean method thisGroupToJsonLd.

/**
 * Cette fonction permet de retourner pour téléchargement un groupe en
 * JsonLd
 *
 * @param idGroup
 * @param idTheso
 * @return
 */
public StreamedContent thisGroupToJsonLd(String idGroup, String idTheso) {
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer skos_local = exportFromBDD.exportThisGroup(connect.getPoolConnexion(), idTheso, idGroup);
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos_local);
    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
    InputStream stream;
    try {
        stream = new ByteArrayInputStream(jsonLd.toString().getBytes("UTF-8"));
        file = new DefaultStreamedContent(stream, "application/xml", idGroup + "_Group_jsonld.xml");
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    return file;
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(skos.SKOSXmlDocument) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD)

Example 14 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class DownloadBean method groupJsonLd.

public String groupJsonLd(String idGroup, String idTheso) {
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer skos_local = exportFromBDD.exportThisGroup(connect.getPoolConnexion(), idTheso, idGroup);
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos_local);
    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
    return jsonLd.toString();
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) SKOSXmlDocument(skos.SKOSXmlDocument) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD)

Example 15 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class DownloadBean method conceptToJsonLd.

/**
 * Cette fonction permet d'exporter un concept en JsonLd
 *
 * @param idC
 * @param idTheso
 * @return
 */
public StreamedContent conceptToJsonLd(String idC, String idTheso) {
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    InputStream stream;
    StringBuffer skos_local = exportFromBDD.exportConcept(connect.getPoolConnexion(), idTheso, idC);
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos_local);
    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
    if (jsonLd == null) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, languageBean.getMsg("error") + " :", languageBean.getMsg("index.exportJsonError")));
        return file;
    }
    try {
        stream = new ByteArrayInputStream(jsonLd.toString().getBytes("UTF-8"));
        file = new DefaultStreamedContent(stream, "application/xml", idC + "_jsonLd.xml");
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    return file;
// new ExportFromBDD().exportConcept(connect.getPoolConnexion(), idTheso, idC).toString();
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(skos.SKOSXmlDocument) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

SKOSXmlDocument (skos.SKOSXmlDocument)19 JsonHelper (mom.trd.opentheso.core.jsonld.helper.JsonHelper)12 ExportFromBDD (mom.trd.opentheso.core.exports.old.ExportFromBDD)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)4 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)4 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 FacesMessage (javax.faces.application.FacesMessage)1