Search in sources :

Example 1 with Template

use of org.restlet.routing.Template in project ambit-mirror by ideaconsult.

the class StatisticsResource method createQuery.

@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
    String[] datasetsURI = getParams().getValuesArray(OpenTox.params.dataset_uri.toString());
    Template t = new Template(String.format("%s%s/{%s}", getRequest().getRootRef(), DatasetStructuresResource.dataset, DatasetStructuresResource.datasetKey));
    setStatus(Status.SUCCESS_OK);
    mode = getSearchMode();
    switch(mode) {
        case dataset_intersection:
            {
                QueryCountDatasetIntersection q = null;
                for (int i = 0; i < datasetsURI.length; i++) {
                    if (q == null)
                        q = new QueryCountDatasetIntersection(null);
                    String datasetURI = datasetsURI[i];
                    Map<String, Object> vars = new HashMap<String, Object>();
                    t.parse(datasetURI, vars);
                    if (i == 0)
                        q.setFieldname(vars.get(DatasetStructuresResource.datasetKey).toString());
                    else
                        q.setValue(vars.get(DatasetStructuresResource.datasetKey).toString());
                }
                if (q == null)
                    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Missing dataset_uri parameters!");
                return (Q) q;
            }
        case structures:
            {
                return (Q) new QueryCount<FACET>(mode.getURL());
            }
        case properties:
            {
                return (Q) new QueryCountProperties(mode.getURL());
            }
        case values:
            {
                return (Q) new QueryCountValues(mode.getURL());
            }
        case dataset:
            {
                return (Q) new QueryCountDataset(mode.getURL());
            }
        case models:
            {
                return (Q) new QueryCountModels(mode.getURL());
            }
        case substances:
            {
                return (Q) new QueryCountSubstances(mode.getURL());
            }
        case substancetypes:
            {
                return (Q) new QueryCountSubstanceTypes(mode.getURL());
            }
        case experiment_endpoints:
            {
                QueryCountEndpoints q = new QueryCountEndpoints(mode.getURL());
                q.setFieldname(getParams().getFirstValue("top"));
                q.setValue(getParams().getFirstValue("category"));
                q.setEndpoint(getParams().getFirstValue("search"));
                return (Q) q;
            }
        case protocol_applications:
            {
                QueryCountProtocolApplications q = new QueryCountProtocolApplications(mode.getURL());
                q.setPageSize(1000);
                // ?bundle_uri=
                // Object bundleURI =
                // OpenTox.params.bundle_uri.getFirstValue(getParams());
                Object bundleURI = getParams().getFirstValue("filterbybundle");
                if (bundleURI != null) {
                    Integer idbundle = getIdBundle(bundleURI, request);
                    q.setBundle(new SubstanceEndpointsBundle(idbundle));
                }
                q.setFieldname(getParams().getFirstValue("topcategory"));
                q.setValue(getParams().getFirstValue("category"));
                return (Q) q;
            }
        case data_availability:
            {
                QueryCountProtocolApplications q = new QueryCountProtocolApplications(mode.getURL(), QueryCountProtocolApplications._mode_related.data_availability);
                q.setPageSize(2000);
                q.setFieldname(getParams().getFirstValue("topcategory"));
                q.setValue(getParams().getFirstValue("category"));
                return (Q) q;
            }
        case study_summary:
            {
                QueryCountProtocolApplications q = new QueryCountProtocolApplications(mode.getURL(), QueryCountProtocolApplications._mode_related.detail);
                q.setPageSize(2000);
                // ?bundle_uri=
                // Object bundleURI =
                // OpenTox.params.bundle_uri.getFirstValue(getParams());
                /*
			 * Object bundleURI = getParams().getFirstValue("filterbybundle");
			 * if (bundleURI!=null) { Integer idbundle = getIdBundle(bundleURI,
			 * request); q.setBundle(new SubstanceEndpointsBundle(idbundle)); }
			 */
                q.setFieldname(getParams().getFirstValue("topcategory"));
                q.setValue(getParams().getFirstValue("category"));
                return (Q) q;
            }
        case interpretation_result:
            {
                QueryCountInterpretationResults q = new QueryCountInterpretationResults(mode.getURL());
                q.setFieldname(getParams().getFirstValue("top"));
                q.setValue(getParams().getFirstValue("category"));
                q.setInterpretation_result(getParams().getFirstValue("search"));
                return (Q) q;
            }
        case chemicals_in_dataset:
            {
                QueryCountChemicalInDataset q = null;
                for (int i = 0; i < datasetsURI.length; i++) {
                    if (q == null)
                        q = new QueryCountChemicalInDataset(mode.getURL());
                    String datasetURI = datasetsURI[i];
                    Map<String, Object> vars = new HashMap<String, Object>();
                    t.parse(datasetURI, vars);
                    q.setFieldname(vars.get(DatasetStructuresResource.datasetKey).toString());
                }
                if (q == null)
                    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Missing dataset_uri parameters!");
                return (Q) q;
            }
        case bundles:
            {
                return (Q) new QueryCountBundles(mode.getURL());
            }
        default:
            {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
            }
    }
}
Also used : QueryCountDataset(ambit2.db.update.dataset.QueryCountDataset) QueryCountInterpretationResults(ambit2.db.substance.QueryCountInterpretationResults) QueryCountSubstanceTypes(ambit2.db.substance.QueryCountSubstanceTypes) QueryCountDatasetIntersection(ambit2.db.update.dataset.QueryCountDatasetIntersection) QueryCountChemicalInDataset(ambit2.db.update.dataset.QueryCountChemicalInDataset) QueryCountModels(ambit2.db.model.QueryCountModels) QueryCountProtocolApplications(ambit2.db.substance.QueryCountProtocolApplications) Template(org.restlet.routing.Template) QueryCountSubstances(ambit2.db.substance.QueryCountSubstances) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) QueryCount(ambit2.db.update.dataset.QueryCount) ResourceException(org.restlet.resource.ResourceException) HashMap(java.util.HashMap) Map(java.util.Map) QueryCountProperties(ambit2.db.update.dataset.QueryCountProperties) QueryCountEndpoints(ambit2.db.substance.QueryCountEndpoints) QueryCountValues(ambit2.db.update.dataset.QueryCountValues) QueryCountBundles(ambit2.db.substance.QueryCountBundles)

Example 2 with Template

use of org.restlet.routing.Template 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 3 with Template

use of org.restlet.routing.Template 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 4 with Template

use of org.restlet.routing.Template in project ambit-mirror by ideaconsult.

the class DatasetResource method createQueryIntersection.

protected Q createQueryIntersection(Context context, Request request, Response response) throws ResourceException {
    Form form = getResourceRef(request).getQueryAsForm();
    String[] datasetsURI = form.getValuesArray(dataset_intersection_uri);
    if ((datasetsURI != null) && (datasetsURI.length > 0)) {
        QueryCombinedStructure qc = new QueryCombinedStructure() {

            /**
             */
            private static final long serialVersionUID = -9042008008516030524L;

            @Override
            protected String getMainSQL() {
                return "select idchemical from chemicals\n";
            }

            @Override
            protected String groupBy() {
                return "";
            }
        };
        qc.setChemicalsOnly(true);
        qc.setCombine_as_and(true);
        try {
            ChemicalByDataset cd = new ChemicalByDataset(new Integer(getRequest().getAttributes().get(datasetKey).toString()));
            qc.add(cd);
        } catch (Exception x) {
        }
        Template t = new Template(String.format("%s%s/{%s}", getRequest().getRootRef(), DatasetStructuresResource.dataset, DatasetStructuresResource.datasetKey));
        for (String datasetURI : datasetsURI) {
            Map<String, Object> vars = new HashMap<String, Object>();
            t.parse(datasetURI, vars);
            try {
                qc.add(new ChemicalByDataset(new Integer(vars.get(DatasetStructuresResource.datasetKey).toString())));
            } catch (Exception x) {
            }
        }
        return (Q) qc;
    }
    return null;
}
Also used : ChemicalByDataset(ambit2.db.update.structure.ChemicalByDataset) Form(org.restlet.data.Form) HashMap(java.util.HashMap) ResourceException(org.restlet.resource.ResourceException) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure) Template(org.restlet.routing.Template)

Example 5 with Template

use of org.restlet.routing.Template in project ambit-mirror by ideaconsult.

the class BookmarksAuthorizer method authorize.

@Override
protected boolean authorize(OpenSSOToken ssoToken, Request request) throws Exception {
    if (super.authorize(ssoToken, request)) {
        // parent method only retrieves user name for non-GET
        if (Method.GET.equals(request.getMethod())) {
            try {
                retrieveUserAttributes(ssoToken, request);
            } catch (Exception x) {
            }
        }
        return true;
    }
    Template template1 = new Template(String.format("%s/bookmark/{%s}", request.getRootRef(), BookmarkResource.creator));
    Template template2 = OpenTox.URI.bookmark.getTemplate(request.getRootRef());
    Template template3 = new Template(String.format("%s/bookmark/{%s}/entries", request.getRootRef(), BookmarkResource.creator));
    Template template4 = new Template(String.format("%s/bookmark/{%s}/topics", request.getRootRef(), BookmarkResource.creator));
    Map<String, Object> vars = new HashMap<String, Object>();
    Reference ref = request.getResourceRef().clone();
    ref.setQuery(null);
    template1.parse(ref.toString(), vars);
    template2.parse(ref.toString(), vars);
    template3.parse(ref.toString(), vars);
    template4.parse(ref.toString(), vars);
    try {
        retrieveUserAttributes(ssoToken, request);
    } catch (Exception x) {
        logger.log(Level.WARNING, x.getMessage(), x);
    }
    return request.getClientInfo().getUser().getIdentifier().equals(vars.get(BookmarkResource.creator));
}
Also used : HashMap(java.util.HashMap) Reference(org.restlet.data.Reference) Template(org.restlet.routing.Template)

Aggregations

Template (org.restlet.routing.Template)9 HashMap (java.util.HashMap)8 ResourceException (org.restlet.resource.ResourceException)7 InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)4 ISourceDataset (ambit2.base.data.ISourceDataset)3 SourceDataset (ambit2.base.data.SourceDataset)3 StoredQuery (ambit2.db.search.StoredQuery)3 Form (org.restlet.data.Form)3 ChemicalByDataset (ambit2.db.update.structure.ChemicalByDataset)2 IOException (java.io.IOException)2 Reference (org.restlet.data.Reference)2 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)1 QueryCountModels (ambit2.db.model.QueryCountModels)1 QueryCombinedStructure (ambit2.db.search.structure.QueryCombinedStructure)1 QueryComplement (ambit2.db.search.structure.QueryComplement)1 QueryCountBundles (ambit2.db.substance.QueryCountBundles)1 QueryCountEndpoints (ambit2.db.substance.QueryCountEndpoints)1 QueryCountInterpretationResults (ambit2.db.substance.QueryCountInterpretationResults)1 QueryCountProtocolApplications (ambit2.db.substance.QueryCountProtocolApplications)1 QueryCountSubstanceTypes (ambit2.db.substance.QueryCountSubstanceTypes)1