Search in sources :

Example 11 with JsonHelper

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

the class Rest method getConceptJson.

// ///////////////////////////////////////////////////
// ///////////////////////////////////////////////////
/*
     * Partie du REST pour produire du JsonLd
     * 
     */
// ///////////////////////////////////////////////////
// ///////////////////////////////////////////////////
/**
 * pour tester le retour des données en Jsonp pour être compatible avec
 * Jquery et Ajax
 */
/**
 * permet de récuperer un Concept par son identifiant
 *
 * @param idConcept
 * @param idTheso
 * @param jsonp
 * @return
 */
/*    @Path("/jsonld/concept/id={id}&th={th}&callback={jsonp}")
    @GET
    //@Produces("text/plain")
    //@Produces("application/json")
    @Produces("application/json;charset=UTF-8")
    public String getConceptJson(@PathParam("id") String idConcept,
            @PathParam("th") String idTheso,
            @PathParam("jsonp") String jsonp) {
        
        
        StringBuffer skos = conceptToSkos(idConcept, idTheso);
        JsonHelper jsonHelper = new JsonHelper();
        SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
        StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
        jsonLd.insert(0, jsonp +"(");
        jsonLd.append(");");
        System.out.println(jsonLd.toString());
        ds.close();
        return jsonLd.toString();
    }    


    @GET
    @Path("jsonp/concept/{th}/{lang}/value={value}")

    /**
     * Permet de retourner les Concepts par value (en précisant un thésaurus et
     * une langue)
     *
     * @param value
     * @param idLang
     * @param idTheso
     * @return
     */
// @Produces("text/plain")
// @Produces("application/json")
/*    @Produces("application/json;charset=UTF-8")
    public Response getConceptJsonByValueForJsonp(
            @PathParam("value") String value,
            @PathParam("lang") String idLang,
            @PathParam("th") String idTheso) {
                // 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);
        }
/*        JSONObject jSONObject = new JSONObject();
        jSONObject.put("name", "value");
        jSONObject.put("name2", "value2");
     */
/*        String s = 
        "[\"vase\",\n" +
"    [\"vase\", \"vase\", \"Vase (dépôt)\", \"Vase à bouche carrée, Culture du\", \"vase à cuire\", \"vase à étrier\", \"vase à libation\", \"vase à parfum\",\n" +
"         \"vase à pharmacie\", \"Vase campaniforme, Culture du\", \"vase canope\",\n" +
"              \"vase composite\", \"Vase cordé, Culture du\", \"vase d'albâtre\",\n" +
"                   \"vase de bronze\", \"vase de céramique\", \"vase de libation\",\n" +
"                        \"vase de métal\", \"vase de pierre\", \"Vase en entonnoir, Culture du\"],\n" +
"    [{\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtfv4IrNiWE8\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/www.eionet.europa.eu\\/gemet\\/concept\\/5417\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/data.bnf.fr\\/ark:\\/12148\\/cb12304971x\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/data.bnf.fr\\/ark:\\/12148\\/cb135347317\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtj4JceDlyFS\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtzmEytuBTdR\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrt2WTqu2BkNA\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtE3TkiyYR8i\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrt0rEs0KaVGT\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/data.bnf.fr\\/ark:\\/12148\\/cb11942230n\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtwqOtuijtQu\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtraWOfawdUB\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/data.bnf.fr\\/ark:\\/12148\\/cb12105101f\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtOd6LMcoTMh\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtrmoRMOPqj9\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrt1DMOWvDF4j\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrt2WTqu2BkNA\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtjxHvdqN73m\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/ark.frantiq.fr\\/ark:\\/26678\\/pcrtOd6LMcoTMh\"\n" +
"        }, {\n" +
"            \"uri\": \"http:\\/\\/data.bnf.fr\\/ark:\\/12148\\/cb119484779\"\n" +
"        }]]";
     */
/*        
        StringBuffer skos = ConceptByValueToSkos(value, idTheso, idLang);
        JsonHelper jsonHelper = new JsonHelper();
        SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos);
        StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
//        jsonLd.insert(0, "jsonp(");
//        jsonLd.append(");");
        ds.close();
       // return jsonLd.toString();
       return Response.ok(jsonLd.toString()).header("Access-Control-Allow-Origin", "*").build();
     //  return s;

    }*/
/**
 * permet de récuperer un Concept par son identifiant
 *
 * @param idConcept
 * @param idTheso
 * @return
 */
@Path("/jsonld/concept/id={id}&th={th}")
@GET
// @Produces("application/json")
@Produces("application/json;charset=UTF-8")
public Response getConceptJson(@PathParam("id") String idConcept, @PathParam("th") String idTheso) {
    if (!getStatusOfWebservices(idTheso)) {
        ds.close();
        return Response.status(Status.SERVICE_UNAVAILABLE).entity(messageJson()).type(MediaType.APPLICATION_JSON).build();
    }
    StringBuffer skos = conceptToSkos(idConcept, 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 12 with JsonHelper

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

the class JsonTest method testReadSkosBuffer.

/*    @Test
    public void testWriteJsonLd() throws IOException, FileNotFoundException, JsonLdError{
    //    Jsonld_test writeJson = new Jsonld_test();
    //    writeJson.test("/Users/Miled/Google Drive/Projets/OpenTheso/Jsonld/exemple/exp1_compressed.jsonld");
        
    }
    
    @Test
    public void testWriteRdfToJsonLd() throws IOException, FileNotFoundException, JsonLdError{
   //     Jsonld_test writeJson = new Jsonld_test();
   //     writeJson.testRDF();//test("/Users/Miled/Google Drive/Projets/OpenTheso/Jsonld/exemple/exp1.jsonld");
        
    }
    */
@Test
public void testReadSkosBuffer() {
    SKOSXmlDocument sKOSXmlDocument;
    try {
        ReadFileSKOS readFileSKOS = new ReadFileSKOS();
        StringBuffer skos = new StringBuffer();
        skos.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<rdf:RDF\n" + "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" + "    xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\"\n" + "    xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" + "    xmlns:dcterms=\"http://purl.org/dc/terms/\">\n" + "    <skos:Concept rdf:about=\"http://ark.frantiq.fr/ark:/26678/pcrttq9gp2ZMuc\">\n" + "        <skos:prefLabel xml:lang=\"en\">art</skos:prefLabel>\n" + "        <skos:prefLabel xml:lang=\"fr\">art</skos:prefLabel>\n" + "        <skos:prefLabel xml:lang=\"es\">arte</skos:prefLabel>\n" + "        <skos:prefLabel xml:lang=\"it\">arte</skos:prefLabel>\n" + "        <skos:prefLabel xml:lang=\"nl\">kunst</skos:prefLabel>\n" + "        <skos:prefLabel xml:lang=\"de\">Kunst</skos:prefLabel>\n" + "        <skos:prefLabel xml:lang=\"ar\">فن</skos:prefLabel>\n" + "        <skos:altLabel xml:lang=\"fr\">Arts</skos:altLabel>\n" + "        <skos:altLabel xml:lang=\"en\">Arts_en</skos:altLabel>\n" + "        <skos:inScheme rdf:resource=\"http://pactols.frantiq.fr/?idd=6&amp;idt=TH_1\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtWSbu1fKhxG\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtQ2d2FOaxN5\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrt7SWBi5qQSl\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtWbThvTYYf4\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtTv2xhrEwPW\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtET0l280TUS\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtkOgxvd4Ijy\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrt8e84y5qvKb\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtWSqJyedQws\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtgI8DSt7eam\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtvsFBSmOKN2\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrt4rR2kyMQuW\"/>\n" + "        <skos:narrower rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtGKMelLKwRd\"/>\n" + "        <skos:related rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtP6goqQWM9k\"/>\n" + "        <skos:related rdf:resource=\"http://ark.frantiq.fr/ark:/26678/pcrtb4M5pvMjvr\"/>\n" + "        <skos:definition xml:lang=\"fr\">Ensemble des oeuvres artistiques d'un pays, d'une époque (Lar.)</skos:definition>\n" + "        <dcterms:created>2007-02-08</dcterms:created>\n" + "        <dcterms:modified>2014-04-11</dcterms:modified>\n" + "        <skos:closeMatch rdf:resource=\"http://www.eionet.europa.eu/gemet/concept/568 \"/>\n" + "        <skos:closeMatch rdf:resource=\"http://eurovoc.europa.eu/2688\"/>\n" + "        <skos:closeMatch rdf:resource=\"http://en.wikipedia.org/wiki/Art\"/>\n" + "    </skos:Concept>\n" + "</rdf:RDF>");
        sKOSXmlDocument = readFileSKOS.readStringBuffer(skos);
        JsonHelper jsonHelper = new JsonHelper();
        // StringBuffer jsonLd = jsonHelper.getJsonLdForSchemaOrg(sKOSXmlDocument);
        StringBuffer jsonLd = jsonHelper.getJsonLdForSchemaOrgForConceptScheme(sKOSXmlDocument);
        String toto = "";
    } catch (Exception ex) {
        Logger.getLogger(JsonTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) SKOSXmlDocument(skos.SKOSXmlDocument) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

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