Search in sources :

Example 1 with SynchronizeAccountResultHandler

use of com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler in project midpoint by Evolveum.

the class ImportAccountsFromResourceTaskHandler method createHandler.

// shadowToImport - it is used to derive objectClass/intent/kind when importing a single shadow
private SynchronizeAccountResultHandler createHandler(ResourceType resource, PrismObject<ShadowType> shadowToImport, TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) {
    RefinedResourceSchema refinedSchema;
    ObjectClassComplexTypeDefinition objectClass;
    try {
        refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Refined schema:\n{}", refinedSchema.debugDump());
        }
        if (shadowToImport != null) {
            objectClass = Utils.determineObjectClass(refinedSchema, shadowToImport);
        } else {
            objectClass = Utils.determineObjectClass(refinedSchema, coordinatorTask);
        }
        if (objectClass == null) {
            LOGGER.error("Import: No objectclass specified and no default can be determined.");
            opResult.recordFatalError("No objectclass specified and no default can be determined");
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            return null;
        }
    } catch (SchemaException e) {
        LOGGER.error("Import: 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 null;
    }
    LOGGER.info("Start executing import from resource {}, importing object class {}", resource, objectClass.getTypeName());
    SynchronizeAccountResultHandler handler = new SynchronizeAccountResultHandler(resource, objectClass, "import", coordinatorTask, changeNotificationDispatcher, taskManager);
    handler.setSourceChannel(SchemaConstants.CHANGE_CHANNEL_IMPORT);
    handler.setForceAdd(true);
    handler.setStopOnError(false);
    handler.setContextDesc("from " + resource);
    handler.setLogObjectProgress(true);
    return handler;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SynchronizeAccountResultHandler(com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 2 with SynchronizeAccountResultHandler

use of com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler in project midpoint by Evolveum.

the class ImportAccountsFromResourceTaskHandler method importSingleShadow.

/**
     * Imports a single shadow. Synchronously. The task is NOT switched to background by default. 
     */
public boolean importSingleShadow(String shadowOid, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, shadowOid, null, task, parentResult);
    PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, ShadowUtil.getResourceOid(shadow), null, task, parentResult);
    // Create a result handler just for one object. Invoke the handle() method manually.
    TaskRunResult runResult = new TaskRunResult();
    SynchronizeAccountResultHandler resultHandler = createHandler(resource.asObjectable(), shadow, runResult, task, parentResult);
    if (resultHandler == null) {
        return false;
    }
    // This is required for proper error reporting
    resultHandler.setStopOnError(true);
    boolean cont = initializeRun(resultHandler, runResult, task, parentResult);
    if (!cont) {
        return false;
    }
    cont = resultHandler.handle(shadow, parentResult);
    if (!cont) {
        return false;
    }
    finish(resultHandler, runResult, task, parentResult);
    return true;
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) SynchronizeAccountResultHandler(com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Aggregations

SynchronizeAccountResultHandler (com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)1 TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1