Search in sources :

Example 36 with PrismReference

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());
}
Also used : QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 37 with PrismReference

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);
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) PrismReference(com.evolveum.midpoint.prism.PrismReference) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 38 with PrismReference

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);
}
Also used : PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 39 with PrismReference

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");
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) JRException(net.sf.jasperreports.engine.JRException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismContainerable(com.evolveum.midpoint.prism.PrismContainerable) PrismObject(com.evolveum.midpoint.prism.PrismObject) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReference(com.evolveum.midpoint.prism.PrismReference) ArrayList(java.util.ArrayList) List(java.util.List) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerable(com.evolveum.midpoint.prism.PrismContainerable) Containerable(com.evolveum.midpoint.prism.Containerable) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 40 with PrismReference

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");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismObject(com.evolveum.midpoint.prism.PrismObject) Test(org.testng.annotations.Test)

Aggregations

PrismReference (com.evolveum.midpoint.prism.PrismReference)41 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)15 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)8 Task (com.evolveum.midpoint.task.api.Task)8 ArrayList (java.util.ArrayList)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 QName (javax.xml.namespace.QName)7 Test (org.testng.annotations.Test)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)5 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4