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 !");
}
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));
}
}
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();
}
}
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;
}
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();
}
Aggregations