use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestTolerantAttributes method test104modifyReplaceAttributeTolerantPattern.
@Test
public void test104modifyReplaceAttributeTolerantPattern() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, USER_JACK_OID);
ItemPath drinkItemPath = ItemPath.create(new QName(MidPointConstants.NS_RI, "drink"));
PropertyDelta propertyDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(UserType.F_EMPLOYEE_NUMBER, getUserDefinition(), "thiIsOk");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
modelService.executeChanges(deltas, executeOptions().reconcile(), task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
// Check value in "quote attribute"
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
// assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
// Check value of drink attribute
assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "gossip", "thiIsOk");
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUcfOpenDj method createDeleteAttributeChange.
private PropertyModificationOperation createDeleteAttributeChange(String propertyName, String propertyValue) throws SchemaException {
PrismProperty<?> property = createProperty(propertyName, propertyValue);
ItemPath propertyPath = ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(MidPointConstants.NS_RI, propertyName));
PropertyDelta delta = prismContext.deltaFactory().property().create(propertyPath, property.getDefinition());
delta.addRealValuesToDelete(propertyValue);
PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta);
return attributeModification;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class RefreshHelper method retryOperation.
private void retryOperation(ProvisioningContext ctx, ObjectDelta<ShadowType> pendingDelta, ProvisioningOperationState<? extends AsynchronousOperationResult> opState, Task task, OperationResult result) throws CommunicationException, GenericFrameworkException, ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, EncryptionException {
ProvisioningOperationOptions options = ProvisioningOperationOptions.createForceRetry(false);
// TODO
OperationProvisioningScriptsType scripts = null;
if (pendingDelta.isAdd()) {
PrismObject<ShadowType> resourceObjectToAdd = pendingDelta.getObjectToAdd();
addHelper.addShadowAttempt(ctx, resourceObjectToAdd, scripts, (ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>>) opState, options, task, result);
}
if (pendingDelta.isModify()) {
if (opState.objectExists()) {
modifyHelper.modifyShadowAttempt(ctx, pendingDelta.getModifications(), scripts, options, (ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>>) opState, true, task, result);
} else {
result.recordFatalError("Object does not exist on the resource yet, modification attempt was skipped");
}
}
if (pendingDelta.isDelete()) {
if (opState.objectExists()) {
deleteHelper.deleteShadowAttempt(ctx, options, scripts, (ProvisioningOperationState<AsynchronousOperationResult>) opState, task, result);
} else {
result.recordFatalError("Object does not exist on the resource yet, deletion attempt was skipped");
}
}
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ModifyHelper method modifyShadowAttempt.
/**
* @param inRefresh True if we are already in refresh shadow method. This means we shouldn't refresh ourselves!
*/
String modifyShadowAttempt(ProvisioningContext ctx, Collection<? extends ItemDelta<?, ?>> modifications, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> opState, boolean inRefresh, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, EncryptionException, ObjectAlreadyExistsException {
PrismObject<ShadowType> repoShadow = opState.getRepoShadow();
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
PendingOperationType duplicateOperation = shadowManager.checkAndRecordPendingModifyOperationBeforeExecution(ctx, modifications, opState, parentResult);
if (duplicateOperation != null) {
parentResult.setInProgress();
return repoShadow.getOid();
}
shadowCaretaker.applyAttributesDefinition(ctx, repoShadow);
accessChecker.checkModify(ctx, modifications, parentResult);
entitlementsHelper.preprocessEntitlements(ctx, modifications, "delta for shadow " + repoShadow.getOid(), parentResult);
OperationResultStatus finalOperationStatus = null;
if (shadowManager.isRepositoryOnlyModification(modifications)) {
opState.setExecutionStatus(PendingOperationExecutionStatusType.COMPLETED);
LOGGER.debug("MODIFY {}: repository-only modification", repoShadow);
} else {
if (shouldExecuteResourceOperationDirectly(ctx)) {
LOGGER.trace("MODIFY {}: resource modification, execution starting\n{}", repoShadow, DebugUtil.debugDumpLazily(modifications));
RefreshShadowOperation refreshShadowOperation = null;
if (!inRefresh && Util.shouldRefresh(repoShadow)) {
refreshShadowOperation = refreshHelper.refreshShadow(repoShadow, options, task, parentResult);
}
if (refreshShadowOperation != null) {
repoShadow = refreshShadowOperation.getRefreshedShadow();
}
if (repoShadow == null) {
LOGGER.trace("Shadow is gone. Nothing more to do");
parentResult.recordPartialError("Shadow disappeared during modify.");
throw new ObjectNotFoundException("Shadow is gone.");
}
ConnectorOperationOptions connOptions = commonHelper.createConnectorOperationOptions(ctx, options, parentResult);
try {
if (ResourceTypeUtil.isInMaintenance(ctx.getResource())) {
throw new MaintenanceException("Resource " + ctx.getResource() + " is in the maintenance");
}
if (!shouldExecuteModify(refreshShadowOperation)) {
ProvisioningUtil.postponeModify(ctx, repoShadow, modifications, opState, refreshShadowOperation.getRefreshResult(), parentResult);
shadowManager.recordModifyResult(ctx, repoShadow, modifications, opState, now, parentResult);
return repoShadow.getOid();
} else {
LOGGER.trace("Shadow exists: {}", repoShadow.debugDump());
}
AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>> asyncReturnValue = resourceObjectConverter.modifyResourceObject(ctx, repoShadow, scripts, connOptions, modifications, now, parentResult);
opState.processAsyncResult(asyncReturnValue);
Collection<PropertyDelta<PrismPropertyValue>> knownExecutedDeltas = asyncReturnValue.getReturnValue();
if (knownExecutedDeltas != null) {
ItemDeltaCollectionsUtil.addNotEquivalent(modifications, knownExecutedDeltas);
}
} catch (Exception ex) {
LOGGER.debug("Provisioning exception: {}:{}, attempting to handle it", ex.getClass(), ex.getMessage(), ex);
finalOperationStatus = handleModifyError(ctx, repoShadow, modifications, options, opState, ex, parentResult.getLastSubresult(), task, parentResult);
}
LOGGER.debug("MODIFY {}: resource operation executed, operation state: {}", repoShadow, opState.shortDumpLazily());
} else {
opState.setExecutionStatus(PendingOperationExecutionStatusType.EXECUTION_PENDING);
// Create dummy subresult with IN_PROGRESS state.
// This will force the entire result (parent) to be IN_PROGRESS rather than SUCCESS.
parentResult.createSubresult(OP_DELAYED_OPERATION).recordInProgress();
LOGGER.debug("MODIFY {}: Resource operation NOT executed, execution pending", repoShadow);
}
}
shadowManager.recordModifyResult(ctx, repoShadow, modifications, opState, now, parentResult);
notifyAfterModify(ctx, repoShadow, modifications, opState, task, parentResult);
setParentOperationStatus(parentResult, opState, finalOperationStatus);
return repoShadow.getOid();
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ModifyHelper method executeResourceModify.
/**
* Used to execute delayed operations.
* Mostly copy&paste from modifyShadow(). But as consistency (handleError()) branch expects to return immediately
* I could not find a more elegant way to structure this without complicating the code too much.
*/
ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> executeResourceModify(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, Collection<? extends ItemDelta<?, ?>> modifications, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, XMLGregorianCalendar now, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException {
ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> opState = new ProvisioningOperationState<>();
opState.setRepoShadow(repoShadow);
ConnectorOperationOptions connOptions = commonHelper.createConnectorOperationOptions(ctx, options, parentResult);
try {
LOGGER.trace("Applying change: {}", DebugUtil.debugDumpLazily(modifications));
AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>> asyncReturnValue = resourceObjectConverter.modifyResourceObject(ctx, repoShadow, scripts, connOptions, modifications, now, parentResult);
opState.processAsyncResult(asyncReturnValue);
Collection<PropertyDelta<PrismPropertyValue>> knownExecutedDeltas = asyncReturnValue.getReturnValue();
if (knownExecutedDeltas != null) {
ItemDeltaCollectionsUtil.addNotEquivalent(modifications, knownExecutedDeltas);
}
} catch (Exception ex) {
LOGGER.debug("Provisioning exception: {}:{}, attempting to handle it", ex.getClass(), ex.getMessage(), ex);
try {
handleModifyError(ctx, repoShadow, modifications, options, opState, ex, parentResult.getLastSubresult(), task, parentResult);
parentResult.computeStatus();
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("While compensating communication problem for modify operation got: " + ex.getMessage(), ex);
throw new SystemException(e);
}
}
return opState;
}
Aggregations