-
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.
Merge branch 'master' of github.com:Evolveum/midpoint
- Loading branch information
Showing
33 changed files
with
1,216 additions
and
713 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
...hema/src/main/java/com/evolveum/midpoint/schema/config/ExpressionParameterConfigItem.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,48 @@ | ||
/* | ||
* 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.config; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.evolveum.midpoint.util.MiscUtil; | ||
import com.evolveum.midpoint.util.exception.ConfigurationException; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionParameterType; | ||
|
||
public class ExpressionParameterConfigItem | ||
extends ConfigurationItem<ExpressionParameterType> { | ||
|
||
@SuppressWarnings("unused") // called dynamically | ||
public ExpressionParameterConfigItem(@NotNull ConfigurationItem<ExpressionParameterType> original) { | ||
super(original); | ||
} | ||
|
||
protected ExpressionParameterConfigItem(@NotNull ExpressionParameterType value, @NotNull ConfigurationItemOrigin origin) { | ||
super(value, origin); | ||
} | ||
|
||
public static ExpressionParameterConfigItem of(@NotNull ExpressionParameterType bean, @NotNull ConfigurationItemOrigin origin) { | ||
return new ExpressionParameterConfigItem(bean, origin); | ||
} | ||
|
||
public @Nullable ExpressionConfigItem getExpression() { | ||
return ExpressionConfigItem.of(value().getExpression(), origin()); | ||
} | ||
|
||
public @NotNull String getName() throws ConfigurationException { | ||
return MiscUtil.configNonNull( | ||
value().getName(), | ||
"No name in %s", fullDescription()); | ||
} | ||
|
||
public @NotNull QName getType() throws ConfigurationException { | ||
return MiscUtil.configNonNull(value().getType(), () -> "No type of " + fullDescription()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ema/src/main/java/com/evolveum/midpoint/schema/config/FunctionCallArgumentConfigItem.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,36 @@ | ||
/* | ||
* 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.config; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionParameterType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionExpressionEvaluatorType; | ||
|
||
/** | ||
* Represents an {@link ExpressionParameterType} that is part of a {@link FunctionExpressionEvaluatorType} i.e. a function call. | ||
* | ||
* Intentionally differs from the standard naming convention. The embedded value is used as an argument value specification. | ||
* | ||
* TODO reconsider the necessity | ||
*/ | ||
public class FunctionCallArgumentConfigItem extends ExpressionParameterConfigItem { | ||
|
||
@SuppressWarnings("unused") // called dynamically | ||
public FunctionCallArgumentConfigItem(@NotNull ConfigurationItem<ExpressionParameterType> original) { | ||
super(original); | ||
} | ||
|
||
protected FunctionCallArgumentConfigItem(@NotNull ExpressionParameterType value, @NotNull ConfigurationItemOrigin origin) { | ||
super(value, origin); | ||
} | ||
|
||
public static FunctionCallArgumentConfigItem of(@NotNull ExpressionParameterType bean, @NotNull ConfigurationItemOrigin origin) { | ||
return new FunctionCallArgumentConfigItem(bean, origin); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
infra/schema/src/main/java/com/evolveum/midpoint/schema/config/FunctionConfigItem.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,103 @@ | ||
/* | ||
* 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.config; | ||
|
||
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; | ||
|
||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
import javax.xml.namespace.QName; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.util.DOMUtil; | ||
import com.evolveum.midpoint.util.MiscUtil; | ||
import com.evolveum.midpoint.util.exception.ConfigurationException; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionReturnMultiplicityType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType; | ||
|
||
/** | ||
* Represents an {@link ExpressionType} that is part of a {@link FunctionLibraryType} as a custom function. | ||
* | ||
* Intentionally differs from the standard naming convention. The embedded value is {@link ExpressionType} but it is used | ||
* in a specialized way. | ||
*/ | ||
public class FunctionConfigItem extends ExpressionConfigItem { | ||
|
||
// called dynamically | ||
public FunctionConfigItem(@NotNull ConfigurationItem<ExpressionType> original) { | ||
super(original); | ||
} | ||
|
||
private FunctionConfigItem(@NotNull ExpressionType value, @NotNull ConfigurationItemOrigin origin) { | ||
super(value, origin); | ||
} | ||
|
||
public static FunctionConfigItem of(@NotNull ExpressionType bean, @NotNull ConfigurationItemOrigin origin) { | ||
return new FunctionConfigItem(bean, origin); | ||
} | ||
|
||
/** Unlike general {@link ExpressionConfigItem}, the function must have a name. */ | ||
public @NotNull String getName() throws ConfigurationException { | ||
return MiscUtil.configNonNull( | ||
value().getName(), | ||
() -> "No name in " + fullDescription()); | ||
} | ||
|
||
public @NotNull String getCommaDelimitedParameterNames() { | ||
return value().getParameter().stream() | ||
.map(p -> "'" + p.getName() + "'") | ||
.collect(Collectors.joining(", ")); | ||
} | ||
|
||
/** Matching parameter names, ignoring all the other information (e.g., types). */ | ||
public boolean doesMatchArguments(Collection<String> argumentNames) { | ||
var parameters = value().getParameter(); | ||
if (argumentNames.size() != parameters.size()) { | ||
return false; | ||
} | ||
for (String argumentName : argumentNames) { | ||
if (parameters.stream().noneMatch( | ||
param -> param.getName().equals(argumentName))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public @NotNull ExpressionParameterConfigItem getParameter(@NotNull String paramName) throws ConfigurationException { | ||
var matching = value().getParameter().stream() | ||
.filter(param -> param.getName().equals(paramName)) | ||
.toList(); | ||
var paramBean = MiscUtil.extractSingletonRequired( | ||
matching, | ||
() -> new ConfigurationException( | ||
"More than one parameter named '%s' in function '%s' found".formatted( | ||
paramName, value().getName())), | ||
() -> new ConfigurationException( | ||
"No parameter named '%s' in function '%s' found. Known parameters are: %s.".formatted( | ||
paramName, value().getName(), getCommaDelimitedParameterNames()))); | ||
return ExpressionParameterConfigItem.of(paramBean, origin()); | ||
} | ||
|
||
public @NotNull QName getReturnTypeName() { | ||
return defaultIfNull(value().getReturnType(), DOMUtil.XSD_STRING); | ||
} | ||
|
||
// FIXME it is interesting that the default for multiplicity is not clear, see uses of these methods | ||
// Maybe it has no default? | ||
|
||
public boolean isReturnMultiValue() { | ||
return value().getReturnMultiplicity() == ExpressionReturnMultiplicityType.MULTI; | ||
} | ||
|
||
public boolean isReturnSingleValue() { | ||
return value().getReturnMultiplicity() == ExpressionReturnMultiplicityType.SINGLE; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../main/java/com/evolveum/midpoint/schema/config/FunctionExpressionEvaluatorConfigItem.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,66 @@ | ||
/* | ||
* 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.config; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.util.MiscUtil; | ||
import com.evolveum.midpoint.util.exception.ConfigurationException; | ||
|
||
/** Represents an {@link FunctionExpressionEvaluatorType} i.e. a call to a library function. */ | ||
public class FunctionExpressionEvaluatorConfigItem extends ConfigurationItem<FunctionExpressionEvaluatorType> { | ||
|
||
// called dynamically | ||
public FunctionExpressionEvaluatorConfigItem(@NotNull ConfigurationItem<FunctionExpressionEvaluatorType> original) { | ||
super(original); | ||
} | ||
|
||
private FunctionExpressionEvaluatorConfigItem(@NotNull FunctionExpressionEvaluatorType value, @NotNull ConfigurationItemOrigin origin) { | ||
super(value, origin); | ||
} | ||
|
||
public static FunctionExpressionEvaluatorConfigItem of( | ||
@NotNull FunctionExpressionEvaluatorType bean, @NotNull ConfigurationItemOrigin origin) { | ||
return new FunctionExpressionEvaluatorConfigItem(bean, origin); | ||
} | ||
|
||
public @NotNull String getLibraryOid() throws ConfigurationException { | ||
ObjectReferenceType functionLibraryRef = value().getLibraryRef(); | ||
if (functionLibraryRef == null) { | ||
// Eventually, we could support a default value here: the current library where the expression is defined (if any) | ||
throw new ConfigurationException("No functions library defined in " + fullDescription()); | ||
} | ||
return MiscUtil.configNonNull( | ||
functionLibraryRef.getOid(), | ||
() -> "No OID in function library reference in " + fullDescription()); | ||
} | ||
|
||
public String getFunctionName() throws ConfigurationException { | ||
return MiscUtil.configNonNull( | ||
value().getName(), | ||
"No function name in %s", fullDescription()); | ||
} | ||
|
||
public Collection<String> getArgumentNames() { | ||
return value().getParameter().stream() | ||
.map(p -> p.getName()) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public List<FunctionCallArgumentConfigItem> getArguments() { | ||
return value().getParameter().stream() | ||
.map(p -> FunctionCallArgumentConfigItem.of(p, origin())) | ||
.toList(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.