use of ambit2.db.update.dataset.QueryDatasetByFeatures 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.db.update.dataset.QueryDatasetByFeatures in project ambit-mirror by ideaconsult.
the class QueryDatasetByFeaturesTest method createQuery.
@Override
protected IQueryRetrieval<ISourceDataset> createQuery() throws Exception {
QueryDatasetByFeatures query = new QueryDatasetByFeatures();
Property p = new Property("Property 1");
p.setClazz(null);
p.setLabel(null);
query.setFieldname(p);
return query;
}
Aggregations