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);
}
}
}
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;
}
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;
}
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;
}
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));
}
Aggregations