use of com.evolveum.midpoint.init.InitialDataImport in project midpoint by Evolveum.
the class PageAbout method resetStateToInitialConfig.
private void resetStateToInitialConfig(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_DELETE_ALL_OBJECTS);
String taskOid = null;
String taskName = "Delete all objects";
QueryFactory factory = getPrismContext().queryFactory();
TypeFilter nodeFilter = factory.createType(NodeType.COMPLEX_TYPE, factory.createAll());
final ObjectFilter taskFilter = getPrismContext().queryFor(TaskType.class).item(TaskType.F_NAME).eq(taskName).buildFilter();
NotFilter notNodeFilter = factory.createNot(nodeFilter);
NotFilter notTaskFilter = factory.createNot(taskFilter);
try {
QName type = ObjectType.COMPLEX_TYPE;
taskOid = deleteObjectsAsync(type, factory.createQuery(factory.createAnd(notTaskFilter, notNodeFilter)), taskName, result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.allObject.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete all objects", ex);
}
final String taskOidToRemoving = taskOid;
try {
while (!getTaskManager().getTaskPlain(taskOid, result).isClosed()) {
TimeUnit.SECONDS.sleep(5);
}
runPrivileged(new Producer<Object>() {
private static final long serialVersionUID = 1L;
@Override
public Object run() {
Task task = createAnonymousTask(OPERATION_DELETE_TASK);
OperationResult result = new OperationResult(OPERATION_DELETE_TASK);
ObjectDelta<TaskType> delta = getPrismContext().deltaFactory().object().createDeleteDelta(TaskType.class, taskOidToRemoving);
Collection<ObjectDelta<? extends ObjectType>> deltaCollection = Collections.singletonList(delta);
try {
getModelService().executeChanges(deltaCollection, null, task, result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.task.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete task", ex);
}
result.computeStatus();
return null;
}
});
InitialDataImport initialDataImport = new InitialDataImport();
initialDataImport.setModel(getModelService());
initialDataImport.setTaskManager(getTaskManager());
initialDataImport.setPrismContext(getPrismContext());
initialDataImport.setConfiguration(getMidpointConfiguration());
initialDataImport.init(true);
// TODO consider if we need to go clusterwide here
getCacheDispatcher().dispatchInvalidation(null, null, true, null);
getModelService().shutdown();
getModelService().postInit(result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.import.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import initial objects", ex);
}
showResult(result);
target.add(getFeedbackPanel());
}
Aggregations