use of com.evolveum.midpoint.schema.AbstractSummarizingResultHandler in project midpoint by Evolveum.
the class PageAccounts method exportPerformed.
private void exportPerformed(AjaxRequestTarget target) {
if (resourceModel.getObject() == null) {
warn(getString("pageAccounts.message.resourceNotSelected"));
refreshEverything(target);
return;
}
String fileName = "accounts-" + WebComponentUtil.formatDate("yyyy-MM-dd-HH-mm-ss", new Date()) + ".xml";
OperationResult result = new OperationResult(OPERATION_EXPORT);
Writer writer = null;
try {
Task task = createSimpleTask(OPERATION_EXPORT);
writer = createWriter(fileName);
writeHeader(writer);
final Writer handlerWriter = writer;
ResultHandler handler = new AbstractSummarizingResultHandler() {
@Override
protected boolean handleObject(PrismObject object, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OPERATION_EXPORT_ACCOUNT);
try {
String xml = getPrismContext().serializeObjectToString(object, PrismContext.LANG_XML);
handlerWriter.write(xml);
result.computeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize account", ex);
result.recordFatalError("Couldn't serialize account.", ex);
return false;
}
return true;
}
};
try {
ObjectQuery query = ObjectQuery.createObjectQuery(createResourceAndQueryFilter());
getModelService().searchObjectsIterative(ShadowType.class, query, handler, SelectorOptions.createCollection(GetOperationOptions.createRaw()), task, result);
} finally {
writeFooter(writer);
}
result.recomputeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't export accounts", ex);
error(getString("PageAccounts.exportException", ex.getMessage()));
} finally {
IOUtils.closeQuietly(writer);
}
filesModel.reset();
success(getString("PageAccounts.message.success.export", fileName));
target.add(getFeedbackPanel(), get(createComponentPath(ID_FORM_ACCOUNT, ID_FILES_CONTAINER)));
}
Aggregations