Search in sources :

Example 81 with FocusType

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();
        }
    }
}
Also used : PropertyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyConstraintType) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NoFocusNameSchemaException(com.evolveum.midpoint.util.exception.NoFocusNameSchemaException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 82 with FocusType

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);
        }
    }
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) GlobalPolicyRuleType(com.evolveum.midpoint.xml.ns._public.common.common_3.GlobalPolicyRuleType) EvaluatedPolicyRuleImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) ObjectSelectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSelectorType)

Example 83 with FocusType

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);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) TimeIntervalStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 84 with FocusType

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;
}
Also used : AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 85 with FocusType

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());
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7