Search in sources :

Example 1 with StringCondition

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;
}
Also used : QueryDatasetByFeatures(ambit2.db.update.dataset.QueryDatasetByFeatures) Form(org.restlet.data.Form) AbstractReadDataset(ambit2.db.update.dataset.AbstractReadDataset) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) ResourceException(org.restlet.resource.ResourceException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) StringCondition(net.idea.modbcum.q.conditions.StringCondition) ReadStoredQuery(ambit2.db.update.storedquery.ReadStoredQuery) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) ResourceException(org.restlet.resource.ResourceException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Property(ambit2.base.data.Property) ReadDataset(ambit2.db.update.dataset.ReadDataset) AbstractReadDataset(ambit2.db.update.dataset.AbstractReadDataset)

Example 2 with StringCondition

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;
}
Also used : EndpointCompoundFacetQuery(ambit2.db.facets.datasets.EndpointCompoundFacetQuery) Property(ambit2.base.data.Property) ResourceException(org.restlet.resource.ResourceException) StringCondition(net.idea.modbcum.q.conditions.StringCondition)

Example 3 with StringCondition

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 !");
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) IStructureRecord(ambit2.base.interfaces.IStructureRecord) Form(org.restlet.data.Form) ResourceException(org.restlet.resource.ResourceException) SourceDataset(ambit2.base.data.SourceDataset) QueryStructureType(ambit2.db.search.structure.QueryStructureType) ResourceException(org.restlet.resource.ResourceException) StringCondition(net.idea.modbcum.q.conditions.StringCondition)

Example 4 with StringCondition

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;
}
Also used : QueryField(ambit2.db.search.structure.QueryField) StringCondition(net.idea.modbcum.q.conditions.StringCondition)

Example 5 with StringCondition

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;
}
Also used : QueryField(ambit2.db.search.structure.QueryField) QueryFieldNumeric(ambit2.db.search.structure.QueryFieldNumeric) Property(ambit2.base.data.Property) AbstractStructureQuery(ambit2.db.search.structure.AbstractStructureQuery) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) StringCondition(net.idea.modbcum.q.conditions.StringCondition)

Aggregations

StringCondition (net.idea.modbcum.q.conditions.StringCondition)9 JComboBox (javax.swing.JComboBox)4 ResourceException (org.restlet.resource.ResourceException)4 Property (ambit2.base.data.Property)3 SourceDataset (ambit2.base.data.SourceDataset)2 QueryField (ambit2.db.search.structure.QueryField)2 Form (org.restlet.data.Form)2 ISourceDataset (ambit2.base.data.ISourceDataset)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 EndpointCompoundFacetQuery (ambit2.db.facets.datasets.EndpointCompoundFacetQuery)1 StoredQuery (ambit2.db.search.StoredQuery)1 AbstractStructureQuery (ambit2.db.search.structure.AbstractStructureQuery)1 QueryFieldNumeric (ambit2.db.search.structure.QueryFieldNumeric)1 QueryStructureType (ambit2.db.search.structure.QueryStructureType)1 AbstractReadDataset (ambit2.db.update.dataset.AbstractReadDataset)1 QueryDatasetByFeatures (ambit2.db.update.dataset.QueryDatasetByFeatures)1 ReadDataset (ambit2.db.update.dataset.ReadDataset)1 ReadStoredQuery (ambit2.db.update.storedquery.ReadStoredQuery)1 InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)1 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)1