Search in sources :

Example 1 with RetrieveDatasets

use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.

the class DatasetsByStructureResource method createQuery.

@Override
protected IQueryRetrieval<SourceDataset> createQuery(Context context, Request request, Response response) throws ResourceException {
    try {
        Form form = request.getResourceRef().getQueryAsForm();
        headless = Boolean.parseBoolean(form.getFirstValue("headless"));
    } catch (Exception x) {
        headless = false;
    }
    int idcompound = -1;
    int idstructure = -1;
    try {
        idcompound = OpenTox.URI.compound.getIntValue(getRequest());
        try {
            idstructure = OpenTox.URI.conformer.getIntValue(getRequest());
        } catch (Exception x) {
            idstructure = -1;
        }
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, OpenTox.URI.compound.getKey());
    }
    IStructureRecord record = new StructureRecord(idcompound, idstructure, null, null);
    RetrieveDatasets q = new RetrieveDatasets();
    q.setFieldname(record);
    return q;
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) Form(org.restlet.data.Form) StructureRecord(ambit2.base.data.StructureRecord) IStructureRecord(ambit2.base.interfaces.IStructureRecord) RetrieveDatasets(ambit2.db.readers.RetrieveDatasets) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException)

Example 2 with RetrieveDatasets

use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.

the class RetrieveDatasetsTest method testGetDatasetbyChemical.

@Test
public void testGetDatasetbyChemical() throws Exception {
    setUpDatabaseFromResource(getTestDatabase());
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where name='Dataset 1'");
    Assert.assertEquals(1, names.getRowCount());
    QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
    qe.setConnection(c.getConnection());
    IStructureRecord record = new StructureRecord();
    record.setIdchemical(29141);
    ((RetrieveDatasets) query).setFieldname(record);
    ResultSet rs = qe.process((RetrieveDatasets) query);
    int count = 0;
    while (rs.next()) {
        ISourceDataset dataset = query.getObject(rs);
        names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
        Assert.assertEquals(1, names.getRowCount());
        count++;
    }
    Assert.assertEquals(2, count);
    rs.close();
    qe.close();
    c.close();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) ISourceDataset(ambit2.base.data.ISourceDataset) QueryExecutor(ambit2.db.search.QueryExecutor) IStructureRecord(ambit2.base.interfaces.IStructureRecord) StructureRecord(ambit2.base.data.StructureRecord) ResultSet(java.sql.ResultSet) RetrieveDatasets(ambit2.db.readers.RetrieveDatasets) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 3 with RetrieveDatasets

use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.

the class RetrieveDatasetsTest method testGetObject.

@Test
public void testGetObject() throws Exception {
    setUpDatabaseFromResource(getTestDatabase());
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset");
    Assert.assertEquals(3, names.getRowCount());
    QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
    qe.setConnection(c.getConnection());
    ResultSet rs = qe.process((RetrieveDatasets) query);
    while (rs.next()) {
        ISourceDataset dataset = query.getObject(rs);
        names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
        Assert.assertEquals(1, names.getRowCount());
    }
    rs.close();
    qe.close();
    c.close();
}
Also used : ISourceDataset(ambit2.base.data.ISourceDataset) QueryExecutor(ambit2.db.search.QueryExecutor) ResultSet(java.sql.ResultSet) RetrieveDatasets(ambit2.db.readers.RetrieveDatasets) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 4 with RetrieveDatasets

use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.

the class RetrieveDatasetsTest method testGetDatasetbyStructure.

@Test
public void testGetDatasetbyStructure() throws Exception {
    setUpDatabaseFromResource(getTestDatabase());
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where name='Dataset 1'");
    Assert.assertEquals(1, names.getRowCount());
    QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
    qe.setConnection(c.getConnection());
    IStructureRecord record = new StructureRecord();
    record.setIdstructure(129345);
    ((RetrieveDatasets) query).setFieldname(record);
    ResultSet rs = qe.process((RetrieveDatasets) query);
    int count = 0;
    while (rs.next()) {
        ISourceDataset dataset = query.getObject(rs);
        names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
        Assert.assertEquals(1, names.getRowCount());
        count++;
    }
    Assert.assertEquals(2, count);
    rs.close();
    qe.close();
    c.close();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) ISourceDataset(ambit2.base.data.ISourceDataset) QueryExecutor(ambit2.db.search.QueryExecutor) IStructureRecord(ambit2.base.interfaces.IStructureRecord) StructureRecord(ambit2.base.data.StructureRecord) ResultSet(java.sql.ResultSet) RetrieveDatasets(ambit2.db.readers.RetrieveDatasets) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 5 with RetrieveDatasets

use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.

the class RetrieveDatasetsTest method testGetObjectByName.

@Test
public void testGetObjectByName() throws Exception {
    setUpDatabaseFromResource(getTestDatabase());
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where name='Dataset 1'");
    Assert.assertEquals(1, names.getRowCount());
    QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
    qe.setConnection(c.getConnection());
    ((RetrieveDatasets) query).setValue(new SourceDataset("Dataset 1"));
    ResultSet rs = qe.process((RetrieveDatasets) query);
    while (rs.next()) {
        ISourceDataset dataset = query.getObject(rs);
        names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
        Assert.assertEquals(1, names.getRowCount());
    }
    rs.close();
    qe.close();
    c.close();
}
Also used : ISourceDataset(ambit2.base.data.ISourceDataset) QueryExecutor(ambit2.db.search.QueryExecutor) ResultSet(java.sql.ResultSet) RetrieveDatasets(ambit2.db.readers.RetrieveDatasets) ITable(org.dbunit.dataset.ITable) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Aggregations

RetrieveDatasets (ambit2.db.readers.RetrieveDatasets)6 ISourceDataset (ambit2.base.data.ISourceDataset)4 QueryExecutor (ambit2.db.search.QueryExecutor)4 ResultSet (java.sql.ResultSet)4 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)4 ITable (org.dbunit.dataset.ITable)4 Test (org.junit.Test)4 StructureRecord (ambit2.base.data.StructureRecord)3 IStructureRecord (ambit2.base.interfaces.IStructureRecord)3 SourceDataset (ambit2.base.data.SourceDataset)2 Form (org.restlet.data.Form)2 OTDatasets (ambit2.rest.legacy.OTDatasets)1 OTOntologyService (ambit2.rest.legacy.OTOntologyService)1 QuerySolution (com.hp.hpl.jena.query.QuerySolution)1 IQueryObject (net.idea.modbcum.i.IQueryObject)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 ResourceException (org.restlet.resource.ResourceException)1