use of ambit2.base.data.substance.SubstanceEndpointsBundle 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 ambit2.base.data.substance.SubstanceEndpointsBundle in project ambit-mirror by ideaconsult.
the class StudySearchResource method createQuery.
@Override
protected QueryCountProtocolApplications createQuery(Context context, Request request, Response response) throws ResourceException {
try {
Form form = getRequest().getResourceRef().getQueryAsForm();
mergeDatasets = Boolean.parseBoolean(form.getFirstValue("mergeDatasets"));
} catch (Exception x) {
mergeDatasets = false;
}
Object bundleURI = OpenTox.params.bundle_uri.getFirstValue(getParams());
if (bundleURI != null) {
Integer idbundle = getIdBundle(bundleURI, request);
bundle = new SubstanceEndpointsBundle(idbundle);
}
QueryCountProtocolApplications q = super.createQuery(context, request, response);
try {
q.setMode(_mode_related.valueOf(getParams().getFirstValue("selected")));
} catch (Exception x) {
q.setMode(_mode_related.endpoints);
}
return q;
}
use of ambit2.base.data.substance.SubstanceEndpointsBundle in project ambit-mirror by ideaconsult.
the class UserByURIResource method readBundle.
protected SubstanceEndpointsBundle readBundle(int idbundle) throws ResourceException {
SubstanceEndpointsBundle dataset = new SubstanceEndpointsBundle();
dataset.setID(idbundle);
Connection c = null;
ResultSet rs = null;
QueryExecutor xx = null;
try {
DBConnection dbc = new DBConnection(getContext(), getAmbitConfigFile());
c = dbc.getConnection();
Set<_published_status> status = new TreeSet<_published_status>();
status.add(_published_status.published);
ReadBundle read = new ReadBundle(status);
read.setValue(dataset);
xx = new QueryExecutor();
xx.setConnection(c);
rs = xx.process(read);
while (rs.next()) {
dataset = read.getObject(rs);
}
return dataset;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
} finally {
try {
rs.close();
} catch (Exception x) {
}
try {
c.close();
} catch (Exception x) {
}
try {
xx.close();
} catch (Exception x) {
}
}
}
use of ambit2.base.data.substance.SubstanceEndpointsBundle in project ambit-mirror by ideaconsult.
the class UserByURIResource method createQuery.
@Override
protected ReadUser createQuery(Context context, Request request, Response response) throws ResourceException {
if (!Method.GET.equals(request.getMethod()))
return null;
check(context, request, response);
String usersdbname = getContext().getParameters().getFirstValue(AMBITConfig.users_dbname.name());
Form form = request.getResourceRef().getQueryAsForm();
Object search_value = null;
try {
search_value = form.getFirstValue(param_q);
if (search_value == null)
search_value = form.getFirstValue("search");
if (search_value != null) {
ReadUser query = new ReadUser();
DBUser user = new DBUser();
String s = String.format("^%s", search_value.toString());
user.setLastname(s);
user.setFirstname(s);
query.setValue(user);
addPublicGroup = true;
return query;
}
} catch (Exception x) {
search_value = null;
}
try {
search_value = form.getFirstValue(param_bundle_uri);
Integer idbundle = search_value == null ? null : getIdBundle(search_value, request);
SubstanceEndpointsBundle bundle = readBundle(idbundle);
ReadUserByBundleNumber query = new ReadUserByBundleNumber();
query.setDatabaseName(usersdbname);
query.setFieldname(bundle.getBundle_number().toString());
search_value = form.getFirstValue(param_mode);
if ("W".equals(search_value))
query.setAllowWrite(true);
else
query.setAllowWrite(false);
return query;
} catch (Exception x) {
search_value = null;
}
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
}
use of ambit2.base.data.substance.SubstanceEndpointsBundle in project ambit-mirror by ideaconsult.
the class SimilarityResource method createQuery.
@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
Form form = getResourceRef(getRequest()).getQueryAsForm();
try {
Object bundleURI = OpenTox.params.bundle_uri.getFirstValue(form);
Integer idbundle = bundleURI == null ? null : getIdBundle(bundleURI, request);
SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(idbundle);
bundles = new SubstanceEndpointsBundle[1];
bundles[0] = bundle;
} catch (Exception x) {
bundles = null;
}
try {
includeMol = "true".equals(form.getFirstValue("mol"));
} catch (Exception x) {
includeMol = false;
}
folders = form.getValuesArray("folder");
filterBySubstance = false;
try {
String filter = form.getFirstValue("filterBySubstance");
if (filter != null) {
filter = filter.toLowerCase();
filterBySubstance = "yes".equals(filter) || "on".equals(filter) || "true".equals(filter);
}
} catch (Exception x) {
filterBySubstance = false;
}
QueryAtomEnvironment.q_modifier ae = null;
try {
String filter = form.getFirstValue("mode");
if (filter != null) {
filter = filter.toLowerCase();
ae = QueryAtomEnvironment.q_modifier.valueOf(filter.replace("ae", ""));
}
} catch (Exception x) {
ae = null;
}
mol = getMolecule(form);
if ((mol == null) || (mol.getAtomCount() == 0))
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Empty molecule");
threshold = 0.0;
try {
threshold = new Double(Reference.decode(form.getFirstValue("threshold")));
} catch (Exception x) {
threshold = 0.9;
}
QuerySimilarity q = null;
if (ae != null) {
q = new QueryAtomEnvironment(ae);
try {
q.setValue(getAE(mol));
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
}
} else
try {
q = new QuerySimilarityBitset();
q.setValue(getBitset(mol));
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
}
q.setChemicalsOnly(true);
q.setThreshold(threshold);
q.setCondition(NumberCondition.getInstance(">"));
q.setName("Similarity");
try {
q.setForceOrdering(((AmbitApplication) getApplication()).isSimilarityOrder());
} catch (Exception x) {
q.setForceOrdering(true);
}
try {
if (filterBySubstance) {
ChemicalBySubstanceRelation qa = new ChemicalBySubstanceRelation();
QueryCombinedStructure qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
qc.setScope(qa);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} else if ((folders != null) && (folders.length > 0)) {
ChemicalByQueryFolder qa = new ChemicalByQueryFolder(folders);
QueryCombinedStructure qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
qc.setScope(qa);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} else {
Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
ISourceDataset srcdataset = null;
if (datasetURI != null)
try {
srcdataset = getDataset(datasetURI.toString());
QueryCombinedStructure qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
if (srcdataset instanceof SourceDataset) {
ChemicalByDataset cd = new ChemicalByDataset(new Integer(srcdataset.getID()));
qc.setScope(cd);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} else {
// TODO, resort to all db
}
} catch (Exception x) {
srcdataset = null;
}
QueryCombinedStructure qc = null;
try {
this.dataset_id = Reference.decode(getRequest().getAttributes().get(DatasetResource.datasetKey).toString());
qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
ChemicalByDataset cd = new ChemicalByDataset(new Integer(dataset_id));
qc.setScope(cd);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} catch (Exception x) {
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) q;
}
}
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
}
}
Aggregations