-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstract SearchItemDefinition is created
- Loading branch information
1 parent
dffb5db
commit 53c4ec0
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...rc/main/java/com/evolveum/midpoint/web/component/search/AbstractSearchItemDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
.../src/main/java/com/evolveum/midpoint/web/component/search/FilterSearchItemDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...rc/main/java/com/evolveum/midpoint/web/component/search/PropertySearchItemDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |