Search in sources :

Example 1 with ModelTemplates

use of ambit2.db.search.property.ModelTemplates in project ambit-mirror by ideaconsult.

the class PropertyModelResource method createQuery.

@Override
protected IQueryRetrieval<Property> createQuery(Context context, Request request, Response response) throws ResourceException {
    Form form = request.getResourceRef().getQueryAsForm();
    try {
        headless = Boolean.parseBoolean(form.getFirstValue("headless"));
    } catch (Exception x) {
        headless = false;
    }
    ModelQueryResults model = new ModelQueryResults();
    try {
        model.setId(Integer.parseInt(getRequest().getAttributes().get(MLResources.model_resourcekey).toString()));
    } catch (Exception x) {
        model.setId(-1);
        if ("null".equals(getRequest().getAttributes().get(MLResources.model_resourcekey).toString()))
            model = null;
        else
            model.setName(getRequest().getAttributes().get(MLResources.model_resourcekey).toString());
    }
    ModelTemplates query = new ModelTemplates();
    try {
        query.setValue(Reference.decode(getRequest().getAttributes().get(resourceKey).toString()));
    } catch (Exception x) {
        query.setValue(null);
    }
    query.setFieldname(model);
    return query;
}
Also used : ModelTemplates(ambit2.db.search.property.ModelTemplates) ModelQueryResults(ambit2.core.data.model.ModelQueryResults) Form(org.restlet.data.Form) ResourceException(org.restlet.resource.ResourceException)

Example 2 with ModelTemplates

use of ambit2.db.search.property.ModelTemplates in project ambit-mirror by ideaconsult.

the class ModelResource method readVariables.

protected void readVariables(ModelQueryResults model) throws ResourceException {
    ModelTemplates query = new ModelTemplates();
    query.setFieldname(model);
    QueryTemplateReporter<ModelTemplates> reporter = null;
    Connection connection = null;
    try {
        DBConnection dbc = new DBConnection(getContext());
        connection = dbc.getConnection();
        query.setValue("dependent");
        reporter = new QueryTemplateReporter<ModelTemplates>(model.getDependent());
        reporter.setCloseConnection(false);
        reporter.setConnection(connection);
        // dependent
        try {
            reporter.process(query);
        } catch (BatchProcessingException x) {
            if (x.getCause() instanceof NotFoundException) {
            // this is ok
            } else
                throw x;
        }
        query.setValue("independent");
        reporter.setConnection(connection);
        reporter.setOutput(model.getPredictors());
        try {
            reporter.process(query);
        } catch (BatchProcessingException x) {
            if (x.getCause() instanceof NotFoundException) {
            // this is ok
            } else
                throw x;
        }
        query.setValue("predicted");
        reporter.setConnection(connection);
        reporter.setOutput(model.getPredicted());
        try {
            reporter.process(query);
        } catch (BatchProcessingException x) {
            if (x.getCause() instanceof NotFoundException) {
            // ok, it may change the structure only
            } else
                throw x;
        }
    } catch (Exception x) {
        getLogger().log(Level.FINE, x.getMessage(), x);
    }
    try {
        reporter.setCloseConnection(true);
    } catch (Exception x) {
        getLogger().log(Level.WARNING, x.getMessage(), x);
    } finally {
        try {
            reporter.close();
        } catch (Exception x) {
        }
    }
    try {
        connection.close();
    } catch (Exception x) {
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) ModelTemplates(ambit2.db.search.property.ModelTemplates) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException)

Aggregations

ModelTemplates (ambit2.db.search.property.ModelTemplates)2 ResourceException (org.restlet.resource.ResourceException)2 ModelQueryResults (ambit2.core.data.model.ModelQueryResults)1 DBConnection (ambit2.rest.DBConnection)1 Connection (java.sql.Connection)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 BatchProcessingException (net.idea.modbcum.i.exceptions.BatchProcessingException)1 NotFoundException (net.idea.modbcum.i.exceptions.NotFoundException)1 Form (org.restlet.data.Form)1