Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Jul 18, 2023
2 parents 7ba9d3d + c4a80b2 commit b8d3669
Show file tree
Hide file tree
Showing 27 changed files with 560 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void showAllWarnings() {
public <O extends ObjectType> UpgradeValidationResult validate(PrismObject<O> object) {
ValidationResult result = validator.validate(object);

UpgradeObjectsHandler handler = new UpgradeObjectsHandler();
return handler.verify(object, result);
UpgradeProcessor processor = new UpgradeProcessor();
return processor.process(object, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.reflect.Modifier;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -12,14 +13,21 @@
import com.evolveum.midpoint.util.ClassPathUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public class UpgradeObjectsHandler {
public class UpgradeProcessor {

public static final List<UpgradeObjectProcessor<?>> PROCESSORS;

static {
PROCESSORS = initProcessors();
}

public static <T extends ObjectType> UpgradeObjectProcessor<T> getProcessor(String identifier) {
return (UpgradeObjectProcessor<T>) PROCESSORS.stream()
.filter(p -> Objects.equals(identifier, p.getIdentifier()))
.findFirst()
.orElse(null);
}

private static List<UpgradeObjectProcessor<?>> initProcessors() {
Set<Class<?>> processors = ClassPathUtil.listClasses("com.evolveum.midpoint")
.stream()
Expand All @@ -40,7 +48,7 @@ private static List<UpgradeObjectProcessor<?>> initProcessors() {
.collect(Collectors.toUnmodifiableList());
}

public <T extends ObjectType> UpgradeValidationItem verify(PrismObject<T> object, ValidationItem item) {
private <T extends ObjectType> UpgradeValidationItem process(PrismObject<T> object, ValidationItem item) {
ItemPath path = item.getItemPath();

PrismObject<T> cloned = object.clone();
Expand Down Expand Up @@ -72,11 +80,11 @@ public <T extends ObjectType> UpgradeValidationItem verify(PrismObject<T> object
return result;
}

public <T extends ObjectType> UpgradeValidationResult verify(PrismObject<T> object, ValidationResult result) {
public <T extends ObjectType> UpgradeValidationResult process(PrismObject<T> object, ValidationResult result) {
UpgradeValidationResult verificationResult = new UpgradeValidationResult(result);

for (ValidationItem item : result.getItems()) {
UpgradeValidationItem upgrade = verify(object, item);
UpgradeValidationItem upgrade = process(object, item);
if (upgrade != null) {
verificationResult.getItems().add(upgrade);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ public String debugDump(int indent) {
DebugUtil.debugDumpWithLabel(sb, "delta", delta, indent + 1);
return sb.toString();
}

@Override
public String toString() {
return debugDump();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public boolean process(PrismObject<SystemConfigurationType> object, ItemPath pat
roleCatalog.getCollection().addAll(views);

roleManagement.setRoleCatalogCollections(null);
if (roleManagement.asPrismContainerValue().isEmpty()) {
system.setRoleManagement(null);
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleManagementConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;

// todo tests
/**
* support-4.4 - not usable
* support-4.7 - BEFORE phase
*/
@SuppressWarnings("unused")
public class RoleCatalogRefProcessor implements UpgradeObjectProcessor<SystemConfigurationType>, ProcessorMixin {

Expand Down Expand Up @@ -57,6 +60,9 @@ public boolean process(PrismObject<SystemConfigurationType> object, ItemPath pat
roleCatalog.setRoleCatalogRef(roleCatalogRef);

roleManagement.setRoleCatalogRef(null);
if (roleManagement.asPrismContainerValue().isEmpty()) {
system.setRoleManagement(null);
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public class TestUpgradeProcessors extends AbstractSchemaTest {
private static final Trace LOGGER = TraceManager.getTrace(TestUpgradeProcessors.class);

private static final File RESOURCES = new File("./src/test/resources/validator/processor");
private static final File EXPECTED = new File("./src/test/resources/validator/expected");

private PrismContext getPrismContext() {
return PrismTestUtil.getPrismContext();
}

private <O extends ObjectType> void testUpgradeValidator(String fileName, Consumer<UpgradeValidationResult> resultConsumer) throws Exception {
PrismObject<O> object = parseObject(fileName);
PrismObject<O> object = parseObject(new File(RESOURCES, fileName));

ObjectUpgradeValidator validator = new ObjectUpgradeValidator(getPrismContext());
validator.showAllWarnings();
Expand All @@ -54,8 +55,7 @@ private <O extends ObjectType> void testUpgradeValidator(String fileName, Consum
resultConsumer.accept(result);
}

private <O extends ObjectType> PrismObject<O> parseObject(String fileName) throws SchemaException, IOException {
File file = new File(RESOURCES, fileName);
private <O extends ObjectType> PrismObject<O> parseObject(File file) throws SchemaException, IOException {
Assertions.assertThat(file)
.exists()
.isFile()
Expand All @@ -67,10 +67,10 @@ private <O extends ObjectType> PrismObject<O> parseObject(String fileName) throw
return object;
}

private void assertUpgrade(String originalFile, String expectedFile, UpgradeValidationResult result) {
private void assertUpgrade(String file, UpgradeValidationResult result) {
try {
PrismObject<ResourceType> original = parseObject(originalFile);
PrismObject<ResourceType> expected = parseObject(expectedFile);
PrismObject<ResourceType> original = parseObject(new File(RESOURCES, file));
PrismObject<ResourceType> expected = parseObject(new File(EXPECTED, file));

result.getItems().forEach(i -> {
try {
Expand All @@ -94,7 +94,7 @@ private void assertUpgrade(String originalFile, String expectedFile, UpgradeVali
@Test
public void test00CheckIdentifierUniqueness() {
Map<String, Class<?>> identifiers = new HashMap<>();
UpgradeObjectsHandler.PROCESSORS.forEach(p -> {
UpgradeProcessor.PROCESSORS.forEach(p -> {
String identifier = p.getIdentifier();
Class<?> existing = identifiers.get(identifier);
if (existing != null) {
Expand Down Expand Up @@ -142,7 +142,7 @@ private String getProcessorIdentifier(Class<?> processorClass) {
@Test
public void test30TestSystemConfig() throws Exception {
testUpgradeValidator("system-configuration.xml", result -> {
Assertions.assertThat(result.getItems()).hasSize(2);
Assertions.assertThat(result.getItems()).hasSize(3);

UpgradeValidationItem item = assertGetItem(result, getProcessorIdentifier(RoleCatalogCollectionsProcessor.class));
Assertions.assertThat(item.getDelta().getModifiedItems()).hasSize(2);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void test50SecurityPolicy() throws Exception {

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

assertUpgrade("security-policy.xml", "security-policy-expected.xml", result);
assertUpgrade("security-policy.xml", result);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<case xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
<case xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="10a2c2b4-4d02-4f52-a4ac-092d8e321006">

<name>case</name>
<taskRef oid="0e5b7304-ea5c-438e-84d1-2b0ce40517ce"/>
</case>
15 changes: 15 additions & 0 deletions infra/schema/src/test/resources/validator/expected/resource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<resource xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3"
oid="5b55729f-8866-442a-b39d-c5a9def5b345">

<name>Invalid resource</name>

<capabilities>
<native/>
<configured>
<cap:update>
<cap:addRemoveAttributeValues>false</cap:addRemoveAttributeValues>
</cap:update>
</configured>
</capabilities>
</resource>
20 changes: 20 additions & 0 deletions infra/schema/src/test/resources/validator/expected/role.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ 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.
-->

<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="f4244705-69a7-4602-95ad-6a4ad7beddb7">

<name>role</name>

<assignment id="1">
<personaConstruction>
<targetType>some-type</targetType>
<targetSubtype>some-subtype</targetSubtype>
</personaConstruction>
</assignment>

</role>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-->

<securityPolicy xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="28676177-5884-4625-805d-bae552932666">
oid="28676177-5884-4625-805d-bae552932666">

<name>security policy</name>

Expand Down
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.
-->
<systemConfiguration xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="3947d3b1-b6e8-46ec-b382-1bde67da6f07">

<name>system-configuration</name>

<notificationConfiguration>
<!--<sms>
<gateway>
<urlExpression>
<script>
<code>
return 'one.example'
</code>
</script>
</urlExpression>
</gateway>
</sms>
<sms>
<redirectToFile>redirected.log</redirectToFile>
<blackList>blacklisted@example.com</blackList>
<debug>true</debug>
<logToFile>log.log</logToFile>
<recipientFilterExpression>
<script>
<code>
return null
</code>
</script>
</recipientFilterExpression>
<whiteList>whitelisted@example.com</whiteList>
<gateway>
<method>get</method>
<urlExpression>
<script>
<code>
return 'example.com'
</code>
</script>
</urlExpression>
<username>user</username>
<password>pass</password>
</gateway>
</sms>-->
</notificationConfiguration>

<adminGuiConfiguration>
<userDashboardLink>
<targetUrl>https://google.com</targetUrl>
</userDashboardLink>
<accessRequest>
<roleCatalog>
<roleCatalogRef oid="0e5b7304-ea5c-438e-84d1-2b0ce40517ce" type="OrgType"/>
<collection>
<identifier>allRoles</identifier>
<collectionIdentifier>allRoles</collectionIdentifier>
</collection>
<collection>
<identifier>myCustomCollection</identifier>
<collectionIdentifier>myCustomCollection</collectionIdentifier>
</collection>
</roleCatalog>
</accessRequest>
</adminGuiConfiguration>
</systemConfiguration>
2 changes: 2 additions & 0 deletions infra/schema/src/test/resources/validator/processor/role.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="f4244705-69a7-4602-95ad-6a4ad7beddb7">

<name>role</name>

<assignment id="1">
<personaConstruction>
<targetType>some-type</targetType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<systemConfiguration xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="3947d3b1-b6e8-46ec-b382-1bde67da6f07">

<name>system-configuration</name>

<notificationConfiguration>
<!--<sms>
<gateway>
Expand Down Expand Up @@ -58,4 +60,10 @@
</collection>
</roleCatalogCollections>
</roleManagement>

<adminGuiConfiguration>
<userDashboardLink>
<targetUrl>https://google.com</targetUrl>
</userDashboardLink>
</adminGuiConfiguration>
</systemConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
</expression>
</outbound>
</administrativeStatus>
<disableInsteadDelete>
<disableInsteadOfDelete>
<lifecycleState>active</lifecycleState>
</disableInsteadDelete>
</disableInsteadOfDelete>
</activation>
<credentials>
<password>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public VerificationCategoryConverter() {

public static final String P_CONTINUE_VERIFICATION_ON_ERROR = "--continue-verification-on-error";

public static final String P_FILES = "--files";
public static final String P_FILE = "--file";
public static final String P_PLANNED_REMOVAL_VERSION = "--planned-removal-version";

@Parameter(names = { P_VERIFICATION_CATEGORY_LONG }, descriptionKey = "verify.verificationCategory",
Expand All @@ -76,7 +76,7 @@ public VerificationCategoryConverter() {
@Parameter(names = { P_CONTINUE_VERIFICATION_ON_ERROR }, descriptionKey = "verify.continueVerificationOnError")
private boolean continueVerificationOnError = true;

@Parameter(names = { P_FILES }, descriptionKey = "verify.files", variableArity = true)
@Parameter(names = { P_FILE }, descriptionKey = "verify.files", variableArity = true)
private List<File> files = new ArrayList<>();

@Parameter(names = { P_PLANNED_REMOVAL_VERSION }, descriptionKey = "verify.plannedRemovalVersion")
Expand Down

0 comments on commit b8d3669

Please sign in to comment.