Search in sources :

Example 6 with SKOSXmlDocument

use of skos.SKOSXmlDocument 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 7 with SKOSXmlDocument

use of skos.SKOSXmlDocument 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 8 with SKOSXmlDocument

use of skos.SKOSXmlDocument 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 9 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class TestImportBranch method TestImportMultiBranchUnderGroup.

/**
 * Test of Tabulate reading.
 */
/*    @org.junit.Test

    public void testImportBranchAfterGroup() {    
        HikariDataSource conn = openConnexionPool();
        
        String idTheso = "";
        String idGroup = "";
        String path = "/Users/Miled/ownCloud_cnrs/Projets/OpenTheso/artefacts/25.xml";
       
        String dateFromat = "yyyy-MM-dd";
        boolean useArk = false;
        String adresseSite = "http://localhost";      
        int idUser = 1;


        
        FileInputStream file = readFile(path); 
        
        SKOSXmlDocument sKOSXmlDocument = readSkosFile(conn,
                file,
                dateFromat,
                useArk,
                adresseSite);
                

        // permet d'importer une branche entière sous un domaine avec l'alignement automatique à la source
        WriteBranchSkosBDD writeBranchSkosBDD = new WriteBranchSkosBDD(conn);
        //idGroup, idThesaurus, sKOSXmlDocument, dateFormat, ark, adressSite, user);
        writeBranchSkosBDD.importBranchAfterGroup(
                idGroup,
                idTheso,
                sKOSXmlDocument, dateFromat, useArk,
                adresseSite, idUser);
    }*/
/**
 * Test of Tabulate reading.
 */
@org.junit.Test
public void TestImportMultiBranchUnderGroup() {
    HikariDataSource conn = openConnexionPool();
    String idTheso = "1";
    String idGroup = "";
    String path = "/Users/Miled/ownCloud_cnrs/GDS_FRANTIQ/Pactols/2016-11-15/Sujets.xml";
    String dateFromat = "yyyy-MM-dd";
    boolean useArk = false;
    String adresseSite = "http://localhost";
    int idUser = 1;
    FileInputStream file = readFile(path);
    SKOSXmlDocument sKOSXmlDocument = readSkosFile(conn, file, dateFromat, useArk, adresseSite);
    // permet d'importer une branche entière avec son domaine en intégrant l'alignement à la source
    WriteBranchSkosBDD writeBranchSkosBDD = new WriteBranchSkosBDD(conn);
    // idGroup, idThesaurus, sKOSXmlDocument, dateFormat, ark, adressSite, user);
    writeBranchSkosBDD.importMultiBranchUnderGroup(idTheso, idGroup, sKOSXmlDocument, dateFromat, useArk, adresseSite, idUser);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) WriteBranchSkosBDD(mom.trd.opentheso.core.imports.old.WriteBranchSkosBDD) SKOSXmlDocument(skos.SKOSXmlDocument) FileInputStream(java.io.FileInputStream)

Example 10 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class TestImportBranch method readSkosFile.

private SKOSXmlDocument readSkosFile(HikariDataSource conn, FileInputStream file, String dateFromat, boolean useArk, String adresseSite) {
    try {
        ReadFileSKOS readFileSKOS = new ReadFileSKOS();
        readFileSKOS.readBranchFile(conn, file, dateFromat, useArk, adresseSite);
        SKOSXmlDocument sKOSXmlDocument = readFileSKOS.getThesaurus();
        return sKOSXmlDocument;
    } catch (Exception ex) {
        Logger.getLogger(TestImportBranch.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : SKOSXmlDocument(skos.SKOSXmlDocument) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

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