Search in sources :

Example 26 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class PageResource method createTabsPanel.

private AjaxTabbedPanel<ITab> createTabsPanel() {
    List<ITab> tabs = new ArrayList<>();
    tabs.add(new PanelTab(createStringResource("PageResource.tab.details")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceDetailsTabPanel(panelId, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.tasks")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceTasksPanel(panelId, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.account")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, ShadowKindType.ACCOUNT, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.entitlement")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, ShadowKindType.ENTITLEMENT, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.generic")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, ShadowKindType.GENERIC, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.others")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, null, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.connector")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceConnectorPanel(panelId, loadWrapperModel(resourceModel));
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.schemaHandling")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            PrismObjectWrapperFactory<ResourceType> resourceFactory = PageResource.this.findObjectWrapperFactory(resourceModel.getObject().getDefinition());
            Task task = createSimpleTask("Create resource wrapper");
            OperationResult result = task.getResult();
            WrapperContext ctx = new WrapperContext(task, result);
            PrismObjectWrapper<ResourceType> resourceWrapper;
            try {
                resourceWrapper = resourceFactory.createObjectWrapper(resourceModel.getObject(), ItemStatus.NOT_CHANGED, ctx);
            } catch (SchemaException e) {
                resourceWrapper = null;
            }
            if (resourceWrapper == null) {
                return new WebMarkupContainer(panelId);
            }
            return new ResourceSchemaHandlingTabPanel(panelId, PrismContainerWrapperModel.fromContainerWrapper(Model.of(resourceWrapper), ResourceType.F_SCHEMA_HANDLING));
        }
    });
    AjaxTabbedPanel<ITab> resourceTabs = new AjaxTabbedPanel<ITab>(ID_TAB_PANEL, tabs) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onTabChange(int index) {
            updateBreadcrumbParameters(PARAMETER_SELECTED_TAB, index);
        }
    };
    resourceTabs.setOutputMarkupId(true);
    return resourceTabs;
}
Also used : PanelTab(com.evolveum.midpoint.gui.api.component.tabs.PanelTab) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObjectWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) AjaxTabbedPanel(com.evolveum.midpoint.web.component.AjaxTabbedPanel) PrismObjectWrapperFactory(com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory)

Example 27 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class WebComponentUtil method getAssociationExpression.

// TODO refactor..
@Deprecated
public static ExpressionType getAssociationExpression(PrismContainerValueWrapper<AssignmentType> assignmentValueWrapper, boolean createIfNotExist, PrismContext prismContext, PageBase pageBase) {
    if (assignmentValueWrapper == null) {
        return null;
    }
    if (createIfNotExist && prismContext == null) {
        throw new IllegalArgumentException("createIfNotExist is set but prismContext is null");
    }
    PrismContainerWrapper<ResourceObjectAssociationType> association;
    try {
        association = assignmentValueWrapper.findContainer(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ASSOCIATION));
    } catch (SchemaException e) {
        LOGGER.error("Cannot find association wrapper, reason: {}", e.getMessage(), e);
        pageBase.getSession().error("Cannot find association wrapper, reason: " + e.getMessage());
        return null;
    }
    if (association == null || association.getValues() == null || association.getValues().size() == 0) {
        return null;
    }
    PrismContainerValueWrapper<ResourceObjectAssociationType> associationValueWrapper = association.getValues().get(0);
    PrismPropertyWrapper<ExpressionType> expressionWrapper;
    try {
        expressionWrapper = associationValueWrapper.findProperty(ItemPath.create(ResourceObjectAssociationType.F_OUTBOUND, MappingType.F_EXPRESSION));
    } catch (SchemaException e) {
        LOGGER.error("Cannot find expression wrapper, reason: {}", e.getMessage(), e);
        pageBase.getSession().error("Cannot find expression wrapper, reason: " + e.getMessage());
        return null;
    }
    if (expressionWrapper == null) {
        return null;
    }
    List<PrismPropertyValueWrapper<ExpressionType>> expressionValues = expressionWrapper.getValues();
    if (expressionValues == null || expressionValues.size() == 0) {
        return null;
    }
    try {
        ExpressionType expression = expressionValues.get(0).getRealValue();
        if (expression == null && createIfNotExist) {
            expression = new ExpressionType();
            PrismPropertyValue<ExpressionType> exp = prismContext.itemFactory().createPropertyValue(expression);
            WrapperContext context = new WrapperContext(null, null);
            PrismPropertyValueWrapper<ExpressionType> val = (PrismPropertyValueWrapper<ExpressionType>) pageBase.createValueWrapper(expressionWrapper, exp, ValueStatus.ADDED, context);
            // ValueWrapperOld<ExpressionType> val = new
            // ValueWrapperOld<>(expressionWrapper, exp, prismContext);
            expressionValues.remove(0);
            expressionValues.add(0, val);
        }
    } catch (SchemaException e) {
        // TODO erro handling
        return null;
    }
    return expressionValues.get(0).getRealValue();
}
Also used : PrismPropertyValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)

Example 28 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class WebPrismUtil method createNewValueWrapper.

public static <IW extends ItemWrapper, PV extends PrismValue, VW extends PrismValueWrapper> VW createNewValueWrapper(IW itemWrapper, PV newValue, ValueStatus status, ModelServiceLocator modelServiceLocator) throws SchemaException {
    LOGGER.debug("Adding value to {}", itemWrapper);
    Task task = modelServiceLocator.createSimpleTask(OPERATION_CREATE_NEW_VALUE);
    OperationResult result = task.getResult();
    WrapperContext context = new WrapperContext(task, result);
    context.setObjectStatus(itemWrapper.findObjectStatus());
    context.setShowEmpty(true);
    context.setCreateIfEmpty(true);
    VW newValueWrapper = modelServiceLocator.createValueWrapper(itemWrapper, newValue, status, context);
    result.recordSuccess();
    return newValueWrapper;
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 29 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class WebPrismUtil method createNewValueWrapper.

public static <IW extends ItemWrapper, PV extends PrismValue, VW extends PrismValueWrapper> VW createNewValueWrapper(IW itemWrapper, PV newValue, PageBase pageBase, AjaxRequestTarget target) {
    LOGGER.debug("Adding value to {}", itemWrapper);
    Task task = pageBase.createSimpleTask(OPERATION_CREATE_NEW_VALUE);
    OperationResult result = task.getResult();
    VW newValueWrapper = null;
    try {
        if (!(itemWrapper instanceof PrismContainerWrapper)) {
            itemWrapper.getItem().add(newValue);
        }
        WrapperContext context = new WrapperContext(task, result);
        context.setObjectStatus(itemWrapper.findObjectStatus());
        context.setShowEmpty(true);
        context.setCreateIfEmpty(true);
        newValueWrapper = pageBase.createValueWrapper(itemWrapper, newValue, ValueStatus.ADDED, context);
        itemWrapper.getValues().add(newValueWrapper);
        result.recordSuccess();
    } catch (SchemaException e) {
        LOGGER.error("Cannot create new value for {}", itemWrapper, e);
        result.recordFatalError(pageBase.createStringResource("WebPrismUtil.message.createNewValueWrapper.fatalError", newValue, e.getMessage()).getString(), e);
        target.add(pageBase.getFeedbackPanel());
    }
    return newValueWrapper;
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 30 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class PageResource method loadWrapperModel.

private LoadableModel<PrismObjectWrapper<ResourceType>> loadWrapperModel(IModel<PrismObject<ResourceType>> resourceModel) {
    return new LoadableModel<>(false) {

        @Override
        protected PrismObjectWrapper<ResourceType> load() {
            PrismObject<ResourceType> resource = resourceModel.getObject();
            PrismObjectWrapperFactory<ResourceType> factory = findObjectWrapperFactory(resource.getDefinition());
            Task task = createSimpleTask("createWrapper");
            OperationResult result = task.getResult();
            WrapperContext ctx = new WrapperContext(task, result);
            ctx.setCreateIfEmpty(true);
            try {
                return factory.createObjectWrapper(resource, ItemStatus.NOT_CHANGED, ctx);
            } catch (SchemaException e) {
                // TODO:
                return null;
            }
        }
    };
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)46 Task (com.evolveum.midpoint.task.api.Task)32 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 Test (org.testng.annotations.Test)15 ModelServiceLocator (com.evolveum.midpoint.gui.api.util.ModelServiceLocator)11 ItemStatus (com.evolveum.midpoint.gui.api.prism.ItemStatus)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)7 RestartResponseException (org.apache.wicket.RestartResponseException)5 PrismObjectWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QName (javax.xml.namespace.QName)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 NotNull (org.jetbrains.annotations.NotNull)3 PrismObjectWrapperFactory (com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory)2 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)2 ShadowWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ShadowWrapper)2 PrismPropertyValueWrapper (com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper)2