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;
}
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();
}
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();
}
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();
}
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 ""; */
}
Aggregations