use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class ChangeExecutor method isEquivalentModifyDelta.
private boolean isEquivalentModifyDelta(Collection<? extends ItemDelta<?, ?>> modifications1, Collection<? extends ItemDelta<?, ?>> modifications2) {
Collection<? extends ItemDelta<?, ?>> attrDeltas1 = ItemDelta.findItemDeltasSubPath(modifications1, new ItemPath(ShadowType.F_ATTRIBUTES));
Collection<? extends ItemDelta<?, ?>> attrDeltas2 = ItemDelta.findItemDeltasSubPath(modifications2, new ItemPath(ShadowType.F_ATTRIBUTES));
return MiscUtil.unorderedCollectionEquals(attrDeltas1, attrDeltas2);
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class LensUtil method createActivationTimestampDelta.
public static PropertyDelta<XMLGregorianCalendar> createActivationTimestampDelta(ActivationStatusType status, XMLGregorianCalendar now, PrismContainerDefinition<ActivationType> activationDefinition, OriginType origin) {
QName timestampPropertyName;
if (status == null || status == ActivationStatusType.ENABLED) {
timestampPropertyName = ActivationType.F_ENABLE_TIMESTAMP;
} else if (status == ActivationStatusType.DISABLED) {
timestampPropertyName = ActivationType.F_DISABLE_TIMESTAMP;
} else if (status == ActivationStatusType.ARCHIVED) {
timestampPropertyName = ActivationType.F_ARCHIVE_TIMESTAMP;
} else {
throw new IllegalArgumentException("Unknown activation status " + status);
}
PrismPropertyDefinition<XMLGregorianCalendar> timestampDef = activationDefinition.findPropertyDefinition(timestampPropertyName);
PropertyDelta<XMLGregorianCalendar> timestampDelta = timestampDef.createEmptyDelta(new ItemPath(FocusType.F_ACTIVATION, timestampPropertyName));
timestampDelta.setValueToReplace(new PrismPropertyValue<XMLGregorianCalendar>(now, origin, null));
return timestampDelta;
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class LensUtil method checkObjectPolicy.
private static <F extends ObjectType> void checkObjectPolicy(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException, PolicyViolationException {
if (objectPolicyConfigurationType == null) {
return;
}
PrismObject<F> focusObjectNew = focusContext.getObjectNew();
ObjectDelta<F> focusDelta = focusContext.getDelta();
for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType.getPropertyConstraint()) {
ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
if (focusDelta != null) {
if (focusDelta.isAdd()) {
PrismProperty<Object> propNew = focusObjectNew.findProperty(itemPath);
if (propNew != null) {
// prop delta is OK, but it has to match
if (focusObjectNew.getOid() != null) {
if (!focusObjectNew.getOid().equals(propNew.getRealValue().toString())) {
throw new PolicyViolationException("Cannot set " + itemPath + " to a value different than OID in oid bound mode");
}
}
}
} else {
PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(itemPath);
if (nameDelta != null) {
if (nameDelta.isReplace()) {
Collection<PrismPropertyValue<Object>> valuesToReplace = nameDelta.getValuesToReplace();
if (valuesToReplace.size() == 1) {
String stringValue = valuesToReplace.iterator().next().getValue().toString();
if (focusContext.getOid().equals(stringValue)) {
// This is OK. It is most likely a correction made by a recompute.
continue;
}
}
}
throw new PolicyViolationException("Cannot change " + itemPath + " in oid bound mode");
}
}
}
}
}
// Deprecated
if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
if (focusDelta != null) {
if (focusDelta.isAdd()) {
PolyStringType namePolyType = focusObjectNew.asObjectable().getName();
if (namePolyType != null) {
// name delta is OK, but it has to match
if (focusObjectNew.getOid() != null) {
if (!focusObjectNew.getOid().equals(namePolyType.getOrig())) {
throw new PolicyViolationException("Cannot set name to a value different than OID in name-oid bound mode");
}
}
}
} else {
PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(FocusType.F_NAME);
if (nameDelta != null) {
throw new PolicyViolationException("Cannot change name in name-oid bound mode");
}
}
}
}
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class PrismInternalTestUtil method assertUserJackContent.
public static void assertUserJackContent(PrismObject<UserType> user, boolean expectRawInConstructions) throws SchemaException {
assertEquals("Wrong oid", USER_JACK_OID, user.getOid());
assertEquals("Wrong version", "42", user.getVersion());
PrismAsserts.assertObjectDefinition(user.getDefinition(), USER_QNAME, USER_TYPE_QNAME, UserType.class);
PrismAsserts.assertParentConsistency(user);
assertPropertyValue(user, "fullName", "cpt. Jack Sparrow");
assertPropertyDefinition(user, "fullName", DOMUtil.XSD_STRING, 1, 1);
assertPropertyValue(user, "givenName", "Jack");
assertPropertyDefinition(user, "givenName", DOMUtil.XSD_STRING, 0, 1);
assertPropertyValue(user, "familyName", "Sparrow");
assertPropertyDefinition(user, "familyName", DOMUtil.XSD_STRING, 0, 1);
assertPropertyValue(user, "name", new PolyString("jack", "jack"));
assertPropertyDefinition(user, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
assertPropertyValue(user, "special", "got it!");
assertPropertyDefinition(user, "special", DOMUtil.XSD_STRING, 0, 1);
assertPropertyValue(user, "polyName", new PolyString("Džek Sperou", "dzek sperou"));
assertPropertyDefinition(user, "polyName", PolyStringType.COMPLEX_TYPE, 0, 1);
ItemPath enabledPath = USER_ENABLED_PATH;
PrismProperty<Boolean> enabledProperty1 = user.findProperty(enabledPath);
assertNotNull("No enabled property", enabledProperty1);
PrismAsserts.assertDefinition(enabledProperty1.getDefinition(), USER_ENABLED_QNAME, DOMUtil.XSD_BOOLEAN, 0, 1);
assertNotNull("Property " + enabledPath + " not found", enabledProperty1);
PrismAsserts.assertPropertyValue(enabledProperty1, true);
PrismProperty<XMLGregorianCalendar> validFromProperty = user.findProperty(USER_VALID_FROM_PATH);
assertNotNull("Property " + USER_VALID_FROM_PATH + " not found", validFromProperty);
PrismAsserts.assertPropertyValue(validFromProperty, USER_JACK_VALID_FROM);
QName actName = new QName(NS_FOO, "activation");
// Use path
ItemPath actPath = new ItemPath(actName);
PrismContainer<ActivationType> actContainer1 = user.findContainer(actPath);
assertContainerDefinition(actContainer1, "activation", ACTIVATION_TYPE_QNAME, 0, 1);
assertNotNull("Property " + actPath + " not found", actContainer1);
assertEquals("Wrong activation name", actName, actContainer1.getElementName());
// Use name
PrismContainer<ActivationType> actContainer2 = user.findContainer(actName);
assertNotNull("Property " + actName + " not found", actContainer2);
assertEquals("Wrong activation name", actName, actContainer2.getElementName());
// Compare
assertEquals("Eh?", actContainer1, actContainer2);
PrismProperty<Boolean> enabledProperty2 = actContainer1.findProperty(new QName(NS_FOO, "enabled"));
assertNotNull("Property enabled not found", enabledProperty2);
PrismAsserts.assertPropertyValue(enabledProperty2, true);
assertEquals("Eh?", enabledProperty1, enabledProperty2);
QName assName = new QName(NS_FOO, "assignment");
QName descriptionName = new QName(NS_FOO, "description");
QName accountConstructionName = new QName(NS_FOO, "accountConstruction");
PrismContainer<AssignmentType> assContainer = user.findContainer(assName);
assertEquals("Wrong assignement values", 2, assContainer.getValues().size());
PrismProperty<String> a2DescProperty = assContainer.getValue(USER_ASSIGNMENT_2_ID).findProperty(descriptionName);
assertEquals("Wrong assigment 2 description", "Assignment 2", a2DescProperty.getValue().getValue());
ItemPath a1Path = new ItemPath(new NameItemPathSegment(assName), new IdItemPathSegment(USER_ASSIGNMENT_1_ID), new NameItemPathSegment(descriptionName));
PrismProperty a1Property = user.findProperty(a1Path);
assertNotNull("Property " + a1Path + " not found", a1Property);
PrismAsserts.assertPropertyValue(a1Property, "Assignment 1");
ItemPath a2Path = new ItemPath(new NameItemPathSegment(assName), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(accountConstructionName));
PrismProperty a2Property = user.findProperty(a2Path);
assertNotNull("Property " + a2Path + " not found", a2Property);
AccountConstructionType accountConstructionType = (AccountConstructionType) a2Property.getRealValue();
assertEquals("Wrong number of values in accountConstruction", 2, accountConstructionType.getValue().size());
RawType value1 = accountConstructionType.getValue().get(0).clone();
if (expectRawInConstructions) {
assertNotNull("Value #1 has no XNode present", value1.getXnode());
PrismPropertyDefinition value1def = new PrismPropertyDefinitionImpl(// element name
new QName(NS_FOO, "dummy"), // type name
DOMUtil.XSD_STRING, user.getPrismContext());
PrismPropertyValue<String> prismValue1 = value1.getParsedValue(value1def, value1def.getName());
assertEquals("Wrong value #1", "ABC", prismValue1.getValue());
} else {
assertNull("Value #1 has XNode present", value1.getXnode());
assertEquals("Wrong value #1", "ABC", value1.getParsedRealValue(String.class));
}
RawType value2 = accountConstructionType.getValue().get(1).clone();
assertNotNull("Value #2 has no XNode present", value2.getXnode());
PrismValue prismValue2 = value2.getParsedValue(user.getDefinition(), user.getDefinition().getName());
PrismContainerValue<UserType> prismUserValue2 = (PrismContainerValue<UserType>) prismValue2;
assertEquals("Wrong value #2", "Nobody", prismUserValue2.findProperty(new QName(NS_FOO, "fullName")).getRealValue());
PrismReference accountRef = user.findReference(USER_ACCOUNTREF_QNAME);
assertNotNull("Reference " + USER_ACCOUNTREF_QNAME + " not found", accountRef);
assertEquals("Wrong number of accountRef values", 3, accountRef.getValues().size());
PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1111");
PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1112");
PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1113");
PrismReferenceValue accountRefVal2 = accountRef.findValueByOid("c0c010c0-d34d-b33f-f00d-aaaaaaaa1112");
assertEquals("Wrong oid for accountRef", "c0c010c0-d34d-b33f-f00d-aaaaaaaa1112", accountRefVal2.getOid());
assertEquals("Wrong accountRef description", "This is a reference with a filter", accountRefVal2.getDescription());
assertNotNull("No filter in accountRef", accountRefVal2.getFilter());
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class TestCompare method testDiffJack.
/**
* Parse original jack and modified Jack. Diff and assert if the resulting
* delta is OK.
*/
@Test
public void testDiffJack() throws Exception {
System.out.println("===[ testDiffJack ]===");
// GIVEN
PrismContext prismContext = constructInitializedPrismContext();
PrismObject<UserType> jackOriginal = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME));
PrismObject<UserType> jackModified = prismContext.parseObject(getFile(USER_JACK_MODIFIED_FILE_BASENAME));
// WHEN
ObjectDelta<UserType> jackDelta = jackOriginal.diff(jackModified);
// THEN
System.out.println("Jack delta:");
System.out.println(jackDelta.debugDump());
jackDelta.assertDefinitions();
jackDelta.checkConsistence(true, true, true);
assertEquals("Wrong delta type", ChangeType.MODIFY, jackDelta.getChangeType());
assertEquals("Wrong delta OID", USER_JACK_OID, jackDelta.getOid());
assertEquals("Wrong number of modificaitions", 8, jackDelta.getModifications().size());
PrismAsserts.assertPropertyReplace(jackDelta, USER_FULLNAME_QNAME, "Jack Sparrow");
PrismAsserts.assertPropertyDelete(jackDelta, new ItemPath(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "dva");
PrismAsserts.assertPropertyAdd(jackDelta, new ItemPath(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "osem");
// TODO: assert BAR
PrismAsserts.assertPropertyDelete(jackDelta, USER_ADDITIONALNAMES_QNAME, "Captain");
PrismAsserts.assertPropertyAdd(jackDelta, USER_LOCALITY_QNAME, "World's End");
// There won't be any activation deltas. Activation is operational.
PrismAsserts.assertNoItemDelta(jackDelta, USER_ENABLED_PATH);
PrismAsserts.assertNoItemDelta(jackDelta, USER_VALID_FROM_PATH);
PrismAsserts.assertPropertyReplace(jackDelta, new ItemPath(new NameItemPathSegment(USER_ASSIGNMENT_QNAME), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(USER_DESCRIPTION_QNAME)), "Assignment II");
ContainerDelta<?> assignment3Delta = PrismAsserts.assertContainerAddGetContainerDelta(jackDelta, new ItemPath(USER_ASSIGNMENT_QNAME));
PrismContainerValue<?> assignment3DeltaAddValue = assignment3Delta.getValuesToAdd().iterator().next();
assertEquals("Assignment 3 wrong ID", USER_ASSIGNMENT_3_ID, assignment3DeltaAddValue.getId());
// TODO assert assignment[i1112]/accountConstruction
}
Aggregations