Search in sources :

Example 1 with PrismReferenceWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper in project midpoint by Evolveum.

the class ShadowAssociationWrapperImpl method getDelta.

@Override
public <D extends ItemDelta<?, ?>> Collection<D> getDelta() throws SchemaException {
    Collection<D> deltas = new ArrayList<D>();
    ContainerDelta<ShadowAssociationType> delta = createEmptyDelta(getDeltaPathForStatus(getStatus()));
    switch(getStatus()) {
        case ADDED:
            if (CollectionUtils.isEmpty(getValues())) {
                return null;
            }
            // we know that there is always only one value
            PrismContainerValueWrapper<ShadowAssociationType> containerValueWrappers = getValues().iterator().next();
            for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
                if (!(itemWrapper instanceof PrismReferenceWrapper)) {
                    LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
                    continue;
                }
                PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
                for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
                    if (updatedRefValue.getNewValue().isEmpty()) {
                        continue;
                    }
                    ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
                    shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
                    shadowAssociationType.setName(refWrapper.getItemName());
                    shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
                    delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
                }
            }
            if (delta.isEmpty()) {
                return null;
            }
            return (Collection) MiscUtil.createCollection(delta);
        case NOT_CHANGED:
            containerValueWrappers = getValues().iterator().next();
            for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
                if (!(itemWrapper instanceof PrismReferenceWrapper)) {
                    LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
                    continue;
                }
                PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
                for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
                    if (updatedRefValue.getNewValue().isEmpty()) {
                        continue;
                    }
                    ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
                    shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
                    shadowAssociationType.setName(refWrapper.getItemName());
                    shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
                    switch(updatedRefValue.getStatus()) {
                        case ADDED:
                            delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
                            break;
                        case NOT_CHANGED:
                            break;
                        case DELETED:
                            delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
                            break;
                    }
                }
            }
            break;
        case DELETED:
            containerValueWrappers = getValues().iterator().next();
            for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
                if (!(itemWrapper instanceof PrismReferenceWrapper)) {
                    LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
                    continue;
                }
                PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
                for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
                    if (updatedRefValue.getNewValue().isEmpty()) {
                        continue;
                    }
                    ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
                    shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
                    shadowAssociationType.setName(refWrapper.getItemName());
                    shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef((PrismReferenceValue) updatedRefValue.getNewValue()));
                    delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
                }
            }
            break;
    }
    if (!delta.isEmpty()) {
        deltas.add((D) delta);
    }
    if (deltas.isEmpty()) {
        return null;
    }
    return deltas;
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 2 with PrismReferenceWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper in project midpoint by Evolveum.

the class ShadowAssociationWrapperFactoryImpl method createValuesWrapper.

@Override
protected List<PrismContainerValueWrapper<ShadowAssociationType>> createValuesWrapper(PrismContainerWrapper<ShadowAssociationType> itemWrapper, PrismContainer<ShadowAssociationType> item, WrapperContext context) throws SchemaException {
    if (!(itemWrapper instanceof ShadowAssociationWrapperImpl)) {
        return super.createValuesWrapper(itemWrapper, item, context);
    }
    ShadowAssociationWrapperImpl associationWrapper = (ShadowAssociationWrapperImpl) itemWrapper;
    PrismContainerValueWrapper<ShadowAssociationType> shadowValueWrapper = createContainerValueWrapper(associationWrapper, associationWrapper.getItem().createNewValue(), ItemStatus.ADDED == associationWrapper.getStatus() ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, context);
    Collection<PrismReferenceWrapper> shadowReferences = new ArrayList<>();
    for (ResourceAssociationDefinition def : context.getRefinedAssociationDefinitions()) {
        PrismReference shadowAss = fillInShadowReference(def, item);
        PrismReferenceWrapper shadowReference = (PrismReferenceWrapper) referenceWrapperFactory.createWrapper(shadowValueWrapper, shadowAss, shadowAss.isEmpty() ? ItemStatus.ADDED : ItemStatus.NOT_CHANGED, context);
        shadowReference.setFilter(WebComponentUtil.createAssociationShadowRefFilter(def, getPrismContext(), context.getResource().getOid()));
        shadowReferences.add(shadowReference);
    }
    shadowValueWrapper.getItems().addAll((Collection) shadowReferences);
    setupExpanded(shadowValueWrapper);
    return Collections.singletonList(shadowValueWrapper);
}
Also used : PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 3 with PrismReferenceWrapper

use of com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper in project midpoint by Evolveum.

the class AssignmentPanel method getAssignmentMenuActions.

private <AH extends FocusType> List<InlineMenuItem> getAssignmentMenuActions() {
    List<InlineMenuItem> menuItems = new ArrayList<>();
    PrismObject<AH> obj = getMultivalueContainerListPanel().getFocusObject();
    try {
        boolean isUnassignAuthorized = getParentPage().isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI, AuthorizationPhaseType.REQUEST, obj, null, null, null);
        if (isUnassignAuthorized) {
            menuItems.add(new ButtonInlineMenuItem(getAssignmentsLimitReachedUnassignTitleModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                public CompositedIconBuilder getIconCompositedBuilder() {
                    return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_DELETE_MENU_ITEM);
                }

                @Override
                public InlineMenuItemAction initAction() {
                    return getMultivalueContainerListPanel().createDeleteColumnAction();
                }
            });
        }
    } catch (Exception ex) {
        LOGGER.error("Couldn't check unassign authorization for the object: {}, {}", obj.getName(), ex.getLocalizedMessage());
        if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_ASSIGN_ACTION_URI)) {
            menuItems.add(new ButtonInlineMenuItem(createStringResource("PageBase.button.unassign")) {

                private static final long serialVersionUID = 1L;

                @Override
                public CompositedIconBuilder getIconCompositedBuilder() {
                    return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_DELETE_MENU_ITEM);
                }

                @Override
                public InlineMenuItemAction initAction() {
                    return getMultivalueContainerListPanel().createDeleteColumnAction();
                }
            });
        }
    }
    menuItems.add(new ButtonInlineMenuItem(createStringResource("PageBase.button.edit")) {

        private static final long serialVersionUID = 1L;

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_EDIT_MENU_ITEM);
        }

        @Override
        public InlineMenuItemAction initAction() {
            return getMultivalueContainerListPanel().createEditColumnAction();
        }
    });
    ButtonInlineMenuItem menu = new ButtonInlineMenuItem(createStringResource("AssignmentPanel.viewTargetObject")) {

        private static final long serialVersionUID = 1L;

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_NAVIGATE_ARROW);
        }

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<PrismContainerValueWrapper<AssignmentType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    PrismContainerValueWrapper<AssignmentType> assignmentContainer = getRowModel().getObject();
                    PrismReferenceWrapper<ObjectReferenceType> targetRef;
                    try {
                        targetRef = assignmentContainer.findReference(ItemPath.create(AssignmentType.F_TARGET_REF));
                    } catch (SchemaException e) {
                        getSession().error("Couldn't show details page. More information provided in log.");
                        LOGGER.error("Couldn't show details page, no targetRef reference wrapper found: {}", e.getMessage(), e);
                        target.add(getPageBase().getFeedbackPanel());
                        return;
                    }
                    if (targetRef != null && targetRef.getValues() != null && targetRef.getValues().size() > 0) {
                        PrismReferenceValueWrapperImpl<ObjectReferenceType> refWrapper = targetRef.getValues().get(0);
                        if (!StringUtils.isEmpty(refWrapper.getNewValue().getOid())) {
                            Class<? extends ObjectType> targetClass = ObjectTypes.getObjectTypeFromTypeQName(refWrapper.getRealValue().getType()).getClassDefinition();
                            WebComponentUtil.dispatchToObjectDetailsPage(targetClass, refWrapper.getNewValue().getOid(), AssignmentPanel.this, false);
                        }
                    }
                }
            };
        }

        @Override
        public boolean isHeaderMenuItem() {
            return false;
        }
    };
    menu.setVisibilityChecker((InlineMenuItem.VisibilityChecker) (rowModel, isHeader) -> {
        PrismContainerValueWrapper<AssignmentType> assignment = (PrismContainerValueWrapper<AssignmentType>) rowModel.getObject();
        if (assignment == null) {
            return false;
        }
        PrismReferenceWrapper<Referencable> target = null;
        try {
            target = assignment.findReference(AssignmentType.F_TARGET_REF);
        } catch (Exception e) {
            LOGGER.error("Couldn't find targetRef in assignment");
        }
        return target != null && !target.isEmpty();
    });
    menuItems.add(menu);
    return menuItems;
}
Also used : PrismContainerWrapperModel(com.evolveum.midpoint.web.model.PrismContainerWrapperModel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) PrismContainerWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) PrismContainerWrapperColumn(com.evolveum.midpoint.gui.impl.component.data.column.PrismContainerWrapperColumn) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) AuthorizationConstants(com.evolveum.midpoint.security.api.AuthorizationConstants) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AssignmentCandidatesSpecification(com.evolveum.midpoint.model.api.AssignmentCandidatesSpecification) StringUtils(org.apache.commons.lang3.StringUtils) AjaxLinkColumn(com.evolveum.midpoint.web.component.data.column.AjaxLinkColumn) QNameUtil(com.evolveum.midpoint.util.QNameUtil) AbstractColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) IModel(org.apache.wicket.model.IModel) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) Search(com.evolveum.midpoint.web.component.search.Search) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) Label(org.apache.wicket.markup.html.basic.Label) AjaxIconButton(com.evolveum.midpoint.web.component.AjaxIconButton) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) ListItem(org.apache.wicket.markup.html.list.ListItem) Collection(java.util.Collection) CompositedIcon(com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon) SearchFactory(com.evolveum.midpoint.web.component.search.SearchFactory) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) Task(com.evolveum.midpoint.task.api.Task) SessionStorage(com.evolveum.midpoint.web.session.SessionStorage) MultivalueContainerListPanelWithDetailsPanel(com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel) List(java.util.List) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) AssignmentListProvider(com.evolveum.midpoint.web.component.util.AssignmentListProvider) ColumnMenuAction(com.evolveum.midpoint.web.component.data.column.ColumnMenuAction) PropertyModel(org.apache.wicket.model.PropertyModel) Item(org.apache.wicket.markup.repeater.Item) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) MultivalueContainerDetailsPanel(com.evolveum.midpoint.gui.impl.component.MultivalueContainerDetailsPanel) AssignmentPopup(com.evolveum.midpoint.gui.api.component.AssignmentPopup) SearchItemDefinition(com.evolveum.midpoint.web.component.search.SearchItemDefinition) QName(javax.xml.namespace.QName) CompiledObjectCollectionView(com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView) NotNull(org.jetbrains.annotations.NotNull) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) PrismReferenceValueWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismReferenceValueWrapperImpl) AssignmentPopupDto(com.evolveum.midpoint.gui.api.component.AssignmentPopupDto) GuiDisplayTypeUtil(com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil) RefFilter(com.evolveum.midpoint.prism.query.RefFilter) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) IconCssStyle(com.evolveum.midpoint.gui.impl.component.icon.IconCssStyle) Trace(com.evolveum.midpoint.util.logging.Trace) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) GuiStyleConstants(com.evolveum.midpoint.gui.api.GuiStyleConstants) PageStorage(com.evolveum.midpoint.web.session.PageStorage) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) InlineMenuButtonColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn) PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) AssignmentObjectRelation(com.evolveum.midpoint.model.api.AssignmentObjectRelation) PrismObjectWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper) AssignmentsDetailsPanel(com.evolveum.midpoint.gui.impl.component.AssignmentsDetailsPanel) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) CompositedIconColumn(com.evolveum.midpoint.gui.impl.component.data.column.CompositedIconColumn) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ArrayList(java.util.ArrayList) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ColumnMenuAction(com.evolveum.midpoint.web.component.data.column.ColumnMenuAction) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)

Aggregations

PrismReferenceWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper)3 ArrayList (java.util.ArrayList)2 GuiStyleConstants (com.evolveum.midpoint.gui.api.GuiStyleConstants)1 AssignmentPopup (com.evolveum.midpoint.gui.api.component.AssignmentPopup)1 AssignmentPopupDto (com.evolveum.midpoint.gui.api.component.AssignmentPopupDto)1 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)1 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)1 PrismContainerWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper)1 PrismObjectWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper)1 GuiDisplayTypeUtil (com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil)1 WebComponentUtil (com.evolveum.midpoint.gui.api.util.WebComponentUtil)1 WebModelServiceUtils (com.evolveum.midpoint.gui.api.util.WebModelServiceUtils)1 AssignmentsDetailsPanel (com.evolveum.midpoint.gui.impl.component.AssignmentsDetailsPanel)1 MultivalueContainerDetailsPanel (com.evolveum.midpoint.gui.impl.component.MultivalueContainerDetailsPanel)1 MultivalueContainerListPanelWithDetailsPanel (com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel)1 CompositedIconColumn (com.evolveum.midpoint.gui.impl.component.data.column.CompositedIconColumn)1 PrismContainerWrapperColumn (com.evolveum.midpoint.gui.impl.component.data.column.PrismContainerWrapperColumn)1