Search in sources :

Example 21 with WrapperContext

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

the class PageAccount method loadAccount.

private ShadowWrapper loadAccount(PageParameters parameters) {
    Task task = createSimpleTask(OPERATION_LOAD_ACCOUNT);
    OperationResult result = task.getResult();
    Collection<SelectorOptions<GetOperationOptions>> options = getOperationOptionsBuilder().item(ShadowType.F_RESOURCE_REF).resolve().build();
    StringValue oid = parameters != null ? parameters.get(OnePageParameterEncoder.PARAMETER) : null;
    if (oid == null) {
        getSession().error(getString("pageAccount.message.cantEditAccount"));
        showResult(result);
        throw new RestartResponseException(PageResources.class);
    }
    PrismObject<ShadowType> account = WebModelServiceUtils.loadObject(ShadowType.class, oid.toString(), options, PageAccount.this, task, result);
    if (account == null) {
        getSession().error(getString("pageAccount.message.cantEditAccount"));
        showResult(result);
        throw new RestartResponseException(PageResources.class);
    }
    PrismObjectWrapperFactory<ShadowType> owf = getRegistry().getObjectWrapperFactory(account.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    context.setShowEmpty(false);
    ShadowWrapper wrapper;
    try {
        wrapper = (ShadowWrapper) owf.createObjectWrapper(account, ItemStatus.NOT_CHANGED, context);
    // TODO: fetch result???
    } catch (SchemaException e) {
        LOGGER.error("Cannot create wrapper for shadow {}", account);
        result.recordFatalError(getString("PageAccount.message.loadAccount.fatalError"));
        throw new RestartResponseException(PageResources.class);
    }
    return wrapper;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PageResources(com.evolveum.midpoint.web.page.admin.resources.PageResources) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) RestartResponseException(org.apache.wicket.RestartResponseException) ShadowWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ShadowWrapper) StringValue(org.apache.wicket.util.string.StringValue)

Example 22 with WrapperContext

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

the class MetadataWrapperFactoryImpl method createWrapper.

@Override
public PrismContainerWrapper<C> createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException {
    WrapperContext ctx = context.clone();
    ctx.setReadOnly(true);
    ctx.setMetadata(true);
    PrismContainerWrapper<C> wrapper = super.createWrapper(parent, def, ctx);
    return wrapper;
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)

Example 23 with WrapperContext

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

the class ExpressionPropertyPanel method expressionValueAddPerformed.

private void expressionValueAddPerformed(AjaxRequestTarget target, ExpressionValueTypes expressionType) {
    getPageBase().hideMainPopup(target);
    try {
        ExpressionType newExpressionValue = new ExpressionType();
        if (ExpressionValueTypes.SHADOW_REF_EXPRESSION.equals(expressionType)) {
            ExpressionUtil.addShadowRefEvaluatorValue(newExpressionValue, null, getPrismContext());
        } else if (ExpressionValueTypes.ASSOCIATION_TARGET_SEARCH_EXPRESSION.equals(expressionType)) {
            ExpressionUtil.getOrCreateAssociationTargetSearchValues(newExpressionValue, getPrismContext());
        } else if (ExpressionValueTypes.LITERAL_VALUE_EXPRESSION.equals(expressionType)) {
            ExpressionUtil.updateLiteralExpressionValue(newExpressionValue, Collections.singletonList(""), getPrismContext());
        }
        WrapperContext context = new WrapperContext(null, null);
        PrismPropertyValue<ExpressionType> expressionValue = getPageBase().getPrismContext().itemFactory().createPropertyValue(newExpressionValue);
        PrismPropertyValueWrapper<ExpressionType> newExpressionValueWrapper = getPageBase().createValueWrapper(getModelObject(), expressionValue, ValueStatus.ADDED, context);
        getModelObject().getValues().clear();
        getModelObject().getValues().add(newExpressionValueWrapper);
        getModelObject().getItem().setRealValue(newExpressionValue);
    } catch (SchemaException ex) {
        LOGGER.error("Unable to create new expression value: {}", ex.getLocalizedMessage());
    }
    target.add(ExpressionPropertyPanel.this);
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 24 with WrapperContext

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

the class ConfigurationStep method createConfigContainerWrappers.

// @NotNull
private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers() throws SchemaException {
    PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
    PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    if (parentPage.isNewResource()) {
        return null;
    }
    ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
    if (configuration == null) {
        PrismObject<ConnectorType> connector = ResourceTypeUtil.getConnectorIfPresent(resource);
        if (connector == null) {
            throw new IllegalStateException("No resolved connector object in resource object");
        }
        ConnectorType connectorType = connector.asObjectable();
        PrismSchema schema;
        try {
            schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, parentPage.getPrismContext());
        } catch (SchemaException e) {
            throw new SystemException("Couldn't parse connector schema: " + e.getMessage(), e);
        }
        PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
        // Fixing (errorneously) set maxOccurs = unbounded. See MID-2317 and related issues.
        PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
        definitionFixed.toMutable().setMaxOccurs(1);
        configuration = definitionFixed.instantiate();
        configurationStatus = ItemStatus.ADDED;
    }
    Task task = getPageBase().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
    WrapperContext ctx = new WrapperContext(task, getResult());
    ctx.setReadOnly(parentPage.isReadOnly());
    ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
    return getPageBase().createItemWrapper(configuration, configurationStatus, ctx);
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 25 with WrapperContext

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

the class ContainerListDataProvider method internalIterator.

@Override
public Iterator<? extends PrismContainerValueWrapper<C>> internalIterator(long first, long count) {
    LOGGER.trace("begin::iterator() from {} count {}.", first, count);
    getAvailableData().clear();
    Task task = getPageBase().createSimpleTask(OPERATION_SEARCH_CONTAINERS);
    OperationResult result = task.getResult();
    try {
        ObjectPaging paging = createPaging(first, count);
        ObjectQuery query = getQuery();
        if (query == null) {
            query = getPrismContext().queryFactory().createQuery();
        }
        query.setPaging(paging);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} with {}", getType().getSimpleName(), query.debugDump());
        }
        List<C> list = WebModelServiceUtils.searchContainers(getType(), query, options, result, getPageBase());
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} resulted in {} containers", getType().getSimpleName(), list.size());
        }
        for (C object : list) {
            WrapperContext context = new WrapperContext(task, result);
            PrismContainerWrapperFactory<C> factory = getPageBase().findContainerWrapperFactory(object.asPrismContainerValue().getDefinition());
            getAvailableData().add(factory.createValueWrapper(null, object.asPrismContainerValue(), ValueStatus.NOT_CHANGED, context));
        }
    } catch (Exception ex) {
        result.recordFatalError(getPageBase().createStringResource("ContainerListDataProvider.message.listContainers.fatalError").getString(), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list containers", ex);
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!WebComponentUtil.isSuccessOrHandledError(result)) {
        getPageBase().showResult(result);
        throw new RestartResponseException(PageError.class);
    }
    LOGGER.trace("end::iterator()");
    return getAvailableData().iterator();
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Task(com.evolveum.midpoint.task.api.Task) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RestartResponseException(org.apache.wicket.RestartResponseException)

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