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