Search in sources :

Example 1 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 2 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 3 with ObjectWrapper

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

the class PageAdminFocus method getForceDeleteDelta.

private ObjectDelta getForceDeleteDelta(ObjectWrapper focusWrapper) throws SchemaException {
    List<FocusSubwrapperDto<ShadowType>> accountDtos = getFocusShadows();
    List<ReferenceDelta> refDeltas = new ArrayList<ReferenceDelta>();
    ObjectDelta<F> forceDeleteDelta = null;
    for (FocusSubwrapperDto<ShadowType> accDto : accountDtos) {
        if (!accDto.isLoadedOK()) {
            continue;
        }
        if (accDto.getStatus() == UserDtoStatus.DELETE) {
            ObjectWrapper accWrapper = accDto.getObject();
            ReferenceDelta refDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, focusWrapper.getObject().getDefinition(), accWrapper.getObject());
            refDeltas.add(refDelta);
        } else if (accDto.getStatus() == UserDtoStatus.UNLINK) {
            ObjectWrapper accWrapper = accDto.getObject();
            ReferenceDelta refDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, focusWrapper.getObject().getDefinition(), accWrapper.getObject().getOid());
            refDeltas.add(refDelta);
        }
    }
    if (!refDeltas.isEmpty()) {
        forceDeleteDelta = ObjectDelta.createModifyDelta(focusWrapper.getObject().getOid(), refDeltas, getCompileTimeClass(), getPrismContext());
    }
    PrismContainerDefinition def = focusWrapper.getObject().findContainer(UserType.F_ASSIGNMENT).getDefinition();
    if (forceDeleteDelta == null) {
        forceDeleteDelta = ObjectDelta.createEmptyModifyDelta(getCompileTimeClass(), focusWrapper.getObject().getOid(), getPrismContext());
    }
    handleAssignmentDeltas(forceDeleteDelta, getFocusAssignments(), def);
    return forceDeleteDelta;
}
Also used : FocusSubwrapperDto(com.evolveum.midpoint.web.page.admin.users.dto.FocusSubwrapperDto) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper)

Example 4 with ObjectWrapper

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

the class PageAdminFocus method getShadowModifyDeltas.

private List<ObjectDelta<? extends ObjectType>> getShadowModifyDeltas(OperationResult result) {
    List<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
    List<FocusSubwrapperDto<ShadowType>> accounts = getFocusShadows();
    OperationResult subResult = null;
    for (FocusSubwrapperDto<ShadowType> account : accounts) {
        if (!account.isLoadedOK()) {
            continue;
        }
        try {
            ObjectWrapper accountWrapper = account.getObject();
            ObjectDelta delta = accountWrapper.getObjectDelta();
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Account delta computed from {} as:\n{}", new Object[] { accountWrapper, delta.debugDump(3) });
            }
            if (!UserDtoStatus.MODIFY.equals(account.getStatus())) {
                continue;
            }
            if (delta.isEmpty() && (accountWrapper.getOldDelta() == null || accountWrapper.getOldDelta().isEmpty())) {
                continue;
            }
            if (accountWrapper.getOldDelta() != null) {
                delta = ObjectDelta.summarize(delta, accountWrapper.getOldDelta());
            }
            // what is this???
            // subResult = result.createSubresult(OPERATION_MODIFY_ACCOUNT);
            WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Modifying account:\n{}", new Object[] { delta.debugDump(3) });
            }
            deltas.add(delta);
        // subResult.recordSuccess();
        } catch (Exception ex) {
            // if (subResult != null) {
            result.recordFatalError("Couldn't compute account delta.", ex);
            // }
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't compute account delta", ex);
        }
    }
    return deltas;
}
Also used : FocusSubwrapperDto(com.evolveum.midpoint.web.page.admin.users.dto.FocusSubwrapperDto) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 5 with ObjectWrapper

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

the class PageAdminFocus method prepareUserAccountsDeltaForModify.

private ReferenceDelta prepareUserAccountsDeltaForModify(PrismReferenceDefinition refDef) throws SchemaException {
    ReferenceDelta refDelta = new ReferenceDelta(refDef, getPrismContext());
    List<FocusSubwrapperDto<ShadowType>> accounts = getFocusShadows();
    for (FocusSubwrapperDto<ShadowType> accDto : accounts) {
        if (accDto.isLoadedOK()) {
            ObjectWrapper accountWrapper = accDto.getObject();
            accountWrapper.revive(getPrismContext());
            ObjectDelta delta = accountWrapper.getObjectDelta();
            PrismReferenceValue refValue = new PrismReferenceValue(null, OriginType.USER_ACTION, null);
            PrismObject<ShadowType> account;
            switch(accDto.getStatus()) {
                case ADD:
                    account = delta.getObjectToAdd();
                    addDefaultKindAndIntent(account);
                    WebComponentUtil.encryptCredentials(account, true, getMidpointApplication());
                    refValue.setObject(account);
                    refDelta.addValueToAdd(refValue);
                    break;
                case DELETE:
                    account = accountWrapper.getObject();
                    refValue.setObject(account);
                    refDelta.addValueToDelete(refValue);
                    break;
                case MODIFY:
                    // before
                    continue;
                case UNLINK:
                    refValue.setOid(delta.getOid());
                    refValue.setTargetType(ShadowType.COMPLEX_TYPE);
                    refDelta.addValueToDelete(refValue);
                    break;
                default:
                    warn(getString("pageAdminFocus.message.illegalAccountState", accDto.getStatus()));
            }
        }
    }
    return refDelta;
}
Also used : FocusSubwrapperDto(com.evolveum.midpoint.web.page.admin.users.dto.FocusSubwrapperDto) 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