Search in sources :

Example 56 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.

the class TestRefinedSchema method assertAccountShadow.

private void assertAccountShadow(PrismObject<ShadowType> accObject, PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException, JAXBException {
    ResourceType resourceType = resource.asObjectable();
    QName objectClassQName = new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass");
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_NAME, createPolyString("jack"));
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_OBJECT_CLASS, objectClassQName);
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_INTENT, SchemaConstants.INTENT_DEFAULT);
    PrismContainer<?> attributes = accObject.findOrCreateContainer(SchemaConstants.C_ATTRIBUTES);
    assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinitionImpl.class, attributes.getDefinition().getClass());
    ResourceAttributeContainerDefinition attrDef = (ResourceAttributeContainerDefinition) attributes.getDefinition();
    assertAttributeDefs(attrDef, resourceType, null, LayerType.MODEL);
    PrismAsserts.assertPropertyValue(attributes, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "cn"), "Jack Sparrow");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "givenName"), "Jack");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "sn"), "Sparrow");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "uid"), "jack");
    assertEquals("JAXB class name doesn't match (1)", ShadowType.class, accObject.getCompileTimeClass());
    accObject.checkConsistence();
    ShadowType accObjectType = accObject.asObjectable();
    assertEquals("Wrong JAXB name", createPolyStringType("jack"), accObjectType.getName());
    assertEquals("Wrong JAXB objectClass", objectClassQName, accObjectType.getObjectClass());
    ShadowAttributesType attributesType = accObjectType.getAttributes();
    assertNotNull("null ResourceObjectShadowAttributesType (JAXB)", attributesType);
    List<Object> attributeElements = attributesType.getAny();
    TestUtil.assertElement(attributeElements, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "cn"), "Jack Sparrow");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "givenName"), "Jack");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "sn"), "Sparrow");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "uid"), "jack");
    String accString = PrismTestUtil.serializeObjectToString(accObjectType.asPrismObject());
    System.out.println("Result of JAXB marshalling:\n" + accString);
    accObject.checkConsistence(true, true, ConsistencyCheckScope.THOROUGH);
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 57 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.

the class TestRefinedSchema method testApplyAttributeDefinition.

@Test
public void testApplyAttributeDefinition() throws JAXBException, SchemaException, SAXException, IOException {
    System.out.println("\n===[ testApplyAttributeDefinition ]===\n");
    // GIVEN
    PrismContext prismContext = createInitializedPrismContext();
    PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resource, prismContext);
    RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("No refined default account definition in " + rSchema, defaultAccountDefinition);
    System.out.println("Refined account definition:");
    System.out.println(defaultAccountDefinition.debugDump());
    PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml"));
    PrismContainer<Containerable> attributesContainer = accObject.findContainer(ShadowType.F_ATTRIBUTES);
    System.out.println("Attributes container:");
    System.out.println(attributesContainer.debugDump());
    // WHEN
    attributesContainer.applyDefinition((PrismContainerDefinition) defaultAccountDefinition.toResourceAttributeContainerDefinition(), true);
    // THEN
    System.out.println("Parsed account:");
    System.out.println(accObject.debugDump());
    assertAccountShadow(accObject, resource, prismContext);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) File(java.io.File) Test(org.testng.annotations.Test)

Example 58 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.

the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.

private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
    for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
        ShadowType shadowType;
        try {
            shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
        } catch (ObjectNotFoundException e) {
            // Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
            // the chance to react yet. Just ignore such shadow.
            LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
            continue;
        }
        if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
            PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
            ShadowAssociationType shadowAssociationType = newValue.asContainerable();
            shadowAssociationType.setName(assocName);
            ObjectReferenceType shadowRef = new ObjectReferenceType();
            shadowRef.setOid(linkRef.getOid());
            shadowAssociationType.setShadowRef(shadowRef);
        }
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 59 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.

the class AssociationSearchExpressionEvaluatorCache method invalidate.

// shadow may be null
public void invalidate(PrismObject<ResourceType> resource, PrismObject<? extends ShadowType> shadow) {
    LOGGER.trace("Invalidating cache for resource = {}, shadow kind = {}", resource, shadow != null ? shadow.asObjectable().getKind() : "(no shadow)");
    if (resource == null || resource.getOid() == null) {
        // shouldn't occur
        LOGGER.warn("No resource - invalidating all the cache");
        queries.clear();
        return;
    }
    String resourceOid = resource.getOid();
    ShadowKindType kind = null;
    if (shadow != null) {
        kind = shadow.asObjectable().getKind();
    }
    Set<Map.Entry<AssociationSearchQueryKey, AssociationSearchQueryResult>> entries = queries.entrySet();
    Iterator<Map.Entry<AssociationSearchQueryKey, AssociationSearchQueryResult>> iterator = entries.iterator();
    while (iterator.hasNext()) {
        Map.Entry<AssociationSearchQueryKey, AssociationSearchQueryResult> entry = iterator.next();
        if (matches(entry, resourceOid, kind)) {
            LOGGER.trace("Invalidating query key {}", entry.getKey());
            iterator.remove();
        }
    }
}
Also used : ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) Map(java.util.Map)

Example 60 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.

the class TestProjector method test251ModifyUserBarbossaFullname.

/**
	 * User barbossa has a direct account assignment. This assignment has an expression for user/fullName -> dummy/fullname.
	 * cn is also overridden to be single-value.
	 * Let's try if the "cn" gets updated if we update barbosa's fullName. Also check if delta is replace.
	 */
@Test
public void test251ModifyUserBarbossaFullname() throws Exception {
    final String TEST_NAME = "test251ModifyUserBarbossaFullname";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestProjector.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_BARBOSSA_OID, result);
    fillContextWithAccount(context, ACCOUNT_HBARBOSSA_DUMMY_OID, task, result);
    addModificationToContextReplaceUserProperty(context, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Captain Hector Barbossa"));
    context.recompute();
    display("Input context", context);
    assertFocusModificationSanity(context);
    // WHEN
    projector.project(context, "test", task, result);
    // THEN
    display("Output context", context);
    assertTrue(context.getFocusContext().getPrimaryDelta().getChangeType() == ChangeType.MODIFY);
    assertSideEffectiveDeltasOnly("user secondary delta", context.getFocusContext().getSecondaryDelta());
    assertFalse("No account changes", context.getProjectionContexts().isEmpty());
    Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
    assertEquals(1, accountContexts.size());
    LensProjectionContext accContext = accountContexts.iterator().next();
    assertNull(accContext.getPrimaryDelta());
    assertEquals(SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
    assertEquals("Unexpected number of account secondary changes", 3, accountSecondaryDelta.getModifications().size());
    PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Captain Hector Barbossa");
    PrismAsserts.assertOrigin(accountSecondaryDelta, OriginType.OUTBOUND);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)903 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)728 Test (org.testng.annotations.Test)693 Task (com.evolveum.midpoint.task.api.Task)600 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)398 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)170 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)154 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)153 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)129 QName (javax.xml.namespace.QName)123 PrismObject (com.evolveum.midpoint.prism.PrismObject)105 ArrayList (java.util.ArrayList)95 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)89 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)78 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)74 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)71 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)64 Entry (org.apache.directory.api.ldap.model.entry.Entry)61 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)60 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)55