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