Search in sources :

Example 1 with AbstractSummarizingResultHandler

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)));
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) AbstractSummarizingResultHandler(com.evolveum.midpoint.schema.AbstractSummarizingResultHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AbstractSummarizingResultHandler(com.evolveum.midpoint.schema.AbstractSummarizingResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Date(java.util.Date) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 AbstractSummarizingResultHandler (com.evolveum.midpoint.schema.AbstractSummarizingResultHandler)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 CommonException (com.evolveum.midpoint.util.exception.CommonException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Date (java.util.Date)1 RestartResponseException (org.apache.wicket.RestartResponseException)1