Skip to content

Commit

Permalink
MID-8842 ninja - search item display name processor + test
Browse files Browse the repository at this point in the history
(cherry picked from commit d5fb423)
  • Loading branch information
1azyman committed Aug 1, 2023
1 parent 82853a6 commit 97c3cd5
Show file tree
Hide file tree
Showing 4 changed files with 87 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.*;

@SuppressWarnings("unused")
public class SearchItemDisplayNameProcessor 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 matchParentTypeAndItemName(object, path, SearchItemType.class, SearchItemType.F_DISPLAY_NAME);
}

@Override
public boolean process(PrismObject<ObjectType> object, ItemPath path) throws Exception {
SearchItemType item = getItemParent(object, path);

DisplayType display = item.getDisplay();
if (display == null) {
display = new DisplayType();
item.setDisplay(display);
}

if (display.getLabel() == null) {
display.setLabel(item.getDisplayName());
}

item.setDisplayName(null);

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

UpgradeValidationItem item = assertGetItem(result, getProcessorIdentifier(RoleCatalogCollectionsProcessor.class));
Assertions.assertThat(item.getDelta().getModifiedItems()).hasSize(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@
<objectTypeConfiguration>
<defaultValue>UserType</defaultValue>
</objectTypeConfiguration>
<searchItems>
<searchItem id="7">
<display>
<label>sample1</label>
</display>
</searchItem>
</searchItems>
</searchBoxConfiguration>
</objectCollectionView>
<objectCollectionView id="6">
Expand All @@ -149,6 +156,13 @@
<objectTypeConfiguration>
<defaultValue>OrgType</defaultValue>
</objectTypeConfiguration>
<searchItems>
<searchItem id="8">
<display>
<label>sample3</label>
</display>
</searchItem>
</searchItems>
</searchBoxConfiguration>
</objectCollectionView>
</objectCollectionViews>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
<searchBoxConfiguration>
<defaultScope>oneLevel</defaultScope>
<defaultObjectType>UserType</defaultObjectType>
<searchItems>
<searchItem id="7">
<displayName>sample1</displayName>
</searchItem>
</searchItems>
</searchBoxConfiguration>
</objectCollectionView>
<objectCollectionView id="6">
Expand All @@ -149,6 +154,14 @@
<objectTypeConfiguration>
<defaultValue>OrgType</defaultValue>
</objectTypeConfiguration>
<searchItems>
<searchItem id="8">
<displayName>sample2</displayName>
<display>
<label>sample3</label>
</display>
</searchItem>
</searchItems>
</searchBoxConfiguration>
</objectCollectionView>
</objectCollectionViews>
Expand Down

0 comments on commit 97c3cd5

Please sign in to comment.