Search in sources :

Example 1 with RDFTermBNode

use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode in project SEPA by arces-wot.

the class JSAP method getQueryBindings.

public ForcedBindings getQueryBindings(String id) throws IllegalArgumentException {
    if (!jsap.get("queries").getAsJsonObject().has(id))
        throw new IllegalArgumentException("Query ID not found: " + id);
    ForcedBindings ret = new ForcedBindings();
    if (!jsap.getAsJsonObject("queries").getAsJsonObject(id).has("forcedBindings"))
        return ret;
    try {
        for (Entry<String, JsonElement> binding : jsap.getAsJsonObject("queries").getAsJsonObject(id).getAsJsonObject("forcedBindings").entrySet()) {
            RDFTerm bindingValue = null;
            String value = null;
            if (binding.getValue().getAsJsonObject().has("value"))
                value = binding.getValue().getAsJsonObject().get("value").getAsString();
            switch(binding.getValue().getAsJsonObject().get("type").getAsString()) {
                case "literal":
                    String datatype = null;
                    if (binding.getValue().getAsJsonObject().has("datatype"))
                        datatype = binding.getValue().getAsJsonObject().get("datatype").getAsString();
                    String language = null;
                    if (binding.getValue().getAsJsonObject().has("language"))
                        language = binding.getValue().getAsJsonObject().get("language").getAsString();
                    bindingValue = new RDFTermLiteral(value, datatype, language);
                    break;
                case "uri":
                    bindingValue = new RDFTermURI(value);
                    break;
                case "bnode":
                    bindingValue = new RDFTermBNode(value);
                    break;
                default:
                    logger.error("JSAP unknown type: " + binding);
                    continue;
            }
            ret.addBinding(binding.getKey(), bindingValue);
        }
    } catch (Exception e) {
        logger.error("getQueryBindings " + id + " exception: " + e.getMessage());
    }
    return ret;
}
Also used : RDFTermBNode(it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode) JsonElement(com.google.gson.JsonElement) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) RDFTerm(it.unibo.arces.wot.sepa.commons.sparql.RDFTerm) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral) URISyntaxException(java.net.URISyntaxException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with RDFTermBNode

use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode in project SEPA by arces-wot.

the class JSAP method getUpdateBindings.

/**
 * <pre>
 * "forcedBindings" : {
 *					"variable_1" : {
 *						"type" : "literal",
 *						"datatype" : "xsd:short"}
 *					 ,
 *					"variable_2" : {
 *						"type" : "uri"}
 *					 ,
 *					 "variable_3" : {
 *					 	"type": "literal",
 *					 	"datatype" : "xsd:string",
 *					 	"language" : "it"},
 *					 ...
 *					"variable_N" : {
 *						"type" : "literal",
 *						"datatype" : "xsd:dateTime" ,
 *						"value" : "1985-08-03T01:02:03Z"}
 *				}
 * </pre>
 */
public ForcedBindings getUpdateBindings(String id) throws IllegalArgumentException {
    if (!jsap.get("updates").getAsJsonObject().has(id))
        throw new IllegalArgumentException("Update ID not found: " + id);
    ForcedBindings ret = new ForcedBindings();
    if (!jsap.getAsJsonObject("updates").getAsJsonObject(id).has("forcedBindings"))
        return ret;
    try {
        for (Entry<String, JsonElement> binding : jsap.getAsJsonObject("updates").getAsJsonObject(id).getAsJsonObject("forcedBindings").entrySet()) {
            if (!binding.getValue().getAsJsonObject().has("type")) {
                logger.error("JSAP missing binding type: " + binding);
                continue;
            }
            RDFTerm bindingValue = null;
            String value = null;
            if (binding.getValue().getAsJsonObject().has("value"))
                value = binding.getValue().getAsJsonObject().get("value").getAsString();
            switch(binding.getValue().getAsJsonObject().get("type").getAsString()) {
                case "literal":
                    String datatype = null;
                    if (binding.getValue().getAsJsonObject().has("datatype"))
                        datatype = binding.getValue().getAsJsonObject().get("datatype").getAsString();
                    String language = null;
                    if (binding.getValue().getAsJsonObject().has("language"))
                        language = binding.getValue().getAsJsonObject().get("language").getAsString();
                    bindingValue = new RDFTermLiteral(value, datatype, language);
                    break;
                case "uri":
                    bindingValue = new RDFTermURI(value);
                    break;
                case "bnode":
                    bindingValue = new RDFTermBNode(value);
                    break;
                default:
                    logger.error("JSAP unknown type: " + binding);
                    continue;
            }
            ret.addBinding(binding.getKey(), bindingValue);
        }
    } catch (Exception e) {
        logger.error("getUpdateBindings " + id + " exception: " + e.getMessage());
    }
    return ret;
}
Also used : RDFTermBNode(it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode) JsonElement(com.google.gson.JsonElement) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) RDFTerm(it.unibo.arces.wot.sepa.commons.sparql.RDFTerm) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral) URISyntaxException(java.net.URISyntaxException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

JsonElement (com.google.gson.JsonElement)2 SEPABindingsException (it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException)2 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)2 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)2 RDFTerm (it.unibo.arces.wot.sepa.commons.sparql.RDFTerm)2 RDFTermBNode (it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode)2 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)2 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2