Search in sources :

Example 31 with RestartResponseException

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TaskManager(com.evolveum.midpoint.task.api.TaskManager) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 32 with RestartResponseException

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();
        }
    };
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) StringValue(org.apache.wicket.util.string.StringValue) DashboardType(com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardType)

Example 33 with RestartResponseException

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;
}
Also used : RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with RestartResponseException

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;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 35 with RestartResponseException

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);
    }
}
Also used : java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ItemVisibility(com.evolveum.midpoint.web.component.prism.ItemVisibility) StringUtils(org.apache.commons.lang3.StringUtils) RestartResponseException(org.apache.wicket.RestartResponseException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) PrismPropertyWrapperModel(com.evolveum.midpoint.web.model.PrismPropertyWrapperModel) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Component(org.apache.wicket.Component) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Panel(org.apache.wicket.markup.html.panel.Panel) TaskHandler(com.evolveum.midpoint.task.api.TaskHandler) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) PrismObjectWrapperFactory(com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory) com.evolveum.midpoint.gui.api.prism.wrapper(com.evolveum.midpoint.gui.api.prism.wrapper) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) TaskHandler(com.evolveum.midpoint.task.api.TaskHandler) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Panel(org.apache.wicket.markup.html.panel.Panel) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) RestartResponseException(org.apache.wicket.RestartResponseException)

Aggregations

RestartResponseException (org.apache.wicket.RestartResponseException)73 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 Task (com.evolveum.midpoint.task.api.Task)27 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)20 ArrayList (java.util.ArrayList)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 CommonException (com.evolveum.midpoint.util.exception.CommonException)8 SecurityPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)5 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)5 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 PageError (com.evolveum.midpoint.web.page.error.PageError)5 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 Collection (java.util.Collection)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 IModel (org.apache.wicket.model.IModel)4 StringValue (org.apache.wicket.util.string.StringValue)4