Search in sources :

Example 21 with AssignmentEditorDto

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

the class PageUser method processDeputyAssignments.

private boolean processDeputyAssignments(boolean previewOnly) {
    boolean isAnythingChanged = false;
    for (AssignmentEditorDto dto : getObjectDetailsModels().getDelegationsModelObject()) {
        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 22 with AssignmentEditorDto

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

the class PageUser method processAdditionalFocalObjectsForPreview.

/**
 * for now used only for delegation changes
 * @param modelContextMap preview changes deltas
 */
protected void processAdditionalFocalObjectsForPreview(Map<PrismObject<UserType>, ModelContext<? extends ObjectType>> modelContextMap) {
    for (AssignmentEditorDto dto : getObjectDetailsModels().getDelegationsModelObject()) {
        if (!UserDtoStatus.MODIFY.equals(dto.getStatus())) {
            UserType user = dto.getDelegationOwner();
            OperationResult result = new OperationResult(OPERATION_PREVIEW_CHANGES);
            Task task = createSimpleTask(OPERATION_PREVIEW_CHANGES);
            try {
                Collection<ObjectDelta<? extends ObjectType>> deltas = prepareDelegationDelta(user.asPrismObject(), dto);
                ModelContext<UserType> modelContext = getModelInteractionService().previewChanges(deltas, getDelegationPreviewOptions(), task, result);
                modelContextMap.put(user.asPrismObject(), modelContext);
            } catch (Exception e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Could not save delegation ", e);
                error("Could not save delegation. Reason: " + e);
            } finally {
                result.recomputeStatus();
            }
        }
    }
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 23 with AssignmentEditorDto

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

the class PageUser method handleDelegationAssignmentDeltas.

protected void handleDelegationAssignmentDeltas(ObjectDelta<UserType> focusDelta, List<AssignmentEditorDto> assignments, PrismContainerDefinition<AssignmentType> def) throws SchemaException {
    ContainerDelta<AssignmentType> assDelta = def.createEmptyDelta(def.getItemName());
    for (AssignmentEditorDto assDto : assignments) {
        PrismContainerValue<AssignmentType> newValue = assDto.getNewValue(getPrismContext());
        switch(assDto.getStatus()) {
            case ADD:
                newValue.applyDefinition(def, false);
                assDelta.addValueToAdd(newValue.clone());
                break;
            case DELETE:
                PrismContainerValue<AssignmentType> oldValue = assDto.getOldValue();
                oldValue.applyDefinition(def, false);
                assDelta.addValueToDelete(oldValue.clone());
                break;
            case MODIFY:
                if (!assDto.isModified(getPrismContext())) {
                    LOGGER.trace("Assignment '{}' not modified.", assDto.getName());
                    continue;
                }
                handleModifyAssignmentDelta(assDto, def, newValue, focusDelta);
                break;
            default:
                warn(getString("pageAdminUser.message.illegalAssignmentState", assDto.getStatus()));
        }
    }
    if (!assDelta.isEmpty()) {
        focusDelta.addModification(assDelta);
    }
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto)

Example 24 with AssignmentEditorDto

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

the class UserDelegationsPanel method initLayout.

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

        private static final long serialVersionUID = 1L;

        @Override
        public void populateAssignmentDetailsPanel(ListItem<AssignmentEditorDto> item) {
            DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(), false, getObjectDetailsModels().getPrivilegesListModel());
            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(getPrivilegesListModel().getObject());
                    getDelegationModel().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) 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) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)

Example 25 with AssignmentEditorDto

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

the class PageAssignmentsList method getAssignmentsToRemoveList.

private List<AssignmentEditorDto> getAssignmentsToRemoveList(UserType user) {
    List<ConflictDto> conflicts = getSessionStorage().getRoleCatalog().getConflictsList();
    List<String> assignmentsToRemoveOids = new ArrayList<>();
    for (ConflictDto dto : conflicts) {
        if (dto.isResolved()) {
            if (dto.getAssignment1().isResolved() && dto.getAssignment1().isOldAssignment()) {
                assignmentsToRemoveOids.add(dto.getAssignment1().getAssignmentTargetObject().getOid());
            } else if (dto.getAssignment2().isResolved() && dto.getAssignment2().isOldAssignment()) {
                assignmentsToRemoveOids.add(dto.getAssignment2().getAssignmentTargetObject().getOid());
            }
        }
    }
    List<AssignmentEditorDto> assignmentsToDelete = new ArrayList<>();
    for (AssignmentType assignment : user.getAssignment()) {
        if (assignment.getTargetRef() == null) {
            continue;
        }
        if (assignmentsToRemoveOids.contains(assignment.getTargetRef().getOid())) {
            assignmentsToDelete.add(new AssignmentEditorDto(UserDtoStatus.DELETE, assignment, this));
        }
    }
    return assignmentsToDelete;
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) AssignmentConflictDto(com.evolveum.midpoint.web.page.self.dto.AssignmentConflictDto) ConflictDto(com.evolveum.midpoint.web.page.self.dto.ConflictDto)

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