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;
}
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;
}
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) {
}
}
}
Aggregations