Search in sources :

Example 41 with ResourceAttribute

use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.

the class ResourceObjectPattern method matches.

public boolean matches(PrismObject<ShadowType> shadowToMatch, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
    if (objectFilter != null) {
        // we suppose references in shadowToMatch are normalized (on return from repo)
        ObjectTypeUtil.normalizeFilter(objectFilter);
        return ObjectQuery.match(shadowToMatch, objectFilter, matchingRuleRegistry);
    } else {
        // Deprecated method
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadowToMatch);
        if (attributesContainer == null) {
            return false;
        }
        Collection<ResourceAttribute<?>> attributesToMatch = attributesContainer.getAttributes();
        for (ResourceAttribute<?> identifier : identifiers) {
            if (!matches(identifier, attributesToMatch, matchingRuleRegistry)) {
                return false;
            }
        }
        return true;
    }
}
Also used : ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 42 with ResourceAttribute

use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.

the class AssociationFromLinkExpressionEvaluator method toAssociation.

private void toAssociation(PrismObject<ShadowType> shadow, ShadowAssociationType shadowAssociationType) {
    shadowAssociationType.setShadowRef(new ObjectReferenceType().oid(shadow.getOid()).type(ShadowType.COMPLEX_TYPE));
    // This is not a clean systemic solution. But there was no time for a better solution before 3.9 release.
    try {
        ResourceAttributeContainer shadowAttributesContainer = ShadowUtil.getAttributesContainer(shadow);
        ResourceAttributeContainer identifiersContainer = ObjectFactory.createResourceAttributeContainer(ShadowAssociationType.F_IDENTIFIERS, shadowAttributesContainer.getDefinition());
        shadowAssociationType.asPrismContainerValue().add(identifiersContainer);
        Collection<ResourceAttribute<?>> shadowIdentifiers = Objects.requireNonNull(ShadowUtil.getAllIdentifiers(shadow), "no shadow identifiers");
        for (ResourceAttribute<?> shadowIdentifier : shadowIdentifiers) {
            identifiersContainer.add(shadowIdentifier.clone());
        }
    } catch (SchemaException e) {
        // Should not happen
        throw new SystemException(e.getMessage(), e);
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 43 with ResourceAttribute

use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.

the class TestDummyCaching method test107AGetModifiedAccountFromCacheMax.

/**
 * Make a native modification to an account and read it from the cache. Make sure that
 * cached data are returned and there is no read from the resource.
 * MID-3481
 */
@Test
@Override
public void test107AGetModifiedAccountFromCacheMax() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = createOperationResult();
    rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
    DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Nice Pirate");
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Interceptor");
    accountWill.setEnabled(true);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createMaxStaleness());
    XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    when();
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, task, result);
    // THEN
    then();
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
    display("Retrieved account shadow", shadow);
    assertNotNull("No dummy account", shadow);
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertRepoShadowCachedAttributeValue(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
    assertEquals("Unexpected number of attributes", 7, attributes.size());
    PrismObject<ShadowType> shadowRepo = getShadowRepo(ACCOUNT_WILL_OID);
    checkRepoAccountShadowWillBasic(shadowRepo, null, startTs, null);
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertRepoShadowCachedAttributeValue(shadowRepo, DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.DISABLED);
    checkUniqueness(shadow);
    assertCachingMetadata(shadow, true, null, startTs);
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
    assertSteadyResource();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 44 with ResourceAttribute

use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.

the class ObjectAlreadyExistHandler method createQueryBySecondaryIdentifier.

protected static ObjectQuery createQueryBySecondaryIdentifier(ShadowType shadow, PrismContext prismContext) {
    // TODO ensure that the identifiers are normalized here
    // Note that if the query is to be used against the repository, we should not provide matching rules here. See MID-5547.
    Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow);
    S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class);
    q = q.block();
    if (secondaryIdentifiers.isEmpty()) {
        for (ResourceAttribute<?> primaryIdentifier : ShadowUtil.getPrimaryIdentifiers(shadow)) {
            q = q.itemAs(primaryIdentifier).or();
        }
    } else {
        // secondary identifiers connected by 'or' clause
        for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) {
            q = q.itemAs(secondaryIdentifier).or();
        }
    }
    q = q.none().endBlock().and();
    // resource + object class
    q = q.item(ShadowType.F_RESOURCE_REF).ref(shadow.getResourceRef().getOid()).and();
    return q.item(ShadowType.F_OBJECT_CLASS).eq(shadow.getObjectClass()).build();
}
Also used : S_AtomicFilterEntry(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 45 with ResourceAttribute

use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.

the class SyncDeltaConverter method createChange.

@NotNull
UcfLiveSyncChange createChange(int localSequenceNumber, SyncDelta connIdDelta, OperationResult result) {
    // The following should not throw any exception. And if it does, we are lost anyway, because
    // we need this information to create even "errored" change object.
    // For non-nullability of these variables see the code of SyncDelta.
    @NotNull SyncDeltaType icfDeltaType = connIdDelta.getDeltaType();
    @NotNull Uid uid = connIdDelta.getUid();
    @NotNull String uidValue = uid.getUidValue();
    @NotNull UcfSyncToken token = toUcf(connIdDelta.getToken());
    Collection<ResourceAttribute<?>> identifiers = new ArrayList<>();
    ResourceObjectDefinition actualObjectDefinition = null;
    ObjectDelta<ShadowType> objectDelta = null;
    PrismObject<ShadowType> resourceObject = null;
    LOGGER.trace("START creating delta of type {}", icfDeltaType);
    UcfErrorState errorState;
    try {
        actualObjectDefinition = getActualObjectDefinition(connIdDelta);
        assert actualObjectDefinition != null || icfDeltaType == SyncDeltaType.DELETE;
        if (icfDeltaType == SyncDeltaType.DELETE) {
            identifiers.addAll(ConnIdUtil.convertToIdentifiers(uid, actualObjectDefinition, connectorInstance.getRawResourceSchema()));
            objectDelta = PrismContext.get().deltaFactory().object().create(ShadowType.class, ChangeType.DELETE);
        } else if (icfDeltaType == SyncDeltaType.CREATE || icfDeltaType == SyncDeltaType.CREATE_OR_UPDATE || icfDeltaType == SyncDeltaType.UPDATE) {
            PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(actualObjectDefinition);
            LOGGER.trace("Object definition: {}", objectDefinition);
            // We can consider using "fetch result" error reporting method here, and go along with a partial object.
            resourceObject = connIdConvertor.convertToUcfObject(connIdDelta.getObject(), objectDefinition, false, connectorInstance.isCaseIgnoreAttributeNames(), connectorInstance.isLegacySchema(), UcfFetchErrorReportingMethod.EXCEPTION, result).getResourceObject();
            LOGGER.trace("Got (current) resource object: {}", resourceObject.debugDumpLazily());
            identifiers.addAll(emptyIfNull(ShadowUtil.getAllIdentifiers(resourceObject)));
            if (icfDeltaType == SyncDeltaType.CREATE) {
                objectDelta = PrismContext.get().deltaFactory().object().create(ShadowType.class, ChangeType.ADD);
                objectDelta.setObjectToAdd(resourceObject);
            }
        } else {
            throw new GenericFrameworkException("Unexpected sync delta type " + icfDeltaType);
        }
        if (identifiers.isEmpty()) {
            throw new SchemaException("No identifiers in sync delta " + connIdDelta);
        }
        errorState = UcfErrorState.success();
    } catch (Exception e) {
        result.recordFatalError(e);
        errorState = UcfErrorState.error(e);
    }
    UcfLiveSyncChange change = new UcfLiveSyncChange(localSequenceNumber, uidValue, identifiers, actualObjectDefinition, objectDelta, resourceObject, token, errorState);
    LOGGER.trace("END creating change of type {}:\n{}", icfDeltaType, change.debugDumpLazily());
    return change;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SyncDeltaType(org.identityconnectors.framework.common.objects.SyncDeltaType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Uid(org.identityconnectors.framework.common.objects.Uid) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)52 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)23 Test (org.testng.annotations.Test)18 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)16 Task (com.evolveum.midpoint.task.api.Task)16 QName (javax.xml.namespace.QName)16 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 Entry (org.apache.directory.api.ldap.model.entry.Entry)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ArrayList (java.util.ArrayList)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)7 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 Containerable (com.evolveum.midpoint.prism.Containerable)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)4 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)4 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)4