Search in sources :

Example 1 with InvalidResourceIDException

use of ambit2.rest.error.InvalidResourceIDException 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 2 with InvalidResourceIDException

use of ambit2.rest.error.InvalidResourceIDException 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)

Example 3 with InvalidResourceIDException

use of ambit2.rest.error.InvalidResourceIDException in project ambit-mirror by ideaconsult.

the class ChemicalSpaceResource method getQueryById.

@Override
protected Q getQueryById(String key) throws ResourceException {
    if (key.startsWith(DatasetStructuresResource.QR_PREFIX)) {
        key = key.substring(DatasetStructuresResource.QR_PREFIX.length());
        try {
            queryResultsID = Integer.parseInt(key.toString());
        } catch (NumberFormatException x) {
            throw new InvalidResourceIDException(key);
        }
        ChemicalSpaceQuery q = new ChemicalSpaceQuery();
        q.setValue(getProperty());
        StoredQuery dataset = new StoredQuery();
        dataset.setID(queryResultsID);
        q.setFieldname(dataset);
        Form form = getResourceRef(getRequest()).getQueryAsForm();
        try {
            q.setMaxPoints(Integer.parseInt(form.getFirstValue("resolution")));
        } catch (Exception x) {
        // default
        }
        setPaging(form, q);
        return (Q) q;
    }
    // else return getDatasetByName(key);
    throw new InvalidResourceIDException(key);
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) Form(org.restlet.data.Form) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) ChemicalSpaceQuery(ambit2.db.search.structure.pairwise.ChemicalSpaceQuery) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) ResourceException(org.restlet.resource.ResourceException)

Example 4 with InvalidResourceIDException

use of ambit2.rest.error.InvalidResourceIDException in project ambit-mirror by ideaconsult.

the class DatasetQueryCombined 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) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Template(org.restlet.routing.Template)

Example 5 with InvalidResourceIDException

use of ambit2.rest.error.InvalidResourceIDException in project ambit-mirror by ideaconsult.

the class QueryStructureRelationResource method getQueryById.

@Override
protected Q getQueryById(String key) throws ResourceException {
    if (key.startsWith(DatasetStructuresResource.QR_PREFIX)) {
        key = key.substring(DatasetStructuresResource.QR_PREFIX.length());
        try {
            queryResultsID = Integer.parseInt(key.toString());
        } catch (NumberFormatException x) {
            throw new InvalidResourceIDException(key);
        }
        ReadDatasetRelation q = new ReadDatasetRelation();
        q.setFieldname(relation.name());
        StoredQuery dataset = new StoredQuery();
        dataset.setID(queryResultsID);
        q.setValue(dataset);
        Form form = getResourceRef(getRequest()).getQueryAsForm();
        setPaging(form, q);
        return (Q) q;
    }
    // else return getDatasetByName(key);
    throw new InvalidResourceIDException(key);
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) Form(org.restlet.data.Form) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) ReadDatasetRelation(ambit2.db.chemrelation.ReadDatasetRelation)

Aggregations

InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)15 ResourceException (org.restlet.resource.ResourceException)10 Form (org.restlet.data.Form)9 StoredQuery (ambit2.db.search.StoredQuery)8 ISourceDataset (ambit2.base.data.ISourceDataset)6 SourceDataset (ambit2.base.data.SourceDataset)5 Property (ambit2.base.data.Property)4 HashMap (java.util.HashMap)4 Template (org.restlet.routing.Template)4 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 IStructureRecord (ambit2.base.interfaces.IStructureRecord)2 AbstractDataset (ambit2.base.data.AbstractDataset)1 StructureRecord (ambit2.base.data.StructureRecord)1 ReadDatasetRelation (ambit2.db.chemrelation.ReadDatasetRelation)1 IStoredQuery (ambit2.db.search.IStoredQuery)1 QueryPairwiseTanimoto (ambit2.db.search.property.QueryPairwiseTanimoto)1 RetrieveFieldNamesByAlias (ambit2.db.search.property.RetrieveFieldNamesByAlias)1 QueryCombinedStructure (ambit2.db.search.structure.QueryCombinedStructure)1 QueryStoredResults (ambit2.db.search.structure.QueryStoredResults)1 QueryStoredResultsByName (ambit2.db.search.structure.QueryStoredResultsByName)1