use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ObjectTemplateProcessor method computeItemDeltas.
<F extends FocusType, T extends FocusType> Collection<ItemDelta<?, ?>> computeItemDeltas(Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, @Nullable Map<ItemPath, ObjectTemplateItemDefinitionType> itemDefinitionsMap, ObjectDelta<T> targetObjectAPrioriDelta, PrismObject<T> targetObject, PrismObjectDefinition<F> focusDefinition, String contextDesc) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
Collection<ItemDelta<?, ?>> itemDeltas = new ArrayList<>();
LOGGER.trace("Computing deltas in {}, focusDelta:\n{}", contextDesc, targetObjectAPrioriDelta);
boolean addUnchangedValues = false;
if (targetObjectAPrioriDelta != null && targetObjectAPrioriDelta.isAdd()) {
addUnchangedValues = true;
}
for (Entry<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> entry : outputTripleMap.entrySet()) {
ItemPath itemPath = entry.getKey();
DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>> outputTriple = entry.getValue();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Computed triple for {}:\n{}", itemPath, outputTriple.debugDump());
}
final ObjectTemplateItemDefinitionType templateItemDefinition;
if (itemDefinitionsMap != null) {
templateItemDefinition = ItemPathUtil.getFromMap(itemDefinitionsMap, itemPath);
} else {
templateItemDefinition = null;
}
boolean isNonTolerant = templateItemDefinition != null && Boolean.FALSE.equals(templateItemDefinition.isTolerant());
ItemDelta aprioriItemDelta = getAprioriItemDelta(targetObjectAPrioriDelta, itemPath);
// if non-tolerant, we want to gather ZERO & PLUS sets
boolean filterExistingValues = !isNonTolerant;
ItemDefinition itemDefinition = focusDefinition.findItemDefinition(itemPath);
ItemDelta itemDelta = LensUtil.consolidateTripleToDelta(itemPath, (DeltaSetTriple) outputTriple, itemDefinition, aprioriItemDelta, targetObject, null, null, addUnchangedValues, filterExistingValues, false, contextDesc, true);
// Do a quick version of reconciliation. There is not much to reconcile as both the source and the target
// is focus. But there are few cases to handle, such as strong mappings, and sourceless normal mappings.
Collection<? extends ItemValueWithOrigin<?, ?>> zeroSet = outputTriple.getZeroSet();
Item<PrismValue, ItemDefinition> itemNew = null;
if (targetObject != null) {
itemNew = targetObject.findItem(itemPath);
}
for (ItemValueWithOrigin<?, ?> zeroSetIvwo : zeroSet) {
PrismValueDeltaSetTripleProducer<?, ?> mapping = zeroSetIvwo.getMapping();
if ((mapping.getStrength() == null || mapping.getStrength() == MappingStrengthType.NORMAL)) {
if (aprioriItemDelta != null && !aprioriItemDelta.isEmpty()) {
continue;
}
if (!mapping.isSourceless()) {
continue;
}
LOGGER.trace("Adding zero values from normal mapping {}, a-priori delta: {}, isSourceless: {}", mapping, aprioriItemDelta, mapping.isSourceless());
} else if (mapping.getStrength() == MappingStrengthType.WEAK) {
if ((itemNew != null && !itemNew.isEmpty()) || (itemDelta != null && itemDelta.addsAnyValue())) {
continue;
}
LOGGER.trace("Adding zero values from weak mapping {}, itemNew: {}, itemDelta: {}", mapping, itemNew, itemDelta);
} else {
LOGGER.trace("Adding zero values from strong mapping {}", mapping);
}
PrismValue valueFromZeroSet = zeroSetIvwo.getItemValue();
if (itemNew == null || !itemNew.containsRealValue(valueFromZeroSet)) {
LOGGER.trace("Reconciliation will add value {} for item {}. Existing item: {}", valueFromZeroSet, itemPath, itemNew);
itemDelta.addValuesToAdd(valueFromZeroSet.clone());
}
}
if (isNonTolerant) {
if (itemDelta.isDelete()) {
LOGGER.trace("Non-tolerant item with values to DELETE => removing them");
// these are useless now - we move everything to REPLACE
itemDelta.resetValuesToDelete();
}
if (itemDelta.isReplace()) {
LOGGER.trace("Non-tolerant item with resulting REPLACE delta => doing nothing");
} else {
for (ItemValueWithOrigin<?, ?> zeroSetIvwo : zeroSet) {
itemDelta.addValuesToAdd(zeroSetIvwo.getItemValue().clone());
}
itemDelta.addToReplaceDelta();
LOGGER.trace("Non-tolerant item with resulting ADD delta => converted ADD to REPLACE values: {}", itemDelta.getValuesToReplace());
}
// under a special option "createReplaceDelta", but for the time being, let's keep it here
if (itemDelta instanceof PropertyDelta) {
PropertyDelta propertyDelta = ((PropertyDelta) itemDelta);
QName matchingRuleName = templateItemDefinition != null ? templateItemDefinition.getMatchingRule() : null;
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleName, null);
if (propertyDelta.isRedundant(targetObject, matchingRule)) {
LOGGER.trace("Computed property delta is redundant => skipping it. Delta = \n{}", propertyDelta.debugDump());
continue;
}
} else {
if (itemDelta.isRedundant(targetObject)) {
LOGGER.trace("Computed item delta is redundant => skipping it. Delta = \n{}", itemDelta.debugDump());
continue;
}
}
PrismUtil.setDeltaOldValue(targetObject, itemDelta);
}
itemDelta.simplify();
itemDelta.validate(contextDesc);
itemDeltas.add(itemDelta);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Computed delta:\n{}", itemDelta.debugDump());
}
}
return itemDeltas;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ResourceManager method modifyResourceAvailabilityStatus.
public void modifyResourceAvailabilityStatus(PrismObject<ResourceType> resource, AvailabilityStatusType status, OperationResult result) {
ResourceType resourceType = resource.asObjectable();
synchronized (resource) {
if (resourceType.getOperationalState() == null || resourceType.getOperationalState().getLastAvailabilityStatus() == null || resourceType.getOperationalState().getLastAvailabilityStatus() != status) {
List<PropertyDelta<?>> modifications = new ArrayList<PropertyDelta<?>>();
PropertyDelta<?> statusDelta = createResourceAvailabilityStatusDelta(resource, status);
modifications.add(statusDelta);
try {
repositoryService.modifyObject(ResourceType.class, resourceType.getOid(), modifications, result);
} catch (SchemaException ex) {
throw new SystemException(ex);
} catch (ObjectAlreadyExistsException ex) {
throw new SystemException(ex);
} catch (ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}
// ugly hack: change object even if it's immutable
boolean immutable = resource.isImmutable();
if (immutable) {
resource.setImmutable(false);
}
if (resourceType.getOperationalState() == null) {
OperationalStateType operationalState = new OperationalStateType();
operationalState.setLastAvailabilityStatus(status);
resourceType.setOperationalState(operationalState);
} else {
resourceType.getOperationalState().setLastAvailabilityStatus(status);
}
if (immutable) {
resource.setImmutable(true);
}
}
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class AccessChecker method checkModify.
public void checkModify(ResourceType resource, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> modifications, RefinedObjectClassDefinition objectClassDefinition, OperationResult parentResult) throws SecurityViolationException, SchemaException {
OperationResult result = parentResult.createMinorSubresult(OPERATION_NAME);
for (ItemDelta modification : modifications) {
if (!(modification instanceof PropertyDelta<?>)) {
continue;
}
PropertyDelta<?> attrDelta = (PropertyDelta<?>) modification;
if (!SchemaConstants.PATH_ATTRIBUTES.equivalent(attrDelta.getParentPath())) {
// Not an attribute
continue;
}
QName attrName = attrDelta.getElementName();
RefinedAttributeDefinition attrDef = objectClassDefinition.findAttributeDefinition(attrName);
if (attrDef == null) {
throw new SchemaException("Cannot find definition of attribute " + attrName + " in " + objectClassDefinition);
}
PropertyLimitations limitations = attrDef.getLimitations(LayerType.MODEL);
if (limitations == null) {
continue;
}
// We cannot throw error here. At least not now. Provisioning will internally use ignored attributes
// e.g. for simulated capabilities. This is not a problem for normal operations, but it is a problem
// for delayed operations (e.g. consistency) that are passing through this code again.
// TODO: we need to figure a way how to avoid this loop
// if (limitations.isIgnore()) {
// String message = "Attempt to create shadow with ignored attribute "+attribute.getName();
// LOGGER.error(message);
// throw new SchemaException(message);
// }
PropertyAccessType access = limitations.getAccess();
if (access == null) {
continue;
}
if (access.isModify() == null || !access.isModify()) {
String message = "Attempt to modify non-updateable attribute " + attrName;
LOGGER.error(message);
result.recordFatalError(message);
throw new SecurityViolationException(message);
}
}
result.recordSuccess();
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ErrorHandler method createAttemptModification.
protected <T extends ShadowType> Collection<ItemDelta> createAttemptModification(T shadow, Collection<ItemDelta> modifications) {
if (modifications == null) {
modifications = new ArrayList<ItemDelta>();
}
PropertyDelta attemptDelta = PropertyDelta.createReplaceDelta(shadow.asPrismObject().getDefinition(), ShadowType.F_ATTEMPT_NUMBER, getAttemptNumber(shadow));
modifications.add(attemptDelta);
return modifications;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class CommunicationExceptionHandler method createShadowModification.
private <T extends ShadowType> Collection<ItemDelta> createShadowModification(T shadow) throws ObjectNotFoundException, SchemaException {
Collection<ItemDelta> modifications = new ArrayList<ItemDelta>();
PropertyDelta propertyDelta = PropertyDelta.createReplaceDelta(shadow.asPrismObject().getDefinition(), ShadowType.F_RESULT, shadow.getResult());
modifications.add(propertyDelta);
propertyDelta = PropertyDelta.createReplaceDelta(shadow.asPrismObject().getDefinition(), ShadowType.F_FAILED_OPERATION_TYPE, shadow.getFailedOperationType());
modifications.add(propertyDelta);
if (shadow.getObjectChange() != null) {
propertyDelta = PropertyDelta.createReplaceDelta(shadow.asPrismObject().getDefinition(), ShadowType.F_OBJECT_CHANGE, shadow.getObjectChange());
modifications.add(propertyDelta);
}
modifications = createAttemptModification(shadow, modifications);
return modifications;
}
Aggregations