Search in sources :

Example 1 with Profile

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

the class AmbitFacetResource method getProperty.

protected Template getProperty(String[] propertyURI, int max) throws ResourceException {
    if (propertyURI == null)
        return null;
    Template profile = new Template();
    Connection connection = null;
    try {
        DBConnection dbc = new DBConnection(getContext());
        connection = dbc.getConnection();
        ProfileReader reader = new ProfileReader(getRequest().getRootRef(), profile, getApplication().getContext(), getToken(), getRequest().getCookies(), getRequest().getClientInfo() == null ? null : getRequest().getClientInfo().getAgent(), getRequest().getResourceRef().toString());
        reader.setCloseConnection(false);
        reader.setConnection(connection);
        for (int i = 0; i < propertyURI.length; i++) {
            reader.process(new Reference(propertyURI[i]));
            if ((i + 1) >= max)
                break;
        }
        return profile;
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    } finally {
        try {
            connection.close();
        } catch (Exception x) {
        }
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) ProfileReader(ambit2.rest.property.ProfileReader) Reference(org.restlet.data.Reference) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) Template(ambit2.base.data.Template)

Example 2 with Profile

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

the class ChartResource method createImage.

protected BufferedImage createImage() throws ResourceException {
    BufferedImage image = null;
    Connection connection = null;
    try {
        DBConnection dbc = new DBConnection(getContext());
        connection = dbc.getConnection();
        ambit2.base.data.Template profile = new ambit2.base.data.Template();
        ProfileReader reader = new ProfileReader(getRequest().getRootRef(), profile, getApplication().getContext(), getToken(), getRequest().getCookies(), getRequest().getClientInfo() == null ? null : getRequest().getClientInfo().getAgent(), getRequest().getResourceRef().toString());
        reader.setCloseConnection(false);
        reader.setConnection(connection);
        for (String p : property) reader.process(new Reference(p));
        switch(mode) {
            case pie:
                {
                    Iterator<Property> i = profile.getProperties(true);
                    while (i.hasNext()) {
                        PieChartGenerator<ISourceDataset> chart = new PieChartGenerator<ISourceDataset>();
                        chart.setProperty(i.next());
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        image = chart.process(dataset);
                        // ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
                        break;
                    }
                    break;
                }
            case histogram:
                {
                    Iterator<Property> i = profile.getProperties(true);
                    while (i.hasNext()) {
                        HistogramChartGenerator chart = new HistogramChartGenerator();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setMinX(minX);
                        chart.setMaxX(maxX);
                        chart.setPropertyX(i.next());
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                        // ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
                        break;
                    }
                    break;
                }
            case xy:
                {
                    Property[] p = new Property[2];
                    int i = 0;
                    Iterator<Property> it = profile.getProperties(true);
                    while (it.hasNext()) {
                        p[i] = it.next();
                        i++;
                        if (i >= 2)
                            break;
                    }
                    PropertiesChartGenerator chart = new PropertiesChartGenerator();
                    chart.setLogX(logX);
                    chart.setLogY(logY);
                    chart.setThumbnail(thumbnail);
                    chart.setPropertyX(p[0]);
                    chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
                    chart.setConnection(connection);
                    chart.setWidth(w);
                    chart.setHeight(h);
                    chart.setLegend(legend);
                    image = chart.process(dataset);
                    break;
                }
            case bar:
                {
                    Property[] p = new Property[2];
                    int i = 0;
                    Iterator<Property> it = profile.getProperties(true);
                    while (it.hasNext()) {
                        p[i] = it.next();
                        i++;
                        if (i >= 2)
                            break;
                    }
                    if (i == 0) {
                        FingerprintHistogramDataset chart = new FingerprintHistogramDataset();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setParam(param);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                    } else {
                        BarChartGeneratorDataset chart = new BarChartGeneratorDataset();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setPropertyX(p[0]);
                        chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                    }
                    break;
                }
            default:
                {
                    image = null;
                }
        }
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    } finally {
        try {
            connection.close();
        } catch (Exception x) {
        }
    }
    if (image == null)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    return image;
}
Also used : DBConnection(ambit2.rest.DBConnection) ProfileReader(ambit2.rest.property.ProfileReader) Reference(org.restlet.data.Reference) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) BufferedImage(java.awt.image.BufferedImage) ResourceException(org.restlet.resource.ResourceException) IOException(java.io.IOException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Template(org.restlet.routing.Template) PropertiesChartGenerator(ambit2.db.chart.PropertiesChartGenerator) ISourceDataset(ambit2.base.data.ISourceDataset) BarChartGeneratorDataset(ambit2.db.chart.BarChartGeneratorDataset) Iterator(java.util.Iterator) PieChartGenerator(ambit2.db.chart.PieChartGenerator) ResourceException(org.restlet.resource.ResourceException) HistogramChartGenerator(ambit2.db.chart.HistogramChartGenerator) FingerprintHistogramDataset(ambit2.db.chart.FingerprintHistogramDataset)

Example 3 with Profile

use of ambit2.base.data.Profile 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 4 with Profile

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

the class QueryResource method createTemplate.

protected Template createTemplate(Context context, Request request, Response response, String[] featuresURI) throws ResourceException {
    Connection conn = null;
    try {
        Template profile = new Template(null);
        profile.setId(-1);
        ProfileReader reader = new ProfileReader(getRequest().getRootRef(), profile, getApplication().getContext(), getToken(), getRequest().getCookies(), getRequest().getClientInfo() == null ? null : getRequest().getClientInfo().getAgent(), getRequest().getResourceRef().toString());
        reader.setCloseConnection(false);
        DBConnection dbc = new DBConnection(getApplication().getContext());
        conn = dbc.getConnection(30, true, 5);
        try {
            for (String featureURI : featuresURI) {
                if (featureURI == null)
                    continue;
                reader.setConnection(conn);
                profile = reader.process(new Reference(featureURI));
                reader.setProfile(profile);
            }
            // readFeatures(featureURI, profile);
            if (profile.size() == 0) {
                reader.setConnection(conn);
                String templateuri = getDefaultTemplateURI(context, request, response);
                if (templateuri != null)
                    profile = reader.process(new Reference(templateuri));
                reader.setProfile(profile);
            }
        } catch (Exception x) {
            getLogger().log(Level.SEVERE, x.getMessage(), x);
        } finally {
            // the reader closes the connection
            reader.setCloseConnection(true);
            try {
                reader.close();
            } catch (Exception x) {
            }
        // System.out.println("Closed "+conn.isClosed());
        // try { conn.close();} catch (Exception x) {}
        }
        return profile;
    } catch (Exception x) {
        getLogger().log(Level.SEVERE, x.getMessage(), x);
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception xx) {
        }
        throw new ResourceException(Status.CLIENT_ERROR_REQUEST_TIMEOUT, x);
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) ProfileReader(ambit2.rest.property.ProfileReader) Reference(org.restlet.data.Reference) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) Template(ambit2.base.data.Template)

Example 5 with Profile

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

the class PropertiesByDatasetResource method createTemplate.

protected Template createTemplate(Form form) throws ResourceException {
    Object featureid = getRequest().getAttributes().get(PropertiesByDatasetResource.idfeaturedef);
    if (featureid != null)
        try {
            Template profile = new Template(null);
            Property p = new Property(null);
            p.setEnabled(true);
            p.setId(Integer.parseInt(featureid.toString()));
            profile.add(p);
            return profile;
        } catch (Exception x) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
        }
    String[] featuresURI = OpenTox.params.feature_uris.getValuesArray(form);
    if (featuresURI != null)
        return createTemplate(getContext(), getRequest(), getResponse(), featuresURI);
    else
        return null;
}
Also used : ResourceException(org.restlet.resource.ResourceException) Property(ambit2.base.data.Property) ResourceException(org.restlet.resource.ResourceException) Template(ambit2.base.data.Template)

Aggregations

Property (ambit2.base.data.Property)18 Profile (ambit2.base.data.Profile)9 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)8 Template (ambit2.base.data.Template)7 ResourceException (org.restlet.resource.ResourceException)7 ProfileListModel (ambit2.base.data.ProfileListModel)4 ProfileReader (ambit2.rest.property.ProfileReader)4 Connection (java.sql.Connection)4 Reference (org.restlet.data.Reference)4 StoredQuery (ambit2.db.search.StoredQuery)3 DBConnection (ambit2.rest.DBConnection)3 Test (org.junit.Test)3 ISourceDataset (ambit2.base.data.ISourceDataset)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)2 SourceDataset (ambit2.base.data.SourceDataset)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)2 ProcessorException (ambit2.base.processors.ProcessorException)2 StoredQueryTableModel (ambit2.db.results.StoredQueryTableModel)2 IStoredQuery (ambit2.db.search.IStoredQuery)2 RetrieveProfile (ambit2.db.search.property.RetrieveProfile)2