Search in sources :

Example 26 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project AJAN-service by aantakli.

the class MAJANServiceHandler method CreateAgent.

@Override
public String CreateAgent(String id, String agentTemplate, MRDFGraph content) throws TException {
    Agent agent;
    try {
        RDFFormat format = getRDFFormat(content.ContentType);
        agent = agentManager.createAgent(id, agentTemplate, true, content.Graph, format);
        return agent.getUrl();
    } catch (URISyntaxException | IOException ex) {
        Logger.getLogger(MAJANServiceHandler.class.getName()).log(Level.SEVERE, null, ex);
        // return URI of exectud Agent, else return null.
        return "null";
    }
}
Also used : Agent(de.dfki.asr.ajan.model.Agent) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 27 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project AJAN-service by aantakli.

the class MAJANServiceHandler method getRDFFormat.

private RDFFormat getRDFFormat(String contentType) {
    RDFParserRegistry registry = RDFParserRegistry.getInstance();
    Optional<RDFFormat> format = registry.getFileFormatForMIMEType(contentType);
    if (!format.isPresent()) {
        return null;
    }
    return format.get();
}
Also used : RDFParserRegistry(org.eclipse.rdf4j.rio.RDFParserRegistry) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 28 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class DownloadBean method brancheToFile.

/**
 * Cette fonction permet de retourner une branche en SKOS
 *
 * @param idConcept
 * @param idTheso
 * @return
 */
public StreamedContent brancheToFile(String idConcept, String idTheso, int type) {
    RDFFormat format = null;
    String extention = "";
    switch(type) {
        case 0:
            format = RDFFormat.RDFXML;
            extention = "_skos.xml";
            break;
        case 1:
            format = RDFFormat.JSONLD;
            extention = "_json-ld.json";
            break;
        case 2:
            format = RDFFormat.TURTLE;
            extention = "_turtle.ttl";
            break;
    }
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreferences(connect.getPoolConnexion(), idTheso);
    if (nodePreference == null)
        return null;
    ExportRdf4jHelper exportRdf4jHelper = new ExportRdf4jHelper();
    exportRdf4jHelper.setInfos(connect.getPoolConnexion(), "dd-mm-yyyy", false, idTheso, nodePreference.getCheminSite());
    exportRdf4jHelper.setNodePreference(nodePreference);
    exportRdf4jHelper.addBranch(idTheso, idConcept);
    WriteRdf4j writeRdf4j = new WriteRdf4j(exportRdf4jHelper.getSkosXmlDocument());
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, format);
    file = new ByteArrayContent(out.toByteArray(), "application/xml", idTheso + " " + extention);
    return file;
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ExportRdf4jHelper(mom.trd.opentheso.core.exports.rdf4j.ExportRdf4jHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayContent(org.primefaces.model.ByteArrayContent) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Example 29 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class DownloadBean method thesoToFile.

public StreamedContent thesoToFile(String idTheso, List<NodeLang> selectedLanguages, List<NodeGroup> selectedGroups, int type) {
    RDFFormat format = null;
    String extention = "";
    file = null;
    switch(type) {
        case 0:
            format = RDFFormat.RDFXML;
            extention = "_skos.xml";
            break;
        case 1:
            format = RDFFormat.JSONLD;
            extention = "_json-ld.json";
            break;
        case 2:
            format = RDFFormat.TURTLE;
            extention = "_turtle.ttl";
            break;
        case 3:
            format = RDFFormat.RDFJSON;
            extention = "_json.json";
            break;
    }
    WriteRdf4j writeRdf4j = loadExportHelper(idTheso, selectedLanguages, selectedGroups);
    if (writeRdf4j != null) {
        ByteArrayOutputStream out;
        out = new ByteArrayOutputStream();
        Rio.write(writeRdf4j.getModel(), out, format);
        file = new ByteArrayContent(out.toByteArray(), "application/xml", idTheso + " " + extention);
    }
    progress_per_100 = 0;
    progress_abs = 0;
    return file;
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayContent(org.primefaces.model.ByteArrayContent) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 30 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class DownloadBean method conceptToFile.

/**
 * Cette fonction permet d'exporter un concept en SKOS en temps réel dans la
 * page principale
 *
 * @param idConcept
 * @param idTheso
 * @param type
 * @return
 */
public StreamedContent conceptToFile(String idConcept, String idTheso, int type) {
    RDFFormat format = null;
    String extention = "";
    switch(type) {
        case 0:
            format = RDFFormat.RDFXML;
            extention = "_skos.xml";
            break;
        case 1:
            format = RDFFormat.JSONLD;
            extention = "_json-ld.json";
            break;
        case 2:
            format = RDFFormat.TURTLE;
            extention = "_turtle.ttl";
            break;
        case 3:
            format = RDFFormat.RDFJSON;
            extention = "_turtle.ttl";
            break;
    }
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreferences(connect.getPoolConnexion(), idTheso);
    if (nodePreference == null)
        return null;
    ExportRdf4jHelper exportRdf4jHelper = new ExportRdf4jHelper();
    exportRdf4jHelper.setNodePreference(nodePreference);
    exportRdf4jHelper.setInfos(connect.getPoolConnexion(), "dd-mm-yyyy", false, idTheso, nodePreference.getCheminSite());
    exportRdf4jHelper.setNodePreference(nodePreference);
    exportRdf4jHelper.addSignleConcept(idTheso, idConcept);
    WriteRdf4j writeRdf4j = new WriteRdf4j(exportRdf4jHelper.getSkosXmlDocument());
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, format);
    file = new ByteArrayContent(out.toByteArray(), "application/xml", idTheso + " " + extention);
    return file;
// new ExportFromBDD().exportConcept(connect.getPoolConnexion(), idTheso, idC).toString();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ExportRdf4jHelper(mom.trd.opentheso.core.exports.rdf4j.ExportRdf4jHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayContent(org.primefaces.model.ByteArrayContent) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Aggregations

RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)62 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IOException (java.io.IOException)17 WriteRdf4j (mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j)14 InputStream (java.io.InputStream)12 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)11 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)8 FileInputStream (java.io.FileInputStream)7 Model (org.eclipse.rdf4j.model.Model)6 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)6 RDFParser (org.eclipse.rdf4j.rio.RDFParser)5 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)5 Rdf2GoCore (de.knowwe.rdf2go.Rdf2GoCore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)4 ExportRdf4jHelper (mom.trd.opentheso.core.exports.rdf4j.ExportRdf4jHelper)4 IRI (org.eclipse.rdf4j.model.IRI)4 Statement (org.eclipse.rdf4j.model.Statement)4 Test (org.junit.Test)4