Search in sources :

Example 1 with SourceDataset

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

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

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

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

the class MetadatasetResource method createObjectFromWWWForm.

// udpate support
@Override
protected M createObjectFromWWWForm(Representation entity) throws ResourceException {
    Form form = new Form(entity);
    // only name and license updated
    SourceDataset dataset = new SourceDataset();
    dataset.setName(form.getFirstValue(ISourceDataset.fields.title.name()));
    String licenseOptions = form.getFirstValue("licenseOptions");
    String license = form.getFirstValue(ISourceDataset.fields.license.name());
    if ((licenseOptions == null) || "Other".equals(licenseOptions))
        dataset.setLicenseURI(license);
    else
        dataset.setLicenseURI(licenseOptions);
    dataset.setrightsHolder(form.getFirstValue(ISourceDataset.fields.rightsHolder.name()));
    return (M) dataset;
}
Also used : Form(org.restlet.data.Form) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset)

Example 5 with SourceDataset

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

the class MetadatasetResource method getQuery.

protected IQueryRetrieval<M> getQuery(Context context, Request request, Response response, boolean IDcanBeEmpty) throws ResourceException {
    Form form = getResourceRef(request).getQueryAsForm();
    try {
        headless = Boolean.parseBoolean(form.getFirstValue("headless"));
    } catch (Exception x) {
        headless = false;
    }
    AbstractReadDataset query = null;
    structureParam = getStructureParameter();
    StringCondition condition;
    try {
        condition = StringCondition.getInstance(form.getFirstValue(QueryResource.condition));
    } catch (Exception x) {
        condition = StringCondition.getInstance(StringCondition.C_EQ);
    }
    Property property = new Property(null);
    property.setClazz(null);
    property.setLabel(null);
    property.setReference(null);
    for (search_features sf : search_features.values()) {
        Object id = form.getFirstValue(sf.name());
        if (id != null) {
            // because we are not storing full local references!
            if (search_features.feature_hassource.equals(sf)) {
                String parent = getRequest().getRootRef().toString();
                int p = id.toString().indexOf(parent);
                if (p >= 0) {
                    // yet one more hack ... should store at least prefixes
                    id = id.toString().substring(p + parent.length()).replace("/algorithm/", "").replace("/model/", "");
                }
            }
            sf.setProperty(property, id);
            if (query == null) {
                query = new QueryDatasetByFeatures(property, condition);
                ((QueryDatasetByFeatures) query).setStructure(structureParam);
            }
        }
    }
    if (query == null) {
        query = new ReadDataset();
        query.setValue(null);
    }
    Object id = request.getAttributes().get(DatasetStructuresResource.datasetKey);
    if (id != null)
        try {
            Integer idnum = new Integer(Reference.decode(id.toString()));
            dataset = (M) new SourceDataset();
            dataset.setID(idnum);
            query.setValue(dataset);
        } catch (NumberFormatException x) {
            if (id.toString().startsWith(DatasetStructuresResource.QR_PREFIX)) {
                String key = id.toString().substring(DatasetStructuresResource.QR_PREFIX.length());
                try {
                    IQueryRetrieval<M> q = (IQueryRetrieval<M>) new ReadStoredQuery(Integer.parseInt(key.toString()));
                    return q;
                } catch (NumberFormatException xx) {
                    throw new InvalidResourceIDException(id);
                }
            } else {
                dataset = (M) new SourceDataset();
                dataset.setName(id.toString());
                query.setValue(dataset);
            }
        } catch (Exception x) {
            throw new InvalidResourceIDException(id);
        }
    if (!IDcanBeEmpty && (query.getValue() == null))
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty dataset ID!");
    return query;
}
Also used : QueryDatasetByFeatures(ambit2.db.update.dataset.QueryDatasetByFeatures) Form(org.restlet.data.Form) AbstractReadDataset(ambit2.db.update.dataset.AbstractReadDataset) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) ResourceException(org.restlet.resource.ResourceException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) StringCondition(net.idea.modbcum.q.conditions.StringCondition) ReadStoredQuery(ambit2.db.update.storedquery.ReadStoredQuery) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) ResourceException(org.restlet.resource.ResourceException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Property(ambit2.base.data.Property) ReadDataset(ambit2.db.update.dataset.ReadDataset) AbstractReadDataset(ambit2.db.update.dataset.AbstractReadDataset)

Aggregations

SourceDataset (ambit2.base.data.SourceDataset)84 ISourceDataset (ambit2.base.data.ISourceDataset)33 ResourceException (org.restlet.resource.ResourceException)31 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)22 Form (org.restlet.data.Form)22 IStructureRecord (ambit2.base.interfaces.IStructureRecord)19 Property (ambit2.base.data.Property)11 RepositoryWriter (ambit2.db.processors.RepositoryWriter)10 Reference (org.restlet.data.Reference)10 StoredQuery (ambit2.db.search.StoredQuery)9 InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)8 Test (org.junit.Test)8 StructureRecord (ambit2.base.data.StructureRecord)7 LiteratureEntry (ambit2.base.data.LiteratureEntry)6 ReadDataset (ambit2.db.update.dataset.ReadDataset)6 ResourceTest (ambit2.rest.test.ResourceTest)6 ResultSet (java.sql.ResultSet)6 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)6 ITable (org.dbunit.dataset.ITable)6 StringRepresentation (org.restlet.representation.StringRepresentation)6