use of org.openntf.nsfodp.compiler.dxl.DxlImporterLog in project org.openntf.nsfodp by OpenNTF.
the class ODPCompiler method importDxl.
/**
* @param importer the importer to use during the process
* @param dxl an XML {@link InputStream} to import
* @param database the database to import to
* @param name a human-readable name of the element, for logging
* @return a {@link List} of imported note IDs
* @since 3.4.0
*/
private List<Integer> importDxl(NDXLImporter importer, InputStream dxl, NDatabase database, String name) throws Exception {
try {
Collection<Integer> imported = new HashSet<>();
imported.addAll(importer.importDxl(database, dxl));
String logXml = importer.getResultLogXML();
if (StringUtil.isNotEmpty(logXml)) {
DxlImporterLog log = DxlImporterLog.forXml(logXml);
if (log.getErrors() != null && !log.getErrors().isEmpty()) {
String msg = log.getErrors().stream().map(e -> StringUtil.format("{2} (line={0}, column={1})", e.getLine(), e.getColumn(), e.getText())).collect(// $NON-NLS-1$
Collectors.joining(", "));
throw new Exception(MessageFormat.format("Exception importing {0}: {1}", name, msg));
} else if (log.getFatalErrors() != null && !log.getFatalErrors().isEmpty()) {
String msg = log.getFatalErrors().stream().map(DXLFatalError::getText).collect(// $NON-NLS-1$
Collectors.joining(", "));
throw new Exception(MessageFormat.format("Exception importing {0}: {1}", name, msg));
}
}
List<Integer> importedIds = new ArrayList<>();
for (Integer noteId : imported) {
importedIds.add(noteId);
try (NNote note = database.getNoteByID(noteId)) {
note.sign();
note.save();
}
}
return importedIds;
} catch (Exception ne) {
if (ne.getMessage().contains("DXL importer operation failed")) {
// $NON-NLS-1$
throw new RuntimeException(MessageFormat.format(Messages.ODPCompiler_dxlImportFailed, name, importer.getResultLogXML()), ne);
}
throw ne;
}
}
Aggregations