Search in sources :

Example 6 with ObjectWrapper

use of com.evolveum.midpoint.web.component.prism.ObjectWrapper in project midpoint by Evolveum.

the class PageAccount method savePerformed.

private void savePerformed(AjaxRequestTarget target) {
    LOGGER.debug("Saving account changes.");
    OperationResult result = new OperationResult(OPERATION_SAVE_ACCOUNT);
    try {
        WebComponentUtil.revive(accountModel, getPrismContext());
        ObjectWrapper wrapper = accountModel.getObject();
        ObjectDelta<ShadowType> delta = wrapper.getObjectDelta();
        if (delta == null) {
            return;
        }
        if (delta.getPrismContext() == null) {
            getPrismContext().adopt(delta);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Account delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
        }
        if (delta.isEmpty()) {
            return;
        }
        WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
        Task task = createSimpleTask(OPERATION_SAVE_ACCOUNT);
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
        deltas.add(delta);
        getModelService().executeChanges(deltas, null, task, result);
        result.recomputeStatus();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't save account.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save account", ex);
    }
    if (!result.isSuccess()) {
        showResult(result);
        target.add(getFeedbackPanel());
    } else {
        showResult(result);
        redirectBack();
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 7 with ObjectWrapper

use of com.evolveum.midpoint.web.component.prism.ObjectWrapper in project midpoint by Evolveum.

the class PageAccount method initButtons.

private void initButtons(Form mainForm) {
    AjaxSubmitButton save = new AjaxSubmitButton("save", createStringResource("pageAccount.button.save")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            savePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(getFeedbackPanel());
        }
    };
    save.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            ObjectWrapper wrapper = accountModel.getObject();
            return !wrapper.isProtectedAccount();
        }
    });
    mainForm.add(save);
    AjaxButton back = new AjaxButton("back", createStringResource("pageAccount.button.back")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            cancelPerformed(target);
        }
    };
    mainForm.add(back);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) Form(org.apache.wicket.markup.html.form.Form) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 8 with ObjectWrapper

use of com.evolveum.midpoint.web.component.prism.ObjectWrapper in project midpoint by Evolveum.

the class PageMyPasswordQuestions method loadUserWrapper.

private ObjectWrapper loadUserWrapper(PrismObject<UserType> userToEdit) {
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    PrismObject<UserType> user = null;
    Task task = createSimpleTask(OPERATION_LOAD_USER);
    try {
        Collection options = SelectorOptions.createCollection(UserType.F_CREDENTIALS, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
        user = getModelService().getObject(UserType.class, SecurityUtils.getPrincipalUser().getOid(), options, task, result);
        result.recordSuccess();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get user.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user PageMyQuestions", ex);
    }
    showResult(result, false);
    if (user == null) {
        throw new RestartResponseException(PageDashboard.class);
    }
    ContainerStatus status = ContainerStatus.MODIFYING;
    ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
    ObjectWrapper wrapper;
    try {
        wrapper = owf.createObjectWrapper("pageMyPasswordQuestions.userDetails", null, user, status, task);
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get user.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user", ex);
        wrapper = owf.createObjectWrapper("pageMyPasswordQuestions.userDetails", null, user, null, null, status, false);
    }
    //        ObjectWrapper wrapper = new ObjectWrapper("pageUser.userDetails", null, user, status);
    showResult(wrapper.getResult(), false);
    return wrapper;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ContainerStatus(com.evolveum.midpoint.web.component.prism.ContainerStatus) RestartResponseException(org.apache.wicket.RestartResponseException) Collection(java.util.Collection) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException)

Example 9 with ObjectWrapper

use of com.evolveum.midpoint.web.component.prism.ObjectWrapper in project midpoint by Evolveum.

the class OrgMemberPanel method createManagerContainer.

private WebMarkupContainer createManagerContainer() {
    WebMarkupContainer managerContainer = new WebMarkupContainer(ID_CONTAINER_MANAGER);
    managerContainer.setOutputMarkupId(true);
    managerContainer.setOutputMarkupPlaceholderTag(true);
    RepeatingView view = new RepeatingView(ID_MANAGER_TABLE);
    view.setOutputMarkupId(true);
    ObjectQuery managersQuery = createManagerQuery();
    OperationResult searchManagersResult = new OperationResult(OPERATION_SEARCH_MANAGERS);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(FocusType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
    List<PrismObject<FocusType>> managers = WebModelServiceUtils.searchObjects(FocusType.class, managersQuery, options, searchManagersResult, getPageBase());
    Task task = getPageBase().createSimpleTask(OPERATION_LOAD_MANAGERS);
    for (PrismObject<FocusType> manager : managers) {
        ObjectWrapper<FocusType> managerWrapper = ObjectWrapperUtil.createObjectWrapper(WebComponentUtil.getEffectiveName(manager, RoleType.F_DISPLAY_NAME), "", manager, ContainerStatus.MODIFYING, task, getPageBase());
        WebMarkupContainer managerMarkup = new WebMarkupContainer(view.newChildId());
        AjaxLink<String> link = new AjaxLink<String>(ID_EDIT_MANAGER) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                FocusSummaryPanel<FocusType> summary = (FocusSummaryPanel<FocusType>) getParent().get(ID_MANAGER_SUMMARY);
                detailsPerformed(target, summary.getModelObject());
            }
        };
        link.add(new VisibleEnableBehaviour() {

            private static final long serialVersionUID = 1L;

            @Override
            public boolean isVisible() {
                boolean isVisible = false;
                try {
                    isVisible = getPageBase().getSecurityEnforcer().isAuthorized(AuthorizationConstants.AUTZ_UI_READ_ACTION_URL, AuthorizationPhaseType.REQUEST, managerWrapper.getObject(), null, null, null);
                } catch (Exception ex) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Failed to check authorization for #read operation on object " + managerWrapper.getObject(), ex);
                }
                return isVisible;
            }
        });
        if (manager.getCompileTimeClass().equals(UserType.class)) {
            managerMarkup.add(new UserSummaryPanel(ID_MANAGER_SUMMARY, new Model<ObjectWrapper<UserType>>((ObjectWrapper) managerWrapper)));
        } else if (manager.getCompileTimeClass().equals(RoleType.class)) {
            managerMarkup.add(new RoleSummaryPanel(ID_MANAGER_SUMMARY, new Model<ObjectWrapper<RoleType>>((ObjectWrapper) managerWrapper)));
        } else if (manager.getCompileTimeClass().equals(OrgType.class)) {
            managerMarkup.add(new OrgSummaryPanel(ID_MANAGER_SUMMARY, new Model<ObjectWrapper<OrgType>>((ObjectWrapper) managerWrapper)));
        } else if (manager.getCompileTimeClass().equals(ServiceType.class)) {
            managerMarkup.add(new ServiceSummaryPanel(ID_MANAGER_SUMMARY, new Model<ObjectWrapper<ServiceType>>((ObjectWrapper) managerWrapper)));
        }
        link.setOutputMarkupId(true);
        managerMarkup.setOutputMarkupId(true);
        managerMarkup.add(link);
        view.add(managerMarkup);
        AjaxButton removeManager = new AjaxButton(ID_REMOVE_MANAGER) {

            @Override
            public void onClick(AjaxRequestTarget target) {
                FocusSummaryPanel<FocusType> summary = (FocusSummaryPanel<FocusType>) getParent().get(ID_MANAGER_SUMMARY);
                removeManagerPerformed(summary.getModelObject(), target);
                getParent().setVisible(false);
                target.add(OrgMemberPanel.this);
            }
        };
        removeManager.add(new VisibleEnableBehaviour() {

            private static final long serialVersionUID = 1L;

            @Override
            public boolean isVisible() {
                boolean isVisible = false;
                try {
                    isVisible = getPageBase().getSecurityEnforcer().isAuthorized(AuthorizationConstants.AUTZ_UI_UNASSIGN_ACTION_URL, null, managerWrapper.getObject(), null, getModelObject().asPrismObject(), null);
                } catch (Exception ex) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Failed to check authorization for #unassign operation on object " + managerWrapper.getObject(), ex);
                }
                return isVisible;
            }
        });
        removeManager.setOutputMarkupId(true);
        managerMarkup.add(removeManager);
        AjaxButton deleteManager = new AjaxButton(ID_DELETE_MANAGER) {

            @Override
            public void onClick(AjaxRequestTarget target) {
                FocusSummaryPanel<FocusType> summary = (FocusSummaryPanel<FocusType>) getParent().get(ID_MANAGER_SUMMARY);
                deleteManagerPerformed(summary.getModelObject(), this, target);
            }
        };
        deleteManager.setOutputMarkupId(true);
        deleteManager.add(new VisibleEnableBehaviour() {

            private static final long serialVersionUID = 1L;

            @Override
            public boolean isVisible() {
                boolean isVisible = false;
                try {
                    isVisible = getPageBase().getSecurityEnforcer().isAuthorized(AuthorizationConstants.AUTZ_UI_DELETE_ACTION_URL, null, managerWrapper.getObject(), null, null, null);
                } catch (Exception ex) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Failed to check authorization for #delete operation on object " + managerWrapper.getObject(), ex);
                }
                return isVisible;
            }
        });
        managerMarkup.add(deleteManager);
    }
    managerContainer.add(view);
    InlineMenu menupanel = new InlineMenu(ID_MANAGER_MENU, new Model<Serializable>((Serializable) createManagersHeaderInlineMenu()));
    add(menupanel);
    menupanel.setOutputMarkupId(true);
    managerContainer.add(menupanel);
    return managerContainer;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Serializable(java.io.Serializable) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) InlineMenu(com.evolveum.midpoint.web.component.menu.cog.InlineMenu) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) FocusSummaryPanel(com.evolveum.midpoint.web.component.FocusSummaryPanel) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) RoleSummaryPanel(com.evolveum.midpoint.web.page.admin.roles.component.RoleSummaryPanel)

Example 10 with ObjectWrapper

use of com.evolveum.midpoint.web.component.prism.ObjectWrapper in project midpoint by Evolveum.

the class PageAdminAbstractRole method loadInducements.

// TODO unify with loadAssignments
private List<AssignmentEditorDto> loadInducements() {
    List<AssignmentEditorDto> list = new ArrayList<AssignmentEditorDto>();
    ObjectWrapper focusWrapper = getObjectWrapper();
    PrismObject<T> focus = focusWrapper.getObject();
    List<AssignmentType> inducements = focus.asObjectable().getInducement();
    for (AssignmentType inducement : inducements) {
        list.add(new AssignmentEditorDto(UserDtoStatus.MODIFY, inducement, this));
    }
    Collections.sort(list);
    return list;
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper)

Aggregations

ObjectWrapper (com.evolveum.midpoint.web.component.prism.ObjectWrapper)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 FocusSubwrapperDto (com.evolveum.midpoint.web.page.admin.users.dto.FocusSubwrapperDto)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 ArrayList (java.util.ArrayList)3 RestartResponseException (org.apache.wicket.RestartResponseException)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)2 RoleSummaryPanel (com.evolveum.midpoint.web.page.admin.roles.component.RoleSummaryPanel)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 Form (org.apache.wicket.markup.html.form.Form)2 RepeatingView (org.apache.wicket.markup.repeater.RepeatingView)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1