use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class SynchronizationServiceImpl method reactToChange.
private <F extends FocusType> SynchronizationSituationType reactToChange(Class<F> focusClass, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ResourceType resource, boolean logDebug, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult parentResult) throws ConfigurationException, ObjectNotFoundException, SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, CommunicationException, SecurityViolationException {
SynchronizationSituationType newSituation = situation.getSituation();
SynchronizationReactionType reactionDefinition = findReactionDefinition(synchronizationPolicy, situation, change.getSourceChannel(), resource);
if (reactionDefinition == null) {
LOGGER.trace("No reaction is defined for situation {} in {}", situation.getSituation(), resource);
return newSituation;
}
// seems to be unused so commented it out [med]
// PrismObject<? extends ObjectType> shadow = null;
// if (change.getCurrentShadow() != null) {
// shadow = change.getCurrentShadow();
// } else if (change.getOldShadow() != null) {
// shadow = change.getOldShadow();
// }
Boolean doReconciliation = determineReconciliation(synchronizationPolicy, reactionDefinition);
if (doReconciliation == null) {
// shadow.
if (change.getObjectDelta() == null) {
doReconciliation = true;
}
}
Boolean limitPropagation = determinePropagationLimitation(synchronizationPolicy, reactionDefinition, change.getSourceChannel());
ModelExecuteOptions options = new ModelExecuteOptions();
options.setReconcile(doReconciliation);
options.setLimitPropagation(limitPropagation);
final boolean willSynchronize = isSynchronize(reactionDefinition);
LensContext<F> lensContext = null;
if (willSynchronize) {
lensContext = createLensContext(focusClass, change, reactionDefinition, synchronizationPolicy, situation, options, configuration, parentResult);
}
if (LOGGER.isTraceEnabled() && lensContext != null) {
LOGGER.trace("---[ SYNCHRONIZATION context before action execution ]-------------------------\n" + "{}\n------------------------------------------", lensContext.debugDump());
}
if (willSynchronize) {
// there's no point in calling executeAction without context - so
// the actions are executed only if synchronize == true
executeActions(reactionDefinition, lensContext, situation, BeforeAfterType.BEFORE, resource, logDebug, task, parentResult);
Iterator<LensProjectionContext> iterator = lensContext.getProjectionContextsIterator();
LensProjectionContext originalProjectionContext = iterator.hasNext() ? iterator.next() : null;
try {
clockwork.run(lensContext, task, parentResult);
} catch (ConfigurationException | ObjectNotFoundException | SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectAlreadyExistsException | CommunicationException | SecurityViolationException e) {
LOGGER.error("SYNCHRONIZATION: Error in synchronization on {} for situation {}: {}: {}. Change was {}", new Object[] { resource, situation.getSituation(), e.getClass().getSimpleName(), e.getMessage(), change, e });
// what to do here? We cannot throw the error back. All that the notifyChange method
// could do is to convert it to SystemException. But that indicates an internal error and it will
// break whatever code called the notifyChange in the first place. We do not want that.
// If the clockwork could not do anything with the exception then perhaps nothing can be done at all.
// So just log the error (the error should be remembered in the result and task already)
// and then just go on.
}
// note: actions "AFTER" seem to be useless here (basically they
// modify lens context - which is relevant only if followed by
// clockwork run)
executeActions(reactionDefinition, lensContext, situation, BeforeAfterType.AFTER, resource, logDebug, task, parentResult);
if (originalProjectionContext != null) {
newSituation = originalProjectionContext.getSynchronizationSituationResolved();
}
} else {
LOGGER.trace("Skipping clockwork run on {} for situation {}, synchronize is set to false.", new Object[] { resource, situation.getSituation() });
}
return newSituation;
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class LiveSyncTaskHandler method runInternal.
private TaskRunResult runInternal(Task task) {
LOGGER.trace("LiveSyncTaskHandler.run starting");
long progress = task.getProgress();
OperationResult opResult = new OperationResult(OperationConstants.LIVE_SYNC);
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
String resourceOid = task.getObjectOid();
if (resourceOid == null) {
LOGGER.error("Live Sync: No resource OID specified in the task");
opResult.recordFatalError("No resource OID specified in the task");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
ResourceType resource = null;
try {
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, task, opResult).asObjectable();
} catch (ObjectNotFoundException ex) {
LOGGER.error("Live Sync: Resource {} not found: {}", new Object[] { resourceOid, ex.getMessage(), ex });
// This is bad. The resource does not exist. Permanent problem.
opResult.recordFatalError("Resource not found " + resourceOid, ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (SchemaException ex) {
LOGGER.error("Live Sync: Error dealing with schema: {}", ex.getMessage(), ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
return runResult;
} catch (RuntimeException ex) {
LOGGER.error("Live Sync: Internal Error: {}", ex.getMessage(), ex);
// Can be anything ... but we can't recover from that.
// It is most likely a programming error. Does not make much sense to retry.
opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (CommunicationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
return runResult;
} catch (ConfigurationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (SecurityViolationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (ExpressionEvaluationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (resource == null) {
LOGGER.error("Live Sync: No resource specified");
opResult.recordFatalError("No resource specified");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
RefinedResourceSchema refinedSchema;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
} catch (SchemaException e) {
LOGGER.error("Live Sync: Schema error during processing account definition: {}", e.getMessage());
opResult.recordFatalError("Schema error during processing account definition: " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (refinedSchema == null) {
opResult.recordFatalError("No refined schema defined. Probably some configuration problem.");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
LOGGER.error("Live Sync: No refined schema defined. Probably some configuration problem.");
return runResult;
}
ObjectClassComplexTypeDefinition objectClass;
try {
objectClass = Utils.determineObjectClass(refinedSchema, task);
} catch (SchemaException e) {
LOGGER.error("Live Sync: schema error: {}", e.getMessage());
opResult.recordFatalError(e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (objectClass == null) {
LOGGER.debug("Syncing all object classes");
}
ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(resourceOid, objectClass == null ? null : objectClass.getTypeName());
int changesProcessed;
try {
// MAIN PART
// Calling synchronize(..) in provisioning.
// This will detect the changes and notify model about them.
// It will use extension of task to store synchronization state
Utils.clearRequestee(task);
changesProcessed = provisioningService.synchronize(coords, task, opResult);
progress += changesProcessed;
} catch (ObjectNotFoundException ex) {
LOGGER.error("Live Sync: A required object does not exist, OID: {}", ex.getOid());
LOGGER.error("Exception stack trace", ex);
// This is bad. The resource or task or something like that does not exist. Permanent problem.
opResult.recordFatalError("A required object does not exist, OID: " + ex.getOid(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (CommunicationException ex) {
LOGGER.error("Live Sync: Communication error:", ex);
// Error, but not critical. Just try later.
opResult.recordPartialError("Communication error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (SchemaException ex) {
LOGGER.error("Live Sync: Error dealing with schema:", ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (RuntimeException ex) {
LOGGER.error("Live Sync: Internal Error:", ex);
// Can be anything ... but we can't recover from that.
// It is most likely a programming error. Does not make much sense to retry.
opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (ConfigurationException ex) {
LOGGER.error("Live Sync: Configuration error:", ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (SecurityViolationException ex) {
LOGGER.error("Recompute: Security violation: {}", ex.getMessage(), ex);
opResult.recordFatalError("Security violation: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (ExpressionEvaluationException ex) {
LOGGER.error("Recompute: Expression error: {}", ex.getMessage(), ex);
opResult.recordFatalError("Expression error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
}
opResult.computeStatus("Live sync run has failed");
opResult.createSubresult(OperationConstants.LIVE_SYNC_STATISTICS).recordStatus(OperationResultStatus.SUCCESS, "Changes processed: " + changesProcessed);
// This "run" is finished. But the task goes on ...
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
// Might collide with increasing progress in provisioning module, e.g. when an exception is thrown. But that's OK for now.
runResult.setProgress(progress);
LOGGER.trace("LiveSyncTaskHandler.run stopping (resource {})", resourceOid);
return runResult;
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class ShadowManager method updateShadow.
/**
* Updates repository shadow based on shadow from resource. Handles rename cases,
* change of auxiliary object classes, etc.
* @returns repository shadow as it should look like after the update
*/
@SuppressWarnings("unchecked")
public PrismObject<ShadowType> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> currentResourceShadow, PrismObject<ShadowType> oldRepoShadow, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
RefinedObjectClassDefinition ocDef = ctx.computeCompositeObjectClassDefinition(currentResourceShadow);
ObjectDelta<ShadowType> shadowDelta = oldRepoShadow.createModifyDelta();
PrismContainer<Containerable> currentResourceAttributesContainer = currentResourceShadow.findContainer(ShadowType.F_ATTRIBUTES);
PrismContainer<Containerable> oldRepoAttributesContainer = oldRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
ShadowType oldRepoShadowType = oldRepoShadow.asObjectable();
ShadowType currentResourceShadowType = currentResourceShadow.asObjectable();
if (oldRepoShadowType.isExists() != currentResourceShadowType.isExists()) {
// Resource object obviously exists when we have got here
shadowDelta.addModificationReplaceProperty(ShadowType.F_EXISTS, currentResourceShadowType.isExists());
}
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
for (Item<?, ?> currentResourceItem : currentResourceAttributesContainer.getValue().getItems()) {
if (currentResourceItem instanceof PrismProperty<?>) {
PrismProperty<?> currentResourceAttrProperty = (PrismProperty<?>) currentResourceItem;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(currentResourceAttrProperty.getElementName());
if (ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy)) {
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
PrismProperty<Object> oldRepoAttributeProperty = oldRepoAttributesContainer.findProperty(currentResourceAttrProperty.getElementName());
if (oldRepoAttributeProperty == null) {
PropertyDelta<?> attrAddDelta = currentResourceAttrProperty.createDelta();
for (PrismPropertyValue pval : currentResourceAttrProperty.getValues()) {
Object normalizedRealValue;
if (matchingRule == null) {
normalizedRealValue = pval.getValue();
} else {
normalizedRealValue = matchingRule.normalize(pval.getValue());
}
attrAddDelta.addValueToAdd(new PrismPropertyValue(normalizedRealValue));
LOGGER.trace("CURRENT ATTR:\n{}\nATTR DELTA:\n{}", currentResourceAttrProperty.debugDump(1), attrAddDelta.debugDump(1));
}
shadowDelta.addModification(attrAddDelta);
} else {
if (attrDef.isSingleValue()) {
Object currentResourceRealValue = currentResourceAttrProperty.getRealValue();
Object currentResourceNormalizedRealValue;
if (matchingRule == null) {
currentResourceNormalizedRealValue = currentResourceRealValue;
} else {
currentResourceNormalizedRealValue = matchingRule.normalize(currentResourceRealValue);
}
if (!currentResourceNormalizedRealValue.equals(oldRepoAttributeProperty.getRealValue())) {
LOGGER.trace("CURRENT ATTR:\n{}\ncurrentResourceNormalizedRealValue: {}", currentResourceAttrProperty.debugDump(1), currentResourceNormalizedRealValue);
shadowDelta.addModificationReplaceProperty(currentResourceAttrProperty.getPath(), currentResourceNormalizedRealValue);
}
} else {
PrismProperty<Object> normalizedCurrentResourceAttrProperty = (PrismProperty<Object>) currentResourceAttrProperty.clone();
if (matchingRule != null) {
for (PrismPropertyValue pval : normalizedCurrentResourceAttrProperty.getValues()) {
Object normalizedRealValue = matchingRule.normalize(pval.getValue());
pval.setValue(normalizedRealValue);
}
}
PropertyDelta<Object> attrDiff = oldRepoAttributeProperty.diff(normalizedCurrentResourceAttrProperty);
LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", oldRepoAttributeProperty == null ? null : oldRepoAttributeProperty.debugDump(1), normalizedCurrentResourceAttrProperty == null ? null : normalizedCurrentResourceAttrProperty.debugDump(1), attrDiff == null ? null : attrDiff.debugDump(1));
if (attrDiff != null && !attrDiff.isEmpty()) {
attrDiff.setParentPath(new ItemPath(ShadowType.F_ATTRIBUTES));
shadowDelta.addModification(attrDiff);
}
}
}
}
}
}
for (Item<?, ?> oldRepoItem : oldRepoAttributesContainer.getValue().getItems()) {
if (oldRepoItem instanceof PrismProperty<?>) {
PrismProperty<?> oldRepoAttrProperty = (PrismProperty<?>) oldRepoItem;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(oldRepoAttrProperty.getElementName());
PrismProperty<Object> currentAttribute = currentResourceAttributesContainer.findProperty(oldRepoAttrProperty.getElementName());
if (attrDef == null || !ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy) || currentAttribute == null) {
// No definition for this property it should not be there or no current value: remove it from the shadow
PropertyDelta<?> oldRepoAttrPropDelta = oldRepoAttrProperty.createDelta();
oldRepoAttrPropDelta.addValuesToDelete((Collection) PrismPropertyValue.cloneCollection(oldRepoAttrProperty.getValues()));
shadowDelta.addModification(oldRepoAttrPropDelta);
}
}
}
PolyString currentShadowName = ShadowUtil.determineShadowName(currentResourceShadow);
PolyString oldRepoShadowName = oldRepoShadow.getName();
if (!currentShadowName.equalsOriginalValue(oldRepoShadowName)) {
PropertyDelta<?> shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, oldRepoShadow.getDefinition(), currentShadowName);
shadowDelta.addModification(shadowNameDelta);
}
PropertyDelta<QName> auxOcDelta = (PropertyDelta) PrismProperty.diff(oldRepoShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS), currentResourceShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS));
if (auxOcDelta != null) {
shadowDelta.addModification(auxOcDelta);
}
if (cachingStrategy == CachingStategyType.NONE) {
if (oldRepoShadowType.getCachingMetadata() != null) {
shadowDelta.addModificationReplaceProperty(ShadowType.F_CACHING_METADATA);
}
} else if (cachingStrategy == CachingStategyType.PASSIVE) {
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, currentResourceShadow, oldRepoShadow);
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_VALID_FROM, currentResourceShadow, oldRepoShadow);
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_VALID_TO, currentResourceShadow, oldRepoShadow);
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, currentResourceShadow, oldRepoShadow);
CachingMetadataType cachingMetadata = new CachingMetadataType();
cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
shadowDelta.addModificationReplaceProperty(ShadowType.F_CACHING_METADATA, cachingMetadata);
} else {
throw new ConfigurationException("Unknown caching strategy " + cachingStrategy);
}
if (!shadowDelta.isEmpty()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Updating repo shadow {} with delta:\n{}", oldRepoShadow, shadowDelta.debugDump(1));
}
ConstraintsChecker.onShadowModifyOperation(shadowDelta.getModifications());
try {
repositoryService.modifyObject(ShadowType.class, oldRepoShadow.getOid(), shadowDelta.getModifications(), parentResult);
} catch (ObjectAlreadyExistsException e) {
// This should not happen for shadows
throw new SystemException(e.getMessage(), e);
}
PrismObject<ShadowType> newRepoShadow = oldRepoShadow.clone();
shadowDelta.applyTo(newRepoShadow);
return newRepoShadow;
} else {
LOGGER.trace("No need to update repo shadow {} (empty delta)", oldRepoShadow);
return oldRepoShadow;
}
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class AccCertUpdateHelper method modifyObjectViaModel.
<T extends ObjectType> void modifyObjectViaModel(Class<T> objectClass, String oid, Collection<ItemDelta<?, ?>> itemDeltas, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
ObjectDelta<T> objectDelta = ObjectDelta.createModifyDelta(oid, itemDeltas, objectClass, prismContext);
try {
ModelExecuteOptions options = ModelExecuteOptions.createRaw().setPreAuthorized();
modelService.executeChanges(Collections.singletonList(objectDelta), options, task, result);
} catch (SecurityViolationException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException e) {
throw new SystemException("Unexpected exception when modifying " + objectClass.getSimpleName() + " " + oid + ": " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class ModelCrudService method addObject.
/**
* <p>
* Add new object.
* </p>
* <p>
* The OID provided in the input message may be empty. In that case the OID
* will be assigned by the implementation of this method and it will be
* provided as return value.
* </p>
* <p>
* This operation should fail if such object already exists (if object with
* the provided OID already exists).
* </p>
* <p>
* The operation may fail if provided OID is in an unusable format for the
* storage. Generating own OIDs and providing them to this method is not
* recommended for normal operation.
* </p>
* <p>
* Should be atomic. Should not allow creation of two objects with the same
* OID (even if created in parallel).
* </p>
* <p>
* The operation may fail if the object to be created does not conform to
* the underlying schema of the storage system or the schema enforced by the
* implementation.
* </p>
*
* @param object
* object to create
* @param parentResult
* parent OperationResult (in/out)
* @return OID assigned to the created object
* @throws ObjectAlreadyExistsException
* object with specified identifiers already exists, cannot add
* @throws ObjectNotFoundException
* object required to complete the operation was not found (e.g.
* appropriate connector or resource definition)
* @throws SchemaException
* error dealing with resource schema, e.g. created object does
* not conform to schema
* @throws ExpressionEvaluationException
* evaluation of expression associated with the object has failed
* @throws CommunicationException
* @throws ConfigurationException
* @throws PolicyViolationException
* Policy violation was detected during processing of the object
* @throws IllegalArgumentException
* wrong OID format, etc.
* @throws SystemException
* unknown error from underlying layers or other unexpected
* state
*/
public <T extends ObjectType> String addObject(PrismObject<T> object, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Validate.notNull(object, "Object must not be null.");
Validate.notNull(parentResult, "Result type must not be null.");
object.checkConsistence();
T objectType = object.asObjectable();
prismContext.adopt(objectType);
OperationResult result = parentResult.createSubresult(ADD_OBJECT);
result.addParams(new String[] { "object" }, object);
Utils.resolveReferences(object, repository, false, false, EvaluationTimeType.IMPORT, true, prismContext, result);
String oid;
RepositoryCache.enter();
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Entering addObject with {}", object);
LOGGER.trace(object.debugDump());
}
if (options == null) {
if (StringUtils.isNotEmpty(objectType.getVersion())) {
options = ModelExecuteOptions.createOverwrite();
}
}
ObjectDelta<T> objectDelta = ObjectDelta.createAddDelta(object);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
modelService.executeChanges(deltas, options, task, result);
oid = objectDelta.getOid();
result.computeStatus();
result.cleanupResult();
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | ConfigurationException | RuntimeException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} finally {
RepositoryCache.exit();
}
return oid;
}
Aggregations