Search in sources :

Example 1 with I5_ROOT_OBJECTS

use of net.idea.i5.io.I5_ROOT_OBJECTS 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);
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) OutputStreamConvertor(ambit2.rest.OutputStreamConvertor) SubstanceOwner(ambit2.base.data.substance.SubstanceOwner) SubstanceUUID(ambit2.base.data.substance.SubstanceUUID) I5_ROOT_OBJECTS(net.idea.i5.io.I5_ROOT_OBJECTS) StructureRecordXLSXReporter(ambit2.db.reporters.xlsx.StructureRecordXLSXReporter) Cell(org.apache.poi.ss.usermodel.Cell) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName)

Example 2 with I5_ROOT_OBJECTS

use of net.idea.i5.io.I5_ROOT_OBJECTS in project ambit-mirror by ideaconsult.

the class CallableSubstanceImporter method createBatch.

@Override
protected AbstractBatchProcessor createBatch(FileInputState target) throws Exception {
    if (target == null)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    final BatchDBProcessor<String> batch = new BatchDBProcessor<String>() {

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

        @Override
        public Iterator<String> getIterator(IInputState target) throws AmbitException {
            try {
                IRawReader<IStructureRecord> reader = null;
                File file = ((FileInputState) target).getFile();
                String ext = file.getName().toLowerCase();
                if (ext.endsWith(FileInputState._FILE_TYPE.I5Z_INDEX.getExtension())) {
                    if (writer instanceof DBSubstanceWriter)
                        if (writer instanceof DBSubstanceWriter) {
                            ((DBSubstanceWriter) writer).setSplitRecord(true);
                            ((DBSubstanceWriter) writer).setI5mode(true);
                        }
                    reader = new I5ZReader(file);
                    ((I5ZReader) reader).setQASettings(getQASettings());
                } else if (ext.endsWith(FileInputState._FILE_TYPE.I6Z_INDEX.getExtension())) {
                    if (writer instanceof DBSubstanceWriter)
                        if (writer instanceof DBSubstanceWriter) {
                            ((DBSubstanceWriter) writer).setSplitRecord(true);
                            ((DBSubstanceWriter) writer).setI5mode(true);
                        }
                    reader = new I6ZReader(file);
                    ((I6ZReader) reader).setQASettings(getQASettings());
                } else if (ext.endsWith(FileInputState._FILE_TYPE.CSV_INDEX.getExtension())) {
                    if (writer instanceof DBSubstanceWriter)
                        ((DBSubstanceWriter) writer).setSplitRecord(false);
                    LiteratureEntry reference = new LiteratureEntry(originalname, originalname);
                    reader = new CSV12SubstanceReader(new CSV12Reader(new FileReader(file), reference, "FCSV-"));
                } else if (ext.endsWith(".rdf")) {
                    if (writer instanceof DBSubstanceWriter) {
                        ((DBSubstanceWriter) writer).setSplitRecord(false);
                        ((DBSubstanceWriter) writer).setImportBundles(true);
                    }
                    reader = new NanoWikiRDFReader(new InputStreamReader(new FileInputStream(file), "UTF-8"), null, "RDF/XML");
                } else if (ext.endsWith(".ttl")) {
                    if (writer instanceof DBSubstanceWriter) {
                        ((DBSubstanceWriter) writer).setSplitRecord(false);
                        ((DBSubstanceWriter) writer).setImportBundles(true);
                    }
                    reader = new ENanoMapperRDFReader(new InputStreamReader(new FileInputStream(file), "UTF-8"), "ENM3");
                } else if (FileInputState._FILE_TYPE.XLSX_INDEX.hasExtension(ext) || FileInputState._FILE_TYPE.XLS_INDEX.hasExtension(ext)) {
                    if (configFile == null)
                        throw new AmbitException("XLSX/XLSX file import requires a JSON configuration file");
                    final StructureRecordValidator validator = new StructureRecordValidator(file.getName(), true, "XLSX");
                    reader = new GenericExcelParser(new FileInputStream(file), configFile, FileInputState._FILE_TYPE.XLSX_INDEX.hasExtension(ext)) {

                        public Object next() {
                            Object record = super.next();
                            try {
                                if (record instanceof IStructureRecord)
                                    record = validator.process((IStructureRecord) record);
                            } catch (Exception x) {
                            }
                            return record;
                        }
                    };
                    if (writer instanceof DBSubstanceWriter) {
                        ((DBSubstanceWriter) writer).setSplitRecord(false);
                    /*
							 * ((DBSubstanceWriter) writer)
							 * .setClearComposition(false); ((DBSubstanceWriter)
							 * writer) .setClearMeasurements(false);
							 */
                    }
                } else if (ext.endsWith(".json")) {
                    if (writer instanceof DBSubstanceWriter)
                        ((DBSubstanceWriter) writer).setSplitRecord(false);
                    reader = new SubstanceStudyParser(new InputStreamReader(new FileInputStream(file), "UTF-8")) {

                        protected EffectRecord createEffectRecord(Protocol protocol) {
                            try {
                                I5_ROOT_OBJECTS category = I5_ROOT_OBJECTS.valueOf(protocol.getCategory() + "_SECTION");
                                return category.createEffectRecord();
                            } catch (Exception x) {
                                return super.createEffectRecord(protocol);
                            }
                        }
                    };
                    if (writer instanceof DBSubstanceWriter) {
                        ((DBSubstanceWriter) writer).setClearComposition(false);
                        ((DBSubstanceWriter) writer).setClearMeasurements(false);
                    }
                } else {
                    throw new AmbitException("Unsupported format " + file);
                }
                reader.setErrorHandler(new IChemObjectReaderErrorHandler() {

                    @Override
                    public void handleError(String message, int row, int colStart, int colEnd, Exception exception) {
                    }

                    @Override
                    public void handleError(String message, int row, int colStart, int colEnd) {
                    }

                    @Override
                    public void handleError(String message, Exception exception) {
                    }

                    @Override
                    public void handleError(String message) {
                    }
                });
                return reader;
            } catch (AmbitException x) {
                throw x;
            } catch (Exception x) {
                throw new AmbitException(x);
            }
        }
    };
    return batch;
}
Also used : DBSubstanceWriter(ambit2.db.substance.processor.DBSubstanceWriter) GenericExcelParser(net.enanomapper.parser.GenericExcelParser) LiteratureEntry(ambit2.base.data.LiteratureEntry) StructureRecordValidator(ambit2.base.data.study.StructureRecordValidator) I5_ROOT_OBJECTS(net.idea.i5.io.I5_ROOT_OBJECTS) CSV12Reader(net.idea.loom.nm.csv.CSV12Reader) I5ZReader(net.idea.i5.io.I5ZReader) SubstanceStudyParser(ambit2.core.io.json.SubstanceStudyParser) I6ZReader(net.idea.i6.io.I6ZReader) CSV12SubstanceReader(net.idea.loom.nm.csv.CSV12SubstanceReader) IStructureRecord(ambit2.base.interfaces.IStructureRecord) IChemObjectReaderErrorHandler(org.openscience.cdk.io.IChemObjectReaderErrorHandler) ENanoMapperRDFReader(net.idea.loom.nm.nanowiki.ENanoMapperRDFReader) IInputState(ambit2.core.io.IInputState) ResourceException(org.restlet.resource.ResourceException) FileReader(java.io.FileReader) Protocol(ambit2.base.data.study.Protocol) InputStreamReader(java.io.InputStreamReader) BatchDBProcessor(ambit2.db.processors.BatchDBProcessor) FileInputStream(java.io.FileInputStream) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) EffectRecord(ambit2.base.data.study.EffectRecord) File(java.io.File) FileInputState(ambit2.core.io.FileInputState) NanoWikiRDFReader(net.idea.loom.nm.nanowiki.NanoWikiRDFReader) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with I5_ROOT_OBJECTS

use of net.idea.i5.io.I5_ROOT_OBJECTS in project ambit-mirror by ideaconsult.

the class SubstanceCategoryProperty method createQuery.

@Override
protected Iterator<EffectRecord<String, IParams, String>> createQuery(Context context, Request request, Response response) throws ResourceException {
    try {
        Object topcategory = Reference.decode(request.getAttributes().get(SubstancePropertyResource.topcategory).toString());
        Object endpointcategory = Reference.decode(request.getAttributes().get(SubstancePropertyResource.endpointcategory).toString());
        if (topcategory == null || endpointcategory == null)
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
        I5_ROOT_OBJECTS category;
        try {
            category = I5_ROOT_OBJECTS.valueOf(endpointcategory.toString().replace("_SECTION", ""));
        } catch (Exception x) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage());
        }
        if (!category.getTopCategory().equals(topcategory.toString())) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Expected /property/%s/%s", category.getTopCategory(), category.name()));
        }
        effects = new ArrayList<EffectRecord<String, IParams, String>>();
        if (category.getEndpoints() != null && category.getEndpoints().length > 0)
            for (String endpoint : category.getEndpoints()) {
                EffectRecord record = category.createEffectRecord();
                record.setEndpoint(endpoint);
                effects.add(record);
            }
        else
            effects.add(category.createEffectRecord());
        return effects.iterator();
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage());
    }
}
Also used : EffectRecord(ambit2.base.data.study.EffectRecord) I5_ROOT_OBJECTS(net.idea.i5.io.I5_ROOT_OBJECTS) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException)

Aggregations

I5_ROOT_OBJECTS (net.idea.i5.io.I5_ROOT_OBJECTS)3 EffectRecord (ambit2.base.data.study.EffectRecord)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 ResourceException (org.restlet.resource.ResourceException)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 Protocol (ambit2.base.data.study.Protocol)1 StructureRecordValidator (ambit2.base.data.study.StructureRecordValidator)1 SubstanceName (ambit2.base.data.substance.SubstanceName)1 SubstanceOwner (ambit2.base.data.substance.SubstanceOwner)1 SubstancePublicName (ambit2.base.data.substance.SubstancePublicName)1 SubstanceUUID (ambit2.base.data.substance.SubstanceUUID)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 FileInputState (ambit2.core.io.FileInputState)1 IInputState (ambit2.core.io.IInputState)1 SubstanceStudyParser (ambit2.core.io.json.SubstanceStudyParser)1 BatchDBProcessor (ambit2.db.processors.BatchDBProcessor)1 StructureRecordXLSXReporter (ambit2.db.reporters.xlsx.StructureRecordXLSXReporter)1 DBSubstanceWriter (ambit2.db.substance.processor.DBSubstanceWriter)1 OutputStreamConvertor (ambit2.rest.OutputStreamConvertor)1 File (java.io.File)1