Search in sources :

Example 31 with GenericFrameworkException

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

the class ConnectorInstanceConnIdImpl method getChangesFromSyncDeltas.

private List<Change> getChangesFromSyncDeltas(ObjectClass connIdObjClass, Collection<SyncDelta> connIdDeltas, PrismSchema schema, OperationResult parentResult) throws SchemaException, GenericFrameworkException {
    List<Change> changeList = new ArrayList<Change>();
    QName objectClass = connIdNameMapper.objectClassToQname(connIdObjClass, getSchemaNamespace(), legacySchema);
    ObjectClassComplexTypeDefinition objClassDefinition = null;
    if (objectClass != null) {
        objClassDefinition = (ObjectClassComplexTypeDefinition) schema.findComplexTypeDefinition(objectClass);
    }
    Validate.notNull(connIdDeltas, "Sync result must not be null.");
    for (SyncDelta icfDelta : connIdDeltas) {
        ObjectClass deltaIcfObjClass = connIdObjClass;
        QName deltaObjectClass = objectClass;
        ObjectClassComplexTypeDefinition deltaObjClassDefinition = objClassDefinition;
        if (objectClass == null) {
            deltaIcfObjClass = icfDelta.getObjectClass();
            deltaObjectClass = connIdNameMapper.objectClassToQname(deltaIcfObjClass, getSchemaNamespace(), legacySchema);
            if (deltaIcfObjClass != null) {
                deltaObjClassDefinition = (ObjectClassComplexTypeDefinition) schema.findComplexTypeDefinition(deltaObjectClass);
            }
        }
        if (deltaObjClassDefinition == null) {
            if (icfDelta.getDeltaType() == SyncDeltaType.DELETE) {
            // tolerate this. E.g. LDAP changelogs do not have objectclass in delete deltas.
            } else {
                throw new SchemaException("Got delta with object class " + deltaObjectClass + " (" + deltaIcfObjClass + ") that has no definition in resource schema");
            }
        }
        SyncDeltaType icfDeltaType = icfDelta.getDeltaType();
        if (SyncDeltaType.DELETE.equals(icfDeltaType)) {
            LOGGER.trace("START creating delta of type DELETE");
            ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.DELETE, prismContext);
            Collection<ResourceAttribute<?>> identifiers = ConnIdUtil.convertToIdentifiers(icfDelta.getUid(), deltaObjClassDefinition, resourceSchema);
            Change change = new Change(identifiers, objectDelta, getToken(icfDelta.getToken()));
            change.setObjectClassDefinition(deltaObjClassDefinition);
            changeList.add(change);
            LOGGER.trace("END creating delta of type DELETE");
        } else if (SyncDeltaType.CREATE.equals(icfDeltaType)) {
            PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(deltaObjClassDefinition);
            LOGGER.trace("Object definition: {}", objectDefinition);
            LOGGER.trace("START creating delta of type CREATE");
            PrismObject<ShadowType> currentShadow = connIdConvertor.convertToResourceObject(icfDelta.getObject(), objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Got current shadow: {}", currentShadow.debugDump());
            }
            Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getAllIdentifiers(currentShadow);
            ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.ADD, prismContext);
            objectDelta.setObjectToAdd(currentShadow);
            Change change = new Change(identifiers, objectDelta, getToken(icfDelta.getToken()));
            change.setObjectClassDefinition(deltaObjClassDefinition);
            changeList.add(change);
            LOGGER.trace("END creating delta of type CREATE");
        } else if (SyncDeltaType.CREATE_OR_UPDATE.equals(icfDeltaType) || SyncDeltaType.UPDATE.equals(icfDeltaType)) {
            PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(deltaObjClassDefinition);
            LOGGER.trace("Object definition: {}", objectDefinition);
            LOGGER.trace("START creating delta of type {}", icfDeltaType);
            PrismObject<ShadowType> currentShadow = connIdConvertor.convertToResourceObject(icfDelta.getObject(), objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Got current shadow: {}", currentShadow.debugDump());
            }
            Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getAllIdentifiers(currentShadow);
            Change change = new Change(identifiers, currentShadow, getToken(icfDelta.getToken()));
            change.setObjectClassDefinition(deltaObjClassDefinition);
            changeList.add(change);
            LOGGER.trace("END creating delta of type {}:\n{}", icfDeltaType, change.debugDump());
        } else {
            throw new GenericFrameworkException("Unexpected sync delta type " + icfDeltaType);
        }
    }
    return changeList;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) SyncDeltaType(org.identityconnectors.framework.common.objects.SyncDeltaType) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Change(com.evolveum.midpoint.provisioning.ucf.api.Change) SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 32 with GenericFrameworkException

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

the class AbstractManualConnectorInstance method addObject.

// TODO: operations to check ticket state
@Override
public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObject(PrismObject<? extends ShadowType> object, Collection<Operation> additionalOperations, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(OPERATION_ADD);
    String ticketIdentifier = null;
    try {
        ticketIdentifier = createTicketAdd(object, additionalOperations, result);
    } catch (CommunicationException | GenericFrameworkException | SchemaException | ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    result.recordInProgress();
    result.setAsynchronousOperationReference(ticketIdentifier);
    AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> ret = new AsynchronousOperationReturnValue<>();
    ret.setOperationResult(result);
    return ret;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 33 with GenericFrameworkException

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

the class AbstractManualConnectorInstance method modifyObject.

@Override
public AsynchronousOperationReturnValue<Collection<PropertyModificationOperation>> modifyObject(ObjectClassComplexTypeDefinition objectClass, Collection<? extends ResourceAttribute<?>> identifiers, Collection<Operation> changes, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, SecurityViolationException, ObjectAlreadyExistsException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(OPERATION_MODIFY);
    String ticketIdentifier = null;
    try {
        ticketIdentifier = createTicketModify(objectClass, identifiers, changes, result);
    } catch (ObjectNotFoundException | CommunicationException | GenericFrameworkException | SchemaException | ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    result.recordInProgress();
    result.setAsynchronousOperationReference(ticketIdentifier);
    AsynchronousOperationReturnValue<Collection<PropertyModificationOperation>> ret = new AsynchronousOperationReturnValue<>();
    ret.setOperationResult(result);
    return ret;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 34 with GenericFrameworkException

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

the class ShadowCache method deleteShadow.

public void deleteShadow(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, OperationProvisioningScriptsType scripts, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(shadow, "Object to delete must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    InternalMonitor.recordShadowChangeOperation();
    ProvisioningContext ctx = ctxFactory.create(shadow, task, parentResult);
    try {
        ctx.assertDefinition();
    } catch (ObjectNotFoundException ex) {
        // although the resource does not exists..
        if (ProvisioningOperationOptions.isForce(options)) {
            parentResult.muteLastSubresultError();
            shadowManager.deleteShadow(ctx, shadow, null, parentResult);
            parentResult.recordHandledError("Resource defined in shadow does not exists. Shadow was deleted from the repository.");
            return;
        } else {
            throw ex;
        }
    }
    applyAttributesDefinition(ctx, shadow);
    LOGGER.trace("Deleting object {} from the resource {}.", shadow, ctx.getResource());
    AsynchronousOperationResult asyncReturnValue = null;
    if (shadow.asObjectable().getFailedOperationType() == null || (shadow.asObjectable().getFailedOperationType() != null && FailedOperationTypeType.ADD != shadow.asObjectable().getFailedOperationType())) {
        try {
            asyncReturnValue = resouceObjectConverter.deleteResourceObject(ctx, shadow, scripts, parentResult);
        } catch (Exception ex) {
            try {
                handleError(ctx, ex, shadow, FailedOperation.DELETE, null, isDoDiscovery(ctx.getResource(), options), isCompensate(options), parentResult);
            } catch (ObjectAlreadyExistsException e) {
                parentResult.recordFatalError(e);
                throw new SystemException(e.getMessage(), e);
            }
            return;
        }
    }
    LOGGER.trace("Detele object with oid {} form repository.", shadow.getOid());
    try {
        shadowManager.deleteShadow(ctx, shadow, asyncReturnValue == null ? null : asyncReturnValue.getOperationResult(), parentResult);
    } catch (ObjectNotFoundException ex) {
        parentResult.recordFatalError("Can't delete object " + shadow + ". Reason: " + ex.getMessage(), ex);
        throw new ObjectNotFoundException("An error occured while deleting resource object " + shadow + "whith identifiers " + shadow + ": " + ex.getMessage(), ex);
    }
    ObjectDelta<ShadowType> delta = ObjectDelta.createDeleteDelta(shadow.getCompileTimeClass(), shadow.getOid(), prismContext);
    ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, shadow, delta, parentResult);
    if (asyncReturnValue != null && asyncReturnValue.isInProgress()) {
        operationListener.notifyInProgress(operationDescription, task, parentResult);
    } else {
        operationListener.notifySuccess(operationDescription, task, parentResult);
    }
    LOGGER.trace("Object deleted from repository successfully.");
    parentResult.computeStatus();
    resourceManager.modifyResourceAvailabilityStatus(ctx.getResource().asPrismObject(), AvailabilityStatusType.UP, parentResult);
}
Also used : AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)

Example 35 with GenericFrameworkException

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

the class ProvisioningServiceImpl method refreshShadow.

@Override
public void refreshShadow(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(shadow, "Shadow for refresh must not be null.");
    OperationResult result = parentResult.createSubresult(ProvisioningServiceImpl.class.getName() + ".finishOperation");
    LOGGER.debug("Refreshing shadow {}", shadow);
    try {
        getShadowCache(Mode.RECON).refreshShadow(shadow, task, result);
        refreshShadowLegacy(shadow, options, task, result);
    } catch (GenericFrameworkException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't refresh shadow: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
        throw new CommunicationException(e.getMessage(), e);
    } catch (CommunicationException | SchemaException | ObjectNotFoundException | ConfigurationException | SecurityViolationException | ObjectAlreadyExistsException | ExpressionEvaluationException | RuntimeException | Error e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't refresh shadow: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
        throw e;
    }
    result.computeStatus();
    result.cleanupResult();
    LOGGER.debug("Finished refreshing shadow {}: ", shadow, result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)43 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)33 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)29 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)23 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)20 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)20 SystemException (com.evolveum.midpoint.util.exception.SystemException)18 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)13 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)13 GuardedString (org.identityconnectors.common.security.GuardedString)9 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)9 ConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)8 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)8 QName (javax.xml.namespace.QName)8 OperationOptionsBuilder (org.identityconnectors.framework.common.objects.OperationOptionsBuilder)8 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)7 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 OperationOptions (org.identityconnectors.framework.common.objects.OperationOptions)6