Search in sources :

Example 6 with JsonHelper

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

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

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

Example 9 with JsonHelper

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

the class DownloadBean method groupToJsonLd.

/**
 * Cette fonction permet de retourner la branche entière d'un groupe en
 * JsonLd
 *
 * @param idGroup
 * @param idTheso
 * @return
 */
public StreamedContent groupToJsonLd(String idGroup, String idTheso) {
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer skos_local = exportFromBDD.exportGroup(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 10 with JsonHelper

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

the class Rest method getConceptJsonArk.

/**
 * retourne un concept à partir de son identifiant Ark
 *
 * @param naan
 * @param ark
 * @return
 */
@Path("/jsonld/ark:/{naan}/{ark}")
@GET
// @Produces("application/json")
@Produces("application/json;charset=UTF-8")
public Response getConceptJsonArk(@PathParam("naan") String naan, @PathParam("ark") String ark) {
    String idTheso = new ConceptHelper().getIdThesaurusFromArkId(ds, naan + "/" + ark);
    if (idTheso == null) {
        ds.close();
        return Response.noContent().build();
    }
    if (!getStatusOfWebservices(idTheso)) {
        ds.close();
        return Response.status(Status.SERVICE_UNAVAILABLE).entity(messageJson()).type(MediaType.APPLICATION_JSON).build();
    }
    StringBuffer skos = conceptToSkosFromArk(naan + "/" + ark, 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) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) SKOSXmlDocument(skos.SKOSXmlDocument) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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