Search in sources :

Example 11 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class BundleChemicalsResource method setGroupProperties.

protected void setGroupProperties(Context context, Request request, Response response) throws ResourceException {
    groupProperties = new Profile();
    Form form = getParams();
    String[] gp = OpenTox.params.sameas.getValuesArray(form);
    if (gp == null || gp.length == 0)
        gp = new String[] { "http://www.opentox.org/api/1.1#ChemicalName", "http://www.opentox.org/api/1.1#CASRN", "http://www.opentox.org/api/1.1#EINECS" };
    for (String g : gp) {
        Property p = new Property(g);
        p.setEnabled(true);
        p.setLabel(g);
        groupProperties.add(p);
    }
    if (enableFeatures) {
        LiteratureEntry ref = LiteratureEntry.getBundleReference(bundle);
        Property p = new Property("tag", ref);
        p.setEnabled(true);
        groupProperties.add(p);
        p = new Property("remarks", ref);
        p.setEnabled(true);
        groupProperties.add(p);
    }
}
Also used : Form(org.restlet.data.Form) LiteratureEntry(ambit2.base.data.LiteratureEntry) Property(ambit2.base.data.Property) Profile(ambit2.base.data.Profile)

Example 12 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class BundlePropertyResource method createConvertor.

@Override
public IProcessor<Q, Representation> createConvertor(Variant variant) throws AmbitException, ResourceException {
    /* workaround for clients not being able to set accept headers */
    Form acceptform = getResourceRef(getRequest()).getQueryAsForm();
    Dimension d = new Dimension(250, 250);
    try {
        d.width = Integer.parseInt(acceptform.getFirstValue("w").toString());
    } catch (Exception x) {
    }
    try {
        d.height = Integer.parseInt(acceptform.getFirstValue("h").toString());
    } catch (Exception x) {
    }
    String media = acceptform.getFirstValue("accept-header");
    if (media != null)
        variant.setMediaType(new MediaType(media));
    String filenamePrefix = getRequest().getResourceRef().getPath();
    if (variant.getMediaType().equals(MediaType.TEXT_URI_LIST)) {
        QueryURIReporter r = (QueryURIReporter) getURIReporter(getRequest());
        return new StringConvertor(r, MediaType.TEXT_URI_LIST, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.IMAGE_PNG)) {
        return new ImageConvertor(new ImageReporter(variant.getMediaType().getMainType(), variant.getMediaType().getSubType(), d), variant.getMediaType());
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_JAVASCRIPT)) {
        String jsonpcallback = getParams().getFirstValue("jsonp");
        if (jsonpcallback == null)
            jsonpcallback = getParams().getFirstValue("callback");
        return new OutputWriterConvertor(new PropertyJSONReporter(getRequest(), jsonpcallback), MediaType.APPLICATION_JAVASCRIPT);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_RDF_XML) || variant.getMediaType().equals(MediaType.APPLICATION_RDF_TURTLE) || variant.getMediaType().equals(MediaType.TEXT_RDF_N3) || variant.getMediaType().equals(MediaType.TEXT_RDF_NTRIPLES) || variant.getMediaType().equals(ChemicalMediaType.APPLICATION_JSONLD)) {
        RDFJenaConvertor convertor = new RDFJenaConvertor<Property, IQueryRetrieval<Property>>(new PropertyRDFReporter<IQueryRetrieval<Property>>(getRequest(), variant.getMediaType()), variant.getMediaType(), filenamePrefix);
        return convertor;
    } else {
        // (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) {
        return new OutputWriterConvertor(new PropertyJSONReporter(getRequest()), MediaType.APPLICATION_JSON);
    }
}
Also used : PropertyJSONReporter(ambit2.rest.property.PropertyJSONReporter) Form(org.restlet.data.Form) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) StringConvertor(net.idea.restnet.c.StringConvertor) ImageReporter(ambit2.db.reporters.ImageReporter) Dimension(java.awt.Dimension) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) ImageConvertor(ambit2.rest.ImageConvertor) PropertyRDFReporter(ambit2.rest.property.PropertyRDFReporter) ChemicalMediaType(net.idea.restnet.c.ChemicalMediaType) MediaType(org.restlet.data.MediaType) RDFJenaConvertor(ambit2.rest.RDFJenaConvertor) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) Property(ambit2.base.data.Property)

Example 13 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class BundlePropertyResource method createCallable.

@Override
protected CallableProtectedTask<String> createCallable(Method method, Form form, Property item) throws ResourceException {
    SubstanceEndpointsBundle bundle = null;
    Object id = getRequest().getAttributes().get(OpenTox.URI.bundle.getKey());
    if ((id != null))
        try {
            bundle = new SubstanceEndpointsBundle(new Integer(Reference.decode(id.toString())));
        } catch (Exception x) {
        }
    Connection conn = null;
    try {
        PropertyURIReporter r = new PropertyURIReporter(getRequest());
        DBConnection dbc = new DBConnection(getApplication().getContext(), getConfigFile());
        conn = dbc.getConnection(30, true, 8);
        return new CallableEndpointsBundle(bundle, r, method, form, conn, getToken());
    } catch (Exception x) {
        x.printStackTrace();
        try {
            conn.close();
        } catch (Exception xx) {
        }
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
    }
}
Also used : DBConnection(net.idea.restnet.db.DBConnection) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) Connection(java.sql.Connection) DBConnection(net.idea.restnet.db.DBConnection) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter)

Example 14 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class QMapResource method createQuery.

@Override
protected IQueryRetrieval<QMap> createQuery(Context context, Request request, Response response) throws ResourceException {
    QueryQMap query = new QueryQMap();
    Object qid = request.getAttributes().get(QMapResource.qmapKey);
    if (qid != null)
        try {
            query.setValue(new QMap(Integer.parseInt(qid.toString())));
            return query;
        } catch (Exception x) {
        }
    // filter by dataset
    Form form = request.getResourceRef().getQueryAsForm();
    Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
    if (datasetURI != null)
        try {
            int id = (Integer) OpenTox.URI.dataset.getId(Reference.decode(datasetURI.toString().trim()), request.getRootRef());
            QMap map = new QMap();
            map.setDataset(new SourceDataset());
            map.getDataset().setID(id);
            query.setValue(map);
        } catch (Exception x) {
        /* ignore the filter */
        }
    Object propertyURI = OpenTox.params.feature_uris.getFirstValue(form);
    if (propertyURI != null)
        try {
            int id = (Integer) OpenTox.URI.feature.getId(Reference.decode(propertyURI.toString().trim()), request.getRootRef());
            if (query.getValue() == null)
                query.setValue(new QMap());
            Property p = new Property(null);
            p.setId(id);
            query.getValue().setProperty(p);
        } catch (Exception x) {
        /* ignore the filter */
        }
    return query;
}
Also used : Form(org.restlet.data.Form) SourceDataset(ambit2.base.data.SourceDataset) Property(ambit2.base.data.Property) QueryQMap(ambit2.db.simiparity.space.QueryQMap) QMap(ambit2.db.simiparity.space.QMap) QueryQMap(ambit2.db.simiparity.space.QueryQMap) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException)

Example 15 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class QMapSpaceResource method createQuery.

@Override
protected IQueryRetrieval<QMapSpace> createQuery(Context context, Request request, Response response) throws ResourceException {
    QueryQMapSpace query = new QueryQMapSpace();
    Form form = request.getResourceRef().getQueryAsForm();
    try {
        query.setThreshold_a(Integer.parseInt(form.getFirstValue("thresholda")));
    } catch (Exception x) {
        query.setThreshold_a(0);
    }
    Object qmapURI = OpenTox.params.qmap_uri.getFirstValue(form);
    if (qmapURI != null)
        try {
            int id = (Integer) OpenTox.URI.qmap.getId(Reference.decode(qmapURI.toString().trim()), request.getRootRef());
            query.setValue(new QMap(id));
            return query;
        } catch (Exception x) {
        /* ignore the filter */
        }
    // filter by dataset
    Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
    if (datasetURI != null)
        try {
            int id = (Integer) OpenTox.URI.dataset.getId(Reference.decode(datasetURI.toString().trim()), request.getRootRef());
            QMap map = new QMap();
            map.setDataset(new SourceDataset());
            map.getDataset().setID(id);
            query.setValue(map);
        } catch (Exception x) {
        /* ignore the filter */
        }
    Object propertyURI = OpenTox.params.feature_uris.getFirstValue(form);
    if (propertyURI != null)
        try {
            int id = (Integer) OpenTox.URI.feature.getId(Reference.decode(propertyURI.toString().trim()), request.getRootRef());
            if (query.getValue() == null)
                query.setValue(new QMap());
            Property p = new Property(null);
            p.setId(id);
            query.getValue().setProperty(p);
        } catch (Exception x) {
        /* ignore the filter */
        }
    return query;
}
Also used : Form(org.restlet.data.Form) QueryQMapSpace(ambit2.db.simiparity.space.QueryQMapSpace) SourceDataset(ambit2.base.data.SourceDataset) Property(ambit2.base.data.Property) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) QMap(ambit2.db.simiparity.space.QMap)

Aggregations

Property (ambit2.base.data.Property)247 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)113 Test (org.junit.Test)69 IStructureRecord (ambit2.base.interfaces.IStructureRecord)56 ResourceException (org.restlet.resource.ResourceException)46 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)44 ITable (org.dbunit.dataset.ITable)44 Reference (org.restlet.data.Reference)37 LiteratureEntry (ambit2.base.data.LiteratureEntry)36 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)28 InputStream (java.io.InputStream)27 StructureRecord (ambit2.base.data.StructureRecord)26 Form (org.restlet.data.Form)25 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)24 ResourceTest (ambit2.rest.test.ResourceTest)22 PropertyAnnotation (ambit2.base.data.PropertyAnnotation)19 SourceDataset (ambit2.base.data.SourceDataset)16 Template (ambit2.base.data.Template)16