use of ambit2.base.ro.SubstanceRecordAnnotationProcessor in project ambit-mirror by ideaconsult.
the class SubstanceExportResource method createJSONReporter.
@Override
protected IProcessor<Q, Representation> createJSONReporter(String filenamePrefix) {
String jsonpcallback = getParams().getFirstValue("jsonp");
if (jsonpcallback == null)
jsonpcallback = getParams().getFirstValue("callback");
String command = "results";
try {
if (Boolean.parseBoolean(getParams().getFirstValue("array").toString()))
command = null;
} catch (Exception x) {
}
ProcessorsChain chain = new ProcessorsChain<>();
chain.add(new SubstanceStudyDetailsProcessor());
getCompositionProcessors(chain);
SubstanceRecordAnnotationProcessor annotator = null;
try {
annotator = new SubstanceRecordAnnotationProcessor(new File(((AmbitFreeMarkerApplication) getApplication()).getProperties().getMapFolder()), false);
} catch (Exception x) {
Logger.getGlobal().log(Level.WARNING, x.getMessage());
annotator = null;
}
return new OutputWriterConvertor<SubstanceRecord, Q>((QueryAbstractReporter<SubstanceRecord, Q, Writer>) new Substance2BucketJsonReporter(command, chain, jsonmode, summaryMeasurement, dbTag, annotator), jsonpcallback == null ? MediaType.APPLICATION_JSON : MediaType.APPLICATION_JAVASCRIPT, filenamePrefix);
}
use of ambit2.base.ro.SubstanceRecordAnnotationProcessor in project ambit-mirror by ideaconsult.
the class SubstanceResource 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();
String configResource = String.format("config-%s.js", ((IFreeMarkerApplication) getApplication()).getProfile());
try {
retrieveStudySummary = Boolean.parseBoolean(acceptform.getFirstValue("studysummary"));
} catch (Exception x) {
retrieveStudySummary = false;
}
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)) {
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) {
}
return new ImageConvertor(new ImageReporter(variant.getMediaType().getMainType(), variant.getMediaType().getSubType(), d), variant.getMediaType());
} else if (variant.getMediaType().equals(MediaType.TEXT_CSV)) {
SubstanceCSVReporter csvreporter = new SubstanceCSVReporter(getRequest(), bundles);
return new OutputWriterConvertor<SubstanceRecord, Q>(csvreporter, MediaType.TEXT_CSV, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_MSOFFICE_XLSX)) {
SubstanceRecordXLSXReporter xlsxreporter = new SubstanceRecordXLSXReporter(getRequest().getRootRef().toString(), false, bundles, configResource);
return new OutputStreamConvertor<SubstanceRecord, Q>(xlsxreporter, MediaType.APPLICATION_MSOFFICE_XLSX, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_EXCEL)) {
SubstanceRecordXLSXReporter xlsxreporter = new SubstanceRecordXLSXReporter(getRequest().getRootRef().toString(), true, bundles, configResource);
return new OutputStreamConvertor<SubstanceRecord, Q>(xlsxreporter, MediaType.APPLICATION_EXCEL, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_RDF_XML) || // filenamePrefix);
variant.getMediaType().equals(MediaType.APPLICATION_RDF_TURTLE) || variant.getMediaType().equals(MediaType.TEXT_RDF_NTRIPLES) || variant.getMediaType().equals(MediaType.TEXT_RDF_N3) || variant.getMediaType().equals(ChemicalMediaType.APPLICATION_JSONLD)) {
SubstanceRecordAnnotationProcessor annotator = null;
try {
annotator = new SubstanceRecordAnnotationProcessor(new File(((AmbitFreeMarkerApplication) getApplication()).getProperties().getMapFolder()), false);
} catch (Exception x) {
Logger.getGlobal().log(Level.WARNING, x.getMessage());
annotator = null;
}
return new RDFJenaConvertor(new SubstanceRDFReporter(getRequest(), variant.getMediaType(), annotator), variant.getMediaType(), filenamePrefix) {
@Override
protected OntModel createOutput(IQueryRetrieval query) throws AmbitException {
try {
OntModel jenaModel = OT.createModel();
jenaModel.setNsPrefix("sio", "http://semanticscience.org/resource/");
jenaModel.setNsPrefix("obo", "http://purl.obolibrary.org/obo/");
jenaModel.setNsPrefix("bao", "http://www.bioassayontology.org/bao#");
jenaModel.setNsPrefix("npo", "http://purl.bioontology.org/ontology/npo/");
jenaModel.setNsPrefix("enm", "http://purl.enanomapper.org/onto/");
return jenaModel;
} catch (Exception x) {
throw new AmbitException(x);
}
}
};
} else if (variant.getMediaType().equals(ISAJSON)) {
return new OutputStreamConvertor<SubstanceRecord, Q>(createISAReporter(getRequest()), MediaType.APPLICATION_JAVASCRIPT, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_JAVASCRIPT)) {
return createJSONReporter(filenamePrefix);
} else
// json by default
return createJSONReporter(filenamePrefix);
}
Aggregations