use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class TestEditSchema method test210UserDefinition.
@Test
public void test210UserDefinition() throws Exception {
final String TEST_NAME = "test210UserDefinition";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObject<UserType> user = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertPropertyValues(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
@Override
public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
assertNotNull("No definition for additionalName in user", propDef);
assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
assertTrue("additionalName not readable", propDef.canRead());
}
}, PrismTestUtil.createPolyString("Jackie"));
assertPropertyValues(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for costCenter in user", propDef);
assertEquals("Wrong costCenter displayOrder", (Integer) 123, propDef.getDisplayOrder());
assertTrue("costCenter not readable", propDef.canRead());
}
});
assertPropertyValues(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for preferredLanguage in user", propDef);
assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
assertTrue("preferredLanguage not readable", propDef.canRead());
PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
}
});
assertContainer(user, UserType.F_CREDENTIALS, new Validator<PrismContainerDefinition<CredentialsType>>() {
@Override
public void validate(PrismContainerDefinition<CredentialsType> credentialsDef, String name) throws Exception {
assertNotNull("No definition for credentials in user", credentialsDef);
assertTrue("Credentials not readable", credentialsDef.canRead());
}
}, true);
assertProperty(user, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE), new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertTrue("Password not readable", propDef.canRead());
}
});
assertSteadyResources();
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class TestEditSchema method test810OtisGetJack.
@Test
public void test810OtisGetJack() throws Exception {
final String TEST_NAME = "test810OtisGetJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
login(USER_OTIS_USERNAME);
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObject<UserType> user = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertPropertyValues(user, UserType.F_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
@Override
public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
assertNotNull("No definition for name in user", propDef);
assertEquals("Wrong name displayName", "ObjectType.name", propDef.getDisplayName());
assertTrue(name + " not readable", propDef.canRead());
assertTrue(name + " is creatable", !propDef.canAdd());
assertTrue(name + " is modifiable", !propDef.canModify());
}
}, PrismTestUtil.createPolyString("jack"));
assertPropertyValues(user, UserType.F_DESCRIPTION, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for description in user", propDef);
assertEquals("Wrong description displayName", "Comment", propDef.getDisplayName());
assertTrue(name + " not readable", propDef.canRead());
assertTrue(name + " is creatable", !propDef.canAdd());
assertTrue(name + " not modifiable", propDef.canModify());
}
}, "Where's the rum?");
assertPropertyValues(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
@Override
public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
assertNotNull("No definition for additionalName in user", propDef);
assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
assertTrue(name + " is readable", !propDef.canRead());
assertTrue(name + " is creatable", !propDef.canAdd());
assertTrue(name + " not modifiable", propDef.canModify());
}
});
assertPropertyValues(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for costCenter in user", propDef);
assertEquals("Wrong costCenter displayOrder", (Integer) 123, propDef.getDisplayOrder());
assertTrue(name + " is readable", !propDef.canRead());
assertTrue(name + " is creatable", !propDef.canAdd());
assertTrue(name + " is modifiable", !propDef.canModify());
}
});
assertPropertyValues(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for preferredLanguage in user", propDef);
assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
assertTrue(name + " is readable", !propDef.canRead());
assertTrue(name + " is creatable", !propDef.canAdd());
assertTrue(name + " is modifiable", !propDef.canModify());
}
});
PrismAsserts.assertNoItem(user, UserType.F_CREDENTIALS);
assertUntouchedUserDefinition();
assertSteadyResources();
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class TestEditSchema method test213ModifiedUserJack.
/**
* Modify jack, see if the schema still applies.
*/
@Test
public void test213ModifiedUserJack() throws Exception {
final String TEST_NAME = "test213ModifiedUserJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
modifyObjectReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_PREFERRED_LANGUAGE, task, result, "en_PR");
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObject<UserType> user = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertPropertyValues(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
@Override
public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
assertNotNull("No definition for additionalName in user", propDef);
assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
assertTrue("additionalName not readable", propDef.canRead());
}
}, PrismTestUtil.createPolyString("Jackie"));
assertPropertyValues(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for costCenter in user", propDef);
assertEquals("Wrong costCenter displayOrder", (Integer) 123, propDef.getDisplayOrder());
assertTrue("costCenter not readable", propDef.canRead());
}
}, // This is set by user template
"G001");
assertPropertyValues(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertNotNull("No definition for preferredLanguage in user", propDef);
assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
assertTrue("preferredLanguage not readable", propDef.canRead());
PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
}
}, "en_PR");
assertContainer(user, UserType.F_CREDENTIALS, new Validator<PrismContainerDefinition<CredentialsType>>() {
@Override
public void validate(PrismContainerDefinition<CredentialsType> credentialsDef, String name) throws Exception {
assertNotNull("No definition for credentials in user", credentialsDef);
assertTrue("Credentials not readable", credentialsDef.canRead());
}
}, true);
assertProperty(user, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE), new Validator<PrismPropertyDefinition<String>>() {
@Override
public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
assertTrue("Password not readable", propDef.canRead());
}
});
assertUntouchedUserDefinition();
assertSteadyResources();
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class WfExpressionEvaluationHelper method evaluateExpression.
@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, ExpressionVariables variables, String contextDescription, Class<T> clazz, QName typeName, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
ExpressionFactory expressionFactory = getExpressionFactory();
PrismContext prismContext = expressionFactory.getPrismContext();
PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl<>(new QName(SchemaConstants.NS_C, "result"), typeName, prismContext);
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, contextDescription, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task, result);
context.setAdditionalConvertor(additionalConvertor);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, context, task, result);
return exprResultTriple.getZeroSet().stream().map(ppv -> (T) ppv.getRealValue()).collect(Collectors.toList());
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class GcpExpressionHelper method evaluateBooleanExpression.
private boolean evaluateBooleanExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String opContext, Task taskFromModel, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
PrismContext prismContext = expressionFactory.getPrismContext();
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<Boolean> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_BOOLEAN, prismContext);
Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, opContext, taskFromModel, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, opContext, taskFromModel, result);
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, taskFromModel, result);
Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
if (exprResult.size() == 0) {
return false;
} else if (exprResult.size() > 1) {
throw new IllegalStateException("Expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
}
Boolean boolResult = exprResult.iterator().next().getValue();
return boolResult != null ? boolResult : false;
}
Aggregations