Search in sources :

Example 56 with ItemName

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);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 57 with ItemName

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Entry(org.opends.server.types.Entry) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemName(com.evolveum.midpoint.prism.path.ItemName) Test(org.testng.annotations.Test)

Example 58 with ItemName

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;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ArrayList(java.util.ArrayList) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismValue(com.evolveum.midpoint.prism.PrismValue) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with ItemName

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Entry(org.opends.server.types.Entry) QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 60 with ItemName

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Entry(org.opends.server.types.Entry) ItemName(com.evolveum.midpoint.prism.path.ItemName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3