Search in sources :

Example 6 with WrapperContext

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

the class PageValuePolicy method createValuePolicy.

private PrismObjectWrapper<ValuePolicyType> createValuePolicy() throws SchemaException {
    Task task = createSimpleTask(OPERATION_LOAD_VALUEPOLICY);
    PrismObject<ValuePolicyType> valuePolicyObject = getPrismContext().createObject(ValuePolicyType.class);
    PrismObjectWrapperFactory<ValuePolicyType> owf = getRegistry().getObjectWrapperFactory(valuePolicyObject.getDefinition());
    WrapperContext context = new WrapperContext(task, task.getResult());
    PrismObjectWrapper<ValuePolicyType> valuePolicyWrapper = owf.createObjectWrapper(valuePolicyObject, ItemStatus.ADDED, context);
    return valuePolicyWrapper;
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)

Example 7 with WrapperContext

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

the class ApplicablePolicyGroupPanel method onPolicyAddedOrRemoved.

private void onPolicyAddedOrRemoved(PrismObject<AbstractRoleType> assignmentTargetObject, boolean added) {
    if (isAssignmentAlreadyInList(assignmentTargetObject.getOid())) {
        PrismContainerValueWrapper<AssignmentType> assignmentToRemove = null;
        for (PrismContainerValueWrapper<AssignmentType> assignment : assignmentsModel.getObject().getValues()) {
            ObjectReferenceType targetRef = assignment.getRealValue().getTargetRef();
            if (targetRef != null && targetRef.getOid().equals(assignmentTargetObject.getOid())) {
                if (added && assignment.getStatus() == ValueStatus.DELETED) {
                    assignment.setStatus(ValueStatus.NOT_CHANGED);
                } else if (!added && assignment.getStatus() == ValueStatus.ADDED) {
                    assignmentToRemove = assignment;
                } else if (!added) {
                    assignment.setStatus(ValueStatus.DELETED);
                }
            }
        }
        assignmentsModel.getObject().getValues().remove(assignmentToRemove);
    } else {
        if (added) {
            // TODO: not sure if this is correct way of creating new value.. this value is added directly to the origin object... what about deltas??
            PrismContainerValue<AssignmentType> newAssignment = assignmentsModel.getObject().getItem().createNewValue();
            ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(assignmentTargetObject, getPageBase().getPrismContext());
            AssignmentType assignmentType = newAssignment.asContainerable();
            assignmentType.setTargetRef(ref);
            Task task = getPageBase().createSimpleTask("Creating new applicable policy");
            WrapperContext context = new WrapperContext(task, null);
            PrismContainerValueWrapper<AssignmentType> valueWrapper;
            try {
                valueWrapper = (PrismContainerValueWrapper<AssignmentType>) getPageBase().createValueWrapper(assignmentsModel.getObject(), newAssignment, ValueStatus.ADDED, context);
                assignmentsModel.getObject().getValues().add(valueWrapper);
            } catch (SchemaException e) {
            // TOTO error handling
            }
        // 
        // valueWrapper.setShowEmpty(true, false);
        }
    }
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) Task(com.evolveum.midpoint.task.api.Task) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 8 with WrapperContext

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

the class TestIntegrationObjectWrapperFactory method test150CreateWrapperShadow.

@Test
public void test150CreateWrapperShadow() throws Exception {
    PrismObject<ShadowType> shadow = getShadowModel(accountJackOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    display("Shadow", shadow);
    PrismObject<ShadowType> shadowOld = shadow.clone();
    when();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    PrismObjectWrapperFactory<ShadowType> factory = modelServiceLocator.findObjectWrapperFactory(shadow.getDefinition());
    assertTrue("Wrong object factory found, expected shadow factory but got " + factory.getClass().getSimpleName(), factory instanceof ShadowWrapperFactoryImpl);
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(true);
    PrismObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper(shadow, ItemStatus.NOT_CHANGED, context);
    assertTrue("Wrong wrapper created. Expected ShadowWrapper but got " + objectWrapper.getClass().getSimpleName(), objectWrapper instanceof ShadowWrapper);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "shadow description", shadow, shadowOld, ItemStatus.NOT_CHANGED);
    assertContainersPaths(objectWrapper, BASIC_SHADOW_CONTAINERS_PATHS);
    PrismContainerWrapper<ShadowAttributesType> attributesContainerWrapper = objectWrapper.findContainer(ShadowType.F_ATTRIBUTES);
    assertEquals("wrong number of values in " + attributesContainerWrapper, 1, attributesContainerWrapper.getValues().size());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "Attributes", ShadowType.F_ATTRIBUTES, attributesContainer, false, ItemStatus.NOT_CHANGED);
    PrismContainerValueWrapper<ShadowAttributesType> attributesContainerValueWrapper = attributesContainerWrapper.getValue();
    WrapperTestUtil.assertPropertyWrapperByName(attributesContainerValueWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_JACK_FULL_NAME);
    WrapperTestUtil.assertPropertyWrapperByName(attributesContainerValueWrapper, SchemaConstants.ICFS_NAME, USER_JACK_USERNAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 18, attributesContainerValueWrapper.getItems().size());
    PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(ShadowType.F_ACTIVATION);
    assertEquals("wrong number of values in " + activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
    PrismContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
    WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ShadowType.activation"), UserType.F_ACTIVATION, shadow, ItemStatus.NOT_CHANGED);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    assertEquals("Wrong attributes container wrapper readOnly", Boolean.FALSE, (Boolean) attributesContainerValueWrapper.isReadOnly());
    PrismPropertyWrapper<String> fullnameWrapper = attributesContainerValueWrapper.findProperty(ItemPath.create(dummyResourceCtl.getAttributeFullnameQName()));
    // Is this OK?
    assertEquals("Wrong attribute fullname readOnly", Boolean.FALSE, (Boolean) fullnameWrapper.isReadOnly());
    assertEquals("Wrong attribute fullname visible", Boolean.TRUE, (Boolean) fullnameWrapper.isVisible(attributesContainerValueWrapper, null));
    displayDumpable("fullname attribute definition", fullnameWrapper);
    assertEquals("Wrong attribute fullname definition.canRead", Boolean.TRUE, (Boolean) fullnameWrapper.canRead());
    assertEquals("Wrong attribute fullname definition.canAdd", Boolean.TRUE, (Boolean) fullnameWrapper.canAdd());
    assertEquals("Wrong attribute fullname definition.canModify", Boolean.TRUE, (Boolean) fullnameWrapper.canModify());
    // MID-3144
    if (fullnameWrapper.getDisplayOrder() == null || fullnameWrapper.getDisplayOrder() < 100 || fullnameWrapper.getDisplayOrder() > 400) {
        AssertJUnit.fail("Wrong fullname definition.displayOrder: " + fullnameWrapper.getDisplayOrder());
    }
    assertEquals("Wrong attribute fullname definition.displayName", "Full Name", fullnameWrapper.getDisplayName());
    ObjectDelta<ShadowType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-empty delta produced from wrapper: " + objectDelta, objectDelta.isEmpty());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ShadowWrapperFactoryImpl(com.evolveum.midpoint.gui.impl.factory.wrapper.ShadowWrapperFactoryImpl) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with WrapperContext

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

the class TestIntegrationObjectWrapperFactory method test112CreateWrapperUserNewman.

/**
 * Create wrapper for brand new user, but "fill in" some data.
 */
@Test
public void test112CreateWrapperUserNewman() throws Exception {
    PrismObject<UserType> user = getUserDefinition().instantiate();
    when();
    Task task = createTask();
    OperationResult result = task.getResult();
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    PrismObjectWrapperFactory<UserType> factory = modelServiceLocator.findObjectWrapperFactory(user.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.ADDED, context);
    PrismObjectValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_USERNAME));
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_GIVEN_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_GIVEN_NAME));
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_FAMILY_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_FAMILY_NAME));
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_EMPLOYEE_NUMBER, USER_NEWMAN_EMPLOYEE_NUMBER);
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, extensionPath(PIRACY_SHIP), USER_NEWMAN_SHIP);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, getUserDefinition().instantiate(), ItemStatus.ADDED);
    assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), null, user, ItemStatus.ADDED);
    assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_USERNAME));
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
    WrapperTestUtil.assertPropertyWrapper(mainContainerValueWrapper, extensionPath(PIRACY_SHIP), USER_NEWMAN_SHIP);
    PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(UserType.F_ACTIVATION);
    WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ActivationType.activation"), UserType.F_ACTIVATION, user, ItemStatus.ADDED);
    assertEquals("wrong number of containers in " + activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_WEAPON), null);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_COLORS), ItemProcessing.AUTO);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_SECRET), ItemProcessing.IGNORE);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_RANT), ItemProcessing.MINIMAL);
    ItemStatus objectStatus = objectWrapper.getStatus();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, true);
    when();
    mainContainerValueWrapper.setShowEmpty(false);
    then();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // not visible, because it is empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
    ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-add delta produced from wrapper: " + objectDelta, objectDelta.isAdd());
    PrismObject<UserType> objectToAdd = objectDelta.getObjectToAdd();
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_USERNAME));
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_GIVEN_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_GIVEN_NAME));
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_FAMILY_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_FAMILY_NAME));
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_EMPLOYEE_NUMBER, USER_NEWMAN_EMPLOYEE_NUMBER);
    PrismAsserts.assertPropertyValue(objectToAdd, extensionPath(PIRACY_SHIP), USER_NEWMAN_SHIP);
    PrismAsserts.assertItems(objectToAdd, 5);
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with WrapperContext

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

the class TestIntegrationObjectWrapperFactory method test242OrgScummBarAddTransform.

@Test
public void test242OrgScummBarAddTransform() throws Exception {
    PrismObject<OrgType> org = getObject(OrgType.class, ORG_SCUMM_BAR_OID);
    Task task = getTestTask();
    PrismObjectWrapper<OrgType> objectWrapper = createObjectWrapper(task, org, ItemStatus.NOT_CHANGED);
    displayDumpable("Wrapper before", objectWrapper);
    PrismContainerValueWrapper<OrgType> mainContainerValueWrapper = objectWrapper.getValue();
    PrismContainerWrapper<Containerable> transformContainerWrapper = mainContainerValueWrapper.findContainer(extensionPath(PIRACY_TRANSFORM));
    List<PrismContainerValueWrapper<Containerable>> transformValueWrappers = transformContainerWrapper.getValues();
    assertEquals("Unexpected number of transform value wrappers", 3, transformValueWrappers.size());
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    WrapperContext context = new WrapperContext(task, task.getResult());
    context.setShowEmpty(true);
    context.setCreateIfEmpty(true);
    PrismContainerValueWrapper<Containerable> newContainerValueWrapper = modelServiceLocator.createValueWrapper(transformContainerWrapper, transformContainerWrapper.getItem().createNewValue(), ValueStatus.ADDED, context);
    transformContainerWrapper.getValues().add(newContainerValueWrapper);
    modifyTransformProp(newContainerValueWrapper, PIRACY_PATTERN, "D");
    modifyTransformProp(newContainerValueWrapper, PIRACY_REPLACEMENT, "Doubloon");
    displayDumpable("Wrapper after", objectWrapper);
    when();
    ObjectDelta<OrgType> objectDelta = objectWrapper.getObjectDelta();
    then();
    displayDumpable("Delta", objectDelta);
    ItemPath transformPath = ItemPath.create(ObjectType.F_EXTENSION, PIRACY_TRANSFORM);
    PrismAsserts.assertModifications(objectDelta, 1);
    ContainerDelta<Containerable> transformDelta = (ContainerDelta) objectDelta.getModifications().iterator().next();
    assertTrue("Wrong container delta path. Expected " + transformPath + " but was " + transformDelta.getPath(), transformDelta.getPath().equivalent(transformPath));
    PrismAsserts.assertNoDelete(transformDelta);
    PrismAsserts.assertNoReplace(transformDelta);
    Collection<PrismContainerValue<Containerable>> valuesToAdd = transformDelta.getValuesToAdd();
    assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
    PrismContainerValue<Containerable> containerValueToAdd = valuesToAdd.iterator().next();
    assertEquals("Unexpected number of items in value to add", 2, containerValueToAdd.size());
    PrismProperty<String> patternProp = (PrismProperty) containerValueToAdd.findItem(PIRACY_PATTERN);
    PrismAsserts.assertPropertyValue(patternProp, "D");
    PrismProperty<String> replacementProp = (PrismProperty) containerValueToAdd.findItem(PIRACY_REPLACEMENT);
    PrismAsserts.assertPropertyValue(replacementProp, "Doubloon");
    OperationResult result = task.getResult();
    executeChanges(objectDelta, null, task, result);
    assertSuccess(result);
    PrismObject<OrgType> orgAfter = getObject(OrgType.class, ORG_MINISTRY_OF_RUM_OID);
    display("Org after", orgAfter);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) 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