use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType in project midpoint by Evolveum.
the class ActivationConverter method createLockoutStatusChange.
private void createLockoutStatusChange(Collection<? extends ItemDelta<?, ?>> objectChange, ShadowType shadow, ActivationCapabilityType activationCapability, ResourceType resource, Collection<Operation> operations, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
PropertyDelta<LockoutStatusType> propertyDelta = findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS);
if (propertyDelta == null) {
return;
}
ActivationLockoutStatusCapabilityType lockoutCapability = CapabilityUtil.getEnabledActivationLockoutStrict(activationCapability);
if (lockoutCapability == null) {
SchemaException e = new SchemaException("Attempt to change activation lockoutStatus on " + resource + " which does not have the capability");
result.recordFatalError(e);
throw e;
}
QName simulatingAttributeName = lockoutCapability.getAttribute();
if (simulatingAttributeName == null) {
LOGGER.trace("No simulation attribute, using native value");
addModification(operations, propertyDelta);
return;
}
LockoutStatusType newStatus = getRealValue(propertyDelta.getPropertyNewMatchingPath());
LOGGER.trace("Found activation lockout change to: {}", newStatus);
PropertyModificationOperation<?> simulatingAttributeModification = TwoStateRealToSimulatedConverter.create(lockoutCapability, simulatingAttributeName, ctx, beans).convertDelta(newStatus, shadow, result);
if (simulatingAttributeModification != null) {
operations.add(simulatingAttributeModification);
} else {
addModification(operations, propertyDelta);
}
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType in project midpoint by Evolveum.
the class ActivationConverter method transformActivationOnAdd.
// endregion
// region midPoint -> resource object (activation -> simulating/native) on object ADD
/**
* Transforms activation information when an object is being added.
*/
void transformActivationOnAdd(ShadowType shadow, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ActivationType activation = shadow.getActivation();
if (activation == null) {
return;
}
ActivationCapabilityType activationCapability = ctx.getEffectiveCapability(ActivationCapabilityType.class);
if (activation.getAdministrativeStatus() != null) {
transformActivationStatusOnAdd(shadow, activationCapability, result);
}
if (activation.getLockoutStatus() != null) {
transformLockoutStatusOnAdd(shadow, activationCapability, result);
}
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType in project midpoint by Evolveum.
the class ActivationConverter method transformActivationStatusOnAdd.
private void transformActivationStatusOnAdd(ShadowType shadow, ActivationCapabilityType activationCapability, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ActivationStatusCapabilityType statusCapability = CapabilityUtil.getEnabledActivationStatusStrict(activationCapability);
LOGGER.trace("Activation status capability:\n{}", statusCapability);
if (statusCapability == null) {
throw new SchemaException("Attempt to set activation/administrativeStatus on " + ctx.getResource() + " that has neither native nor simulated activation/status capability");
}
QName simulatingAttributeName = statusCapability.getAttribute();
if (simulatingAttributeName == null) {
LOGGER.trace("Using native activation status capability");
return;
}
boolean converted = TwoStateRealToSimulatedConverter.create(statusCapability, simulatingAttributeName, ctx, beans).convertProperty(shadow.getActivation().getAdministrativeStatus(), shadow, result);
if (converted) {
shadow.getActivation().setAdministrativeStatus(null);
}
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType in project midpoint by Evolveum.
the class ActivationConverter method determineActivationStatus.
/**
* Determines activation status for resource object. Uses either native or simulated value.
*/
private ActivationStatusType determineActivationStatus(PrismObject<ShadowType> resourceObject, ActivationCapabilityType activationCapability, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ActivationType existingActivation = resourceObject.asObjectable().getActivation();
ActivationStatusType nativeValue = existingActivation != null ? existingActivation.getAdministrativeStatus() : null;
ActivationStatusCapabilityType statusCapability = CapabilityUtil.getEnabledActivationStatusStrict(activationCapability);
if (statusCapability == null) {
if (nativeValue != null) {
LOGGER.trace("The status capability is disabled. Ignoring native value: {}", nativeValue);
}
// TODO Reconsider this. Maybe we should return native value.
return null;
}
if (statusCapability.getAttribute() == null) {
LOGGER.trace("Simulated activation status is not configured. Using native value: {}", nativeValue);
return nativeValue;
}
Collection<Object> simulatingAttributeValues = getSimulatingAttributeValues(resourceObject, statusCapability.getAttribute());
TwoStateSimulatedToRealConverter<ActivationStatusType> converter = new TwoStateSimulatedToRealConverter<>(statusCapability.getEnableValue(), statusCapability.getDisableValue(), ActivationStatusType.ENABLED, ActivationStatusType.DISABLED, "activation status", ctx);
ActivationStatusType status = converter.convert(simulatingAttributeValues, result);
LOGGER.trace("Detected simulated activation administrativeStatus attribute {} on {} with value {}, resolved into {}", lazy(() -> SchemaDebugUtil.prettyPrint(statusCapability.getAttribute())), ctx.getResource(), simulatingAttributeValues, status);
if (!Boolean.FALSE.equals(statusCapability.isIgnoreAttribute())) {
removeSimulatingAttribute(resourceObject, statusCapability.getAttribute());
}
return status;
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType in project midpoint by Evolveum.
the class AbstractManualResourceTest method test006Capabilities.
@Test
public void test006Capabilities() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = createOperationResult();
// WHEN
ResourceType resource = provisioningService.getObject(ResourceType.class, getResourceOid(), null, task, result).asObjectable();
// THEN
display("Resource from provisioninig", resource);
displayValue("Resource from provisioninig (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));
CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
CreateCapabilityType capCreate = CapabilityUtil.getCapability(nativeCapabilitiesList, CreateCapabilityType.class);
assertNotNull("Missing create capability", capCreate);
assertManual(capCreate);
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
assertNotNull("Missing activation capability", capAct);
ReadCapabilityType capRead = CapabilityUtil.getCapability(nativeCapabilitiesList, ReadCapabilityType.class);
assertNotNull("Missing read capability", capRead);
assertEquals("Wrong caching-only setting in read capability", Boolean.TRUE, capRead.isCachingOnly());
List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
for (Object capability : effectiveCapabilities) {
System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
}
}
Aggregations