-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MID-8842 ninja - livesync error handling processor
(cherry picked from commit e9acab0)
- Loading branch information
Showing
4 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...java/com/evolveum/midpoint/schema/validator/processor/LiveSyncErrorHandlingProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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 javax.xml.namespace.QName; | ||
|
||
import com.evolveum.midpoint.prism.PrismContainer; | ||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.schema.constants.SchemaConstants; | ||
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.ActivityControlFlowDefinitionType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityDefinitionType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityErrorHandlingStrategyType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; | ||
|
||
@SuppressWarnings("unused") | ||
public class LiveSyncErrorHandlingProcessor implements UpgradeObjectProcessor<TaskType> { | ||
|
||
@Override | ||
public UpgradePhase getPhase() { | ||
return UpgradePhase.BEFORE; | ||
} | ||
|
||
@Override | ||
public UpgradePriority getPriority() { | ||
return UpgradePriority.NECESSARY; | ||
} | ||
|
||
@Override | ||
public UpgradeType getType() { | ||
return UpgradeType.PREVIEW; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(PrismObject<?> object, ItemPath path) { | ||
return matchObjectTypeAndPathTemplate( | ||
object, path, | ||
TaskType.class, | ||
ItemPath.create( | ||
TaskType.F_EXTENSION, | ||
new QName(SchemaConstants.NS_MODEL_EXTENSION, "liveSyncErrorHandlingStrategy") | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean process(PrismObject<TaskType> object, ItemPath path) { | ||
ActivityErrorHandlingStrategyType errorHandling = object.findItem(path) | ||
.getRealValue(ActivityErrorHandlingStrategyType.class).clone(); | ||
|
||
TaskType task = object.asObjectable(); | ||
ActivityDefinitionType activity = task.getActivity(); | ||
if (activity == null) { | ||
activity = new ActivityDefinitionType(); | ||
task.setActivity(activity); | ||
} | ||
|
||
ActivityControlFlowDefinitionType controlFlow = activity.getControlFlow(); | ||
if (controlFlow == null) { | ||
controlFlow = new ActivityControlFlowDefinitionType(); | ||
activity.setControlFlow(controlFlow); | ||
} | ||
|
||
controlFlow.setErrorHandling(errorHandling); | ||
|
||
PrismContainer extension = object.findContainer(TaskType.F_EXTENSION); | ||
extension.removeItem(path.lastName(), PrismContainer.class); | ||
|
||
if (extension.isEmpty()) { | ||
object.remove(extension); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
infra/schema/src/test/resources/validator/expected/task-livesync.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" | ||
xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3" | ||
oid="979ec101-d36c-49ea-a6c1-5d0c087d9689"> | ||
|
||
<name>livesync</name> | ||
<activity> | ||
<controlFlow> | ||
<errorHandling> | ||
<entry id="1"> | ||
<order>1</order> | ||
<situation> | ||
<status>fatal_error</status> | ||
</situation> | ||
</entry> | ||
</errorHandling> | ||
</controlFlow> | ||
</activity> | ||
</task> |
23 changes: 23 additions & 0 deletions
23
infra/schema/src/test/resources/validator/processor/task-livesync.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" | ||
xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3" | ||
oid="979ec101-d36c-49ea-a6c1-5d0c087d9689"> | ||
|
||
<name>livesync</name> | ||
<extension> | ||
<mext:liveSyncErrorHandlingStrategy> | ||
<entry id="1"> | ||
<order>1</order> | ||
<situation> | ||
<status>fatal_error</status> | ||
</situation> | ||
</entry> | ||
</mext:liveSyncErrorHandlingStrategy> | ||
</extension> | ||
</task> |