use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ValuePolicyProcessor method checkExpression.
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private <O extends ObjectType> boolean checkExpression(String generatedValue, ExpressionType checkExpression, ExpressionProfile expressionProfile, ObjectBasedValuePolicyOriginResolver<O> originResolver, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
VariablesMap variables = new VariablesMap();
MutablePrismPropertyDefinition<Object> defInput = prismContext.definitionFactory().createPropertyDefinition(new ItemName(SchemaConstants.NS_C, ExpressionConstants.VAR_INPUT), PrimitiveType.STRING.getQname());
variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, generatedValue, defInput);
PrismObject<O> object = null;
PrismObjectDefinition<O> objectDef = null;
if (originResolver != null) {
object = originResolver.getObject();
if (object != null) {
objectDef = object.getDefinition();
}
}
if (objectDef == null) {
// noinspection unchecked
objectDef = (PrismObjectDefinition<O>) prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ObjectType.class);
}
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT, object, objectDef);
return ExpressionUtil.evaluateConditionDefaultFalse(variables, checkExpression, expressionProfile, expressionFactory, shortDesc, task, result);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestLdap method test202AssignLdapAccountToGuybrush.
/**
* Just a first step for the following test.
* Also, Guybrush has a photo. Check that binary property mapping works.
*/
@Test
public void test202AssignLdapAccountToGuybrush() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
byte[] photoIn = Files.readAllBytes(Paths.get(DOT_JPG_FILENAME));
displayValue("Photo in", MiscUtil.binaryToHex(photoIn));
modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_JPEG_PHOTO, task, result, photoIn);
Collection<SelectorOptions<GetOperationOptions>> options = getOperationOptionsBuilder().item(UserType.F_JPEG_PHOTO).retrieve().build();
PrismObject<UserType> userBefore = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, options, task, result);
display("User before", userBefore);
byte[] userJpegPhotoBefore = userBefore.asObjectable().getJpegPhoto();
assertEquals("Photo byte length changed (user before)", photoIn.length, userJpegPhotoBefore.length);
assertTrue("Photo bytes do not match (user before)", Arrays.equals(photoIn, userJpegPhotoBefore));
// WHEN
when();
assignAccountToUser(USER_GUYBRUSH_OID, RESOURCE_OPENDJ_OID, null, task, result);
// THEN
then();
assertSuccess(result);
Entry entry = assertOpenDjAccount(USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
byte[] jpegPhotoLdap = OpenDJController.getAttributeValueBinary(entry, "jpegPhoto");
assertNotNull("No jpegPhoto in LDAP entry", jpegPhotoLdap);
assertEquals("Byte length changed (LDAP)", photoIn.length, jpegPhotoLdap.length);
assertTrue("Bytes do not match (LDAP)", Arrays.equals(photoIn, jpegPhotoLdap));
PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, options, task, result);
display("User after", userAfter);
String accountOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadow = getShadowModel(accountOid);
PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
ItemName jpegPhotoQName = new ItemName(RESOURCE_OPENDJ_NAMESPACE, "jpegPhoto");
PrismProperty<byte[]> jpegPhotoAttr = attributesContainer.findProperty(jpegPhotoQName);
byte[] photoBytesOut = jpegPhotoAttr.getValues().get(0).getValue();
displayValue("Photo bytes out", MiscUtil.binaryToHex(photoBytesOut));
assertEquals("Photo byte length changed (shadow)", photoIn.length, photoBytesOut.length);
assertTrue("Photo bytes do not match (shadow)", Arrays.equals(photoIn, photoBytesOut));
assertUsers(NUM_INITIAL_USERS);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class CaseExpressionEvaluationHelper method evaluateExpression.
@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, VariablesMap variables, String contextDescription, Class<T> clazz, QName typeName, boolean multiValued, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
MutableItemDefinition<?> resultDef;
ItemName resultName = new ItemName(SchemaConstants.NS_C, "result");
if (QNameUtil.match(typeName, ObjectReferenceType.COMPLEX_TYPE)) {
resultDef = prismContext.definitionFactory().createReferenceDefinition(resultName, typeName);
} else {
resultDef = prismContext.definitionFactory().createPropertyDefinition(resultName, typeName);
}
if (multiValued) {
resultDef.setMaxOccurs(-1);
}
Expression<?, ?> expression = expressionFactory.makeExpression(expressionType, resultDef, MiscSchemaUtil.getExpressionProfile(), contextDescription, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task);
context.setAdditionalConvertor(additionalConvertor);
PrismValueDeltaSetTriple<?> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateAnyExpressionInContext(expression, context, task, result);
List<T> list = new ArrayList<>();
for (PrismValue pv : exprResultTriple.getZeroSet()) {
T realValue;
if (pv instanceof PrismReferenceValue) {
// pv.getRealValue sometimes returns synthesized Referencable, not ObjectReferenceType
// If we would stay with that we would need to make many changes throughout workflow module.
// So it is safer to stay with ObjectReferenceType.
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue((PrismReferenceValue) pv);
realValue = (T) ort;
} else {
realValue = pv.getRealValue();
}
list.add(realValue);
}
return list;
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestOpenDj method test147ModifyAccountJackGivenNameDuplicit.
/**
* Make a duplicate modification. Add a givenName value that is already there.
* Normal LDAP should fail. So check that connector and midPoitn handles that.
*/
@Test
public void test147ModifyAccountJackGivenNameDuplicit() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PropertyDelta<String> givenNameDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_OPENDJ_NS, "givenName")), null);
givenNameDelta.addRealValuesToAdd("Jack");
// Also make an ordinary non-conflicting modification. We need to make sure that
// the operation was not ignored as a whole
PropertyDelta<String> titleDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_OPENDJ_NS, "title")), null);
titleDelta.addRealValuesToAdd("Great Captain");
Collection<? extends ItemDelta<?, ?>> modifications = MiscSchemaUtil.createCollection(givenNameDelta, titleDelta);
display("Modifications", modifications);
// WHEN
when();
provisioningService.modifyObject(ShadowType.class, ACCOUNT_JACK_OID, modifications, null, null, task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
Entry entry = openDJController.searchByUid("rename");
display("LDAP Entry", entry);
OpenDJController.assertAttribute(entry, "givenName", "Jack");
OpenDJController.assertAttribute(entry, "title", "Great Captain");
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, taskManager.createTaskInstance(), result);
display("Object after change", shadow);
PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
PrismAsserts.assertPropertyValue(attributesContainer, new ItemName(RESOURCE_OPENDJ_NS, "givenName"), "Jack");
PrismAsserts.assertPropertyValue(attributesContainer, new ItemName(RESOURCE_OPENDJ_NS, "title"), "Great Captain");
assertShadows(3);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestOpenDj method test145ModifyAccountJackJpegPhoto.
@Test
public void test145ModifyAccountJackJpegPhoto() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
byte[] bytesIn = Files.readAllBytes(Paths.get(ProvisioningTestUtil.DOT_JPG_FILENAME));
displayValue("Bytes in", MiscUtil.binaryToHex(bytesIn));
ItemName jpegPhotoQName = new ItemName(RESOURCE_OPENDJ_NS, "jpegPhoto");
PropertyDelta<byte[]> jpegPhotoDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, jpegPhotoQName), null);
jpegPhotoDelta.setRealValuesToReplace(bytesIn);
Collection<? extends ItemDelta<?, ?>> modifications = MiscSchemaUtil.createCollection(jpegPhotoDelta);
display("Modifications", modifications);
// WHEN
when();
provisioningService.modifyObject(ShadowType.class, ACCOUNT_JACK_OID, modifications, null, null, task, result);
// THEN
then();
assertSuccess(result);
Entry entry = openDJController.searchByUid("rename");
display("LDAP Entry", entry);
byte[] jpegPhotoLdap = OpenDJController.getAttributeValueBinary(entry, "jpegPhoto");
assertNotNull("No jpegPhoto in LDAP entry", jpegPhotoLdap);
assertEquals("Byte length changed (LDAP)", bytesIn.length, jpegPhotoLdap.length);
assertArrayEquals("Bytes do not match (LDAP)", bytesIn, jpegPhotoLdap);
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, taskManager.createTaskInstance(), result);
display("Object after change", shadow);
PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
PrismProperty<byte[]> jpegPhotoAttr = attributesContainer.findProperty(jpegPhotoQName);
byte[] bytesOut = jpegPhotoAttr.getValues().get(0).getValue();
displayValue("Bytes out", MiscUtil.binaryToHex(bytesOut));
assertEquals("Byte length changed (shadow)", bytesIn.length, bytesOut.length);
assertArrayEquals("Bytes do not match (shadow)", bytesIn, bytesOut);
assertShadows(3);
}
Aggregations