Search in sources :

Example 31 with ActivationStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType in project midpoint by Evolveum.

the class TestActivationComputer method testGetProposedAdministrativeEnabled.

@Test
public void testGetProposedAdministrativeEnabled() throws Exception {
    System.out.println("\n===[ testGetProposedAdministrativeEnabled ]===\n");
    // GIVEN
    Clock clock = createClock(YEAR_START);
    ActivationComputer activationComputer = createActivationComputer(clock);
    ActivationType activationType = createActivationType(ActivationStatusType.DISABLED, SPRING_EQUINOX, AUTUMN_EQUINOX);
    // WHEN
    ActivationStatusType effectiveStatus = activationComputer.getEffectiveStatus(SchemaConstants.LIFECYCLE_PROPOSED, activationType);
    // THEN
    assertEquals("Unexpected effective status", ActivationStatusType.DISABLED, effectiveStatus);
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) Test(org.testng.annotations.Test)

Example 32 with ActivationStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType in project midpoint by Evolveum.

the class InactivateShadowAction method handle.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.model.sync.Action#handle(com.evolveum.midpoint.model.lens.LensContext, com.evolveum.midpoint.model.sync.SynchronizationSituation, java.util.Map, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public <F extends FocusType> void handle(LensContext<F> context, SynchronizationSituation<F> situation, Map<QName, Object> parameters, Task task, OperationResult parentResult) {
    ActivationStatusType desiredStatus = ActivationStatusType.DISABLED;
    LensProjectionContext projectionContext = context.getProjectionContextsIterator().next();
    PrismObject<ShadowType> objectCurrent = projectionContext.getObjectCurrent();
    if (objectCurrent != null) {
        PrismProperty<Object> administrativeStatusProp = objectCurrent.findProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
        if (administrativeStatusProp != null) {
            if (desiredStatus.equals(administrativeStatusProp.getRealValue())) {
                // Desired status already set, nothing to do
                return;
            }
        }
    }
    ObjectDelta<ShadowType> activationDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, projectionContext.getOid(), SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getPrismContext(), desiredStatus);
    projectionContext.setPrimaryDelta(activationDelta);
}
Also used : ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 33 with ActivationStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType in project midpoint by Evolveum.

the class TestActivation method assertEffectiveStatus.

private <F extends FocusType> void assertEffectiveStatus(PrismObject<F> focus, ActivationStatusType expected) {
    ActivationType activation = focus.asObjectable().getActivation();
    assertNotNull("No activation in " + focus, activation);
    assertEquals("Unexpected effective activation status in " + focus, expected, activation.getEffectiveStatus());
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)

Example 34 with ActivationStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType in project midpoint by Evolveum.

the class ResourceObjectConverter method determineActivationChange.

private Collection<Operation> determineActivationChange(ProvisioningContext ctx, ShadowType shadow, Collection<? extends ItemDelta> objectChange, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    Collection<Operation> operations = new ArrayList<>();
    CapabilitiesType connectorCapabilities = ctx.getConnectorCapabilities(UpdateCapabilityType.class);
    ActivationCapabilityType activationCapability = CapabilityUtil.getEffectiveCapability(connectorCapabilities, ActivationCapabilityType.class);
    // administrativeStatus
    PropertyDelta<ActivationStatusType> enabledPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
    if (enabledPropertyDelta != null) {
        if (activationCapability == null) {
            SchemaException e = new SchemaException("Attempt to change activation administrativeStatus on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        ActivationStatusType status = enabledPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation administrativeStatus change to: {}", status);
        if (CapabilityUtil.hasNativeCapability(connectorCapabilities, ActivationCapabilityType.class)) {
            // Native activation, need to check if there is not also change to simulated activation which may be in conflict
            checkSimulatedActivationAdministrativeStatus(ctx, objectChange, status, activationCapability, shadow, result);
            operations.add(new PropertyModificationOperation(enabledPropertyDelta));
        } else {
            // Try to simulate activation capability
            PropertyModificationOperation activationAttribute = convertToSimulatedActivationAdministrativeStatusAttribute(ctx, enabledPropertyDelta, shadow, status, activationCapability, result);
            if (activationAttribute != null) {
                operations.add(activationAttribute);
            }
        }
    }
    // validFrom
    PropertyDelta<XMLGregorianCalendar> validFromPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_VALID_FROM);
    if (validFromPropertyDelta != null) {
        if (CapabilityUtil.getEffectiveActivationValidFrom(activationCapability) == null) {
            SchemaException e = new SchemaException("Attempt to change activation validFrom on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        XMLGregorianCalendar xmlCal = validFromPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation validFrom change to: {}", xmlCal);
        operations.add(new PropertyModificationOperation(validFromPropertyDelta));
    }
    // validTo
    PropertyDelta<XMLGregorianCalendar> validToPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_VALID_TO);
    if (validToPropertyDelta != null) {
        if (CapabilityUtil.getEffectiveActivationValidTo(activationCapability) == null) {
            SchemaException e = new SchemaException("Attempt to change activation validTo on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        XMLGregorianCalendar xmlCal = validToPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation validTo change to: {}", xmlCal);
        operations.add(new PropertyModificationOperation(validToPropertyDelta));
    }
    PropertyDelta<LockoutStatusType> lockoutPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS);
    if (lockoutPropertyDelta != null) {
        if (activationCapability == null) {
            SchemaException e = new SchemaException("Attempt to change activation lockoutStatus on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        LockoutStatusType status = lockoutPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation lockoutStatus change to: {}", status);
        if (CapabilityUtil.hasNativeCapability(connectorCapabilities, ActivationCapabilityType.class)) {
            // Native lockout, need to check if there is not also change to simulated activation which may be in conflict
            checkSimulatedActivationLockoutStatus(ctx, objectChange, status, activationCapability, shadow, result);
            operations.add(new PropertyModificationOperation(lockoutPropertyDelta));
        } else {
            // Try to simulate lockout capability
            PropertyModificationOperation activationAttribute = convertToSimulatedActivationLockoutStatusAttribute(ctx, lockoutPropertyDelta, shadow, status, activationCapability, result);
            operations.add(activationAttribute);
        }
    }
    return operations;
}
Also used : ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 35 with ActivationStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType in project midpoint by Evolveum.

the class ResourceObjectConverter method convertToSimulatedActivationAdministrativeStatusAttribute.

private PropertyModificationOperation convertToSimulatedActivationAdministrativeStatusAttribute(ProvisioningContext ctx, PropertyDelta activationDelta, ShadowType shadow, ActivationStatusType status, ActivationCapabilityType activationCapabilityType, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    ActivationStatusCapabilityType capActStatus = getActivationAdministrativeStatusFromSimulatedActivation(ctx, activationCapabilityType, shadow, result);
    if (capActStatus == null) {
        throw new SchemaException("Attempt to modify activation on " + resource + " which does not have activation capability");
    }
    ResourceAttribute<?> simulatedAttribute = getSimulatedActivationAdministrativeStatusAttribute(ctx, shadow, capActStatus, result);
    if (simulatedAttribute == null) {
        return null;
    }
    Class<?> simulatedAttrValueClass = getAttributeValueClass(ctx, shadow, simulatedAttribute, capActStatus);
    PropertyDelta<?> simulatedAttrDelta;
    if (status == null && activationDelta.isDelete()) {
        LOGGER.trace("deleting activation property.");
        simulatedAttrDelta = PropertyDelta.createModificationDeleteProperty(new ItemPath(ShadowType.F_ATTRIBUTES, simulatedAttribute.getElementName()), simulatedAttribute.getDefinition(), simulatedAttribute.getRealValue());
    } else if (status == ActivationStatusType.ENABLED) {
        Object enableValue = getEnableValue(capActStatus, simulatedAttrValueClass);
        simulatedAttrDelta = createActivationPropDelta(simulatedAttribute.getElementName(), simulatedAttribute.getDefinition(), enableValue);
    } else {
        Object disableValue = getDisableValue(capActStatus, simulatedAttrValueClass);
        simulatedAttrDelta = createActivationPropDelta(simulatedAttribute.getElementName(), simulatedAttribute.getDefinition(), disableValue);
    }
    PropertyModificationOperation attributeChange = new PropertyModificationOperation(simulatedAttrDelta);
    return attributeChange;
}
Also used : ActivationStatusCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)32 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)24 Test (org.testng.annotations.Test)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)2 LockoutStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType)2 TimeIntervalStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 ActivationStatusCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType)2 ArrayList (java.util.ArrayList)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1