Search in sources :

Example 11 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class CleanUpTaskHandler method runInternal.

private TaskRunResult runInternal(Task task) {
    LOGGER.trace("CleanUpTaskHandler.run starting");
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(OperationConstants.CLEANUP);
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    CleanupPoliciesType cleanupPolicies = task.getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_CLEANUP_POLICIES);
    if (cleanupPolicies != null) {
        LOGGER.info("Using task-specific cleanupPolicies: {}", cleanupPolicies);
    } else {
        PrismObject<SystemConfigurationType> systemConfig;
        try {
            systemConfig = repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, opResult);
        } catch (ObjectNotFoundException ex) {
            LOGGER.error("Cleanup: Object does not exist: {}", ex.getMessage(), ex);
            opResult.recordFatalError("Object does not exist: " + ex.getMessage(), ex);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            runResult.setProgress(progress);
            return runResult;
        } catch (SchemaException ex) {
            LOGGER.error("Cleanup: Error dealing with schema: {}", ex.getMessage(), ex);
            opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            runResult.setProgress(progress);
            return runResult;
        }
        SystemConfigurationType systemConfigType = systemConfig.asObjectable();
        cleanupPolicies = systemConfigType.getCleanupPolicy();
    }
    if (cleanupPolicies == null) {
        LOGGER.trace("Cleanup: No clean up polices specified. Finishing clean up task.");
        opResult.computeStatus();
        runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
        runResult.setProgress(progress);
        return runResult;
    }
    CleanupPolicyType auditCleanupPolicy = cleanupPolicies.getAuditRecords();
    if (auditCleanupPolicy != null) {
        try {
            auditService.cleanupAudit(auditCleanupPolicy, opResult);
        } catch (Exception ex) {
            LOGGER.error("Cleanup: {}", ex.getMessage(), ex);
            opResult.recordFatalError(ex.getMessage(), ex);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            runResult.setProgress(progress);
        }
    } else {
        LOGGER.trace("Cleanup: No clean up policy for audit specified. Finishing clean up task.");
    }
    CleanupPolicyType closedTasksPolicy = cleanupPolicies.getClosedTasks();
    if (closedTasksPolicy != null) {
        try {
            taskManager.cleanupTasks(closedTasksPolicy, task, opResult);
        } catch (Exception ex) {
            LOGGER.error("Cleanup: {}", ex.getMessage(), ex);
            opResult.recordFatalError(ex.getMessage(), ex);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            runResult.setProgress(progress);
        }
    } else {
        LOGGER.trace("Cleanup: No clean up policy for closed tasks specified. Finishing clean up task.");
    }
    CleanupPolicyType reportCleanupPolicy = cleanupPolicies.getOutputReports();
    if (reportCleanupPolicy != null) {
        try {
            if (reportManager == null) {
                //TODO improve dependencies for report-impl (probably for tests) and set autowire to required
                LOGGER.error("Report manager was not autowired, reports cleanup will be skipped.");
            } else {
                reportManager.cleanupReports(reportCleanupPolicy, opResult);
            }
        } catch (Exception ex) {
            LOGGER.error("Cleanup: {}", ex.getMessage(), ex);
            opResult.recordFatalError(ex.getMessage(), ex);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            runResult.setProgress(progress);
        }
    } else {
        LOGGER.trace("Cleanup: No clean up policy for report specified. Finishing clean up task.");
    }
    opResult.computeStatus();
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    LOGGER.trace("CleanUpTaskHandler.run stopping");
    return runResult;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CleanupPoliciesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)11 Duration (javax.xml.datatype.Duration)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 Date (java.util.Date)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Calendar (java.util.Calendar)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 Test (org.testng.annotations.Test)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)2 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 com.evolveum.midpoint.repo.sql.data.audit (com.evolveum.midpoint.repo.sql.data.audit)2 RAuditEventRecord (com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord)2 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)2 BaseHelper (com.evolveum.midpoint.repo.sql.helpers.BaseHelper)2 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)2 GetObjectResult (com.evolveum.midpoint.repo.sql.util.GetObjectResult)2