Search in sources :

Example 61 with PrismPropertyDefinition

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 62 with PrismPropertyDefinition

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 63 with PrismPropertyDefinition

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 64 with PrismPropertyDefinition

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());
}
Also used : SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) SpringApplicationContextHolder.getMiscDataUtil(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getMiscDataUtil) MiscDataUtil(com.evolveum.midpoint.wf.impl.util.MiscDataUtil) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DOMUtil(com.evolveum.midpoint.util.DOMUtil) QNameUtil(com.evolveum.midpoint.util.QNameUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) Expression(com.evolveum.midpoint.repo.common.expression.Expression) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) SpringApplicationContextHolder.getExpressionFactory(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getExpressionFactory) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) Task(com.evolveum.midpoint.task.api.Task) ApprovalUtils(com.evolveum.midpoint.wf.util.ApprovalUtils) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) Component(org.springframework.stereotype.Component) List(java.util.List) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ApprovalLevelOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelOutcomeType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) SpringApplicationContextHolder.getExpressionFactory(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getExpressionFactory) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with PrismPropertyDefinition

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;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)134 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)93 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)82 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)62 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)61 Test (org.testng.annotations.Test)60 PrismObject (com.evolveum.midpoint.prism.PrismObject)24 QName (javax.xml.namespace.QName)23 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)19 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 Task (com.evolveum.midpoint.task.api.Task)12 ArrayList (java.util.ArrayList)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)8 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)7 File (java.io.File)7