use of ambit2.rest.OutputStreamConvertor in project ambit-mirror by ideaconsult.
the class AssayTemplateResource 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 media = acceptform.getFirstValue("accept-header");
if (media != null)
variant.setMediaType(new MediaType(media));
if (variant.getMediaType().equals(MediaType.APPLICATION_MSOFFICE_XLSX)) {
AssayTemplateEntrySpreadsheetReporter reporter = new AssayTemplateEntrySpreadsheetReporter(settings.getTemplatesType(), settings.getLayout_raw_data(), settings.getNumber_of_experiments(), settings.getNumber_of_endpoints(), settings.getNumber_of_replicates(), settings.getNumber_of_timepoints(), settings.getNumber_of_concentration());
return new OutputStreamConvertor(reporter, MediaType.APPLICATION_MSOFFICE_XLSX, settings.getOutputFileName()) {
protected void setDisposition(Representation rep) {
super.setDisposition(rep);
rep.setDownloadName(settings.getOutputFileName());
}
};
} else {
// json by default
return new StringConvertor(new AssayTemplateEntryJSONReporter(getRequest()), MediaType.APPLICATION_JSON, null);
}
}
use of ambit2.rest.OutputStreamConvertor 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);
}
use of ambit2.rest.OutputStreamConvertor in project ambit-mirror by ideaconsult.
the class SubstanceDatasetResource method createXLSXReporter.
protected IProcessor<Q, Representation> createXLSXReporter(MediaType media, boolean hssf, String filenamePrefix) {
groupProperties.add(new SubstancePublicName());
groupProperties.add(new SubstanceName());
groupProperties.add(new SubstanceUUID());
groupProperties.add(new SubstanceOwner());
String jsonpcallback = getParams().getFirstValue("jsonp");
if (jsonpcallback == null)
jsonpcallback = getParams().getFirstValue("callback");
String configResource = String.format("config-%s.js", ((IFreeMarkerApplication) getApplication()).getProfile());
return new OutputStreamConvertor(new StructureRecordXLSXReporter(getRequest().getRootRef().toString(), hssf, getTemplate(), getGroupProperties(), getBundles(), null, true, configResource) {
@Override
protected void configurePropertyProcessors() {
getCompositionProcessors(getProcessors());
getProcessors().add(getPropertyProcessors(false, false));
}
@Override
protected void initColumns(int afterCol) {
for (I5_ROOT_OBJECTS section : I5_ROOT_OBJECTS.values()) {
if (section.isIUCLID5() && section.isScientificPart() && section.isSupported() && !section.isNanoMaterialTemplate()) {
int last = mergedProperties.size();
mergedProperties.put("http://www.opentox.org/echaEndpoints.owl#" + section.name(), last);
Cell hcell = sheet.getRow(0).createCell(last + afterCol);
hcell.setCellStyle(hstyle);
hcell.setCellType(CellType.STRING);
hcell.setCellValue(section.getNumber() + ". " + section.getTitle());
sheet.autoSizeColumn(hcell.getColumnIndex(), true);
// initially hide all columns, unhide if data is added
// to
sheet.setColumnHidden(hcell.getColumnIndex(), true);
}
}
}
}, media, filenamePrefix);
}
use of ambit2.rest.OutputStreamConvertor in project ambit-mirror by ideaconsult.
the class BundleSubstanceResource 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 media = acceptform.getFirstValue("accept-header");
if (media != null)
variant.setMediaType(new MediaType(media));
String filenamePrefix = getRequest().getResourceRef().getPath();
if (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) {
SubstanceJSONReporter cmpreporter = new SubstanceJSONReporter(getRequest(), null, bundles, null, false);
return new OutputWriterConvertor<SubstanceRecord, Q>(cmpreporter, MediaType.APPLICATION_JSON, 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.APPLICATION_MSOFFICE_XLSX)) {
return new OutputStreamConvertor<SubstanceRecord, Q>(createXLSXReporter(getRequest(), false), MediaType.APPLICATION_MSOFFICE_XLSX, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_EXCEL)) {
return new OutputStreamConvertor<SubstanceRecord, Q>(createXLSXReporter(getRequest(), false), MediaType.APPLICATION_EXCEL, filenamePrefix);
} else if (isRDFMediaType(variant.getMediaType())) {
return new RDFJenaConvertor(new SubstanceRDFReporter(getRequest(), variant.getMediaType()), 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(MediaType.TEXT_CSV)) {
return new OutputWriterConvertor<SubstanceRecord, Q>(new SubstanceCSVReporter(getRequest(), bundles), MediaType.TEXT_CSV, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_JAVASCRIPT)) {
String jsonpcallback = getParams().getFirstValue("jsonp");
if (jsonpcallback == null)
jsonpcallback = getParams().getFirstValue("callback");
return new OutputWriterConvertor<SubstanceRecord, Q>(createJSONReporter(getRequest(), jsonpcallback), MediaType.APPLICATION_JAVASCRIPT, filenamePrefix);
} else if (variant.getMediaType().equals(ISAJSON)) {
return new OutputStreamConvertor<SubstanceRecord, Q>(createISAReporter(getRequest()), MediaType.APPLICATION_JAVASCRIPT, filenamePrefix);
} else {
// json by default
return new OutputWriterConvertor<SubstanceRecord, Q>(createJSONReporter(getRequest(), null), MediaType.APPLICATION_JSON, filenamePrefix);
}
}
Aggregations