Skip to content

Commit

Permalink
display name fix for configurable search items
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 17, 2020
1 parent bfdae70 commit 8b0df9b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Expand Up @@ -11,6 +11,9 @@
import java.util.List;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.wicket.model.StringResourceModel;
Expand All @@ -36,8 +39,9 @@ public class PropertySearchItem<T extends Serializable> extends SearchItem {
private final List<QName> allowedRelations;

private DisplayableValue<T> value;
private PolyStringType displayName;

public PropertySearchItem(Search search, ItemPath path, ItemDefinition definition, List<QName> allowedRelations) {
public PropertySearchItem(Search search, ItemPath path, ItemDefinition definition, List<QName> allowedRelations, PolyStringType displayName) {
super(search);
Validate.notNull(path, "Item path must not be null.");
Validate.notNull(definition, "Item definition must not be null.");
Expand All @@ -50,6 +54,7 @@ public PropertySearchItem(Search search, ItemPath path, ItemDefinition definitio
this.path = path;
this.definition = definition;
this.allowedRelations = allowedRelations;
this.displayName = displayName;
}

public ItemDefinition getDefinition() {
Expand Down Expand Up @@ -86,6 +91,9 @@ public ItemPath getPath() {

@Override
public String getName() {
if (displayName != null){
return WebComponentUtil.getTranslatedPolyString(displayName);
}
String key = definition.getDisplayName();
if (StringUtils.isEmpty(key)) {
key = getSearch().getType().getSimpleName() + '.' + definition.getItemName().getLocalPart();
Expand Down Expand Up @@ -123,6 +131,14 @@ public Type getType() {
return Type.TEXT;
}

public PolyStringType getDisplayName() {
return displayName;
}

public void setDisplayName(PolyStringType displayName) {
this.displayName = displayName;
}

@Override
public String toString() {
return "PropertySearchItem{" +
Expand Down
Expand Up @@ -143,7 +143,8 @@ public SearchItem addItem(ItemDefinition def) {
return null;
}

PropertySearchItem item = new PropertySearchItem(this, itemToRemove.getPath(), def, itemToRemove.getAllowedValues());
PropertySearchItem item = new PropertySearchItem(this, itemToRemove.getPath(), def, itemToRemove.getAllowedValues(),
itemToRemove.getDisplayName());
if (def instanceof PrismReferenceDefinition) {
ObjectReferenceType ref = new ObjectReferenceType();
List<QName> supportedTargets = WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) def).getTargetTypeName());
Expand Down
Expand Up @@ -205,6 +205,7 @@ public static <T extends ObjectType> Search createSearch(
if (searchItemDef.getPath() != null) {
ItemDefinition def = objDef.findItemDefinition(searchItemDef.getPath());
item = search.addItem(def);
((PropertySearchItem) item).setDisplayName(searchItemDef.getDisplayName());
} else if (searchItemDef.getPredefinedFilter() != null) {
item = search.addItem(searchItemDef.getPredefinedFilter());
}
Expand Down Expand Up @@ -260,6 +261,7 @@ private static <C extends Containerable> List<SearchItemDefinition> getConfigure
for (SearchItemDefinition def : availableDefinitions) {
ItemPathType searchItemPath = new ItemPathType(def.getPath());
if (searchItem.getPath() != null && searchItem.getPath().equivalent(searchItemPath)) {
def.setDisplayName(searchItem.getDisplayName());
configuredSearchItemList.add(def);
return;
}
Expand Down
Expand Up @@ -12,12 +12,14 @@
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SearchItemType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

public class SearchItemDefinition implements Serializable {

private ItemPath path;
private ItemDefinition def;
private SearchItemType predefinedFilter;
private PolyStringType displayName;
private List<?> allowedValues;

public SearchItemDefinition(ItemPath path, ItemDefinition def, List<?> allowedValues) {
Expand Down Expand Up @@ -49,4 +51,12 @@ public SearchItemType getPredefinedFilter() {
public void setPredefinedFilter(SearchItemType predefinedFilter) {
this.predefinedFilter = predefinedFilter;
}

public PolyStringType getDisplayName() {
return displayName;
}

public void setDisplayName(PolyStringType displayName) {
this.displayName = displayName;
}
}

0 comments on commit 8b0df9b

Please sign in to comment.