Search in sources :

Example 1 with QueryDataset

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;
}
Also used : QueryField(ambit2.db.search.structure.QueryField) IAmbitEditor(ambit2.base.interfaces.IAmbitEditor) QueryParam(net.idea.modbcum.i.query.QueryParam) SourceDataset(ambit2.base.data.SourceDataset) QueryDataset(ambit2.db.search.structure.QueryDataset) QueryCombined(ambit2.db.search.QueryCombined) QueryInfo(ambit2.db.search.QueryInfo) IQueryObject(net.idea.modbcum.i.IQueryObject) QueryInfo2Query(ambit2.db.processors.QueryInfo2Query)

Example 2 with QueryDataset

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;
}
Also used : Form(org.restlet.data.Form) QueryDataset(ambit2.db.search.structure.QueryDataset) SourceDataset(ambit2.base.data.SourceDataset)

Example 3 with QueryDataset

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());
}
Also used : QueryStructure(ambit2.db.search.structure.QueryStructure) QueryDataset(ambit2.db.search.structure.QueryDataset) SourceDataset(ambit2.base.data.SourceDataset) QueryCombined(ambit2.db.search.QueryCombined) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure) Test(org.junit.Test)

Example 4 with QueryDataset

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;
}
Also used : QuerySimilarityBitset(ambit2.db.search.structure.QuerySimilarityBitset) QueryField(ambit2.db.search.structure.QueryField) QueryStoredResults(ambit2.db.search.structure.QueryStoredResults) QueryStructure(ambit2.db.search.structure.QueryStructure) QueryDataset(ambit2.db.search.structure.QueryDataset) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) QueryPrescreenBitSet(ambit2.db.search.structure.QueryPrescreenBitSet)

Example 5 with QueryDataset

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());
}
Also used : QuerySimilarityStructure(ambit2.db.search.structure.QuerySimilarityStructure) QueryField(ambit2.db.search.structure.QueryField) QueryCombinedEditor(ambit2.dbui.QueryCombinedEditor) QueryStructure(ambit2.db.search.structure.QueryStructure) QueryStoredResults(ambit2.db.search.structure.QueryStoredResults) QueryDataset(ambit2.db.search.structure.QueryDataset) QueryFieldNumeric(ambit2.db.search.structure.QueryFieldNumeric) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure)

Aggregations

QueryDataset (ambit2.db.search.structure.QueryDataset)6 SourceDataset (ambit2.base.data.SourceDataset)3 QueryCombinedStructure (ambit2.db.search.structure.QueryCombinedStructure)3 QueryField (ambit2.db.search.structure.QueryField)3 QueryStructure (ambit2.db.search.structure.QueryStructure)3 IAmbitEditor (ambit2.base.interfaces.IAmbitEditor)2 QueryCombined (ambit2.db.search.QueryCombined)2 QueryStoredResults (ambit2.db.search.structure.QueryStoredResults)2 QueryInfo2Query (ambit2.db.processors.QueryInfo2Query)1 QueryInfo (ambit2.db.search.QueryInfo)1 QueryFieldNumeric (ambit2.db.search.structure.QueryFieldNumeric)1 QueryPrescreenBitSet (ambit2.db.search.structure.QueryPrescreenBitSet)1 QuerySimilarityBitset (ambit2.db.search.structure.QuerySimilarityBitset)1 QuerySimilarityStructure (ambit2.db.search.structure.QuerySimilarityStructure)1 QueryCombinedEditor (ambit2.dbui.QueryCombinedEditor)1 Connection (java.sql.Connection)1 IDBProcessor (net.idea.modbcum.i.IDBProcessor)1 IQueryObject (net.idea.modbcum.i.IQueryObject)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)1