Skip to content

Commit

Permalink
abstract SearchItemDefinition is created
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Dec 7, 2021
1 parent dffb5db commit 53c4ec0
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2021 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.web.component.search;

import java.io.Serializable;

public abstract class AbstractSearchItemDefinition<D extends AbstractSearchItemDefinition> implements Serializable, Comparable<D> {

@Override
public int compareTo(D def) {
String n1 = getName();
String n2 = def.getName();

if (n1 == null || n2 == null) {
return 0;
}
return String.CASE_INSENSITIVE_ORDER.compare(n1, n2);
}

public abstract String getName();

public abstract String getHelp();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 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.web.component.search;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SearchItemType;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class FilterSearchItemDefinition extends AbstractSearchItemDefinition {

private SearchItemType predefinedFilter;

public FilterSearchItemDefinition(@NotNull SearchItemType predefinedFilter) {
this.predefinedFilter = predefinedFilter;
}

@Override
public String getName() {
if (predefinedFilter.getDisplayName() != null){
return WebComponentUtil.getTranslatedPolyString(predefinedFilter.getDisplayName());
}
return ""; //todo what if no displayName is configured for filter?
}

@Override
public String getHelp(){
if (StringUtils.isNotBlank(predefinedFilter.getDescription())) {
return predefinedFilter.getDescription();
}
return "";
}

@Override
public int hashCode() {
return Objects.hash(predefinedFilter);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2021 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.web.component.search;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.path.ItemPath;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;

public class PropertySearchItemDefinition extends AbstractSearchItemDefinition {

private ItemPath path;
private ItemDefinition def;
private List allowedValues;

public PropertySearchItemDefinition(@NotNull ItemPath path, @NotNull ItemDefinition def) {
this(path, def, null);
}

public PropertySearchItemDefinition(@NotNull ItemPath path, @NotNull ItemDefinition def, List allowedValues) {
this.path = path;
this.def = def;
this.allowedValues = allowedValues;
}

public ItemPath getPath() {
return path;
}

public ItemDefinition getDef() {
return def;
}

public List getAllowedValues() {
return allowedValues;
}

@Override
public String getHelp(){
String help = "";
if (def != null) {
if (StringUtils.isNotEmpty(def.getHelp())) {
help = def.getHelp();
} else {
help = def.getDocumentation();
}
}
if (StringUtils.isNotBlank(help)) {
help = help.replace("\n", "").replace("\r", "").replaceAll("^ +| +$|( )+", "$1");
}
return help;
}

@Override
public String getName() {
if (StringUtils.isNotEmpty(getDef().getDisplayName())) {
return PageBase.createStringResourceStatic(null, getDef().getDisplayName()).getString();
}
return WebComponentUtil.getItemDefinitionDisplayNameOrName(getDef(), null);
}

@Override
public int hashCode() {
return Objects.hash(path, def, allowedValues);
}

}

0 comments on commit 53c4ec0

Please sign in to comment.