Search in sources :

Example 1 with CleanupPoliciesType

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

the class SystemConfigurationDto method getNewObject.

public SystemConfigurationType getNewObject() throws DatatypeConfigurationException {
    SystemConfigurationType newObject = oldObject.clone();
    if (StringUtils.isNotBlank(getPassPolicyDto().getOid())) {
        ObjectReferenceType globalPassPolicyRef = ObjectTypeUtil.createObjectRef(getPassPolicyDto().getOid(), ObjectTypes.PASSWORD_POLICY);
        newObject.setGlobalPasswordPolicyRef(globalPassPolicyRef);
    } else {
        newObject.setGlobalPasswordPolicyRef(null);
    }
    if (StringUtils.isNotBlank(getSecurityPolicyDto().getOid())) {
        ObjectReferenceType globalSecurityPolicyRef = ObjectTypeUtil.createObjectRef(getSecurityPolicyDto().getOid(), WebComponentUtil.createPolyFromOrigString(getSecurityPolicyDto().getName()), ObjectTypes.SECURITY_POLICY);
        newObject.setGlobalSecurityPolicyRef(globalSecurityPolicyRef);
    } else {
        newObject.setGlobalSecurityPolicyRef(null);
    }
    AssignmentPolicyEnforcementType globalAEP = AEPlevel.toAEPValueType(getAepLevel());
    if (globalAEP != null) {
        ProjectionPolicyType projectionPolicy = new ProjectionPolicyType();
        projectionPolicy.setAssignmentPolicyEnforcement(globalAEP);
        newObject.setGlobalAccountSynchronizationSettings(projectionPolicy);
    }
    Duration auditCleanupDuration = DatatypeFactory.newInstance().newDuration(getAuditCleanupValue());
    Duration cleanupTaskDuration = DatatypeFactory.newInstance().newDuration(getTaskCleanupValue());
    CleanupPolicyType auditCleanup = new CleanupPolicyType();
    CleanupPolicyType taskCleanup = new CleanupPolicyType();
    auditCleanup.setMaxAge(auditCleanupDuration);
    taskCleanup.setMaxAge(cleanupTaskDuration);
    CleanupPoliciesType cleanupPolicies = new CleanupPoliciesType();
    cleanupPolicies.setAuditRecords(auditCleanup);
    cleanupPolicies.setClosedTasks(taskCleanup);
    newObject.setCleanupPolicy(cleanupPolicies);
    SystemConfigurationTypeUtil.setEnableExperimentalCode(newObject, getEnableExperimentalCode());
    newObject.setLogging(loggingConfig.getNewObject());
    newObject.setNotificationConfiguration(notificationConfig.getNewObject(newObject));
    newObject.setProfilingConfiguration(profilingDto.getNewObject());
    ClassLoggerConfigurationType profilingClassLogger = profilingDto.getProfilingClassLogerConfig();
    if (newObject.getLogging() != null) {
        newObject.getLogging().getClassLogger().add(profilingClassLogger);
    } else {
        LoggingConfigurationType profLogging = new LoggingConfigurationType();
        profLogging.getClassLogger().add(profilingClassLogger);
        newObject.setLogging(profLogging);
    }
    return newObject;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) LoggingConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType) AssignmentPolicyEnforcementType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType) CleanupPoliciesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) Duration(javax.xml.datatype.Duration) ClassLoggerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType) ProjectionPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionPolicyType)

Example 2 with CleanupPoliciesType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType 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

CleanupPoliciesType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType)2 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 AssignmentPolicyEnforcementType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType)1 ClassLoggerConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType)1 LoggingConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ProjectionPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionPolicyType)1 Duration (javax.xml.datatype.Duration)1