use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class SynchronizationContext method getIntent.
public String getIntent() throws SchemaException {
if (!hasApplicablePolicy()) {
return SchemaConstants.INTENT_UNKNOWN;
}
if (intent == null) {
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
ResourceObjectDefinition def = schema.findObjectDefinition(getKind(), null);
if (def instanceof ResourceObjectTypeDefinition) {
// TODO ???
intent = ((ResourceObjectTypeDefinition) def).getIntent();
}
}
return intent;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowUpdater method fixShadow.
/**
* Re-reads the shadow, re-evaluates the identifiers and stored values
* (including their normalization under matching rules), updates them if necessary.
*
* Returns fixed shadow.
*/
@NotNull
PrismObject<ShadowType> fixShadow(@NotNull ProvisioningContext ctx, @NotNull PrismObject<ShadowType> origRepoShadow, @NotNull OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException {
PrismObject<ShadowType> currentRepoShadow = repositoryService.getObject(ShadowType.class, origRepoShadow.getOid(), null, result);
ProvisioningContext shadowCtx = ctx.spawnForShadow(currentRepoShadow);
ResourceObjectDefinition oDef = shadowCtx.getObjectDefinitionRequired();
PrismContainer<Containerable> attributesContainer = currentRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer != null) {
ObjectDelta<ShadowType> shadowDelta = currentRepoShadow.createModifyDelta();
for (Item<?, ?> item : attributesContainer.getValue().getItems()) {
fixAttribute(oDef, item, shadowDelta);
}
if (!shadowDelta.isEmpty()) {
LOGGER.trace("Fixing shadow {} with delta:\n{}", origRepoShadow, shadowDelta.debugDumpLazily());
executeShadowModification(ctx, origRepoShadow, shadowDelta.getModifications(), result);
shadowDelta.applyTo(currentRepoShadow);
} else {
LOGGER.trace("No need to fixing shadow {} (empty delta)", origRepoShadow);
}
} else {
LOGGER.trace("No need to fixing shadow {} (no attributes)", origRepoShadow);
}
return currentRepoShadow;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowUpdater method computeUpdateShadowAttributeChanges.
private void computeUpdateShadowAttributeChanges(ProvisioningContext ctx, Collection<ItemDelta<?, ?>> repoShadowChanges, PrismObject<ShadowType> resourceShadow, PrismObject<ShadowType> repoShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
for (ResourceAttributeDefinition<?> attrDef : objectDefinition.getAttributeDefinitions()) {
if (ProvisioningUtil.shouldStoreAttributeInShadow(objectDefinition, attrDef.getItemName(), cachingStrategy)) {
ResourceAttribute<Object> resourceAttr = ShadowUtil.getAttribute(resourceShadow, attrDef.getItemName());
PrismProperty<Object> repoAttr = repoShadow.findProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrDef.getItemName()));
PropertyDelta attrDelta;
if (resourceAttr == null && repoAttr == null) {
continue;
}
ResourceAttribute<Object> normalizedResourceAttribute = resourceAttr.clone();
helper.normalizeAttribute(normalizedResourceAttribute, attrDef);
if (repoAttr == null) {
attrDelta = attrDef.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, attrDef.getItemName()));
attrDelta.setValuesToReplace(PrismValueCollectionsUtil.cloneCollection(normalizedResourceAttribute.getValues()));
} else {
attrDelta = repoAttr.diff(normalizedResourceAttribute);
// LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", repoAttr==null?null:repoAttr.debugDump(1), normalizedResourceAttribute==null?null:normalizedResourceAttribute.debugDump(1), attrDelta==null?null:attrDelta.debugDump(1));
}
if (attrDelta != null && !attrDelta.isEmpty()) {
helper.normalizeDelta(attrDelta, attrDef);
repoShadowChanges.add(attrDelta);
}
}
}
String newPrimaryIdentifierValue = helper.determinePrimaryIdentifierValue(ctx, resourceShadow);
String existingPrimaryIdentifierValue = repoShadow.asObjectable().getPrimaryIdentifierValue();
if (!Objects.equals(existingPrimaryIdentifierValue, newPrimaryIdentifierValue)) {
repoShadowChanges.add(prismContext.deltaFor(ShadowType.class).item(ShadowType.F_PRIMARY_IDENTIFIER_VALUE).replace(newPrimaryIdentifierValue).asItemDelta());
}
// TODO: reflect activation updates on cached shadow
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowUpdater method extractRepoShadowChanges.
@SuppressWarnings("rawtypes")
@NotNull
private Collection<? extends ItemDelta<?, ?>> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
// If type is not present, OC def is fine
ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
Collection<ItemDelta<?, ?>> repoChanges = new ArrayList<>();
for (ItemDelta itemDelta : objectChange) {
if (ShadowType.F_ATTRIBUTES.equivalent(itemDelta.getParentPath())) {
QName attrName = itemDelta.getElementName();
if (objectDefinition.isSecondaryIdentifier(attrName) || (objectDefinition.getAllIdentifiers().size() == 1 && objectDefinition.isPrimaryIdentifier(attrName))) {
// Change of secondary identifier, or primary identifier when it is only one, means object rename. We also need to change $shadow/name
// TODO: change this to displayName attribute later
String newName = null;
if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
newName = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
} else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
newName = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
}
PropertyDelta<PolyString> nameDelta = prismContext.deltaFactory().property().createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
repoChanges.add(nameDelta);
}
if (objectDefinition.isPrimaryIdentifier(attrName)) {
// Change of primary identifier $shadow/primaryIdentifier.
String newPrimaryIdentifier = null;
if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
newPrimaryIdentifier = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
} else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
newPrimaryIdentifier = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
}
ResourceAttribute<String> primaryIdentifier = helper.getPrimaryIdentifier(shadow);
// noinspection unchecked
ResourceAttributeDefinition<String> rDef = (ResourceAttributeDefinition<String>) objectDefinition.findAttributeDefinitionRequired(primaryIdentifier.getElementName());
String normalizedNewPrimaryIdentifier = helper.getNormalizedAttributeValue(rDef, newPrimaryIdentifier);
PropertyDelta<String> primaryIdentifierDelta = prismContext.deltaFactory().property().createReplaceDelta(shadow.getDefinition(), ShadowType.F_PRIMARY_IDENTIFIER_VALUE, normalizedNewPrimaryIdentifier);
repoChanges.add(primaryIdentifierDelta);
}
if (!ProvisioningUtil.shouldStoreAttributeInShadow(objectDefinition, attrName, cachingStrategy)) {
continue;
}
} else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getParentPath())) {
if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
continue;
}
} else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getPath())) {
// should not occur, but for completeness...
if (((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd() != null) {
for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
}
}
if (((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace() != null) {
for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
}
}
} else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
addPasswordDelta(repoChanges, itemDelta, objectDefinition);
continue;
}
helper.normalizeDelta(itemDelta, objectDefinition);
repoChanges.add(itemDelta);
}
return repoChanges;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowUpdater method retrieveIndexOnlyAttributesIfNeeded.
private PrismObject<ShadowType> retrieveIndexOnlyAttributesIfNeeded(ProvisioningContext shadowCtx, PrismObject<ShadowType> repoShadow, OperationResult result) throws SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectNotFoundException {
@Nullable ResourceObjectDefinition objectDefinition = shadowCtx.getObjectDefinition();
if (objectDefinition == null) {
// TODO consider throwing an exception
LOGGER.warn("No object class definition for {}", shadowCtx);
return repoShadow;
}
if (!objectDefinition.hasIndexOnlyAttributes()) {
LOGGER.trace("No index only attributes -> nothing to retrieve");
return repoShadow;
}
if (ShadowUtil.getAttributes(repoShadow).stream().noneMatch(Item::isIncomplete)) {
LOGGER.trace("All repo attributes are complete -> nothing to retrieve");
return repoShadow;
}
LOGGER.debug("Re-reading the shadow, retrieving all attributes (including index-only ones): {}", repoShadow);
Collection<SelectorOptions<GetOperationOptions>> options = SchemaService.get().getOperationOptionsBuilder().item(ShadowType.F_ATTRIBUTES).retrieve(RetrieveOption.INCLUDE).build();
PrismObject<ShadowType> retrievedRepoShadow = repositoryService.getObject(ShadowType.class, repoShadow.getOid(), options, result);
shadowCaretaker.applyAttributesDefinition(shadowCtx, retrievedRepoShadow);
shadowCaretaker.updateShadowState(shadowCtx, retrievedRepoShadow);
LOGGER.trace("Full repo shadow:\n{}", retrievedRepoShadow.debugDumpLazily(1));
return retrievedRepoShadow;
}
Aggregations