Search in sources :

Example 26 with Bindings

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

the class MeanCalculator method onRemovedResults.

@Override
public void onRemovedResults(BindingsResults results) {
    for (Bindings result : results.getBindings()) {
        logger.debug(result);
        if (result.getBindingValue("value") == null) {
            logger.warn("Value is null");
            continue;
        }
        float value;
        try {
            value = Float.parseFloat(result.getBindingValue("value").replace(",", "."));
        } catch (Exception e) {
            logger.error(e.getMessage());
            continue;
        }
        counter++;
        mean = ((mean * (counter - 1)) + value) / counter;
        logger.info(" mean: " + meanURI + " value: " + mean + " counter: " + counter);
    }
    // Update!
    forcedBindings.addBinding("counter", new RDFTermLiteral(String.format("%d", counter)));
    forcedBindings.addBinding("value", new RDFTermLiteral(String.format("%.3f", mean)));
    update(forcedBindings);
}
Also used : Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)

Example 27 with Bindings

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

the class StatusMonitor method onAddedResults.

@Override
public void onAddedResults(BindingsResults results) {
    for (Bindings bindings : results.getBindings()) {
        String thing = bindings.getBindingValue("thing");
        logger.info("Ping received by Web Thing: " + thing);
        synchronized (pings) {
            pings.put(thing, true);
        }
        if (discoverables.contains(thing))
            if (!discoverables.get(thing)) {
                logger.info("Make Web Thing: " + thing + " discoverable again");
                switchStatus(thing, true);
            }
    }
}
Also used : Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 28 with Bindings

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

the class StatusMonitor method switchStatus.

private void switchStatus(String thing, boolean status) {
    // Update
    Bindings bindings = new Bindings();
    if (status)
        bindings.addBinding("value", new RDFTermLiteral("true"));
    else
        bindings.addBinding("value", new RDFTermLiteral("false"));
    bindings.addBinding("thing", new RDFTermURI(thing));
    Response ret = update(bindings);
    if (ret.isUpdateResponse()) {
        discoverables.put(thing, status);
        if (status)
            logger.warn("Web Thing: " + thing + " turned ON");
        else
            logger.warn("Web Thing: " + thing + " turned OFF");
    }
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Example 29 with Bindings

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

the class EventPublisher method post.

public void post(String eventURI) {
    Bindings bind = new Bindings();
    bind.addBinding("event", new RDFTermURI(eventURI));
    bind.addBinding("thing", new RDFTermURI(thing));
    publisherWithoutOutput.update(bind);
}
Also used : RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 30 with Bindings

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

the class ApplicationProfile method subscribeBindings.

public Bindings subscribeBindings(String selectedValue) {
    JsonElement elem;
    Bindings ret = new Bindings();
    if ((elem = doc.get("queries")) != null)
        if ((elem = elem.getAsJsonObject().get(selectedValue)) != null)
            if ((elem = elem.getAsJsonObject().get("forcedBindings")) != null) {
                for (Entry<String, JsonElement> binding : elem.getAsJsonObject().entrySet()) {
                    JsonObject value = binding.getValue().getAsJsonObject();
                    RDFTerm bindingValue = null;
                    if (value.get("type") != null) {
                        if (value.get("type").getAsString().equals("uri")) {
                            bindingValue = new RDFTermURI(value.get("value").getAsString());
                        } else {
                            bindingValue = new RDFTermLiteral(value.get("value").getAsString());
                        }
                    }
                    ret.addBinding(binding.getKey(), bindingValue);
                }
            }
    return ret;
}
Also used : JsonElement(com.google.gson.JsonElement) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) JsonObject(com.google.gson.JsonObject) RDFTerm(it.unibo.arces.wot.sepa.commons.sparql.RDFTerm) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Aggregations

Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)34 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)21 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)19 Response (it.unibo.arces.wot.sepa.commons.response.Response)12 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)11 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)9 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)4 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)4 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)2 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)2 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)2 RDFTerm (it.unibo.arces.wot.sepa.commons.sparql.RDFTerm)2 Producer (it.unibo.arces.wot.sepa.pattern.Producer)2 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 QueryRequest (it.unibo.arces.wot.sepa.commons.request.QueryRequest)1 Notification (it.unibo.arces.wot.sepa.commons.response.Notification)1 ApplicationProfile (it.unibo.arces.wot.sepa.pattern.ApplicationProfile)1