Search in sources :

Example 11 with ResourceOperationDescription

use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.

the class ModifyHelper method notifyAfterModify.

void notifyAfterModify(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, Collection<? extends ItemDelta> modifications, ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> opState, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createModifyDelta(repoShadow.getOid(), modifications, repoShadow.getCompileTimeClass());
    ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, repoShadow, delta, parentResult);
    if (opState.isExecuting()) {
        eventDispatcher.notifyInProgress(operationDescription, task, parentResult);
    } else {
        eventDispatcher.notifySuccess(operationDescription, task, parentResult);
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription)

Example 12 with ResourceOperationDescription

use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.

the class ShadowManager method createResourceFailureDescription.

public ResourceOperationDescription createResourceFailureDescription(PrismObject<ShadowType> conflictedShadow, ResourceType resource, OperationResult parentResult) {
    ResourceOperationDescription failureDesc = new ResourceOperationDescription();
    failureDesc.setCurrentShadow(conflictedShadow);
    ObjectDelta<ShadowType> objectDelta = null;
    if (FailedOperationTypeType.ADD == conflictedShadow.asObjectable().getFailedOperationType()) {
        objectDelta = ObjectDelta.createAddDelta(conflictedShadow);
    }
    failureDesc.setObjectDelta(objectDelta);
    failureDesc.setResource(resource.asPrismObject());
    failureDesc.setResult(parentResult);
    failureDesc.setSourceChannel(SchemaConstants.CHANGE_CHANNEL_DISCOVERY.getLocalPart());
    return failureDesc;
}
Also used : ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription)

Example 13 with ResourceOperationDescription

use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.

the class SimpleResourceObjectNotifier method getBody.

@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
    boolean techInfo = Boolean.TRUE.equals(generalNotifierType.isShowTechnicalInformation());
    StringBuilder body = new StringBuilder();
    ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
    FocusType owner = (FocusType) resourceObjectEvent.getRequesteeObject();
    ResourceOperationDescription rod = resourceObjectEvent.getAccountOperationDescription();
    ObjectDelta<ShadowType> delta = (ObjectDelta<ShadowType>) rod.getObjectDelta();
    boolean isAccount = resourceObjectEvent.isShadowKind(ShadowKindType.ACCOUNT);
    String objectTypeDescription = isAccount ? "account" : "resource object";
    String userOrOwner = owner instanceof UserType ? "User" : "Owner";
    body.append("Notification about ").append(objectTypeDescription).append("-related operation\n\n");
    if (isAccount) {
        if (owner != null) {
            body.append(userOrOwner).append(": ").append(resourceObjectEvent.getRequesteeDisplayName());
            body.append(" (").append(owner.getName()).append(", oid ").append(owner.getOid()).append(")\n");
        } else {
            body.append(userOrOwner).append(": unknown\n");
        }
    }
    body.append("Notification created on: " + new Date() + "\n\n");
    body.append("Resource: " + resourceObjectEvent.getResourceName() + " (oid " + resourceObjectEvent.getResourceOid() + ")\n");
    boolean named;
    if (rod.getCurrentShadow() != null && rod.getCurrentShadow().asObjectable().getName() != null) {
        if (isAccount) {
            body.append("Account: " + rod.getCurrentShadow().asObjectable().getName() + "\n");
        } else {
            body.append("Resource object: " + rod.getCurrentShadow().asObjectable().getName() + " (kind: " + rod.getCurrentShadow().asObjectable().getKind() + ")\n");
        }
        named = true;
    } else {
        named = false;
    }
    body.append("\n");
    if (isAccount) {
        body.append((named ? "The" : "An") + " account ");
    } else {
        body.append((named ? "The" : "A") + " resource object ");
    }
    switch(resourceObjectEvent.getOperationStatus()) {
        case SUCCESS:
            body.append("has been successfully ");
            break;
        case IN_PROGRESS:
            body.append("has been ATTEMPTED to be ");
            break;
        case FAILURE:
            body.append("FAILED to be ");
            break;
    }
    final boolean watchSynchronizationAttributes = isWatchSynchronizationAttributes((SimpleResourceObjectNotifierType) generalNotifierType);
    final boolean watchAuxiliaryAttributes = isWatchAuxiliaryAttributes(generalNotifierType);
    if (delta.isAdd()) {
        body.append("created on the resource with attributes:\n");
        body.append(resourceObjectEvent.getContentAsFormattedList(watchSynchronizationAttributes, watchAuxiliaryAttributes));
        body.append("\n");
    } else if (delta.isModify()) {
        body.append("modified on the resource. Modified attributes are:\n");
        body.append(resourceObjectEvent.getContentAsFormattedList(watchSynchronizationAttributes, watchAuxiliaryAttributes));
        body.append("\n");
    } else if (delta.isDelete()) {
        body.append("removed from the resource.\n\n");
    }
    if (resourceObjectEvent.getOperationStatus() == OperationStatus.IN_PROGRESS) {
        body.append("The operation will be retried.\n\n");
    } else if (resourceObjectEvent.getOperationStatus() == OperationStatus.FAILURE) {
        body.append("Error: " + resourceObjectEvent.getAccountOperationDescription().getResult().getMessage() + "\n\n");
    }
    body.append("\n\n");
    functions.addRequesterAndChannelInformation(body, event, result);
    if (techInfo) {
        body.append("----------------------------------------\n");
        body.append("Technical information:\n\n");
        body.append(rod.debugDump(2));
    }
    return body.toString();
}
Also used : ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Date(java.util.Date)

Example 14 with ResourceOperationDescription

use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.

the class SchemaExceptionHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof SchemaException) {
            throw (SchemaException) ex;
        } else {
            throw new SchemaException(ex.getMessage(), ex);
        }
    }
    ObjectDelta delta = null;
    switch(op) {
        case ADD:
            delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
            break;
        case DELETE:
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            break;
        case MODIFY:
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
            break;
    }
    if (op != FailedOperation.GET) {
        //			Task task = taskManager.createTaskInstance();
        ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
        changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
    }
    if (shadow.getOid() == null) {
        parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
        throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    Collection<ItemDelta> modification = createAttemptModification(shadow, null);
    try {
        ConstraintsChecker.onShadowModifyOperation(modification);
        cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
    } catch (Exception e) {
    //this should not happen. But if it happens, we should return original exception
    //			throw new SchemaException("Schema violation during processing shadow: "
    //					+ ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Example 15 with ResourceOperationDescription

use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.

the class SecurityViolationHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof SecurityViolationException) {
            throw (SecurityViolationException) ex;
        } else {
            throw new SecurityViolationException(ex.getMessage(), ex);
        }
    }
    ObjectDelta delta = null;
    switch(op) {
        case ADD:
            delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
            break;
        case DELETE:
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            break;
        case MODIFY:
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
            break;
    }
    if (op != FailedOperation.GET) {
        //		Task task = taskManager.createTaskInstance();
        ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
        changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
    }
    if (shadow.getOid() == null) {
        throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    Collection<ItemDelta> modification = createAttemptModification(shadow, null);
    try {
        ConstraintsChecker.onShadowModifyOperation(modification);
        cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
    } catch (Exception e) {
    //this should not happen. But if it happens, we should return original exception
    }
    throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Aggregations

ResourceOperationDescription (com.evolveum.midpoint.provisioning.api.ResourceOperationDescription)21 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)5 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)4 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)3 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ResourceObjectEvent (com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)2 AsynchronousOperationReturnValue (com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue)2 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 Date (java.util.Date)2 Duration (javax.xml.datatype.Duration)2