Search in sources :

Example 1 with ConsensusLabel

use of ambit2.base.data.ConsensusLabel 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 ConsensusLabel

use of ambit2.base.data.ConsensusLabel in project ambit-mirror by ideaconsult.

the class DatasetChemicalsQualityStats method getObject.

@Override
public DatasetConsensusLabelFacet getObject(ResultSet rs) throws AmbitException {
    if (record == null)
        record = createFacet(null);
    try {
        SourceDataset dataset = null;
        Object iddataset = rs.getObject(1);
        String dbname = rs.getString(2);
        if (iddataset != null) {
            dataset = new SourceDataset(dbname);
            dataset.setId(rs.getInt(1));
            record.setDataset(dataset);
        }
        String label = rs.getString("label");
        String text = rs.getString("text");
        record.setValue(String.format("[%s] %s %s", dataset == null ? "Total" : dataset.getName(), label == null ? "All labels" : label, text == null ? "" : text));
        record.setCount(rs.getInt(3));
        ConsensusLabel l = null;
        if (label != null) {
            l = new ConsensusLabel(CONSENSUS_LABELS.valueOf(rs.getString("label")));
            l.setText(text);
        }
        record.setProperty(l);
        return record;
    } catch (Exception x) {
        record.setValue(x.getMessage());
        record.setCount(-1);
        return record;
    }
}
Also used : ConsensusLabel(ambit2.base.data.ConsensusLabel) SourceDataset(ambit2.base.data.SourceDataset) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with ConsensusLabel

use of ambit2.base.data.ConsensusLabel in project ambit-mirror by ideaconsult.

the class QueryStructureByQualityPairLabel method retrieveValue.

@Override
public Object retrieveValue(ResultSet rs) throws SQLException {
    ConsensusLabel q = new ConsensusLabel();
    if (rs.getObject(5) != null)
        q.setLabel(CONSENSUS_LABELS.values()[rs.getInt(5) - 1]);
    q.setText(rs.getString(6));
    return q;
}
Also used : ConsensusLabel(ambit2.base.data.ConsensusLabel)

Aggregations

ConsensusLabel (ambit2.base.data.ConsensusLabel)3 SourceDataset (ambit2.base.data.SourceDataset)2 CONSENSUS_LABELS (ambit2.base.data.ConsensusLabel.CONSENSUS_LABELS)1 StoredQuery (ambit2.db.search.StoredQuery)1 QueryStructureByQualityPairLabel (ambit2.db.search.structure.QueryStructureByQualityPairLabel)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 Form (org.restlet.data.Form)1 ResourceException (org.restlet.resource.ResourceException)1