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;
}
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);
}
}
}
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());
}
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);
}
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);
}
Aggregations