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) {
}
}
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations