use of com.evolveum.midpoint.provisioning.util.InitializationState in project midpoint by Evolveum.
the class ResourceObjectChange method checkConsistence.
@Override
public void checkConsistence() throws SchemaException {
InitializationState state = getInitializationState();
if (!state.isInitialized() || !state.isOk()) {
return;
}
stateCheck(primaryIdentifierRealValue != null, "No primary identifier value");
boolean hasObjectClassDefinition = hasObjectClassDefinition();
stateCheck(isDelete() || hasObjectClassDefinition, "No object class definition for non-delete change");
checkCollectionImmutable(identifiers);
if (hasObjectClassDefinition) {
schemaCheck(!identifiers.isEmpty(), "No identifiers in the container but primary id value is known");
}
if (resourceObject != null) {
stateCheck(resourceObject.asObjectable().isExists() != null, "Exists is null");
// Unfortunately, other aspects cannot be checked here.
}
}
use of com.evolveum.midpoint.provisioning.util.InitializationState in project midpoint by Evolveum.
the class InitializableMixin method initialize.
/**
* Initializes given object.
*
* - Precondition: lifecycle state is CREATED.
* - Postcondition (unless exception is thrown): lifecycle state is INITIALIZED or INITIALIZATION_FAILED.
*/
default void initialize(Task task, OperationResult result) {
InitializationState state = getInitializationState();
getLogger().trace("Item before initialization (state: {}):\n{}", state, debugDumpLazily());
try {
state.moveFromCreatedToInitializing();
try {
initializeInternal(task, result);
} catch (NotApplicableException e) {
state.recordNotApplicable();
result.recordNotApplicable();
}
state.moveFromInitializingToInitialized();
checkConsistence();
} catch (CommonException | EncryptionException | RuntimeException e) {
// TODO change to debug
getLogger().warn("Got an exception during initialization of {}", this, e);
getInitializationState().recordInitializationFailed(e);
result.recordFatalError(e);
}
state.checkAfterInitialization();
getLogger().trace("Item after initialization (state: {}):\n{}", state, debugDumpLazily());
}
use of com.evolveum.midpoint.provisioning.util.InitializationState in project midpoint by Evolveum.
the class ExternalResourceEventListenerImpl method notifyEvent.
// TODO clean up this!
@Override
public void notifyEvent(ExternalResourceEvent event, Task task, OperationResult result) {
Validate.notNull(event, "Event description must not be null.");
Validate.notNull(task, "Task must not be null.");
Validate.notNull(result, "Operation result must not be null");
LOGGER.trace("Received event notification with the description: {}", event.debugDumpLazily());
if (event.getResourceObject() == null && event.getObjectDelta() == null) {
throw new IllegalStateException("Neither current shadow, nor delta specified. It is required to have at least one of them specified.");
}
try {
applyDefinitions(event, task, result);
PrismObject<ShadowType> anyShadow = getAnyShadow(event);
ProvisioningContext ctx = provisioningContextFactory.createForShadow(anyShadow, task, result);
ctx.assertDefinition();
Object primaryIdentifierRealValue = getPrimaryIdentifierRealValue(anyShadow, event);
Collection<ResourceAttribute<?>> identifiers = emptyIfNull(ShadowUtil.getAllIdentifiers(anyShadow));
if (identifiers.isEmpty()) {
throw new SchemaException("No identifiers");
}
ExternalResourceObjectChange resourceObjectChange = new ExternalResourceObjectChange(currentSequenceNumber.getAndIncrement(), primaryIdentifierRealValue, ctx.getObjectClassDefinition(), identifiers, getResourceObject(event), event.getObjectDelta(), ctx, resourceObjectConverter);
resourceObjectChange.initialize(task, result);
ShadowedExternalChange adoptedChange = new ShadowedExternalChange(resourceObjectChange, changeProcessingBeans);
adoptedChange.initialize(task, result);
InitializationState initializationState = adoptedChange.getInitializationState();
initializationState.checkAfterInitialization();
if (initializationState.isOk()) {
ResourceObjectShadowChangeDescription shadowChangeDescription = adoptedChange.getShadowChangeDescription();
eventDispatcher.notifyChange(shadowChangeDescription, task, result);
} else {
Throwable t = initializationState.getExceptionEncountered();
if (t != null) {
throw t;
} else if (initializationState.isNotApplicable()) {
LOGGER.debug("Change is not applicable:\n{}", adoptedChange.debugDumpLazily());
result.recordNotApplicable();
} else {
throw new AssertionError();
}
}
} catch (Throwable t) {
// Currently we do very simple error handling: throw any exception to the client, wrapped if needed
if (t instanceof CommonException) {
throw new TunnelException(t);
} else if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof Error) {
throw (Error) t;
} else {
throw new SystemException(t);
}
}
}
Aggregations