Search in sources :

Example 1 with CSLSStringRequest

use of ambit2.search.csls.CSLSStringRequest in project ambit-mirror by ideaconsult.

the class CSLSResource method get.

@Override
protected Representation get(Variant variant) throws ResourceException {
    setFrameOptions("SAMEORIGIN");
    try {
        if (term != null) {
            if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_MDLSDF))
                return new OutputRepresentation(variant.getMediaType()) {

                    @Override
                    public void write(OutputStream stream) throws IOException {
                        try {
                            CSLSRequest<InputStream> q = new CSLSRequest<InputStream>() {

                                /**
                                 */
                                private static final long serialVersionUID = 2638378178348461366L;

                                @Override
                                protected InputStream read(InputStream in) throws Exception {
                                    return in;
                                }
                            };
                            q.setRepresentation(representation);
                            DownloadTool.download(q.process(term), stream);
                            stream.flush();
                        } catch (ResourceException x) {
                            throw x;
                        } catch (AmbitException x) {
                            throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
                        // throw new IOException(x.getMessage());
                        } finally {
                            try {
                                if (stream != null)
                                    stream.flush();
                            } catch (Exception x) {
                                getLogger().log(Level.WARNING, x.getMessage(), x);
                            }
                        }
                    }
                };
            else {
                CSLSStringRequest q = new CSLSStringRequest();
                q.setRepresentation(representation);
                return new StringRepresentation(q.process(term), MediaType.TEXT_PLAIN);
            }
        } else
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    } catch (NotFoundException x) {
        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND, "No results for query " + term);
        return null;
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
    }
}
Also used : CSLSStringRequest(ambit2.search.csls.CSLSStringRequest) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) IOException(java.io.IOException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) IOException(java.io.IOException) ResourceException(org.restlet.resource.ResourceException) StringRepresentation(org.restlet.representation.StringRepresentation) OutputRepresentation(org.restlet.representation.OutputRepresentation) ResourceException(org.restlet.resource.ResourceException) CSLSRequest(ambit2.search.csls.CSLSRequest) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with CSLSStringRequest

use of ambit2.search.csls.CSLSStringRequest in project ambit-mirror by ideaconsult.

the class CallableFinder method createProcessors.

@Override
protected ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> createProcessors() throws Exception {
    ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> p = new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>();
    // exactly our
    RetrieveStructure r = new RetrieveStructure(false);
    // structure,
    // nothing else
    r.setPageSize(1);
    r.setPage(0);
    p.add(new ProcessorStructureRetrieval(r));
    IProcessor<IStructureRecord, IStructureRecord> valuesReader = getValuesReader();
    if (valuesReader != null)
        p.add(valuesReader);
    IProcessor<String, String> request;
    LiteratureEntry le;
    switch(searchSite) {
        case PUBCHEM_CID:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.cid));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        case PUBCHEM_SID:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.sid));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        case PUBCHEM_NAME:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.name));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        case PUBCHEM_INCHIKEY:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.inchikey));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        /*
		 * case PUBCHEM: { p.add(new PubchemFinder(profile,mode)); le = new
		 * LiteratureEntry("PubChem",EntrezSearchProcessor.entrezURL); break; }
		 */
        case OPENTOX:
            {
                request = new OpenToxRequest(searchSite.getURI());
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
        case AMBITLRI:
            {
                request = new OpenToxRequest(searchSite.getURI());
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
        case NAME2STRUCTURE:
            {
                p.add(new Name2StructureFinder(getProfile(), mode));
                le = new LiteratureEntry(searchSite.getTitle(), searchSite.getURI());
                break;
            }
        /*
		 * case CHEMBL: { p.add(new ChemBLFinder(profile,mode)); le = new
		 * LiteratureEntry(searchSite.name(),"https://www.ebi.ac.uk/chemblws"); break; }
		 */
        case CHEMIDPLUS:
            {
                request = new ChemIdPlusRequest();
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
        /*
		 * case TBWIKI: { mode = MODE.propertyonly; le = new LiteratureEntry("TBWIKI",
		 * "http://wiki.toxbank.net/wiki/Special:SPARQLEndpoint"); p.add(new
		 * TBWikiFinder(profile, le)); break; }
		 */
        default:
            {
                request = new CSLSStringRequest();
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
    }
    // don't duplicate if there is already a hit
    SourceDataset dataset = new SourceDataset(searchSite.toString(), le);
    dataset = getDataset(dataset);
    QueryStructureByID q = new QueryStructureByID();
    q.setChemicalsOnly(true);
    q.setFieldname(dataset);
    q.setPageSize(1);
    q.setPage(0);
    p.add(new ProcessorStructureRetrieval(q) {

        /**
         */
        private static final long serialVersionUID = 621841537224691538L;

        @Override
        public IStructureRecord process(IStructureRecord target) throws AmbitException {
            if (target == null)
                return null;
            if (((QueryStructureByID) getQuery()).getFieldname().getID() >= 0) {
                IStructureRecord record = super.process(target);
                target.setIdchemical(record.getIdchemical());
                target.setIdstructure(record.getIdstructure());
                return target;
            } else
                return target;
        }
    });
    RepositoryWriter writer = new RepositoryWriter() {

        /**
         */
        private static final long serialVersionUID = 7175414487857418817L;

        @Override
        public List<IStructureRecord> process(IStructureRecord target) throws AmbitException {
            if (target == null)
                return null;
            return super.process(target);
        }
    };
    if (MODE.propertyonly.equals(mode)) {
        writer.setPropertyKey(new NoneKey());
        writer.setUseExistingStructure(true);
        writer.setOperation(OP.CREATE);
    } else
        writer.setOperation(OP.UPDATE);
    writer.setDataset(dataset);
    p.add(writer);
    return p;
}
Also used : Name2StructureFinder(ambit2.namestructure.Name2StructureFinder) CSLSStringRequest(ambit2.search.csls.CSLSStringRequest) OpenToxRequest(ambit2.search.opentox.OpenToxRequest) LiteratureEntry(ambit2.base.data.LiteratureEntry) IBatchStatistics(net.idea.modbcum.i.batch.IBatchStatistics) RepositoryWriter(ambit2.db.processors.RepositoryWriter) NoneKey(ambit2.core.processors.structure.key.NoneKey) IProcessor(net.idea.modbcum.i.processors.IProcessor) ChemIdPlusRequest(ambit2.search.chemidplus.ChemIdPlusRequest) PubChemRestFinder(ambit2.pubchem.rest.PubChemRestFinder) QueryStructureByID(ambit2.db.search.structure.QueryStructureByID) IStructureRecord(ambit2.base.interfaces.IStructureRecord) AllSourcesFinder(ambit2.search.AllSourcesFinder) ProcessorsChain(net.idea.modbcum.i.processors.ProcessorsChain) ProcessorStructureRetrieval(ambit2.db.processors.ProcessorStructureRetrieval) SourceDataset(ambit2.base.data.SourceDataset) RetrieveStructure(ambit2.db.readers.RetrieveStructure) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Aggregations

CSLSStringRequest (ambit2.search.csls.CSLSStringRequest)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 SourceDataset (ambit2.base.data.SourceDataset)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 NoneKey (ambit2.core.processors.structure.key.NoneKey)1 ProcessorStructureRetrieval (ambit2.db.processors.ProcessorStructureRetrieval)1 RepositoryWriter (ambit2.db.processors.RepositoryWriter)1 RetrieveStructure (ambit2.db.readers.RetrieveStructure)1 QueryStructureByID (ambit2.db.search.structure.QueryStructureByID)1 Name2StructureFinder (ambit2.namestructure.Name2StructureFinder)1 PubChemRestFinder (ambit2.pubchem.rest.PubChemRestFinder)1 AllSourcesFinder (ambit2.search.AllSourcesFinder)1 ChemIdPlusRequest (ambit2.search.chemidplus.ChemIdPlusRequest)1 CSLSRequest (ambit2.search.csls.CSLSRequest)1 OpenToxRequest (ambit2.search.opentox.OpenToxRequest)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 IBatchStatistics (net.idea.modbcum.i.batch.IBatchStatistics)1