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);
}
}
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");
}
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);
}
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);
}
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);
}
Aggregations