Search in sources :

Example 86 with PropertyDelta

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");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 87 with PropertyDelta

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;
}
Also used : QName(javax.xml.namespace.QName) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 88 with PropertyDelta

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");
        }
    }
}
Also used : AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 89 with PropertyDelta

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();
}
Also used : PendingOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) RefreshShadowOperation(com.evolveum.midpoint.schema.RefreshShadowOperation) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ConnectorOperationOptions(com.evolveum.midpoint.provisioning.ucf.api.ConnectorOperationOptions) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 90 with PropertyDelta

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;
}
Also used : AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ConnectorOperationOptions(com.evolveum.midpoint.provisioning.ucf.api.ConnectorOperationOptions) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)90 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)33 QName (javax.xml.namespace.QName)28 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)20 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 Task (com.evolveum.midpoint.task.api.Task)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 Collection (java.util.Collection)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6