Skip to content

Commit

Permalink
MID-8842 ninja - livesync error handling processor
Browse files Browse the repository at this point in the history
(cherry picked from commit e9acab0)
  • Loading branch information
1azyman committed Jul 19, 2023
1 parent ace90ab commit 4ba8aed
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 1 deletion.
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ private void assertUpgrade(String file, UpgradeValidationResult result) {
}
});

AssertJUnit.assertTrue(expected.equivalent(original));
AssertJUnit.assertTrue(
"EXPECTED:\n" + PrismTestUtil.serializeObjectToString(expected) +
"\nORIGINAL:\n" + PrismTestUtil.serializeObjectToString(original),
expected.equivalent(original));
} catch (Exception ex) {
LOGGER.error("Couldn't assert upgrade result", ex);
AssertJUnit.fail(ex.getMessage());
Expand Down Expand Up @@ -176,6 +179,18 @@ public void test50SecurityPolicy() throws Exception {
});
}

@Test
public void test60TaskLivesync() throws Exception {
testUpgradeValidator("task-livesync.xml", result -> {
Assertions.assertThat(result.getItems())
.hasSize(1);

Assertions.assertThat(result.hasChanges()).isTrue();

assertUpgrade("task-livesync.xml", result);
});
}

private UpgradeValidationItem assertGetItem(UpgradeValidationResult result, String identifier) {
Assertions.assertThat(result).isNotNull();

Expand Down
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>
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>

0 comments on commit 4ba8aed

Please sign in to comment.