Skip to content

Commit

Permalink
MID-8842 ninja - cleanup policies processor
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jul 24, 2023
1 parent 4887c97 commit adebe73
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.schema.validator.processor;

import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.validator.UpgradeObjectProcessor;
import com.evolveum.midpoint.schema.validator.UpgradePhase;
import com.evolveum.midpoint.schema.validator.UpgradePriority;
import com.evolveum.midpoint.schema.validator.UpgradeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

public class CleanupPolicyProcessor implements UpgradeObjectProcessor<ObjectType> {

@Override
public UpgradePhase getPhase() {
return UpgradePhase.BEFORE;
}

@Override
public UpgradePriority getPriority() {
return UpgradePriority.NECESSARY;
}

@Override
public UpgradeType getType() {
return UpgradeType.SEAMLESS;
}

@Override
public boolean isApplicable(PrismObject<?> object, ItemPath path) {
return matchObjectTypeAndPathTemplate(
object, path, SystemConfigurationType.class, ItemPath.create(
SystemConfigurationType.F_CLEANUP_POLICY,
CleanupPoliciesType.F_OBJECT_RESULTS))
||
matchObjectTypeAndPathTemplate(
object, path, TaskType.class, ItemPath.create(
TaskType.F_ACTIVITY,
ActivityDefinitionType.F_WORK,
WorkDefinitionsType.F_CLEANUP,
CleanupWorkDefinitionType.F_POLICIES,
CleanupPoliciesType.F_OBJECT_RESULTS));
}

@Override
public boolean process(PrismObject<ObjectType> object, ItemPath path) throws Exception {
ItemPath allExceptLast = path.allExceptLast();
PrismContainer<CleanupPoliciesType> container = object.findContainer(allExceptLast);
CleanupPoliciesType policies = container.getRealValue();

CleanupPolicyType policy = policies.getObjectResults();
policies.setObjectResults(null);
if (policies.getSimpleOperationExecutions() == null) {
policies.setSimpleOperationExecutions(policy.clone());
}

if (policies.getComplexOperationExecutions() == null) {
policies.setComplexOperationExecutions(policy.clone());
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private String getProcessorIdentifier(Class<?> processorClass) {
@Test
public void test30TestSystemConfig() throws Exception {
testUpgradeValidator("system-configuration.xml", result -> {
Assertions.assertThat(result.getItems()).hasSize(5);
Assertions.assertThat(result.getItems()).hasSize(6);

UpgradeValidationItem item = assertGetItem(result, getProcessorIdentifier(RoleCatalogCollectionsProcessor.class));
Assertions.assertThat(item.getDelta().getModifiedItems()).hasSize(2);
Expand Down Expand Up @@ -202,7 +202,7 @@ public void test50SecurityPolicy() throws Exception {
public void test60TaskLivesync() throws Exception {
testUpgradeValidator("task-livesync.xml", result -> {
Assertions.assertThat(result.getItems())
.hasSize(1);
.hasSize(2);

Assertions.assertThat(result.hasChanges()).isTrue();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,15 @@
<visibility>visible</visibility>
</itemConstraint>
</defaultObjectPolicyConfiguration>

<cleanupPolicy>
<simpleOperationExecutions>
<maxAge>P1D</maxAge>
<maxRecords>10</maxRecords>
</simpleOperationExecutions>
<complexOperationExecutions>
<maxAge>P1D</maxAge>
<maxRecords>10</maxRecords>
</complexOperationExecutions>
</cleanupPolicy>
</systemConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@

<name>livesync</name>
<activity>
<work>
<cleanup>
<policies>
<simpleOperationExecutions>
<maxAge>P1D</maxAge>
<maxRecords>10</maxRecords>
</simpleOperationExecutions>
<complexOperationExecutions>
<maxAge>P1D</maxAge>
<maxRecords>10</maxRecords>
</complexOperationExecutions>
</policies>
</cleanup>
</work>
<controlFlow>
<errorHandling>
<entry id="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@
<visibility>visible</visibility>
</itemConstraint>
</defaultObjectPolicyConfiguration>
<cleanupPolicy>
<objectResults>
<maxAge>P1D</maxAge>
<maxRecords>10</maxRecords>
</objectResults>
</cleanupPolicy>
</systemConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@
</entry>
</mext:liveSyncErrorHandlingStrategy>
</extension>
<activity>
<work>
<cleanup>
<policies>
<objectResults>
<maxAge>P1D</maxAge>
<maxRecords>10</maxRecords>
</objectResults>
</policies>
</cleanup>
</work>
</activity>
</task>

0 comments on commit adebe73

Please sign in to comment.