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