use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class ObjectWrapperTest method testEmptyPolyString.
@Test
public void testEmptyPolyString() throws Exception {
PrismObject<UserType> user = prismContext.parseObject(new File("./src/test/resources/wrapper/user.xml"));
Task task = taskManager.createTaskInstance("testEmptyPolyString");
ObjectWrapperFactory owf = new ObjectWrapperFactory(null);
ObjectWrapper<UserType> wrapper = owf.createObjectWrapper(null, null, user, ContainerStatus.MODIFYING, task);
//simulate change on honorific prefix
ContainerWrapper containerWrapper = null;
for (ContainerWrapper container : wrapper.getContainers()) {
if (container.isMain()) {
containerWrapper = container;
break;
}
}
PropertyWrapper propertyWrapper = (PropertyWrapper) containerWrapper.findPropertyWrapper(UserType.F_HONORIFIC_SUFFIX);
ValueWrapper valueWrapper = (ValueWrapper) propertyWrapper.getValues().get(0);
PolyString value = (PolyString) ((PrismPropertyValue) valueWrapper.getValue()).getValue();
Field orig = PolyString.class.getDeclaredField("orig");
orig.setAccessible(true);
orig.set(value, null);
orig.setAccessible(false);
ObjectDelta delta = wrapper.getObjectDelta();
AssertJUnit.assertNotNull(delta);
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method collectDeltasForGeneratedValuesIfNeeded.
private <O extends ObjectType> void collectDeltasForGeneratedValuesIfNeeded(PrismObject<O> object, PolicyItemDefinitionType policyItemDefinition, Collection<PropertyDelta<?>> deltasToExecute, ItemPath path, PrismPropertyDefinition<?> itemDef) throws SchemaException {
Object value = policyItemDefinition.getValue();
if (ProtectedStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
ProtectedStringType pst = new ProtectedStringType();
pst.setClearValue((String) value);
value = pst;
} else if (PolyStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
value = new PolyString((String) value);
}
PropertyDelta<?> propertyDelta = PropertyDelta.createModificationReplaceProperty(path, object.getDefinition(), value);
// in bulk actions we need to modify original objects - hope that REST is OK with this
propertyDelta.applyTo(object);
if (BooleanUtils.isTrue(policyItemDefinition.isExecute())) {
deltasToExecute.add(propertyDelta);
}
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method validateValue.
private <T, O extends ObjectType> boolean validateValue(PrismObject<O> object, ValuePolicyType policy, PolicyItemDefinitionType policyItemDefinition, Task task, OperationResult parentResult) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
ValuePolicyType stringPolicy = resolveValuePolicy(policyItemDefinition, policy, task, parentResult);
RawType rawValue = (RawType) policyItemDefinition.getValue();
String valueToValidate = null;
List<String> valuesToValidate = new ArrayList<>();
PolicyItemTargetType target = policyItemDefinition.getTarget();
ItemPath path = null;
if (target != null) {
path = target.getPath().getItemPath();
}
if (rawValue != null) {
valueToValidate = rawValue.getParsedRealValue(String.class);
valuesToValidate.add(valueToValidate);
} else {
if (target == null || target.getPath() == null) {
LOGGER.error("Target item path must be defined");
parentResult.recordFatalError("Target item path must be defined");
throw new SchemaException("Target item path must be defined");
}
path = target.getPath().getItemPath();
PrismProperty<T> property = object.findProperty(path);
if (property == null || property.isEmpty()) {
LOGGER.error("Attribute {} has no value. Nothing to validate.", property);
parentResult.recordFatalError("Attribute " + property + " has no value. Nothing to validate");
throw new SchemaException("Attribute " + property + " has no value. Nothing to validate");
}
PrismPropertyDefinition<T> itemToValidateDefinition = property.getDefinition();
QName definitionName = itemToValidateDefinition.getTypeName();
if (!isSupportedType(definitionName)) {
LOGGER.error("Trying to validate string policy on the property of type {} failed. Unsupported type.", itemToValidateDefinition);
parentResult.recordFatalError("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
throw new SchemaException("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
}
if (itemToValidateDefinition.isSingleValue()) {
if (definitionName.equals(PolyStringType.COMPLEX_TYPE)) {
valueToValidate = ((PolyString) property.getRealValue()).getOrig();
} else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
ProtectedStringType protectedString = ((ProtectedStringType) property.getRealValue());
valueToValidate = getClearValue(protectedString);
} else {
valueToValidate = (String) property.getRealValue();
}
valuesToValidate.add(valueToValidate);
} else {
if (definitionName.equals(DOMUtil.XSD_STRING)) {
valuesToValidate.addAll(property.getRealValues(String.class));
} else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
for (ProtectedStringType protectedString : property.getRealValues(ProtectedStringType.class)) {
valuesToValidate.add(getClearValue(protectedString));
}
} else {
for (PolyString val : property.getRealValues(PolyString.class)) {
valuesToValidate.add(val.getOrig());
}
}
}
}
for (String newValue : valuesToValidate) {
OperationResult result = parentResult.createSubresult(OPERATION_VALIDATE_VALUE + ".value");
if (path != null)
result.addParam("path", path);
result.addParam("valueToValidate", newValue);
if (!policyProcessor.validateValue(newValue, stringPolicy, object, "validate value " + (path != null ? "for " + path : "") + " for " + object + " value " + valueToValidate, task, result)) {
result.recordFatalError("Validation for value " + newValue + " against policy " + stringPolicy + " failed");
LOGGER.error("Validation for value {} against policy {} failed", newValue, stringPolicy);
}
result.computeStatusIfUnknown();
}
parentResult.computeStatus();
policyItemDefinition.setResult(parentResult.createOperationResultType());
return parentResult.isAcceptable();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class ModelDiagController method checkObjectPropertyPolyString.
private <O extends ObjectType> void checkObjectPropertyPolyString(PrismObject<O> object, QName propQName, OperationResult parentResult, String... expectedValues) {
String propName = propQName.getLocalPart();
OperationResult result = parentResult.createSubresult(parentResult.getOperation() + "." + propName);
PrismProperty<PolyString> prop = object.findProperty(propQName);
Collection<PolyString> actualValues = prop.getRealValues();
result.addArbitraryCollectionAsParam("actualValues", actualValues);
assertMultivaluePolyString("User, property '" + propName + "'", expectedValues, actualValues, result);
result.recordSuccessIfUnknown();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class ModelDiagController method toPolyString.
private PolyString toPolyString(String orig) {
PolyString polyString = new PolyString(orig);
polyString.recompute(prismContext.getDefaultPolyStringNormalizer());
return polyString;
}
Aggregations