Search in sources :

Example 1 with IZReader

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

the class CallableSubstanceI5Query method getReader.

private IZReader getReader(File i5z) throws Exception {
    IChemObjectReaderErrorHandler errhandler = new IChemObjectReaderErrorHandler() {

        @Override
        public void handleError(String message, int row, int colStart, int colEnd, Exception exception) {
            localLogger.log(Level.WARNING, String.format("%s [row %d colStart %d colEnd %d] %s", message, row, colStart, colEnd, exception.getMessage()));
        }

        @Override
        public void handleError(String message, int row, int colStart, int colEnd) {
            localLogger.log(Level.WARNING, String.format("%s [row %d colStart %d colEnd %d]", message, row, colStart, colEnd));
        }

        @Override
        public void handleError(String message, Exception exception) {
            localLogger.log(Level.WARNING, exception.getMessage());
        }

        @Override
        public void handleError(String message) {
            localLogger.log(Level.WARNING, message);
        }
    };
    IZReader reader = iuclidversion.getReader(i5z, errhandler);
    reader.setErrorHandler(errhandler);
    return reader;
}
Also used : IChemObjectReaderErrorHandler(org.openscience.cdk.io.IChemObjectReaderErrorHandler) IZReader(net.idea.i5.io.IZReader) ResourceException(org.restlet.resource.ResourceException) ImportSubstanceException(ambit2.rest.exception.ImportSubstanceException) AmbitIOException(ambit2.base.exceptions.AmbitIOException)

Example 2 with IZReader

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

the class CallableSubstanceI5Query method processContainer.

private IIdentifiableResource<IIdentifier> processContainer(List<IIdentifiableResource<IIdentifier>> container, DBSubstanceWriter writer, String server) {
    IIdentifiableResource<IIdentifier> result = null;
    for (IIdentifiableResource<IIdentifier> item : container) {
        IZReader reader = null;
        File file = null;
        if (item instanceof Container)
            try {
                file = ((Container) item).getIpzarchive();
                if (file.exists()) {
                    localLogger.fine(file.getAbsolutePath());
                    reader = getReader(((Container) item).getIpzarchive());
                    reader.setQASettings(getQASettings());
                    write(reader, writer, new ReferenceSubstanceUUID(), server);
                    result = item;
                    localLogger.log(Level.INFO, String.format("Substance UUID=%s imported successfully", item.getResourceIdentifier()));
                } else {
                    localLogger.log(Level.SEVERE, String.format("File %s does not exist.", file.getAbsoluteFile()));
                }
            } catch (Exception x) {
                localLogger.log(Level.SEVERE, item.toString(), x);
            } finally {
                try {
                    if (reader != null)
                        reader.close();
                } catch (Exception x) {
                }
                try {
                    file.delete();
                } catch (Exception x) {
                }
            }
    }
    return result;
}
Also used : Container(net.idea.iuclid.cli.Container) IIdentifier(net.idea.opentox.cli.id.IIdentifier) IZReader(net.idea.i5.io.IZReader) ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) File(java.io.File) ResourceException(org.restlet.resource.ResourceException) ImportSubstanceException(ambit2.rest.exception.ImportSubstanceException) AmbitIOException(ambit2.base.exceptions.AmbitIOException)

Example 3 with IZReader

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

the class Context method importI5Z.

protected int importI5Z(IStructureKey keytomatch, boolean i6, StructureRecordValidator validator) throws Exception {
    // validator uses parsertype
    setParserType(i6 ? _parsertype.i6z : _parsertype.i5z);
    logger_cli.log(Level.INFO, "MSG_IMPORT", new Object[] { String.format("i%sz", i6 ? "6" : "5"), inputFile.getAbsolutePath() });
    IZReader reader = null;
    Connection c = null;
    try {
        DBConnectionConfigurable<Context> dbc = null;
        dbc = getConnection(getConfigFile());
        c = dbc.getConnection();
        c.setAutoCommit(true);
        I5Options options = new I5Options();
        options.setMaxReferenceStructures(maxRefSubstances);
        options.setExceptionOnMaxReferenceStructures(false);
        options.setAllowMultipleSubstances(false);
        if (i6)
            reader = new I6ZReader<>(inputFile, options);
        else
            reader = new I5ZReader<>(inputFile, options);
        QASettings qa = new QASettings(false);
        qa.setAll();
        reader.setQASettings(qa);
        matchByKey = keytomatch == null ? new CASKey() : keytomatch;
        return write(reader, c, matchByKey, true, clearMeasurements, clearComposition, validator, null, true, false);
    } catch (Exception x) {
        throw x;
    } finally {
        if (reader != null)
            reader.close();
        try {
            if (c != null)
                c.close();
        } catch (Exception x) {
        }
    }
}
Also used : I5Options(net.idea.i5.io.I5Options) IZReader(net.idea.i5.io.IZReader) CASKey(ambit2.core.processors.structure.key.CASKey) Connection(java.sql.Connection) MySQLSingleConnection(net.idea.modbcum.c.MySQLSingleConnection) QASettings(net.idea.i5.io.QASettings) I5ZReader(net.idea.i5.io.I5ZReader) I6ZReader(net.idea.i6.io.I6ZReader) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CommunicationsException(com.mysql.jdbc.CommunicationsException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException)

Aggregations

IZReader (net.idea.i5.io.IZReader)3 AmbitIOException (ambit2.base.exceptions.AmbitIOException)2 ImportSubstanceException (ambit2.rest.exception.ImportSubstanceException)2 ResourceException (org.restlet.resource.ResourceException)2 CASKey (ambit2.core.processors.structure.key.CASKey)1 ReferenceSubstanceUUID (ambit2.core.processors.structure.key.ReferenceSubstanceUUID)1 CommunicationsException (com.mysql.jdbc.CommunicationsException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 I5Options (net.idea.i5.io.I5Options)1 I5ZReader (net.idea.i5.io.I5ZReader)1 QASettings (net.idea.i5.io.QASettings)1 I6ZReader (net.idea.i6.io.I6ZReader)1 Container (net.idea.iuclid.cli.Container)1 MySQLSingleConnection (net.idea.modbcum.c.MySQLSingleConnection)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1