use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.
the class FocusProcessor method applyObjectPolicyConstraints.
private <F extends FocusType> void applyObjectPolicyConstraints(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException {
if (objectPolicyConfigurationType == null) {
return;
}
final PrismObject<F> focusNew = focusContext.getObjectNew();
if (focusNew == null) {
// This is delete. Nothing to do.
return;
}
for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType.getPropertyConstraint()) {
ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
PrismProperty<Object> prop = focusNew.findProperty(itemPath);
if (prop == null || prop.isEmpty()) {
String newValue = focusNew.getOid();
if (newValue == null) {
newValue = OidUtil.generateOid();
}
LOGGER.trace("Generating new OID-bound value for {}: {}", itemPath, newValue);
PrismObjectDefinition<F> focusDefinition = focusContext.getObjectDefinition();
PrismPropertyDefinition<Object> propDef = focusDefinition.findPropertyDefinition(itemPath);
if (propDef == null) {
throw new SchemaException("No definition for property " + itemPath + " in " + focusDefinition + " as specified in object policy");
}
PropertyDelta<Object> propDelta = propDef.createEmptyDelta(itemPath);
if (String.class.isAssignableFrom(propDef.getTypeClass())) {
propDelta.setValueToReplace(new PrismPropertyValue<Object>(newValue, OriginType.USER_POLICY, null));
} else if (PolyString.class.isAssignableFrom(propDef.getTypeClass())) {
propDelta.setValueToReplace(new PrismPropertyValue<Object>(new PolyString(newValue), OriginType.USER_POLICY, null));
} else {
throw new SchemaException("Unsupported type " + propDef.getTypeName() + " for property " + itemPath + " in " + focusDefinition + " as specified in object policy, only string and polystring properties are supported for OID-bound mode");
}
focusContext.swallowToSecondaryDelta(propDelta);
focusContext.recompute();
}
}
}
// Deprecated
if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
// Generate the name now - unless it is already present
PolyStringType focusNewName = focusNew.asObjectable().getName();
if (focusNewName == null) {
String newValue = focusNew.getOid();
if (newValue == null) {
newValue = OidUtil.generateOid();
}
LOGGER.trace("Generating new name (bound to OID): {}", newValue);
PrismObjectDefinition<F> focusDefinition = focusContext.getObjectDefinition();
PrismPropertyDefinition<PolyString> focusNameDef = focusDefinition.findPropertyDefinition(FocusType.F_NAME);
PropertyDelta<PolyString> nameDelta = focusNameDef.createEmptyDelta(new ItemPath(FocusType.F_NAME));
nameDelta.setValueToReplace(new PrismPropertyValue<PolyString>(new PolyString(newValue), OriginType.USER_POLICY, null));
focusContext.swallowToSecondaryDelta(nameDelta);
focusContext.recompute();
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.
the class FocusProcessor method triggerGlobalRules.
private <F extends FocusType> void triggerGlobalRules(LensContext<F> context) throws SchemaException, PolicyViolationException {
PrismObject<SystemConfigurationType> systemConfiguration = context.getSystemConfiguration();
if (systemConfiguration == null) {
return;
}
LensFocusContext<F> focusContext = context.getFocusContext();
// We need to consider object before modification here. We need to prohibit the modification, so we
// cannot look at modified object.
PrismObject<F> focus = focusContext.getObjectCurrent();
if (focus == null) {
focus = focusContext.getObjectNew();
}
for (GlobalPolicyRuleType globalPolicyRule : systemConfiguration.asObjectable().getGlobalPolicyRule()) {
ObjectSelectorType focusSelector = globalPolicyRule.getFocusSelector();
if (cacheRepositoryService.selectorMatches(focusSelector, focus, LOGGER, "Global policy rule " + globalPolicyRule.getName() + ": ")) {
EvaluatedPolicyRule evaluatedRule = new EvaluatedPolicyRuleImpl(globalPolicyRule, null);
triggerRule(focusContext, evaluatedRule);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.
the class FocusProcessor method processActivationAdministrativeAndValidity.
private <F extends FocusType> void processActivationAdministrativeAndValidity(LensFocusContext<F> focusContext, XMLGregorianCalendar now, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
TimeIntervalStatusType validityStatusNew = null;
TimeIntervalStatusType validityStatusCurrent = null;
XMLGregorianCalendar validityChangeTimestamp = null;
String lifecycleStateNew = null;
String lifecycleStateCurrent = null;
ActivationType activationNew = null;
ActivationType activationCurrent = null;
PrismObject<F> focusNew = focusContext.getObjectNew();
if (focusNew != null) {
F focusTypeNew = focusNew.asObjectable();
activationNew = focusTypeNew.getActivation();
if (activationNew != null) {
validityStatusNew = activationComputer.getValidityStatus(activationNew, now);
validityChangeTimestamp = activationNew.getValidityChangeTimestamp();
}
lifecycleStateNew = focusTypeNew.getLifecycleState();
}
PrismObject<F> focusCurrent = focusContext.getObjectCurrent();
if (focusCurrent != null) {
F focusCurrentType = focusCurrent.asObjectable();
activationCurrent = focusCurrentType.getActivation();
if (activationCurrent != null) {
validityStatusCurrent = activationComputer.getValidityStatus(activationCurrent, validityChangeTimestamp);
}
lifecycleStateCurrent = focusCurrentType.getLifecycleState();
}
if (validityStatusCurrent == validityStatusNew) {
// No change, (almost) no work
if (validityStatusNew != null && activationNew.getValidityStatus() == null) {
// There was no validity change. But the status is not recorded. So let's record it so it can be used in searches.
recordValidityDelta(focusContext, validityStatusNew, now);
} else {
LOGGER.trace("Skipping validity processing because there was no change ({} -> {})", validityStatusCurrent, validityStatusNew);
}
} else {
LOGGER.trace("Validity change {} -> {}", validityStatusCurrent, validityStatusNew);
recordValidityDelta(focusContext, validityStatusNew, now);
}
ActivationStatusType effectiveStatusNew = activationComputer.getEffectiveStatus(lifecycleStateNew, activationNew, validityStatusNew);
ActivationStatusType effectiveStatusCurrent = activationComputer.getEffectiveStatus(lifecycleStateCurrent, activationCurrent, validityStatusCurrent);
if (effectiveStatusCurrent == effectiveStatusNew) {
// No change, (almost) no work
if (effectiveStatusNew != null && (activationNew == null || activationNew.getEffectiveStatus() == null)) {
// There was no effective status change. But the status is not recorded. So let's record it so it can be used in searches.
recordEffectiveStatusDelta(focusContext, effectiveStatusNew, now);
} else {
if (focusContext.getPrimaryDelta() != null && focusContext.getPrimaryDelta().hasItemDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS)) {
LOGGER.trace("Forcing effective status delta even though there was no change ({} -> {}) because there is explicit administrativeStatus delta", effectiveStatusCurrent, effectiveStatusNew);
// We need this to force the change down to the projections later in the activation processor
// some of the mappings will use effectiveStatus as a source, therefore there has to be a delta for the mapping to work correctly
recordEffectiveStatusDelta(focusContext, effectiveStatusNew, now);
} else {
LOGGER.trace("Skipping effective status processing because there was no change ({} -> {})", effectiveStatusCurrent, effectiveStatusNew);
}
}
} else {
LOGGER.trace("Effective status change {} -> {}", effectiveStatusCurrent, effectiveStatusNew);
recordEffectiveStatusDelta(focusContext, effectiveStatusNew, now);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.
the class AssignmentTripleEvaluator method getExecutionWaveAssignmentDelta.
/**
* Returns delta of user assignments, both primary and secondary (merged together).
* The returned object is (kind of) immutable. Changing it may do strange things (but most likely the changes will be lost).
*
* Originally we took only the delta related to current execution wave, to avoid re-processing of already executed assignments.
* But MID-2422 shows that we need to take deltas from waves 0..N (N=current execution wave) [that effectively means all the secondary deltas]
*/
private <F extends FocusType> ContainerDelta<AssignmentType> getExecutionWaveAssignmentDelta(LensFocusContext<F> focusContext) throws SchemaException {
ObjectDelta<? extends FocusType> focusDelta = focusContext.getAggregatedWaveDelta(focusContext.getLensContext().getExecutionWave());
if (focusDelta == null) {
return createEmptyAssignmentDelta(focusContext);
}
ContainerDelta<AssignmentType> assignmentDelta = focusDelta.findContainerDelta(new ItemPath(FocusType.F_ASSIGNMENT));
if (assignmentDelta == null) {
return createEmptyAssignmentDelta(focusContext);
}
return assignmentDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method dumpFocus.
protected <F extends FocusType> void dumpFocus(String message, PrismObject<F> focus) throws ObjectNotFoundException, SchemaException {
OperationResult result = new OperationResult(AbstractIntegrationTest.class.getName() + ".dumpFocus");
StringBuilder sb = new StringBuilder();
sb.append(focus.debugDump(0));
sb.append("\nOrgs:");
for (ObjectReferenceType parentOrgRef : focus.asObjectable().getParentOrgRef()) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, 1);
PrismObject<OrgType> org = repositoryService.getObject(OrgType.class, parentOrgRef.getOid(), null, result);
sb.append(org);
PolyStringType displayName = org.asObjectable().getDisplayName();
if (displayName != null) {
sb.append(": ").append(displayName);
}
}
sb.append("\nProjections:");
for (ObjectReferenceType linkRef : focus.asObjectable().getLinkRef()) {
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, linkRef.getOid(), null, result);
ObjectReferenceType resourceRef = shadow.asObjectable().getResourceRef();
PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, resourceRef.getOid(), null, result);
sb.append("\n");
DebugUtil.indentDebugDump(sb, 1);
sb.append(resource);
sb.append("/");
sb.append(shadow.asObjectable().getKind());
sb.append("/");
sb.append(shadow.asObjectable().getIntent());
sb.append(": ");
sb.append(shadow.asObjectable().getName());
}
sb.append("\nAssignments:");
for (AssignmentType assignmentType : focus.asObjectable().getAssignment()) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, 1);
if (assignmentType.getConstruction() != null) {
sb.append("Constr(").append(assignmentType.getConstruction().getDescription()).append(") ");
}
if (assignmentType.getTargetRef() != null) {
sb.append("-[");
if (assignmentType.getTargetRef().getRelation() != null) {
sb.append(assignmentType.getTargetRef().getRelation().getLocalPart());
}
sb.append("]-> ");
Class<? extends ObjectType> targetClass = ObjectTypes.getObjectTypeFromTypeQName(assignmentType.getTargetRef().getType()).getClassDefinition();
;
PrismObject<? extends ObjectType> target = repositoryService.getObject(targetClass, assignmentType.getTargetRef().getOid(), null, result);
sb.append(target);
}
}
display(message, sb.toString());
}
Aggregations