Skip to content

Commit

Permalink
MID-8842 ninja - task recurrence processor + test
Browse files Browse the repository at this point in the history
(cherry picked from commit e8cf6f0)
  • Loading branch information
1azyman committed Jul 26, 2023
1 parent 5879e59 commit 6ad3ef1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.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.ScheduleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskRecurrenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

@SuppressWarnings("unused")
public class RecurrenceProcessor implements UpgradeObjectProcessor<TaskType> {

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

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

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

@Override
public boolean isApplicable(PrismObject<?> object, ItemPath path) {
return matchParentTypeAndItemName(object, path, TaskType.class, TaskType.F_RECURRENCE);
}

@Override
public boolean process(PrismObject<TaskType> object, ItemPath path) throws Exception {
TaskType task = object.asObjectable();
TaskRecurrenceType recurrence = task.getRecurrence();

ScheduleType schedule = task.getSchedule();
if (schedule == null) {
schedule = new ScheduleType();
task.setSchedule(schedule);
}

schedule.setRecurrence(recurrence);
task.setRecurrence(null);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void test70Archetype() throws Exception {
public void test80TaskRecomputation() throws Exception {
testUpgradeValidator("task-recomputation.xml", result -> {
Assertions.assertThat(result.getItems())
.hasSize(5);
.hasSize(6);

Assertions.assertThat(result.hasChanges()).isTrue();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@
<name>sample</name>
</policyConstraints>
</policyRule>

<schedule>
<recurrence>recurring</recurrence>
</schedule>
</task>
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
<name>sample</name>
</policyConstraints>
</policyRule>

<recurrence>recurring</recurrence>
</task>

0 comments on commit 6ad3ef1

Please sign in to comment.