use of net.idea.modbcum.q.conditions.StringCondition 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 net.idea.modbcum.q.conditions.StringCondition in project ambit-mirror by ideaconsult.
the class DatasetsByEndpoint method createQuery.
@Override
protected EndpointCompoundFacetQuery createQuery(Context context, Request request, Response response) throws ResourceException {
String endpoint = getParams().getFirstValue(MetadatasetResource.search_features.feature_sameas.toString());
EndpointCompoundFacetQuery q = new EndpointCompoundFacetQuery(getResourceRef(getRequest()).toString());
Property p = null;
if (endpoint != null) {
p = new Property("");
p.setLabel(endpoint);
q.setFieldname(p);
}
q.setValue(getStructure());
StringCondition c = StringCondition.getInstance(StringCondition.C_REGEXP);
String param = getParams().getFirstValue(QueryResource.condition.toString());
try {
if (param != null) {
if ("startswith".equals(param.toLowerCase()))
q.setCondition(StringCondition.getInstance(StringCondition.C_STARTS_WITH));
else
c = StringCondition.getInstance(param);
}
} catch (Exception x) {
} finally {
q.setCondition(c);
}
return q;
}
use of net.idea.modbcum.q.conditions.StringCondition in project ambit-mirror by ideaconsult.
the class StrucTypeQueryResource method createQuery.
@Override
protected IQueryRetrieval<IStructureRecord> createQuery(Context context, Request request, Response response) throws ResourceException {
QueryStructureType q = new QueryStructureType();
Form form = request.getResourceRef().getQueryAsForm();
try {
includeMol = "true".equals(form.getFirstValue("mol"));
} catch (Exception x) {
includeMol = false;
}
Object key = form.getFirstValue(QueryResource.search_param);
if (key != null) {
try {
key = Reference.decode(key.toString());
for (IStructureRecord.STRUC_TYPE ts : IStructureRecord.STRUC_TYPE.values()) if (ts.toString().equals(key.toString())) {
q.setValue(ts);
break;
}
} catch (Exception x) {
StringBuilder b = new StringBuilder();
b.append("Valid values are ");
for (IStructureRecord.STRUC_TYPE v : IStructureRecord.STRUC_TYPE.values()) {
b.append(v);
b.append('\t');
}
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, b.toString(), x);
}
} else {
q.setValue(IStructureRecord.STRUC_TYPE.D3withH);
}
key = form.getFirstValue(QueryResource.condition);
try {
q.setCondition(new StringCondition(StringCondition.STRING_CONDITION.valueOf(key.toString())));
} catch (Exception x) {
}
Object id = request.getAttributes().get(OpenTox.URI.dataset.getKey());
if (id != null)
try {
datasetID = Integer.parseInt(id.toString());
SourceDataset dataset = new SourceDataset();
dataset.setId(datasetID);
q.setFieldname(dataset);
return q;
} catch (Exception x) {
if (id.toString().startsWith("R")) {
queryResultsID = Integer.parseInt(id.toString().substring(1));
StoredQuery dataset = new StoredQuery();
dataset.setId(queryResultsID);
q.setFieldname(dataset);
return q;
} else
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid dataset id");
}
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No dataset !");
}
use of net.idea.modbcum.q.conditions.StringCondition in project ambit-mirror by ideaconsult.
the class CompoundLookup method getTextQuery.
protected QueryField getTextQuery(Property property, boolean caseSensitive, boolean retrieveProperties, String value) {
if (value.startsWith(chebiuri))
value = value.replace(chebiuri, "");
StringCondition sc = StringCondition.getInstance(getCondition());
// TODO check for regexp validity
QueryField q_by_name = new QueryField();
q_by_name.setFieldname(property);
q_by_name.setCaseSensitive(caseSensitive);
q_by_name.setRetrieveProperties(retrieveProperties);
q_by_name.setSearchByAlias(true);
q_by_name.setNameCondition(StringCondition.getInstance(StringCondition.C_EQ));
q_by_name.setCondition(sc);
q_by_name.setChemicalsOnly(true);
q_by_name.setValue(value == null ? null : value.toString());
return q_by_name;
}
use of net.idea.modbcum.q.conditions.StringCondition in project ambit-mirror by ideaconsult.
the class CompoundResource method createSingleQuery.
protected IQueryRetrieval<IStructureRecord> createSingleQuery(String property, String cond, String key, boolean chemicalsOnly, boolean byAlias, boolean caseSens) {
AbstractStructureQuery query;
try {
key = Reference.decode(key.toString().trim());
query = new QueryFieldNumeric(key, cond, byAlias, chemicalsOnly, (property == null) ? null : new Property(property, null));
} catch (Exception x) {
QueryField q_by_name = new QueryField();
q_by_name.setCaseSensitive(caseSens);
q_by_name.setRetrieveProperties(true);
q_by_name.setSearchByAlias(byAlias);
q_by_name.setNameCondition(StringCondition.getInstance(StringCondition.C_EQ));
q_by_name.setChemicalsOnly(chemicalsOnly);
// q_by_name.setChemicalsOnly(true);
StringCondition condition = StringCondition.getInstance(StringCondition.C_EQ);
try {
condition = (cond == null) || ("".equals(cond)) ? StringCondition.getInstance(StringCondition.C_EQ) : StringCondition.getInstance(cond);
} catch (Exception xx) {
condition = StringCondition.getInstance(StringCondition.C_EQ);
} finally {
q_by_name.setCondition(condition);
q_by_name.setValue(String.format("%s%s", Reference.decode(key.toString()), condition.toString().equals(StringCondition.C_LIKE) ? "%" : ""));
if ((property != null) && (!"".equals(property)))
q_by_name.setFieldname(new Property(String.format("%s%s", property, condition.toString().equals(StringCondition.C_LIKE) ? "%" : ""), null));
}
query = q_by_name;
}
return query;
}
Aggregations