use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TestClockwork method assertJackAccountShadow.
private void assertJackAccountShadow(LensContext<UserType> context) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
assertEquals(1, accountContexts.size());
LensProjectionContext accContext = accountContexts.iterator().next();
String accountOid = accContext.getOid();
assertNotNull("No OID in account context " + accContext);
PrismObject<ShadowType> newAccount = getShadowModel(accountOid);
assertEquals(DEFAULT_INTENT, newAccount.findProperty(ShadowType.F_INTENT).getRealValue());
assertEquals(new QName(ResourceTypeUtil.getResourceNamespace(getDummyResourceType()), "AccountObjectClass"), newAccount.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
PrismReference resourceRef = newAccount.findReference(ShadowType.F_RESOURCE_REF);
assertEquals(getDummyResourceType().getOid(), resourceRef.getOid());
PrismContainer<?> attributes = newAccount.findContainer(ShadowType.F_ATTRIBUTES);
assertEquals("jack", attributes.findProperty(SchemaTestConstants.ICFS_NAME).getRealValue());
assertEquals("Jack Sparrow", attributes.findProperty(new QName(ResourceTypeUtil.getResourceNamespace(getDummyResourceType()), "fullname")).getRealValue());
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createParametricAssignmentDelta.
protected ObjectDelta<UserType> createParametricAssignmentDelta(String userOid, String roleOid, String orgOid, String tenantOid, boolean adding) throws SchemaException {
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
if (adding) {
assignmentDelta.addValueToAdd(cval);
} else {
assignmentDelta.addValueToDelete(cval);
}
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
targetRef.getValue().setOid(roleOid);
targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
if (orgOid != null) {
PrismReference orgRef = cval.findOrCreateReference(AssignmentType.F_ORG_REF);
orgRef.getValue().setOid(orgOid);
}
if (tenantOid != null) {
PrismReference tenantRef = cval.findOrCreateReference(AssignmentType.F_TENANT_REF);
tenantRef.getValue().setOid(tenantOid);
}
modifications.add(assignmentDelta);
return ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertResolvedResourceRefs.
private void assertResolvedResourceRefs(PrismObject<ShadowType> shadow, String desc) {
if (shadow == null) {
return;
}
PrismReference resourceRef = shadow.findReference(ShadowType.F_RESOURCE_REF);
if (resourceRef == null) {
AssertJUnit.fail("No resourceRef in " + desc);
}
assertResolvedResourceRefs(resourceRef.getValues(), desc);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class MidPointDataSource method getFieldValue.
@Override
public Object getFieldValue(JRField jrField) throws JRException {
String fieldName = jrField.getName();
if (fieldName.equals("oid")) {
if (currentObject.getParent() instanceof PrismObject) {
return ((PrismObject) currentObject.getParent()).getOid();
} else {
throw new IllegalStateException("oid property is not supported for " + currentObject.getClass());
}
} else if (PARENT_NAME.equals(fieldName)) {
PrismContainerable parent1 = currentObject.getParent();
if (!(parent1 instanceof PrismContainer)) {
return null;
}
return ((PrismContainer) parent1).getParent();
} else if (THIS_NAME.equals(fieldName)) {
return currentObject;
}
ItemPathType itemPathType = new ItemPathType(fieldName);
ItemPath path = itemPathType.getItemPath();
Item i = currentObject.findItem(path);
if (i == null) {
return null;
}
if (i instanceof PrismProperty) {
if (i.isSingleValue()) {
return normalize(((PrismProperty) i).getRealValue(), jrField.getValueClass());
}
List normalized = new ArrayList<>();
for (Object real : ((PrismProperty) i).getRealValues()) {
normalized.add(normalize(real, jrField.getValueClass()));
}
return ((PrismProperty) i).getRealValues();
} else if (i instanceof PrismReference) {
if (i.isSingleValue()) {
return ObjectTypeUtil.createObjectRef(((PrismReference) i).getValue());
}
List<Referencable> refs = new ArrayList<Referencable>();
for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
refs.add(ObjectTypeUtil.createObjectRef(refVal));
}
return refs;
} else if (i instanceof PrismContainer) {
if (i.isSingleValue()) {
return ((PrismContainer) i).getValue().asContainerable();
}
List<Containerable> containers = new ArrayList<Containerable>();
for (Object pcv : i.getValues()) {
if (pcv instanceof PrismContainerValue) {
containers.add(((PrismContainerValue) pcv).asContainerable());
}
}
return containers;
} else
throw new JRException("Could not get value of the fileld: " + fieldName);
// return
// throw new UnsupportedOperationException("dataSource.getFiledValue() not supported");
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TestProjectorRoleEntitlement method test100AddEntitlementToPirateDirect.
/**
* Add direct entitlement assignment to role "pirate". The entitlement projection
* context should appear in the lens context.
*/
@Test
public void test100AddEntitlementToPirateDirect() throws Exception {
final String TEST_NAME = "test100AddEntitlementToPirateDirect";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestProjectorRoleEntitlement.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
LensContext<RoleType> context = createLensContext(RoleType.class);
fillContextWithFocus(context, RoleType.class, ROLE_PIRATE_OID, result);
// We want "shadow" so the fullname will be computed by outbound expression
addModificationToContextAddProjection(context, RoleType.class, ENTITLEMENT_SHADOW_PIRATE_DUMMY_FILE);
display("Input context", context);
assertFocusModificationSanity(context);
// WHEN
projector.project(context, "test", task, result);
// THEN
display("Output context", context);
assertNull("Unexpected focus primary changes " + context.getFocusContext().getPrimaryDelta(), context.getFocusContext().getPrimaryDelta());
assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "focus secondary delta", ActivationStatusType.ENABLED);
assertFalse("No entitlement changes", context.getProjectionContexts().isEmpty());
Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
assertEquals(1, accountContexts.size());
LensProjectionContext projContext = accountContexts.iterator().next();
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, projContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = projContext.getPrimaryDelta();
assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
assertNotNull("No object in projection primary add delta", accountToAddPrimary);
PrismProperty<Object> intentProperty = accountToAddPrimary.findProperty(ShadowType.F_INTENT);
assertNotNull("No intent type in projection primary add delta", intentProperty);
assertEquals("group", intentProperty.getRealValue());
assertEquals(new QName(ResourceTypeUtil.getResourceNamespace(getDummyResourceType()), "GroupObjectClass"), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
assertEquals(getDummyResourceType().getOid(), resourceRef.getOid());
accountToAddPrimary.checkConsistence();
ObjectDelta<ShadowType> projSecondaryDelta = projContext.getSecondaryDelta();
assertEquals(ChangeType.MODIFY, projSecondaryDelta.getChangeType());
PropertyDelta<String> groupDescriptionDelta = projSecondaryDelta.findPropertyDelta(getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION));
assertNotNull("No group description delta", groupDescriptionDelta);
PrismAsserts.assertReplace(groupDescriptionDelta, "Bloody pirates");
PrismAsserts.assertOrigin(groupDescriptionDelta, OriginType.OUTBOUND);
PrismObject<ShadowType> projectionNew = projContext.getObjectNew();
IntegrationTestTools.assertIcfsNameAttribute(projectionNew, "pirate");
IntegrationTestTools.assertAttribute(projectionNew, getDummyResourceController().getAttributeQName(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION), "Bloody pirates");
}
Aggregations