Search in sources :

Example 26 with AssignmentEditorDto

use of com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto in project midpoint by Evolveum.

the class UserDelegationsTabPanel method initLayout.

private void initLayout() {
    WebMarkupContainer delegations = new WebMarkupContainer(ID_DELEGATIONS_CONTAINER);
    delegations.setOutputMarkupId(true);
    add(delegations);
    AssignmentTablePanel panel = new AssignmentTablePanel<UserType>(ID_DELEGATIONS_PANEL, delegationsModel) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateAssignmentDetailsPanel(ListItem<AssignmentEditorDto> item) {
            DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(), false, privilegesListModel);
            item.add(editor);
        }

        @Override
        public String getExcludeOid() {
            return getObjectWrapper().getOid();
        }

        public IModel<String> getLabel() {
            return createStringResource("FocusType.delegations");
        }

        @Override
        protected List<InlineMenuItem> createAssignmentMenu() {
            List<InlineMenuItem> items = new ArrayList<>();
            InlineMenuItem item;
            if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_DELEGATE_ACTION_URL)) {
                item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.addDelegation")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public InlineMenuItemAction initAction() {
                        return new InlineMenuItemAction() {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                List<QName> supportedTypes = new ArrayList<>();
                                supportedTypes.add(UserType.COMPLEX_TYPE);
                                ObjectFilter filter = getPrismContext().queryFactory().createInOid(getObjectWrapper().getOid());
                                ObjectFilter notFilter = getPrismContext().queryFactory().createNot(filter);
                                ObjectBrowserPanel<UserType> panel = new ObjectBrowserPanel<UserType>(getPageBase().getMainPopupBodyId(), UserType.class, supportedTypes, false, getPageBase(), notFilter) {

                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    protected void onSelectPerformed(AjaxRequestTarget target, UserType user) {
                                        getPageBase().hideMainPopup(target);
                                        List<ObjectType> newAssignmentsList = new ArrayList<>();
                                        newAssignmentsList.add(user);
                                        addSelectedAssignablePerformed(target, newAssignmentsList, null, getPageBase().getMainPopup().getId());
                                    }
                                };
                                panel.setOutputMarkupId(true);
                                getPageBase().showMainPopup(panel, target);
                            }
                        };
                    }
                };
                items.add(item);
            }
            if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI)) {
                item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.deleteDelegation")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public InlineMenuItemAction initAction() {
                        return new InlineMenuItemAction() {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                deleteAssignmentPerformed(target, null);
                            }
                        };
                    }
                };
                items.add(item);
            }
            return items;
        }

        @Override
        protected String getNoAssignmentsSelectedMessage() {
            return getString("AssignmentTablePanel.message.noDelegationsSelected");
        }

        @Override
        protected String getAssignmentsDeleteMessage(AssignmentEditorDto dto) {
            return createStringResource("AssignmentTablePanel.modal.message.deleteDelegation", getSelectedAssignments().size()).getString();
        }

        @Override
        protected List<AssignmentEditorDto> getAssignmentListToProcess(AssignmentEditorDto dto) {
            if (dto != null) {
                return Collections.singletonList(dto);
            } else {
                return getSelectedAssignments();
            }
        }

        @Override
        protected void addSelectedAssignablePerformed(AjaxRequestTarget target, List<ObjectType> newAssignments, QName relation, String popupId) {
            ModalWindow window = (ModalWindow) get(popupId);
            if (window != null) {
                window.close(target);
            }
            getPageBase().hideMainPopup(target);
            if (newAssignments.isEmpty()) {
                warn(getString("AssignmentTablePanel.message.noAssignmentSelected"));
                target.add(getPageBase().getFeedbackPanel());
                return;
            }
            for (ObjectType object : newAssignments) {
                try {
                    AssignmentEditorDto dto = AssignmentEditorDto.createDtoAddFromSelectedObject(((PrismObject<UserType>) getObjectWrapper().getObject()).asObjectable(), WebComponentUtil.getDefaultRelationOrFail(RelationKindType.DELEGATION), getPageBase(), (UserType) object);
                    dto.setPrivilegeLimitationList(privilegesListModel.getObject());
                    delegationsModel.getObject().add(dto);
                } catch (Exception e) {
                    error(getString("AssignmentTablePanel.message.couldntAssignObject", object.getName(), e.getMessage()));
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't assign object", e);
                }
            }
            reloadAssignmentsPanel(target);
            reloadMainFormButtons(target);
        }
    };
    delegations.add(panel);
}
Also used : DelegationEditorPanel(com.evolveum.midpoint.web.component.assignment.DelegationEditorPanel) AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AssignmentTablePanel(com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)

Example 27 with AssignmentEditorDto

use of com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto in project midpoint by Evolveum.

the class PageUser method processDeputyAssignments.

@Override
protected boolean processDeputyAssignments(boolean previewOnly) {
    boolean isAnythingChanged = false;
    for (AssignmentEditorDto dto : delegationsModel.getObject()) {
        if (!UserDtoStatus.MODIFY.equals(dto.getStatus())) {
            if (!previewOnly) {
                UserType user = dto.getDelegationOwner();
                saveDelegationToUser(user.asPrismObject(), dto);
            }
            isAnythingChanged = true;
        }
    }
    return isAnythingChanged;
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto)

Example 28 with AssignmentEditorDto

use of com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto in project midpoint by Evolveum.

the class PageUser method loadDelegatedByMeAssignments.

private List<AssignmentEditorDto> loadDelegatedByMeAssignments() {
    OperationResult result = new OperationResult(OPERATION_LOAD_DELEGATED_BY_ME_ASSIGNMENTS);
    List<AssignmentEditorDto> list = new ArrayList<>();
    try {
        Task task = createSimpleTask(OPERATION_LOAD_DELEGATED_BY_ME_ASSIGNMENTS);
        PrismReferenceValue referenceValue = getPrismContext().itemFactory().createReferenceValue(getObjectWrapper().getOid(), UserType.COMPLEX_TYPE);
        referenceValue.setRelation(WebComponentUtil.getDefaultRelationOrFail(RelationKindType.DELEGATION));
        ObjectFilter refFilter = getPrismContext().queryFor(UserType.class).item(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(referenceValue).buildFilter();
        ObjectQuery query = getPrismContext().queryFactory().createQuery(refFilter);
        List<PrismObject<UserType>> usersList = getModelService().searchObjects(UserType.class, query, null, task, result);
        List<String> processedUsersOid = new ArrayList<>();
        if (usersList != null && usersList.size() > 0) {
            for (PrismObject<UserType> user : usersList) {
                if (processedUsersOid.contains(user.getOid())) {
                    continue;
                }
                List<AssignmentType> assignments = user.asObjectable().getAssignment();
                for (AssignmentType assignment : assignments) {
                    if (assignment.getTargetRef() != null && StringUtils.isNotEmpty(assignment.getTargetRef().getOid()) && assignment.getTargetRef().getOid().equals(getObjectWrapper().getOid())) {
                        AssignmentEditorDto dto = new AssignmentEditorDto(UserDtoStatus.MODIFY, assignment, this, user.asObjectable());
                        dto.setEditable(false);
                        list.add(dto);
                    }
                }
                processedUsersOid.add(user.getOid());
            }
        }
    } catch (Exception ex) {
        result.recomputeStatus();
        showResult(result);
    }
    Collections.sort(list);
    return list;
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue)

Aggregations

AssignmentEditorDto (com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto)28 ArrayList (java.util.ArrayList)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)4 Task (com.evolveum.midpoint.task.api.Task)4 DelegationEditorPanel (com.evolveum.midpoint.web.component.assignment.DelegationEditorPanel)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 List (java.util.List)3 ListItem (org.apache.wicket.markup.html.list.ListItem)3 ObjectBrowserPanel (com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel)2 CountablePanelTab (com.evolveum.midpoint.gui.api.component.tabs.CountablePanelTab)2 PanelTab (com.evolveum.midpoint.gui.api.component.tabs.PanelTab)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 FocusTabVisibleBehavior (com.evolveum.midpoint.gui.api.util.FocusTabVisibleBehavior)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)2 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2