Search in sources :

Example 1 with QueryURIReporter

use of net.idea.restnet.db.QueryURIReporter 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);
    }
}
Also used : PropertyJSONReporter(ambit2.rest.property.PropertyJSONReporter) Form(org.restlet.data.Form) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) StringConvertor(net.idea.restnet.c.StringConvertor) ImageReporter(ambit2.db.reporters.ImageReporter) Dimension(java.awt.Dimension) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) ImageConvertor(ambit2.rest.ImageConvertor) PropertyRDFReporter(ambit2.rest.property.PropertyRDFReporter) ChemicalMediaType(net.idea.restnet.c.ChemicalMediaType) MediaType(org.restlet.data.MediaType) RDFJenaConvertor(ambit2.rest.RDFJenaConvertor) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) Property(ambit2.base.data.Property)

Example 2 with QueryURIReporter

use of net.idea.restnet.db.QueryURIReporter 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)

Example 3 with QueryURIReporter

use of net.idea.restnet.db.QueryURIReporter in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource 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.TEXT_URI_LIST)) {
        QueryURIReporter r = (QueryURIReporter) getURIReporter(getRequest());
        return new StringConvertor(r, MediaType.TEXT_URI_LIST, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_JAVASCRIPT)) {
        String jsonpcallback = getParams().getFirstValue("jsonp");
        if (jsonpcallback == null)
            jsonpcallback = getParams().getFirstValue("callback");
        return createJSONReporter(filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) {
        return createJSONReporter(filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.WEKA_ARFF)) {
        return createARFFReporter(filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.THREECOL_ARFF)) {
        QueryAbstractReporter reporter = new ARFF3ColResourceReporter<IQueryRetrieval<IStructureRecord>>(getTemplate(), getGroupProperties(), getRequest(), String.format("%s%s", getRequest().getRootRef(), ""));
        return new OutputWriterConvertor(reporter, ChemicalMediaType.THREECOL_ARFF, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_MSOFFICE_XLSX)) {
        return createXLSXReporter(variant.getMediaType(), false, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_EXCEL)) {
        return createXLSXReporter(variant.getMediaType(), true, filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.TEXT_CSV)) {
        return createCSVReporter(filenamePrefix);
    } else if (variant.getMediaType().equals(MediaType.APPLICATION_RDF_XML)) {
        switch(rdfwriter) {
            case stax:
                {
                    return new RDFStaXConvertor(new SubstanceBundleStAXReporter(getRequest()), filenamePrefix);
                }
            default:
                {
                    // jena
                    return createRDFReporter(variant.getMediaType(), filenamePrefix);
                }
        }
    } else if (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) || variant.getMediaType().equals(ChemicalMediaType.APPLICATION_JSONLD)) {
        return createRDFReporter(variant.getMediaType(), filenamePrefix);
    } else if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_MDLSDF)) {
        return new OutputWriterConvertor(new SDFReporter<QueryStructureByID>(template, getGroupProperties(), changeLineSeparators), ChemicalMediaType.CHEMICAL_MDLSDF, 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) RDFStaXConvertor(ambit2.rest.RDFStaXConvertor) QueryStructureByID(ambit2.db.search.structure.QueryStructureByID) ARFF3ColResourceReporter(ambit2.rest.dataset.ARFF3ColResourceReporter) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ChemicalMediaType(net.idea.restnet.c.ChemicalMediaType) MediaType(org.restlet.data.MediaType) QueryAbstractReporter(net.idea.modbcum.r.QueryAbstractReporter) QueryURIReporter(net.idea.restnet.db.QueryURIReporter)

Example 4 with QueryURIReporter

use of net.idea.restnet.db.QueryURIReporter 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)

Example 5 with QueryURIReporter

use of net.idea.restnet.db.QueryURIReporter in project ambit-mirror by ideaconsult.

the class SubstanceResource method executeUpdate.

/**
 * POST - create entity based on parameters in http header, creates a new entry
 * in the databaseand returns an url to it
 */
public void executeUpdate(Representation entity, T entry, AbstractUpdate updateObject) throws ResourceException {
    Connection c = null;
    // TODO it is inefficient to instantiate executor in all classes
    UpdateExecutor executor = new UpdateExecutor();
    try {
        DBConnection dbc = new DBConnection(getContext());
        c = dbc.getConnection(30, true, 5);
        executor.setConnection(c);
        executor.open();
        executor.process(updateObject);
        customizeEntry(entry, c);
        QueryURIReporter uriReporter = getURIReporter(getRequest());
        if (uriReporter != null) {
            getResponse().setLocationRef(uriReporter.getURI(entry));
            getResponse().setEntity(uriReporter.getURI(entry), MediaType.TEXT_HTML);
        }
        getResponse().setStatus(Status.SUCCESS_OK);
        onUpdateSuccess();
    } catch (SQLException x) {
        Context.getCurrentLogger().severe(x.getMessage());
        getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, x, x.getMessage());
        getResponse().setEntity(null);
    } catch (ProcessorException x) {
        Context.getCurrentLogger().severe(x.getMessage());
        getResponse().setStatus((x.getCause() instanceof SQLException) ? Status.CLIENT_ERROR_FORBIDDEN : Status.SERVER_ERROR_INTERNAL, x, x.getMessage());
        getResponse().setEntity(null);
    } catch (Exception x) {
        Context.getCurrentLogger().severe(x.getMessage());
        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, x, x.getMessage());
        getResponse().setEntity(null);
    } finally {
        try {
            executor.close();
        } catch (Exception x) {
        }
        try {
            if (c != null)
                c.close();
        } catch (Exception x) {
        }
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) ProcessorException(ambit2.base.processors.ProcessorException) SQLException(java.sql.SQLException) UpdateExecutor(ambit2.db.UpdateExecutor) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) 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)

Aggregations

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