Search in sources :

Example 1 with SimpleInputManager

use of org.apache.stanbol.reasoners.web.input.impl.SimpleInputManager in project stanbol by apache.

the class ReasoningServiceTaskResource method prepareInput.

/**
     * Binds the request parameters to a list of {@see ReasoningServiceInputProvider}s, and fed a {@see
     * SimpleInputManager}. TODO In the future we may want to decouple this process from this
     * resource/submodule.
     * 
     * @return
     */
private ReasoningServiceInputManager prepareInput() {
    ReasoningServiceInputManager inmgr = new SimpleInputManager();
    String scope = null;
    String session = null;
    if (file != null) {
        inmgr.addInputProvider(new ByteArrayInputProvider(file.getContent()));
    }
    for (Entry<String, List<String>> entry : this.parameters.entrySet()) {
        if (entry.getKey().equals("url")) {
            if (!entry.getValue().isEmpty()) {
                // We keep only the first value
                // XXX (make sense support multiple values?)
                inmgr.addInputProvider(new UrlInputProvider(entry.getValue().iterator().next()));
                // We remove it form the additional parameter list
                this.parameters.remove("url");
            } else {
                // Parameter exists with no value
                log.error("Parameter 'url' must have a value!");
                throw new WebApplicationException(Response.Status.BAD_REQUEST);
            }
        } else //            } 
        if (entry.getKey().equals("scope")) {
            if (!entry.getValue().isEmpty()) {
                scope = entry.getValue().iterator().next();
            } else {
                // Parameter exists with no value
                log.error("Parameter 'scope' must have a value!");
                throw new WebApplicationException(Response.Status.BAD_REQUEST);
            }
        } else if (entry.getKey().equals("session")) {
            if (!entry.getValue().isEmpty()) {
                session = entry.getValue().iterator().next();
            } else {
                // Parameter exists with no value
                log.error("Parameter 'session' must have a value!");
                throw new WebApplicationException(Response.Status.BAD_REQUEST);
            }
        } else if (entry.getKey().equals("recipe")) {
            if (!entry.getValue().isEmpty()) {
                inmgr.addInputProvider(new RecipeInputProvider(ruleStore, adapterManager, entry.getValue().iterator().next()));
                // We remove it form the additional parameter list
                this.parameters.remove("url");
            } else {
                // Parameter exists with no value
                log.error("Parameter 'recipe' must have a value!");
                throw new WebApplicationException(Response.Status.BAD_REQUEST);
            }
        }
    }
    if (scope != null) {
        inmgr.addInputProvider(new OntologyManagerInputProvider(onm, sessionManager, scope, session));
        this.parameters.remove("scope");
        this.parameters.remove("session");
    }
    return inmgr;
}
Also used : SimpleInputManager(org.apache.stanbol.reasoners.web.input.impl.SimpleInputManager) ReasoningServiceInputManager(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager) WebApplicationException(javax.ws.rs.WebApplicationException) OntologyManagerInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.OntologyManagerInputProvider) List(java.util.List) ArrayList(java.util.ArrayList) UrlInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.UrlInputProvider) ByteArrayInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.ByteArrayInputProvider) RecipeInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.RecipeInputProvider)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ReasoningServiceInputManager (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager)1 SimpleInputManager (org.apache.stanbol.reasoners.web.input.impl.SimpleInputManager)1 ByteArrayInputProvider (org.apache.stanbol.reasoners.web.input.provider.impl.ByteArrayInputProvider)1 OntologyManagerInputProvider (org.apache.stanbol.reasoners.web.input.provider.impl.OntologyManagerInputProvider)1 RecipeInputProvider (org.apache.stanbol.reasoners.web.input.provider.impl.RecipeInputProvider)1 UrlInputProvider (org.apache.stanbol.reasoners.web.input.provider.impl.UrlInputProvider)1