Search in sources :

Example 21 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class ExpressionUtil method resolveDefinitionPath.

public static <ID extends ItemDefinition> ID resolveDefinitionPath(ItemPath path, ExpressionVariables variables, PrismContainerDefinition<?> defaultContext, String shortDesc) throws SchemaException {
    while (path != null && !path.isEmpty() && !(path.first() instanceof NameItemPathSegment)) {
        path = path.rest();
    }
    Object root = defaultContext;
    ItemPath relativePath = path;
    NameItemPathSegment first = (NameItemPathSegment) path.first();
    if (first.isVariable()) {
        relativePath = path.rest();
        QName varName = first.getName();
        if (variables.containsKey(varName)) {
            Object varValue = variables.get(varName);
            if (varValue instanceof ItemDeltaItem<?, ?>) {
                root = ((ItemDeltaItem<?, ?>) varValue).getDefinition();
            } else if (varValue instanceof Item<?, ?>) {
                root = ((Item<?, ?>) varValue).getDefinition();
            } else if (varValue instanceof Objectable) {
                root = ((Objectable) varValue).asPrismObject().getDefinition();
            } else if (varValue instanceof ItemDefinition) {
                root = varValue;
            } else {
                throw new IllegalStateException("Unexpected content of variable " + varName + ": " + varValue + " (" + varValue.getClass() + ")");
            }
            if (root == null) {
                throw new IllegalStateException("Null definition in content of variable " + varName + ": " + varValue);
            }
        } else {
            throw new SchemaException("No variable with name " + varName + " in " + shortDesc);
        }
    }
    if (root == null) {
        return null;
    }
    if (relativePath.isEmpty()) {
        return (ID) root;
    }
    ItemDefinition result = null;
    if (root instanceof PrismObjectDefinition<?>) {
        return ((PrismObjectDefinition<?>) root).findItemDefinition(relativePath);
    } else if (root instanceof PrismContainerDefinition<?>) {
        return ((PrismContainerDefinition<?>) root).findItemDefinition(relativePath);
    } else if (root instanceof ItemDefinition) {
        // Except for container (which is handled above)
        throw new SchemaException("Cannot apply path " + relativePath + " to " + root + " in " + shortDesc);
    } else {
        throw new IllegalArgumentException("Unexpected root " + root + " in " + shortDesc);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 22 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestRbac method test532JackModifyAssignmentRoleCleric.

@Test
public void test532JackModifyAssignmentRoleCleric() throws Exception {
    final String TEST_NAME = "test532JackModifyAssignmentRoleCleric";
    TestUtil.displayTestTile(this, TEST_NAME);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = getObject(UserType.class, USER_JACK_OID);
    ItemPath itemPath = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(user.asObjectable().getAssignment().get(0).getId()), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    ObjectDelta<UserType> assignmentDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, itemPath, prismContext, "soul");
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(MiscSchemaUtil.createCollection(assignmentDelta), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
    display("User jack after", userAfter);
    assertAssignedRole(userAfter, ROLE_CLERIC_OID, task, result);
    assertRoleMembershipRef(userAfter, ROLE_CLERIC_OID);
    assertDelegatedRef(userAfter);
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
    assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Holy soul");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 23 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method modifyAssignmentConstruction.

protected void modifyAssignmentConstruction(LensContext<UserType> context, UserType jack, String attributeName, String value, boolean add) throws SchemaException {
    assertEquals("jack's assignments", 1, jack.getAssignment().size());
    PrismPropertyDefinition<ResourceAttributeDefinitionType> attributeDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findPropertyDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
    assertNotNull("no attributeDef", attributeDef);
    Long assignmentId = jack.getAssignment().get(0).getId();
    PropertyDelta<ResourceAttributeDefinitionType> attributeDelta = new PropertyDelta<ResourceAttributeDefinitionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION), new NameItemPathSegment(ConstructionType.F_ATTRIBUTE)), attributeDef, prismContext);
    ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
    attributeDefinitionType.setRef(new ItemPathType(new ItemPath(new QName(RESOURCE_DUMMY_NAMESPACE, attributeName))));
    MappingType outbound = new MappingType();
    // to see changes on the resource
    outbound.setStrength(MappingStrengthType.STRONG);
    ExpressionType expression = new ExpressionType();
    expression.getExpressionEvaluator().add(new ObjectFactory().createValue(value));
    outbound.setExpression(expression);
    attributeDefinitionType.setOutbound(outbound);
    if (add) {
        attributeDelta.addValueToAdd(new PrismPropertyValue<>(attributeDefinitionType));
    } else {
        attributeDelta.addValueToDelete(new PrismPropertyValue<>(attributeDefinitionType));
    }
    ObjectDelta<UserType> userDelta = new ObjectDelta<>(UserType.class, ChangeType.MODIFY, prismContext);
    userDelta.setOid(USER_JACK_OID);
    userDelta.addModification(attributeDelta);
    addFocusDeltaToContext(context, userDelta);
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method modifyAssignmentValidity.

protected void modifyAssignmentValidity(LensContext<UserType> context, UserType jack, XMLGregorianCalendar validFrom, XMLGregorianCalendar validTo) throws SchemaException {
    assertEquals("jack's assignments", 1, jack.getAssignment().size());
    PrismContainerDefinition<ActivationType> activationDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findContainerDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION));
    assertNotNull("no activationDef", activationDef);
    Long assignmentId = jack.getAssignment().get(0).getId();
    PrismPropertyDefinition<XMLGregorianCalendar> validFromDef = activationDef.findPropertyDefinition(ActivationType.F_VALID_FROM);
    PropertyDelta<XMLGregorianCalendar> validFromDelta = new PropertyDelta<>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_VALID_FROM)), validFromDef, prismContext);
    validFromDelta.setValueToReplace(new PrismPropertyValue<>(validFrom));
    PrismPropertyDefinition<XMLGregorianCalendar> validToDef = activationDef.findPropertyDefinition(ActivationType.F_VALID_TO);
    PropertyDelta<XMLGregorianCalendar> validToDelta = new PropertyDelta<>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_VALID_TO)), validToDef, prismContext);
    validToDelta.setValueToReplace(new PrismPropertyValue<>(validTo));
    ObjectDelta<UserType> userDelta = new ObjectDelta<>(UserType.class, ChangeType.MODIFY, prismContext);
    userDelta.setOid(USER_JACK_OID);
    userDelta.addModification(validFromDelta);
    userDelta.addModification(validToDelta);
    addFocusDeltaToContext(context, userDelta);
}
Also used : NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 25 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestValidityRecomputeTask method test137BarbossaEnableBothAssignments.

@Test
public void test137BarbossaEnableBothAssignments() throws Exception {
    final String TEST_NAME = "test137BarbossaEnableBothAssignments";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    AssignmentType judgeAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_JUDGE_OID);
    AssignmentType sailorAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_SAILOR_OID);
    ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), prismContext, ActivationStatusType.ENABLED);
    objectDelta.addModificationReplaceProperty(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(sailorAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), ActivationStatusType.ENABLED);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(null, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, true);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(null, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, true);
    assertDummyAccountAttribute(null, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, ROLE_JUDGE_TITLE);
    assertDummyAccountAttribute(null, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK, ROLE_JUDGE_DRINK, ROLE_SAILOR_DRINK);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    display("User after", user);
    assertLinks(user, 1);
    MidPointPrincipal principal = userProfileService.getPrincipal(user);
    assertAuthorized(principal, AUTZ_PUNISH_URL);
}
Also used : TestTriggerTask(com.evolveum.midpoint.model.intest.TestTriggerTask) Task(com.evolveum.midpoint.task.api.Task) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Aggregations

NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)69 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)61 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)46 Test (org.testng.annotations.Test)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 QName (javax.xml.namespace.QName)20 Task (com.evolveum.midpoint.task.api.Task)19 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)15 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)14 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 UserType (com.evolveum.midpoint.prism.foo.UserType)7 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)7 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4