Search in sources :

Example 1 with StoredQuery

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

the class ConsensusLabelQueryResource method createQuery.

@Override
protected IQueryRetrieval<IStructureRecord> createQuery(Context context, Request request, Response response) throws ResourceException {
    // collapsed = true;
    setGroupProperties(context, request, response);
    setTemplate(createTemplate(context, request, response));
    QueryStructureByQualityPairLabel q = new QueryStructureByQualityPairLabel();
    Form form = request.getResourceRef().getQueryAsForm();
    Object key = form.getFirstValue(QueryResource.search_param);
    ConsensusLabel label = new ConsensusLabel();
    if (key != null) {
        try {
            label.setLabel(CONSENSUS_LABELS.valueOf(Reference.decode(key.toString())));
        } catch (Exception x) {
            StringBuilder b = new StringBuilder();
            b.append("Valid values are ");
            for (CONSENSUS_LABELS v : CONSENSUS_LABELS.values()) {
                b.append(v);
                b.append('\t');
            }
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, b.toString(), x);
        }
    } else {
        label.setLabel(CONSENSUS_LABELS.Consensus);
    }
    q.setValue(label);
    key = form.getFirstValue("text");
    if (key != null)
        label.setText(key.toString());
    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);
            } else
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid dataset id");
        }
    return q;
// throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,"No dataset !");
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) QueryStructureByQualityPairLabel(ambit2.db.search.structure.QueryStructureByQualityPairLabel) Form(org.restlet.data.Form) ConsensusLabel(ambit2.base.data.ConsensusLabel) CONSENSUS_LABELS(ambit2.base.data.ConsensusLabel.CONSENSUS_LABELS) ResourceException(org.restlet.resource.ResourceException) SourceDataset(ambit2.base.data.SourceDataset) ResourceException(org.restlet.resource.ResourceException)

Example 2 with StoredQuery

use of ambit2.db.search.StoredQuery 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 3 with StoredQuery

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

the class ChartResource method getDataset.

protected ISourceDataset getDataset(String uri) throws InvalidResourceIDException {
    Map<String, Object> vars = new HashMap<String, Object>();
    Template template = OpenTox.URI.dataset.getTemplate(getRequest().getRootRef());
    String id = null;
    try {
        template.parse(uri, vars);
        id = vars.get(OpenTox.URI.dataset.getKey()).toString();
    } catch (Exception x) {
        return null;
    }
    if (id != null)
        try {
            Integer idnum = new Integer(Reference.decode(id.toString()));
            SourceDataset dataset = new SourceDataset();
            dataset.setID(idnum);
            return dataset;
        } catch (NumberFormatException x) {
            if (id.toString().startsWith(DatasetStructuresResource.QR_PREFIX)) {
                String key = id.toString().substring(DatasetStructuresResource.QR_PREFIX.length());
                try {
                    ISourceDataset dataset = new StoredQuery();
                    dataset.setID(Integer.parseInt(key.toString()));
                    return dataset;
                } catch (NumberFormatException xx) {
                    throw new InvalidResourceIDException(id);
                }
            }
        } catch (Exception x) {
            throw new InvalidResourceIDException(id);
        }
    return null;
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) ISourceDataset(ambit2.base.data.ISourceDataset) HashMap(java.util.HashMap) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) ResourceException(org.restlet.resource.ResourceException) IOException(java.io.IOException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Template(org.restlet.routing.Template)

Example 4 with StoredQuery

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

the class DatasetChemicalsQualityStatsResource method createQuery.

@Override
protected DatasetChemicalsQualityStats createQuery(Context context, Request request, Response response) throws ResourceException {
    Form form = getRequest().getResourceRef().getQueryAsForm();
    DatasetChemicalsQualityStats q = new DatasetChemicalsQualityStats(getResourceRef(getRequest()).toString());
    try {
        q.setSummary(Boolean.parseBoolean(form.getFirstValue("summary").toString()));
    } catch (Exception x) {
        q.setSummary(true);
    }
    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.setValue(dataset);
        } 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");
        }
    return q;
}
Also used : Form(org.restlet.data.Form) DatasetChemicalsQualityStats(ambit2.db.facets.qlabel.DatasetChemicalsQualityStats) SourceDataset(ambit2.base.data.SourceDataset) ResourceException(org.restlet.resource.ResourceException) ResourceException(org.restlet.resource.ResourceException)

Example 5 with StoredQuery

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

the class DatasetStructureQualityStatsResource method createQuery.

@Override
protected DatasetStructureQualityStats createQuery(Context context, Request request, Response response) throws ResourceException {
    DatasetStructureQualityStats q = new DatasetStructureQualityStats(getResourceRef(getRequest()).toString());
    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.setValue(dataset);
        } 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");
        }
    return q;
}
Also used : DatasetStructureQualityStats(ambit2.db.facets.qlabel.DatasetStructureQualityStats) SourceDataset(ambit2.base.data.SourceDataset) ResourceException(org.restlet.resource.ResourceException) ResourceException(org.restlet.resource.ResourceException)

Aggregations

StoredQuery (ambit2.db.search.StoredQuery)39 IStoredQuery (ambit2.db.search.IStoredQuery)23 ResourceException (org.restlet.resource.ResourceException)16 SourceDataset (ambit2.base.data.SourceDataset)13 Form (org.restlet.data.Form)10 InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)9 ISourceDataset (ambit2.base.data.ISourceDataset)7 DeleteStoredQuery (ambit2.db.update.storedquery.DeleteStoredQuery)7 Connection (java.sql.Connection)6 QueryStoredResults (ambit2.db.search.structure.QueryStoredResults)5 CreateStoredQuery (ambit2.db.update.storedquery.CreateStoredQuery)5 SessionID (ambit2.db.SessionID)4 Property (ambit2.base.data.Property)3 IStructureRecord (ambit2.base.interfaces.IStructureRecord)3 QueryStructureByID (ambit2.db.search.structure.QueryStructureByID)3 QueryDeleteTemplate (ambit2.db.update.storedquery.QueryDeleteTemplate)3 UpdateStoredQuery (ambit2.db.update.storedquery.UpdateStoredQuery)3 StringRepresentation (org.restlet.representation.StringRepresentation)3 QLabel (ambit2.base.data.QLabel)2 Template (ambit2.base.data.Template)2