Search in sources :

Example 1 with QueryStructureByQuality

use of ambit2.db.search.structure.QueryStructureByQuality in project ambit-mirror by ideaconsult.

the class QLabelQueryResource method createQuery.

@Override
protected IQueryRetrieval<IStructureRecord> createQuery(Context context, Request request, Response response) throws ResourceException {
    QueryStructureByQuality q = new QueryStructureByQuality();
    Form form = request.getResourceRef().getQueryAsForm();
    try {
        includeMol = "true".equals(form.getFirstValue("mol"));
    } catch (Exception x) {
        includeMol = false;
    }
    Object key = form.getFirstValue(QueryResource.search_param);
    if (key != null) {
        try {
            q.setValue(new QLabel(QUALITY.valueOf(Reference.decode(key.toString()))));
        } catch (Exception x) {
            StringBuilder b = new StringBuilder();
            b.append("Valid values are ");
            for (QUALITY v : QUALITY.values()) {
                b.append(v);
                b.append('\t');
            }
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, b.toString(), x);
        }
    } else {
        q.setValue(new QLabel(QUALITY.OK));
    }
    Object id = request.getAttributes().get(OpenTox.URI.dataset.getKey());
    if (id != null)
        try {
            datasetID = Integer.parseInt(id.toString());
            SourceDataset dataset = new SourceDataset();
            dataset.setId(datasetID);
            q.setFieldname(dataset);
            return q;
        } catch (Exception x) {
            if (id.toString().startsWith("R")) {
                queryResultsID = Integer.parseInt(id.toString().substring(1));
                StoredQuery dataset = new StoredQuery();
                dataset.setId(queryResultsID);
                q.setFieldname(dataset);
                return q;
            } else
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid dataset id");
        }
    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No dataset !");
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) QUALITY(ambit2.base.data.QLabel.QUALITY) Form(org.restlet.data.Form) QLabel(ambit2.base.data.QLabel) QueryStructureByQuality(ambit2.db.search.structure.QueryStructureByQuality) ResourceException(org.restlet.resource.ResourceException) SourceDataset(ambit2.base.data.SourceDataset) ResourceException(org.restlet.resource.ResourceException)

Example 2 with QueryStructureByQuality

use of ambit2.db.search.structure.QueryStructureByQuality in project ambit-mirror by ideaconsult.

the class QueryStructurebyQualityTest method verify.

@Override
protected void verify(QueryStructureByQuality query, ResultSet rs) throws Exception {
    while (rs.next()) {
        IStructureRecord record = query.getObject(rs);
        Assert.assertEquals(10, record.getIdchemical());
        Assert.assertEquals(100214, record.getIdstructure());
        Assert.assertEquals(new QLabel(QUALITY.OK), query.retrieveValue(rs));
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) QLabel(ambit2.base.data.QLabel)

Example 3 with QueryStructureByQuality

use of ambit2.db.search.structure.QueryStructureByQuality in project ambit-mirror by ideaconsult.

the class QueryStructureByQualityEditorTest method main.

public static void main(String[] args) {
    QueryStructureByQuality query = new QueryStructureByQuality();
    try {
        JOptionPane.showMessageDialog(null, EditorPreferences.getEditor(query).getJComponent());
        System.out.println(query.toString());
        System.out.println(query.getSQL());
    } catch (Exception x) {
        x.printStackTrace();
    }
}
Also used : QueryStructureByQuality(ambit2.db.search.structure.QueryStructureByQuality)

Example 4 with QueryStructureByQuality

use of ambit2.db.search.structure.QueryStructureByQuality in project ambit-mirror by ideaconsult.

the class QueryStructurebyQualityTest method createQuery.

@Override
protected QueryStructureByQuality createQuery() throws Exception {
    QueryStructureByQuality q = new QueryStructureByQuality();
    q.setValue(new QLabel(QUALITY.OK));
    ISourceDataset d = new StoredQuery(2);
    d.setID(2);
    q.setFieldname(d);
    return q;
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) ISourceDataset(ambit2.base.data.ISourceDataset) QLabel(ambit2.base.data.QLabel) QueryStructureByQuality(ambit2.db.search.structure.QueryStructureByQuality)

Example 5 with QueryStructureByQuality

use of ambit2.db.search.structure.QueryStructureByQuality in project ambit-mirror by ideaconsult.

the class QueryStructurebyQualityTest method testSelectNull.

@Test
public void testSelectNull() throws Exception {
    setUpDatabaseFromResource(getDbFile());
    IDatabaseConnection c = getConnection();
    executor.setConnection(c.getConnection());
    executor.open();
    QueryStructureByQuality q = createQueryNull();
    ResultSet rs = executor.process(q);
    Assert.assertNotNull(rs);
    verifyNull(q, rs);
    rs.close();
    c.close();
}
Also used : QueryStructureByQuality(ambit2.db.search.structure.QueryStructureByQuality) ResultSet(java.sql.ResultSet) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Aggregations

QueryStructureByQuality (ambit2.db.search.structure.QueryStructureByQuality)4 QLabel (ambit2.base.data.QLabel)3 StoredQuery (ambit2.db.search.StoredQuery)2 ISourceDataset (ambit2.base.data.ISourceDataset)1 QUALITY (ambit2.base.data.QLabel.QUALITY)1 SourceDataset (ambit2.base.data.SourceDataset)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 ResultSet (java.sql.ResultSet)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1 Test (org.junit.Test)1 Form (org.restlet.data.Form)1 ResourceException (org.restlet.resource.ResourceException)1