Search in sources :

Example 1 with CSVReporter

use of ambit2.db.reporters.CSVReporter in project ambit-mirror by ideaconsult.

the class StructureQueryResource method createCSVReporter.

protected CSVReporter createCSVReporter() {
    Form form = getParams();
    CSVReporter csvreporter = new CSVReporter(getRequest().getRootRef().toString(), getTemplate(), groupProperties, String.format("%s%s", getRequest().getRootRef(), getCompoundInDatasetPrefix()));
    try {
        csvreporter.setNumberofHeaderLines(Integer.parseInt(form.getFirstValue("headerlines")));
    } catch (Exception x) {
        csvreporter.setNumberofHeaderLines(1);
    }
    return csvreporter;
}
Also used : Form(org.restlet.data.Form) CSVReporter(ambit2.db.reporters.CSVReporter) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException)

Example 2 with CSVReporter

use of ambit2.db.reporters.CSVReporter in project ambit-mirror by ideaconsult.

the class SimilarityResource method createCSVReporter.

@Override
protected CSVReporter createCSVReporter() {
    CSVReporter csvReporter = super.createCSVReporter();
    csvReporter.setSimilarityColumn(Property.getInstance("metric", queryObject == null ? "" : queryObject.toString(), "http://ambit.sourceforge.net"));
    return csvReporter;
}
Also used : CSVReporter(ambit2.db.reporters.CSVReporter)

Example 3 with CSVReporter

use of ambit2.db.reporters.CSVReporter in project ambit-mirror by ideaconsult.

the class QMapDatasetResource method createCSVReporter.

@Override
protected CSVReporter createCSVReporter() {
    CSVReporter csvReporter = super.createCSVReporter();
    csvReporter.setSimilarityColumn(Property.getInstance("metric", queryObject == null ? "" : queryObject.toString(), "http://ambit.sourceforge.net"));
    return csvReporter;
}
Also used : CSVReporter(ambit2.db.reporters.CSVReporter)

Example 4 with CSVReporter

use of ambit2.db.reporters.CSVReporter in project ambit-mirror by ideaconsult.

the class SimilarityMatrixResource method createCSVReporter.

@Override
protected CSVReporter createCSVReporter() {
    CSVReporter csvReporter = new CSVReporter(getRequest().getRootRef().toString(), null, null, String.format("%s%s", getRequest().getRootRef(), getCompoundInDatasetPrefix()));
    csvReporter.setSimilarityColumn(Property.getInstance("metric", queryObject == null ? "" : queryObject.toString(), "http://ambit.sourceforge.net"));
    return csvReporter;
}
Also used : CSVReporter(ambit2.db.reporters.CSVReporter)

Example 5 with CSVReporter

use of ambit2.db.reporters.CSVReporter in project ambit-mirror by ideaconsult.

the class CompoundResource method createConvertor.

@Override
public RepresentationConvertor createConvertor(Variant variant) throws AmbitException, ResourceException {
    /* workaround for clients not being able to set accept headers */
    if (!variant.getMediaType().equals(MediaType.IMAGE_PNG)) {
        setTemplate(createTemplate(getContext(), getRequest(), getResponse()));
        setGroupProperties(getContext(), getRequest(), getResponse());
    }
    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 ((queryObject == null) && !(variant.getMediaType().equals(MediaType.TEXT_HTML)))
        throw new NotFoundException();
    if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_CML))
        // StructureReporter((getRequest()==null)?null:getRequest().getRootRef()));
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new CMLReporter<QueryStructureByID>(), ChemicalMediaType.CHEMICAL_CML, filenamePrefix);
    else if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_MDLSDF)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new SDFReporter<QueryStructureByID>(getTemplate(), getGroupProperties(), changeLineSeparators), ChemicalMediaType.CHEMICAL_MDLSDF, filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_MDLMOL)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new SDFReporter<QueryStructureByID>(new Template(), getGroupProperties(), true, changeLineSeparators), ChemicalMediaType.CHEMICAL_MDLMOL, filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_SMILES)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new SmilesReporter<QueryStructureByID>(), ChemicalMediaType.CHEMICAL_SMILES, filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_INCHI)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new SmilesReporter<QueryStructureByID>(false, Mode.InChI, getTemplate()), ChemicalMediaType.CHEMICAL_INCHI, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) {
        return new StringConvertor(new SmilesReporter<QueryStructureByID>(true, getTemplate()), MediaType.TEXT_PLAIN);
    } else if (variant.getMediaType().equals(MediaType.IMAGE_PNG) || variant.getMediaType().equals(MediaType.IMAGE_BMP) || variant.getMediaType().equals(MediaType.IMAGE_JPEG) || variant.getMediaType().equals(MediaType.IMAGE_TIFF) || variant.getMediaType().equals(MediaType.IMAGE_GIF)) {
        return createImageConvertor(variant);
    } else if (variant.getMediaType().equals(ChemicalMediaType.IMAGE_JSON)) {
        return createImageStringConvertor(variant);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_PDF)) {
        return new PDFConvertor<IStructureRecord, QueryStructureByID, PDFReporter<QueryStructureByID>>(new PDFReporter<QueryStructureByID>(getTemplate(), getGroupProperties()));
    } else if (variant.getMediaType().equals(MediaType.TEXT_URI_LIST)) {
        QueryURIReporter r = (QueryURIReporter) getURIReporter();
        return new StringConvertor(r, MediaType.TEXT_URI_LIST, filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.WEKA_ARFF)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new ARFFResourceReporter(getTemplate(), getGroupProperties(), getRequest(), getRequest().getRootRef().toString() + getCompoundInDatasetPrefix()), ChemicalMediaType.WEKA_ARFF, filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.THREECOL_ARFF)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new ARFF3ColResourceReporter(getTemplate(), getGroupProperties(), getRequest(), getRequest().getRootRef().toString() + getCompoundInDatasetPrefix()), ChemicalMediaType.THREECOL_ARFF, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) {
        CompoundJSONReporter cmpreporter = new CompoundJSONReporter(getTemplate(), getGroupProperties(), folders, bundles, getRequest(), getRequest().getRootRef().toString() + getCompoundInDatasetPrefix(), includeMol, null);
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(cmpreporter, MediaType.APPLICATION_JSON, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_JAVASCRIPT)) {
        String jsonpcallback = getParams().getFirstValue("jsonp");
        if (jsonpcallback == null)
            jsonpcallback = getParams().getFirstValue("callback");
        CompoundJSONReporter cmpreporter = new CompoundJSONReporter(getTemplate(), getGroupProperties(), folders, bundles, getRequest(), getRequest().getRootRef().toString() + getCompoundInDatasetPrefix(), includeMol, jsonpcallback);
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(cmpreporter, MediaType.APPLICATION_JAVASCRIPT, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.TEXT_CSV)) {
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new CSVReporter(getRequest().getRootRef().toString(), getTemplate(), getGroupProperties(), getRequest().getRootRef().toString() + getCompoundInDatasetPrefix()), MediaType.TEXT_CSV, filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.NANO_CML)) {
        // StructureReporter((getRequest()==null)?null:getRequest().getRootRef()));
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(new CMLReporter<QueryStructureByID>(), ChemicalMediaType.NANO_CML, filenamePrefix);
    } 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(MediaType.APPLICATION_RDF_TRIG) || variant.getMediaType().equals(MediaType.APPLICATION_RDF_TRIX)) {
        return new RDFJenaConvertor<IStructureRecord, IQueryRetrieval<IStructureRecord>>(new DatasetRDFReporter(getCompoundInDatasetPrefix(), getRequest(), variant.getMediaType(), getTemplate(), getGroupProperties()), variant.getMediaType(), filenamePrefix);
    } else {
        CompoundJSONReporter cmpreporter = new CompoundJSONReporter(getTemplate(), getGroupProperties(), folders, bundles, getRequest(), getRequest().getRootRef().toString() + getCompoundInDatasetPrefix(), includeMol, null);
        return new OutputWriterConvertor<IStructureRecord, QueryStructureByID>(cmpreporter, MediaType.APPLICATION_JSON, filenamePrefix);
    }
}
Also used : SmilesReporter(ambit2.db.reporters.SmilesReporter) Form(org.restlet.data.Form) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) StringConvertor(net.idea.restnet.c.StringConvertor) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) CSVReporter(ambit2.db.reporters.CSVReporter) CMLReporter(ambit2.db.reporters.CMLReporter) QueryStructureByID(ambit2.db.search.structure.QueryStructureByID) Template(ambit2.base.data.Template) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ARFFResourceReporter(ambit2.rest.dataset.ARFFResourceReporter) ARFF3ColResourceReporter(ambit2.rest.dataset.ARFF3ColResourceReporter) SDFReporter(ambit2.db.reporters.SDFReporter) PDFConvertor(ambit2.rest.PDFConvertor) DatasetRDFReporter(ambit2.rest.dataset.DatasetRDFReporter) ChemicalMediaType(net.idea.restnet.c.ChemicalMediaType) MediaType(org.restlet.data.MediaType) RDFJenaConvertor(ambit2.rest.RDFJenaConvertor) QueryURIReporter(net.idea.restnet.db.QueryURIReporter)

Aggregations

CSVReporter (ambit2.db.reporters.CSVReporter)11 Form (org.restlet.data.Form)5 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)4 OutputWriterConvertor (net.idea.restnet.db.convertors.OutputWriterConvertor)4 ResourceException (org.restlet.resource.ResourceException)4 ChemicalMediaType (net.idea.restnet.c.ChemicalMediaType)3 StringConvertor (net.idea.restnet.c.StringConvertor)3 QueryURIReporter (net.idea.restnet.db.QueryURIReporter)3 MediaType (org.restlet.data.MediaType)3 Template (ambit2.base.data.Template)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)2 ImageReporter (ambit2.db.reporters.ImageReporter)2 SDFReporter (ambit2.db.reporters.SDFReporter)2 SmilesReporter (ambit2.db.reporters.SmilesReporter)2 ImageConvertor (ambit2.rest.ImageConvertor)2 RDFJenaConvertor (ambit2.rest.RDFJenaConvertor)2 ARFF3ColResourceReporter (ambit2.rest.dataset.ARFF3ColResourceReporter)2 ARFFResourceReporter (ambit2.rest.dataset.ARFFResourceReporter)2 DatasetRDFReporter (ambit2.rest.dataset.DatasetRDFReporter)2 Dimension (java.awt.Dimension)2