use of ambit2.db.search.structure.QueryDataset in project ambit-mirror by ideaconsult.
the class QueryInfoTest method createQuery.
@Override
protected IQueryObject createQuery() throws Exception {
QueryInfo info = new QueryInfo();
QueryInfo.setFieldnames(fill_in());
// info.setMolecule(MoleculeFactory.makeBenzene());
info.setFieldname1("Field_1");
info.setCondition1("=");
info.setIdentifier1("20");
info.setFieldname2("Field_2");
info.setCondition2("=");
info.setIdentifier2("40");
info.setCombine(QueryInfo.COMBINE_ANY);
info.setDataset(new SourceDataset("EINECS"));
IAmbitEditor e = EditorPreferences.getEditor(info);
assertNotNull(e);
// JOptionPane.showMessageDialog(null,e.getJComponent());
QueryInfo2Query processor = new QueryInfo2Query();
IQueryObject query = processor.process(info);
assertTrue(query instanceof QueryCombined);
QueryCombined q = (QueryCombined) query;
assertEquals(2, q.size());
// first query
assertTrue(q.get(0) instanceof QueryField);
assertEquals("Field_1", ((QueryField) q.get(0)).getFieldname().getName());
assertEquals("20", ((QueryField) q.get(0)).getValue());
assertEquals(StringCondition.getInstance("="), ((QueryField) q.get(0)).getCondition());
assertTrue(q.get(1) instanceof QueryField);
assertEquals("Field_2", ((QueryField) q.get(1)).getFieldname());
assertEquals("40", ((QueryField) q.get(1)).getValue());
assertEquals(StringCondition.getInstance("="), ((QueryField) q.get(1)).getCondition());
// scope
assertNotNull(q.getScope());
assertTrue(q.getScope() instanceof QueryDataset);
QueryDataset d = (QueryDataset) q.getScope();
assertEquals("EINECS", d.getValue().getName());
System.out.println(q.getSQL());
List<QueryParam> p = query.getParameters();
for (int i = 0; i < p.size(); i++) {
System.out.print(p.get(i).getType());
System.out.print('\t');
System.out.print(p.get(i).getValue());
System.out.print('\n');
}
// fail("not implemented");
return query;
}
use of ambit2.db.search.structure.QueryDataset in project ambit-mirror by ideaconsult.
the class DatasetStructuresResource method getDatasetByName.
protected Q getDatasetByName(String key) throws ResourceException {
datasetID = null;
queryResultsID = null;
datasetName = key;
QueryDataset query = new QueryDataset();
query.setValue(new SourceDataset(key));
Form form = getResourceRef(getRequest()).getQueryAsForm();
setPaging(form, query);
return (Q) query;
}
use of ambit2.db.search.structure.QueryDataset in project ambit-mirror by ideaconsult.
the class QueryCombinedTest method testDataset.
@Test
public void testDataset() throws Exception {
QueryCombined qc = new QueryCombinedStructure();
qc.setId(55);
QueryStructure qs = new QueryStructure();
qs.setFieldname(ExactStructureSearchMode.idchemical);
qs.setValue("10");
QueryDataset dataset = new QueryDataset();
dataset.setValue(new SourceDataset("Dataset 1"));
qc.setScope(dataset);
qc.add(qs);
// System.out.println(qc.getSQL());
}
use of ambit2.db.search.structure.QueryDataset in project ambit-mirror by ideaconsult.
the class QueryInfo2Query method process.
public IQueryObject process(QueryInfo target) throws AmbitException {
QueryCombinedStructure combined = new QueryCombinedStructure();
// scope
if (QueryInfo.SCOPE_DATABASE.equals(target.getScope()))
combined.setScope(null);
else if (QueryInfo.SCOPE_DATASET.equals(target.getScope())) {
if (target.getDataset() != null) {
QueryDataset d = new QueryDataset();
d.setCondition(StringCondition.getInstance(StringCondition.C_EQ));
d.setValue(target.getDataset());
combined.setScope(d);
} else {
logger.warning("Dataset not defined!");
combined.setScope(null);
}
} else if (QueryInfo.SCOPE_QUERY.equals(target.getScope())) {
if (target.getStoredQuery() != null) {
QueryStoredResults d = new QueryStoredResults();
d.setCondition(EQCondition.getInstance());
d.setFieldname(target.getStoredQuery());
combined.setScope(d);
} else {
logger.warning("Stored query not defined!");
combined.setScope(null);
}
}
// and / or
combined.setCombine_as_and(QueryInfo.COMBINE_ALL.equals(target.getCombine()));
// identifiers
QueryField f = createQueryField(Property.getInstance(target.getFieldname1(), ""), target.getIdentifier1(), target.getCondition1());
if (f != null)
combined.add(f);
f = createQueryField(Property.getInstance(target.getFieldname2(), ""), target.getIdentifier2(), target.getCondition2());
if (f != null)
combined.add(f);
f = createQueryField(Property.getInstance(target.getFieldname3(), ""), target.getIdentifier3(), target.getCondition3());
if (f != null)
combined.add(f);
// formula, smiles, inchi
QueryStructure s = createQueryStructure(ExactStructureSearchMode.formula, target.getFormula());
if (s != null)
combined.add(f);
s = createQueryStructure(ExactStructureSearchMode.smiles, target.getSmiles());
if (s != null)
combined.add(f);
s = createQueryStructure(ExactStructureSearchMode.inchi, target.getInchi());
if (s != null)
combined.add(f);
// similarity
try {
QuerySimilarityBitset similarity = createQuerySimilarity(target);
if (similarity != null)
combined.add(similarity);
} catch (AmbitException x) {
logger.log(java.util.logging.Level.WARNING, x.getMessage(), x);
}
// substructure
try {
QueryPrescreenBitSet substructure = createQuerySubstructure(target);
if (substructure != null)
combined.add(substructure);
} catch (AmbitException x) {
logger.log(java.util.logging.Level.WARNING, x.getMessage(), x);
}
// substructure
try {
QueryStructure exact = createExactStructure(target);
if (exact != null)
combined.add(exact);
} catch (AmbitException x) {
logger.log(java.util.logging.Level.WARNING, x.getMessage(), x);
}
combined.setId(-1);
return combined;
}
use of ambit2.db.search.structure.QueryDataset in project ambit-mirror by ideaconsult.
the class QueryCombinedEditorTest method test.
public void test() throws Exception {
QueryCombinedStructure l = new QueryCombinedStructure();
l.add(new QueryField());
// l.add(new QueryStructureByID(100,200));
l.add(new QuerySimilarityStructure());
l.add(new QueryFieldNumeric());
l.add(new QueryDataset());
l.add(new QueryStructure());
l.add(new QueryStoredResults());
QueryCombinedEditor q = new QueryCombinedEditor();
q.setObject(l);
JOptionPane.showMessageDialog(null, q.getJComponent());
System.out.println(q.getObject().getCombine_queries());
System.out.println(q.getObject().getScope());
}
Aggregations