Search in sources :

Example 1 with SubstanceRecordAnnotationProcessor

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);
}
Also used : ProcessorsChain(net.idea.modbcum.i.processors.ProcessorsChain) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) SubstanceStudyDetailsProcessor(ambit2.db.substance.study.SubstanceStudyDetailsProcessor) SubstanceRecordAnnotationProcessor(ambit2.base.ro.SubstanceRecordAnnotationProcessor) SubstanceRecord(ambit2.base.data.SubstanceRecord) AmbitFreeMarkerApplication(ambit2.rest.AmbitFreeMarkerApplication) File(java.io.File) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) Writer(java.io.Writer)

Example 2 with SubstanceRecordAnnotationProcessor

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);
}
Also used : Form(org.restlet.data.Form) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) StringConvertor(net.idea.restnet.c.StringConvertor) ImageReporter(ambit2.db.reporters.ImageReporter) SubstanceRecord(ambit2.base.data.SubstanceRecord) Dimension(java.awt.Dimension) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) PatternSyntaxException(java.util.regex.PatternSyntaxException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) OutputStreamConvertor(ambit2.rest.OutputStreamConvertor) SubstanceRecordXLSXReporter(ambit2.db.reporters.xlsx.SubstanceRecordXLSXReporter) ImageConvertor(ambit2.rest.ImageConvertor) SubstanceRecordAnnotationProcessor(ambit2.base.ro.SubstanceRecordAnnotationProcessor) ChemicalMediaType(net.idea.restnet.c.ChemicalMediaType) MediaType(org.restlet.data.MediaType) OntModel(com.hp.hpl.jena.ontology.OntModel) RDFJenaConvertor(ambit2.rest.RDFJenaConvertor) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) File(java.io.File) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Aggregations

SubstanceRecord (ambit2.base.data.SubstanceRecord)2 SubstanceRecordAnnotationProcessor (ambit2.base.ro.SubstanceRecordAnnotationProcessor)2 File (java.io.File)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 OutputWriterConvertor (net.idea.restnet.db.convertors.OutputWriterConvertor)2 ResourceException (org.restlet.resource.ResourceException)2 ProcessorException (ambit2.base.processors.ProcessorException)1 ImageReporter (ambit2.db.reporters.ImageReporter)1 SubstanceRecordXLSXReporter (ambit2.db.reporters.xlsx.SubstanceRecordXLSXReporter)1 SubstanceStudyDetailsProcessor (ambit2.db.substance.study.SubstanceStudyDetailsProcessor)1 AmbitFreeMarkerApplication (ambit2.rest.AmbitFreeMarkerApplication)1 ImageConvertor (ambit2.rest.ImageConvertor)1 OutputStreamConvertor (ambit2.rest.OutputStreamConvertor)1 RDFJenaConvertor (ambit2.rest.RDFJenaConvertor)1 OntModel (com.hp.hpl.jena.ontology.OntModel)1 Dimension (java.awt.Dimension)1 Writer (java.io.Writer)1 SQLException (java.sql.SQLException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)1