Search in sources :

Example 36 with WrapperContext

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

the class ResourceDetailsModel method createConfigContainerWrappers.

private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers(OperationResult result) throws SchemaException {
    Task task = getModelServiceLocator().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
    PrismObjectWrapper<ResourceType> resourceWrapper = getObjectWrapper();
    PrismContainerWrapper<ConnectorConfigurationType> configuration = resourceWrapper.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<ConnectorConfigurationType> connectorConfigurationType = null;
    ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
    if (configuration == null || configuration.isEmpty()) {
        PrismReferenceWrapper<Referencable> connectorRef = resourceWrapper.findReference(ResourceType.F_CONNECTOR_REF);
        if (connectorRef == null || connectorRef.getValue() == null || connectorRef.getValue().getRealValue() == null) {
            return null;
        }
        PrismObject<ConnectorType> connector = WebModelServiceUtils.resolveReferenceNoFetch(connectorRef.getValue().getRealValue(), getPageBase(), task, result);
        if (connector == null) {
            return null;
        }
        ConnectorType connectorType = connector.asObjectable();
        PrismSchema schema;
        try {
            schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, 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);
        connectorConfigurationType = definitionFixed.instantiate();
        configurationStatus = ItemStatus.ADDED;
        WrapperContext ctx = new WrapperContext(task, result);
        ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
        configuration = getModelServiceLocator().createItemWrapper(connectorConfigurationType, configurationStatus, ctx);
    }
    return configuration;
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Referencable(com.evolveum.midpoint.prism.Referencable) 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 37 with WrapperContext

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

the class PageAdminObjectDetails method createObjectWrapper.

private PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, boolean isReadonly, Task task, OperationResult result) {
    ItemStatus itemStatus = computeWrapperStatus();
    PrismObjectWrapperFactory<O> factory = getRegistry().getObjectWrapperFactory(object.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(ItemStatus.ADDED == itemStatus);
    context.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(object));
    // Boolean instead of boolean isReadonly
    if (isReadonly) {
        context.setReadOnly(isReadonly);
    }
    try {
        PrismObjectWrapper<O> wrapper = factory.createObjectWrapper(object, itemStatus, context);
        result.recordSuccess();
        return wrapper;
    } catch (Exception ex) {
        result.recordFatalError(getString("PageAdminObjectDetails.message.loadObjectWrapper.fatalError"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
        showResult(result, false);
        throw new RestartResponseException(getRestartResponsePage());
    }
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) RestartResponseException(org.apache.wicket.RestartResponseException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 38 with WrapperContext

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

the class PrismContainerValuePanel method prepareNewContainers.

private void prepareNewContainers(AjaxRequestTarget target, List<PrismContainerDefinition<?>> containers) {
    Task task = getPageBase().createSimpleTask("Create child containers");
    WrapperContext ctx = new WrapperContext(task, task.getResult());
    ctx.setCreateIfEmpty(true);
    containers.forEach(container -> {
        try {
            ItemWrapper iw = getPageBase().createItemWrapper(container, getModelObject(), ctx);
            if (iw != null) {
                getModelObject().addItem(iw);
            }
        } catch (SchemaException e) {
            OperationResult result = ctx.getResult();
            result.recordFatalError(createStringResource("PrismContainerValuePanel.message.prepareNewContainers.fatalError", container).getString(), e);
            getPageBase().showResult(ctx.getResult());
        }
    });
    refreshPanel(target);
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) 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 39 with WrapperContext

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

the class FocusProjectionsTabPanel method addSelectedAccountPerformed.

private void addSelectedAccountPerformed(AjaxRequestTarget target, List<ResourceType> newResources) {
    getPageBase().hideMainPopup(target);
    if (newResources.isEmpty()) {
        warn(getString("pageUser.message.noResourceSelected"));
        return;
    }
    for (ResourceType resource : newResources) {
        try {
            ShadowType shadow = new ShadowType();
            ObjectReferenceType resourceRef = new ObjectReferenceType();
            resourceRef.asReferenceValue().setObject(resource.asPrismObject());
            shadow.setResourceRef(resourceRef);
            ResourceType usedResource = resource;
            ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resource.asPrismObject(), LayerType.PRESENTATION);
            if (refinedSchema == null) {
                Task task = getPageBase().createSimpleTask(FocusPersonasTabPanel.class.getSimpleName() + ".loadResource");
                OperationResult result = task.getResult();
                PrismObject<ResourceType> loadedResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
                result.recomputeStatus();
                refinedSchema = ResourceSchemaFactory.getCompleteSchema(loadedResource, LayerType.PRESENTATION);
                if (refinedSchema == null) {
                    error(getString("pageAdminFocus.message.couldntCreateAccountNoSchema", resource.getName()));
                    continue;
                }
                // shadow.setResource(loadedResource.asObjectable());
                usedResource = loadedResource.asObjectable();
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Refined schema for {}\n{}", resource, refinedSchema.debugDump());
            }
            ResourceObjectTypeDefinition accountDefinition = refinedSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
            if (accountDefinition == null) {
                error(getString("pageAdminFocus.message.couldntCreateAccountNoAccountSchema", resource.getName()));
                continue;
            }
            // shadow.asPrismContainer().findOrCreateContainer(ShadowType.F_ATTRIBUTES).applyDefinition(accountDefinition.toResourceAttributeContainerDefinition());
            QName objectClass = accountDefinition.getObjectClassDefinition().getTypeName();
            ObjectReferenceType usedResourceRef = new ObjectReferenceType();
            usedResourceRef.asReferenceValue().setObject(usedResource.asPrismObject());
            shadow.setResourceRef(usedResourceRef);
            shadow.setObjectClass(objectClass);
            shadow.setIntent(accountDefinition.getIntent());
            shadow.setKind(accountDefinition.getKind());
            getPrismContext().adopt(shadow);
            Task task = getPageBase().createSimpleTask(OPERATION_ADD_ACCOUNT);
            PrismObjectWrapperFactory<ShadowType> factory = getPageBase().getRegistry().getObjectWrapperFactory(shadow.asPrismContainer().getDefinition());
            WrapperContext context = new WrapperContext(task, task.getResult());
            ShadowWrapper wrapperNew = (ShadowWrapper) factory.createObjectWrapper(shadow.asPrismContainer(), ItemStatus.ADDED, context);
            if (task.getResult() != null && !WebComponentUtil.isSuccessOrHandledError(task.getResult())) {
                showResult(task.getResult(), false);
            }
            wrapperNew.setProjectionStatus(UserDtoStatus.ADD);
            projectionModel.getObject().add(wrapperNew);
        } catch (Exception ex) {
            error(getString("pageAdminFocus.message.couldntCreateAccount", resource.getName(), ex.getMessage()));
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create account", ex);
        }
    }
    target.add(getMultivalueContainerListPanel());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)

Example 40 with WrapperContext

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

the class TestWrapperDelta method test110modifyUserAddAssignment.

@Test
public void test110modifyUserAddAssignment() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
    WrapperContext ctx = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> objectWrapper = createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
    PrismContainerValue<AssignmentType> newAssignmentClone = createDummyResourceAssignment(objectWrapper, 0, task, result);
    ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
    assertModificationsSize(delta, 1);
    assertModification(delta, UserType.F_ASSIGNMENT, ModificationTypeType.ADD, newAssignmentClone.asContainerable());
    executeChanges(delta, null, task, result);
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
    UserAsserter.forUser(userElaineAfter).assignments().assertAssignments(1);
    PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
    List<PrismContainerValue<AssignmentType>> assignmentValues = assignmentAfter.getValues();
    assertEquals("Unexpected number of assignments " + assignmentValues.size(), 1, assignmentValues.size());
    PrismContainerValue<AssignmentType> assignmentValue = assignmentValues.iterator().next();
    assertTrue(newAssignmentClone.equals(assignmentValue, ParameterizedEquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS));
}
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) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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