use of com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyConstraintType in project midpoint by Evolveum.
the class FocusProcessor method applyObjectPolicyConstraints.
private <F extends FocusType> void applyObjectPolicyConstraints(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException {
if (objectPolicyConfigurationType == null) {
return;
}
final PrismObject<F> focusNew = focusContext.getObjectNew();
if (focusNew == null) {
// This is delete. Nothing to do.
return;
}
for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType.getPropertyConstraint()) {
ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
PrismProperty<Object> prop = focusNew.findProperty(itemPath);
if (prop == null || prop.isEmpty()) {
String newValue = focusNew.getOid();
if (newValue == null) {
newValue = OidUtil.generateOid();
}
LOGGER.trace("Generating new OID-bound value for {}: {}", itemPath, newValue);
PrismObjectDefinition<F> focusDefinition = focusContext.getObjectDefinition();
PrismPropertyDefinition<Object> propDef = focusDefinition.findPropertyDefinition(itemPath);
if (propDef == null) {
throw new SchemaException("No definition for property " + itemPath + " in " + focusDefinition + " as specified in object policy");
}
PropertyDelta<Object> propDelta = propDef.createEmptyDelta(itemPath);
if (String.class.isAssignableFrom(propDef.getTypeClass())) {
propDelta.setValueToReplace(new PrismPropertyValue<Object>(newValue, OriginType.USER_POLICY, null));
} else if (PolyString.class.isAssignableFrom(propDef.getTypeClass())) {
propDelta.setValueToReplace(new PrismPropertyValue<Object>(new PolyString(newValue), OriginType.USER_POLICY, null));
} else {
throw new SchemaException("Unsupported type " + propDef.getTypeName() + " for property " + itemPath + " in " + focusDefinition + " as specified in object policy, only string and polystring properties are supported for OID-bound mode");
}
focusContext.swallowToSecondaryDelta(propDelta);
focusContext.recompute();
}
}
}
// Deprecated
if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
// Generate the name now - unless it is already present
PolyStringType focusNewName = focusNew.asObjectable().getName();
if (focusNewName == null) {
String newValue = focusNew.getOid();
if (newValue == null) {
newValue = OidUtil.generateOid();
}
LOGGER.trace("Generating new name (bound to OID): {}", newValue);
PrismObjectDefinition<F> focusDefinition = focusContext.getObjectDefinition();
PrismPropertyDefinition<PolyString> focusNameDef = focusDefinition.findPropertyDefinition(FocusType.F_NAME);
PropertyDelta<PolyString> nameDelta = focusNameDef.createEmptyDelta(new ItemPath(FocusType.F_NAME));
nameDelta.setValueToReplace(new PrismPropertyValue<PolyString>(new PolyString(newValue), OriginType.USER_POLICY, null));
focusContext.swallowToSecondaryDelta(nameDelta);
focusContext.recompute();
}
}
}
Aggregations