Search in sources :

Example 1 with TaskResult

use of net.idea.restnet.i.task.TaskResult in project ambit-mirror by ideaconsult.

the class CallableSubstancePropertyCreatorTest method testCreateSubstanceProperty.

@Test
public void testCreateSubstanceProperty() throws Exception {
    Form form = new Form();
    form.add("endpointcategory", Protocol._categories.ZETA_POTENTIAL_SECTION.name());
    form.add("name", "ZETA POTENTIAL");
    form.add("unit", "mV");
    form.add("protocol", "Method: other: no data");
    Params p = new Params();
    Value v = new Value();
    v.setLoValue(4.26);
    p.put("pH", v);
    Assert.assertEquals("{\"pH\":{\"loValue\":4.26}}", p.toString());
    try {
        PropertyURIReporter reporter = new PropertyURIReporter(new Reference("http://localhost:8081/ambit2"));
        CallableSubstancePropertyCreator callable = new CallableSubstancePropertyCreator(reporter, Method.POST, form, null, null);
        TaskResult task = callable.call();
        Assert.assertTrue(task.getUri().startsWith("http://localhost:8081/ambit2/property/P-CHEM/ZETA_POTENTIAL_SECTION/ZETA+POTENTIAL/A597EBC063D7A5A605B9535656E09149A72F0C23"));
    // "http://localhost:8081/ambit2/property/P-CHEM/ZETA_POTENTIAL_SECTION/ZETA+POTENTIAL/945DEEC24F876DEE6116F92646EF729107F5B5FD"
    } catch (Exception x) {
        throw x;
    } finally {
    }
}
Also used : Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Value(ambit2.base.data.study.Value) Params(ambit2.base.data.study.Params) IParams(ambit2.base.data.study.IParams) TaskResult(net.idea.restnet.i.task.TaskResult) CallableSubstancePropertyCreator(ambit2.rest.substance.property.CallableSubstancePropertyCreator) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 2 with TaskResult

use of net.idea.restnet.i.task.TaskResult in project ambit-mirror by ideaconsult.

the class CallableSubstancePropertyCreatorTest method testCreateSubstanceProperty_TO_BIODEG_WATER_SCREEN_SECTION.

/**
 * @throws Exception
 */
@Test
public void testCreateSubstanceProperty_TO_BIODEG_WATER_SCREEN_SECTION() throws Exception {
    Form form = new Form();
    form.add("endpointcategory", Protocol._categories.TO_BIODEG_WATER_SCREEN_SECTION.name());
    form.add("name", "% Degradation");
    form.add("unit", "%");
    form.add("protocol", "Method: other: no data");
    Params p = new Params();
    Value v = new Value();
    v.setUnits("d");
    v.setLoValue(7.0);
    p.put("Sampling time", v);
    form.add("conditions", p.toString());
    Assert.assertEquals("{\"Sampling time\":{\"loValue\":7,\"unit\":\"d\"}}", p.toString());
    try {
        PropertyURIReporter reporter = new PropertyURIReporter(new Reference("http://localhost:8081/ambit2"));
        CallableSubstancePropertyCreator callable = new CallableSubstancePropertyCreator(reporter, Method.POST, form, null, null);
        TaskResult task = callable.call();
        Assert.assertTrue(task.getUri().startsWith("http://localhost:8081/ambit2/property/ENV+FATE/TO_BIODEG_WATER_SCREEN_SECTION/%25+Degradation/3CF77D9EFE4E74744E691BF4880B4EF728B16FAE"));
    // /d4cd0dab-cf4c-3a22-ad92-fab40844c786
    /*
			 * "http://localhost:8080/ambit2/property/ENV+FATE/TO_BIODEG_WATER_SCREEN_SECTION/%25+Degradation/5FA6EFD4E83BEC47B626C6149DBBD3907084187F/1f255895-eb7d-37dc-8eb8-bc9580d8be25"
			 * :{
			 * 
			 * "type":"Feature", "title":"% Degradation", "units":"%",
			 * "isNominal":false, "isNumeric":false, "isMultiValue":true,
			 * "sameAs"
			 * :"http://www.opentox.org/echaEndpoints.owl#TO_BIODEG_WATER_SCREEN"
			 * , "isModelPredictionFeature":false,
			 * "creator":"Method: other: see below", "order":1087, "source":{
			 * "URI"
			 * :"http://localhost:8080/ambit2/dataset/Method%3A+other%3A+see+below"
			 * , "type":"Dataset" }, "annotation":[ { "p" : "Sampling time", "o"
			 * : "7.0 d"}]
			 * 
			 * },
			 */
    // http://localhost:8081/ambit2/property/P-CHEM/TO_BIODEG_WATER_SCREEN_SECTION/%25+Degradation/8C9DF1AF60CA3D8706C0156361E97E0DF4391C10/1f255895-eb7d-37dc-8eb8-bc9580d8be25
    } catch (Exception x) {
        throw x;
    } finally {
    }
}
Also used : Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Value(ambit2.base.data.study.Value) Params(ambit2.base.data.study.Params) IParams(ambit2.base.data.study.IParams) TaskResult(net.idea.restnet.i.task.TaskResult) CallableSubstancePropertyCreator(ambit2.rest.substance.property.CallableSubstancePropertyCreator) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 3 with TaskResult

use of net.idea.restnet.i.task.TaskResult in project ambit-mirror by ideaconsult.

the class PingResource method pingI5.

protected ITask<ITaskResult, String> pingI5(Reference uri, Context context) throws ResourceException {
    ITask<ITaskResult, String> task;
    DBConnection dbc = new DBConnection(context);
    I5LightClient cli = null;
    long now = System.currentTimeMillis();
    if (server == null)
        server = dbc.getProperty("i5.server");
    if (user == null)
        user = dbc.getProperty("i5.user");
    if (pass == null)
        pass = dbc.getProperty("i5.pass");
    task = new Task<ITaskResult, String>(user);
    task.setName("Ping " + server);
    task.setStatus(TaskStatus.Running);
    task.setUri(new TaskResult(uri.toString(), false));
    try {
        cli = new I5LightClient(server);
        if (cli.login(user, pass)) {
            task.setStatus(TaskStatus.Completed);
        } else {
            task.setStatus(TaskStatus.Error);
            task.setError(new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED));
        }
    } catch (Exception x) {
        task.setError(new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage()));
        task.setStatus(TaskStatus.Error);
    } finally {
        try {
            cli.logout();
        } catch (Exception x) {
        }
    }
    task.setTimeCompleted(System.currentTimeMillis());
    return task;
}
Also used : DBConnection(ambit2.rest.DBConnection) I5LightClient(net.idea.i5.cli.I5LightClient) ITaskResult(net.idea.restnet.i.task.ITaskResult) TaskResult(net.idea.restnet.i.task.TaskResult) ITaskResult(net.idea.restnet.i.task.ITaskResult) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException)

Example 4 with TaskResult

use of net.idea.restnet.i.task.TaskResult in project ambit-mirror by ideaconsult.

the class CallableBundleCreatorTest method testUpdateBundle.

@Test
public void testUpdateBundle() throws Exception {
    setUpDatabase(dbFile);
    IDatabaseConnection c = getConnection();
    IDatabaseConnection c1 = getConnection();
    Form form = new Form();
    form.add(ISourceDataset.fields.title.name(), "title");
    // form.add(ISourceDataset.fields.source.name(), "source");
    form.add(ISourceDataset.fields.license.name(), "license");
    form.add(ISourceDataset.fields.maintainer.name(), "maintainer");
    form.add(ISourceDataset.fields.rightsHolder.name(), "rightsHolder");
    form.add(ISourceDataset.fields.seeAlso.name(), "NEW VALUE");
    form.add("description", "description");
    form.add(ISourceDataset.fields.stars.name(), "9");
    try {
        ITable table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,updated from bundle where idbundle=1"));
        Assert.assertEquals(1, table.getRowCount());
        Object updated = table.getValue(0, "updated");
        SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(1);
        DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle> reporter = new DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle>(new Reference("http://localhost"));
        CallableBundleCreator callable = new CallableBundleCreator(bundle, reporter, Method.PUT, form, c.getConnection(), new User("testuser"), null);
        TaskResult task = callable.call();
        table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,name,licenseURI,rightsHolder,maintainer,stars,title,url,description,updated,user_name,url,title from bundle join catalog_references using(idreference) where idbundle=1"));
        Assert.assertEquals(1, table.getRowCount());
        Assert.assertEquals("title", table.getValue(0, "name"));
        Assert.assertEquals("maintainer", table.getValue(0, "maintainer"));
        Assert.assertEquals("rightsHolder", table.getValue(0, "rightsHolder"));
        Assert.assertEquals("license", table.getValue(0, "licenseURI"));
        Assert.assertEquals("description", table.getValue(0, "description"));
        Assert.assertNotSame(updated, table.getValue(0, "updated"));
        Assert.assertEquals("guest", table.getValue(0, "user_name"));
        Assert.assertEquals("NEW VALUE", table.getValue(0, "url"));
    // Assert.assertEquals("source",table.getValue(0,"title"));
    } catch (Exception x) {
        throw x;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            c1.close();
        } catch (Exception x) {
        }
    }
}
Also used : User(org.restlet.security.User) CallableBundleCreator(ambit2.rest.bundle.CallableBundleCreator) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) TaskResult(net.idea.restnet.i.task.TaskResult) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 5 with TaskResult

use of net.idea.restnet.i.task.TaskResult in project ambit-mirror by ideaconsult.

the class CallableBundleCreatorTest method testCreateBundle.

@Test
public void testCreateBundle() throws Exception {
    setUpDatabase(dbFile);
    IDatabaseConnection c = getConnection();
    IDatabaseConnection c1 = getConnection();
    Form form = new Form();
    form.add(ISourceDataset.fields.title.name(), "title");
    form.add(ISourceDataset.fields.source.name(), "source");
    form.add(ISourceDataset.fields.license.name(), "license");
    form.add(ISourceDataset.fields.seeAlso.name(), "seeAlso");
    form.add(ISourceDataset.fields.maintainer.name(), "maintainer");
    form.add(ISourceDataset.fields.rightsHolder.name(), "rightsHolder");
    form.add("description", "description");
    form.add(ISourceDataset.fields.stars.name(), "9");
    try {
        DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle> reporter = new DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle>(new Reference("http://localhost"));
        CallableBundleCreator callable = new CallableBundleCreator(null, reporter, Method.POST, form, c.getConnection(), new User("testuser"), null);
        TaskResult task = callable.call();
        ITable table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,description,user_name,title,url from bundle join catalog_references using(idreference) where name='title'"));
        Assert.assertEquals(1, table.getRowCount());
        Assert.assertEquals("description", table.getValue(0, "description"));
        Assert.assertEquals("testuser", table.getValue(0, "user_name"));
        Assert.assertEquals("source", table.getValue(0, "title"));
        Assert.assertEquals("seeAlso", table.getValue(0, "url"));
    } catch (Exception x) {
        throw x;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            c1.close();
        } catch (Exception x) {
        }
    }
}
Also used : User(org.restlet.security.User) CallableBundleCreator(ambit2.rest.bundle.CallableBundleCreator) Form(org.restlet.data.Form) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) Reference(org.restlet.data.Reference) TaskResult(net.idea.restnet.i.task.TaskResult) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Aggregations

TaskResult (net.idea.restnet.i.task.TaskResult)26 DbUnitTest (net.idea.restnet.db.test.DbUnitTest)23 Test (org.junit.Test)23 Form (org.restlet.data.Form)22 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)20 Reference (org.restlet.data.Reference)17 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)14 ITable (org.dbunit.dataset.ITable)14 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)12 DatasetURIReporter (ambit2.rest.dataset.DatasetURIReporter)6 CallableBundleCreator (ambit2.rest.bundle.CallableBundleCreator)5 PropertyURIReporter (ambit2.rest.property.PropertyURIReporter)5 User (org.restlet.security.User)5 IParams (ambit2.base.data.study.IParams)4 Params (ambit2.base.data.study.Params)4 SubstanceRecord (ambit2.base.data.SubstanceRecord)3 IStructureRecord (ambit2.base.interfaces.IStructureRecord)3 CallableCompoundBundle (ambit2.rest.bundle.CallableCompoundBundle)3 CallableSubstanceBundle (ambit2.rest.bundle.CallableSubstanceBundle)3 CompoundURIReporter (ambit2.rest.structure.CompoundURIReporter)3