Search in sources :

Example 1 with JsonHelper

use of mom.trd.opentheso.core.jsonld.helper.JsonHelper in project opentheso by miledrousset.

the class DownloadBean method brancheToJsonLd.

/**
 * Cette fonction permet de retourner une branche en JsonLd
 *
 * @param idConcept
 * @param idTheso
 * @return
 */
public StreamedContent brancheToJsonLd(String idConcept, String idTheso) {
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer skos_local = exportFromBDD.exportBranchOfConcept(connect.getPoolConnexion(), idTheso, idConcept);
    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", idConcept + "_Branch_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 2 with JsonHelper

use of mom.trd.opentheso.core.jsonld.helper.JsonHelper in project opentheso by miledrousset.

the class Rest method getConceptJsonByValue.

/**
 * Permet de retourner les Concepts par value (en précisant un thésaurus et
 * une langue)
 *
 * @param value
 * @param idLang
 * @param idTheso
 * @return
 */
@Path("/jsonld/concept/value={value}&lang={lang}&th={th}")
@GET
// @Produces("application/json")
@Produces("application/json;charset=UTF-8")
public Response getConceptJsonByValue(@PathParam("value") String value, @PathParam("lang") String idLang, @PathParam("th") String idTheso) {
    if (!getStatusOfWebservices(idTheso)) {
        ds.close();
        return Response.status(Status.SERVICE_UNAVAILABLE).entity(messageJson()).type(MediaType.APPLICATION_JSON).build();
    }
    // transforme le codage de la valeur de l'UTF-8
    try {
        value = URLDecoder.decode(value, "UTF-8");
    // System.out.println(URLDecoder.decode("%C3%A9", "UTF-8"));
    // System.out.println(URLDecoder.decode("%E9glise", "UTF-8"));
    // System.out.println(URLDecoder.decode("%E9glise", "ISO-8859-1"));
    // System.out.println(URLDecoder.decode("%E9glise", "US-ASCII"));
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(Rest.class.getName()).log(Level.SEVERE, null, ex);
    }
    StringBuffer skos = ConceptByValueToSkos(value, idTheso, idLang);
    if (skos == null) {
        ds.close();
        return Response.ok(messageErreur()).header("Access-Control-Allow-Origin", "*").build();
    }
    if (skos.length() == 0) {
        ds.close();
        return Response.ok(messageEmptyJson()).header("Access-Control-Allow-Origin", "*").build();
    }
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
    ds.close();
    return Response.ok(jsonLd.toString()).header("Access-Control-Allow-Origin", "*").build();
// return jsonLd.toString();
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(skos.SKOSXmlDocument) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with JsonHelper

use of mom.trd.opentheso.core.jsonld.helper.JsonHelper in project opentheso by miledrousset.

the class Rest method getAllGroupsJson.

/**
 * pour récuperer la liste des domaines d'un thésaurus
 *
 * @param idTheso
 * @return
 */
@Path("/jsonld/concept/th={th}")
@GET
@Produces("application/json;charset=UTF-8")
public Response getAllGroupsJson(@PathParam("th") String idTheso) {
    if (!getStatusOfWebservices(idTheso)) {
        ds.close();
        return Response.status(Status.SERVICE_UNAVAILABLE).entity(messageJson()).type(MediaType.APPLICATION_JSON).build();
    }
    StringBuffer skos = groupsOfThesaurusToSkos(idTheso);
    if (skos == null) {
        ds.close();
        return Response.ok(messageErreur()).header("Access-Control-Allow-Origin", "*").build();
    }
    if (skos.length() == 0) {
        ds.close();
        return Response.ok(messageEmptyJson()).header("Access-Control-Allow-Origin", "*").build();
    }
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
    StringBuffer jsonLd = jsonHelper.getJsonLdForConceptScheme(sKOSXmlDocument);
    ds.close();
    return Response.ok(jsonLd.toString()).header("Access-Control-Allow-Origin", "*").build();
// return jsonLd.toString();
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) SKOSXmlDocument(skos.SKOSXmlDocument) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with JsonHelper

use of mom.trd.opentheso.core.jsonld.helper.JsonHelper in project opentheso by miledrousset.

the class Rest method getConceptsJsonOfGroup.

/**
 * Pour retourner un domaine (Groupe) en JsonLd avec ses concepts
 *
 * @param idGroup
 * @param idTheso
 * @return
 */
@Path("/jsonld/concept/all/idg={idg}&th={th}")
@GET
@Produces("application/json;charset=UTF-8")
public Response getConceptsJsonOfGroup(@PathParam("idg") String idGroup, @PathParam("th") String idTheso) {
    if (!getStatusOfWebservices(idTheso)) {
        ds.close();
        return Response.status(Status.SERVICE_UNAVAILABLE).entity(messageJson()).type(MediaType.APPLICATION_JSON).build();
    }
    StringBuffer skos = conceptsOfGroupToSkos(idGroup, idTheso);
    if (skos == null) {
        ds.close();
        return Response.ok(messageErreur()).header("Access-Control-Allow-Origin", "*").build();
    }
    if (skos.length() == 0) {
        ds.close();
        return Response.ok(messageEmptyJson()).header("Access-Control-Allow-Origin", "*").build();
    }
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
    ds.close();
    return Response.ok(jsonLd.toString()).header("Access-Control-Allow-Origin", "*").build();
// return jsonLd.toString();
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) SKOSXmlDocument(skos.SKOSXmlDocument) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with JsonHelper

use of mom.trd.opentheso.core.jsonld.helper.JsonHelper 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)

Aggregations

JsonHelper (mom.trd.opentheso.core.jsonld.helper.JsonHelper)12 SKOSXmlDocument (skos.SKOSXmlDocument)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 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)4 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 FacesMessage (javax.faces.application.FacesMessage)1 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)1 ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)1 Test (org.junit.Test)1