use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.
the class PageAbout method reindexRepositoryObjectsPerformed.
private void reindexRepositoryObjectsPerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_SUBMIT_REINDEX);
try {
TaskManager taskManager = getTaskManager();
Task task = taskManager.createTaskInstance();
MidPointPrincipal user = AuthUtil.getPrincipalUser();
if (user == null) {
throw new RestartResponseException(PageLogin.class);
} else {
task.setOwner(user.getFocus().asPrismObject());
}
authorize(AuthorizationConstants.AUTZ_ALL_URL, null, null, null, null, null, result);
task.setChannel(SchemaConstants.CHANNEL_USER_URI);
task.setHandlerUri(ModelPublicConstants.REINDEX_TASK_HANDLER_URI);
task.setName("Reindex repository objects");
task.addArchetypeInformation(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value());
taskManager.switchToBackground(task, result);
result.setBackgroundTaskOid(task.getOid());
} catch (SecurityViolationException | SchemaException | RuntimeException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException e) {
result.recordFatalError(e);
} finally {
result.computeStatusIfUnknown();
}
showResult(result);
target.add(getFeedbackPanel());
}
use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.
the class PageDashboardConfigurable method initDashboardObject.
private IModel<DashboardType> initDashboardObject() {
return new LoadableModel<DashboardType>(false) {
@Override
public DashboardType load() {
StringValue dashboardOid = getPageParameters().get(OnePageParameterEncoder.PARAMETER);
if (dashboardOid == null || StringUtils.isEmpty(dashboardOid.toString())) {
getSession().error(getString("PageDashboardConfigurable.message.oidNotDefined"));
throw new RestartResponseException(PageDashboardInfo.class);
}
Task task = createSimpleTask("Search dashboard");
return WebModelServiceUtils.loadObject(DashboardType.class, dashboardOid.toString(), PageDashboardConfigurable.this, task, task.getResult()).getRealValue();
}
};
}
use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.
the class WebModelServiceUtils method loadObject.
@Nullable
public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, boolean allowNotFound, PageBase page, Task task, OperationResult result) {
LOGGER.debug("Loading {} with oid {}, options {}", type.getSimpleName(), oid, options);
OperationResult subResult;
if (result != null) {
subResult = result.createMinorSubresult(OPERATION_LOAD_OBJECT);
} else {
subResult = new OperationResult(OPERATION_LOAD_OBJECT);
}
PrismObject<T> object = null;
try {
if (options == null) {
options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
} else {
GetOperationOptions getOpts = SelectorOptions.findRootOptions(options);
if (getOpts == null) {
options.add(new SelectorOptions<>(GetOperationOptions.createResolveNames()));
} else {
getOpts.setResolveNames(Boolean.TRUE);
}
}
object = page.getModelService().getObject(type, oid, options, task, subResult);
} catch (AuthorizationException e) {
// Not authorized to access the object. This is probably caused by a reference that
// point to an object that the current user cannot read. This is no big deal.
// Just do not display that object.
subResult.recordHandledError(e);
PrismObject<? extends FocusType> taskOwner = task.getOwner(result);
LOGGER.debug("User {} is not authorized to read {} {}", taskOwner != null ? taskOwner.getName() : null, type.getSimpleName(), oid);
return null;
} catch (ObjectNotFoundException e) {
if (allowNotFound) {
// Object does not exist. It was deleted in the meanwhile, or not created yet. This could happen quite often.
subResult.recordHandledError(e);
LOGGER.debug("{} {} does not exist", type.getSimpleName(), oid, e);
return null;
} else {
subResult.recordFatalError(page.createStringResource("WebModelUtils.couldntLoadObject").getString(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", e);
}
} catch (Exception ex) {
subResult.recordFatalError(page.createStringResource("WebModelUtils.couldntLoadObject").getString(), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
} finally {
subResult.computeStatus();
}
// TODO reconsider this part: until recently, the condition was always 'false'
if (WebComponentUtil.showResultInPage(subResult)) {
page.showResult(subResult);
}
if (object == null && !allowNotFound) {
throw new RestartResponseException(PageError.class);
}
LOGGER.debug("Loaded {} with result {}", object, subResult);
return object;
}
use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.
the class WebModelServiceUtils method createSimpleTask.
public static Task createSimpleTask(String operation, String channel, PrismObject<? extends FocusType> owner, TaskManager manager) {
Task task = manager.createTaskInstance(operation);
if (owner == null) {
MidPointPrincipal user = AuthUtil.getPrincipalUser();
if (user == null) {
throw new RestartResponseException(PageLogin.class);
} else {
owner = user.getFocus().asPrismObject();
}
}
task.setOwner(owner);
task.setChannel(Objects.requireNonNullElse(channel, SchemaConstants.CHANNEL_USER_URI));
return task;
}
use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.
the class TaskBasicTabPanel method initLayout.
private void initLayout() {
ItemPanelSettings settings = new ItemPanelSettingsBuilder().editabilityHandler(wrapper -> getTask().getHandlerUri() == null).build();
TaskHandlerSelectorPanel handlerSelectorPanel = new TaskHandlerSelectorPanel(ID_HANDLER, PrismPropertyWrapperModel.fromContainerWrapper(getModel(), TaskType.F_HANDLER_URI), settings) {
@Override
protected void onUpdatePerformed(AjaxRequestTarget target) {
String newHandlerUri = getTask().getHandlerUri();
if (StringUtils.isBlank(newHandlerUri) || !newHandlerUri.startsWith("http://")) {
LOGGER.trace("Nothing to do, handler still not set");
return;
}
TaskHandler taskHandler = getPageBase().getTaskManager().getHandler(newHandlerUri);
if (taskHandler == null) {
LOGGER.trace("Nothing to do, cannot find TaskHandler for {}", newHandlerUri);
return;
}
if (!WebComponentUtil.hasAnyArchetypeAssignment(getTask())) {
String archetypeOid = taskHandler.getArchetypeOid(newHandlerUri);
WebComponentUtil.addNewArchetype(TaskBasicTabPanel.this.getModelObject(), archetypeOid, target, getPageBase());
}
PrismObjectWrapperFactory<TaskType> wrapperFactory = TaskBasicTabPanel.this.getPageBase().findObjectWrapperFactory(getTask().asPrismObject().getDefinition());
Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_WRAPPER);
OperationResult result = task.getResult();
WrapperContext ctx = new WrapperContext(task, result);
ctx.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(getTask().asPrismObject()));
try {
wrapperFactory.updateWrapper(TaskBasicTabPanel.this.getModelObject(), ctx);
// TODO ugly hack: after updateWrapper method is called, both previously set items (handlerUri and assignments)
// are marked as NOT_CHANGED with the same value. We need to find a way how to force the ValueStatus
// or change the mechanism for computing deltas. Probably only the first will work
PrismPropertyWrapper<String> handlerWrapper = TaskBasicTabPanel.this.getModelObject().findProperty(ItemPath.create(TaskType.F_HANDLER_URI));
handlerWrapper.getValue().setStatus(ValueStatus.ADDED);
PrismContainerWrapper<AssignmentType> assignmentWrapper = TaskBasicTabPanel.this.getModelObject().findContainer(ItemPath.create(TaskType.F_ASSIGNMENT));
for (PrismContainerValueWrapper<AssignmentType> assignmentWrapperValue : assignmentWrapper.getValues()) {
if (WebComponentUtil.isArchetypeAssignment(assignmentWrapperValue.getRealValue())) {
assignmentWrapperValue.setStatus(ValueStatus.ADDED);
}
}
} catch (SchemaException | IllegalArgumentException e) {
LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
}
updateHandlerPerformed(target);
}
};
handlerSelectorPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return satisfyArchetypeAssignment();
}
});
add(handlerSelectorPanel);
ItemVisibilityHandler visibilityHandler = wrapper -> getBasicTabVisibility(wrapper.getPath());
ItemEditabilityHandler editabilityHandler = wrapper -> getBasicTabEditability(wrapper.getPath());
try {
ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder().visibilityHandler(visibilityHandler).editabilityHandler(editabilityHandler).mandatoryHandler(getItemMandatoryHandler());
Panel panel = getPageBase().initItemPanel(ID_MAIN_PANEL, TaskType.COMPLEX_TYPE, getModel(), builder.build());
add(panel);
} catch (SchemaException e) {
LOGGER.error("Cannot create task basic panel: {}", e.getMessage(), e);
// TODO opertion result? localization?
getSession().error("Cannot create task basic panel");
throw new RestartResponseException(PageTasks.class);
}
}
Aggregations