Search in sources :

Example 1 with FileInputProvider

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

the class RESTInputFactory method createInputManager.

@Override
public ReasoningServiceInputManager createInputManager(Map<String, List<String>> parameters) {
    ReasoningServiceInputManager inmgr = new SimpleInputManager();
    String scope = null;
    String session = null;
    for (Entry<String, List<String>> entry : 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()));
            } 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("file")) {
            if (!entry.getValue().isEmpty()) {
                // We keep only the first value
                // FIXME We create the file once again...
                inmgr.addInputProvider(new FileInputProvider(new File(entry.getValue().iterator().next())));
            } 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(rStore, adapterManager, entry.getValue().iterator().next()));
            } 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));
    }
    return inmgr;
}
Also used : ReasoningServiceInputManager(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager) WebApplicationException(javax.ws.rs.WebApplicationException) FileInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.FileInputProvider) OntologyManagerInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.OntologyManagerInputProvider) List(java.util.List) UrlInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.UrlInputProvider) RecipeInputProvider(org.apache.stanbol.reasoners.web.input.provider.impl.RecipeInputProvider) File(java.io.File)

Aggregations

File (java.io.File)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ReasoningServiceInputManager (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager)1 FileInputProvider (org.apache.stanbol.reasoners.web.input.provider.impl.FileInputProvider)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