Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 1, 2023
2 parents d1c2e37 + 496a0f2 commit 8438c35
Show file tree
Hide file tree
Showing 33 changed files with 1,216 additions and 713 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ExpressionConfigItem(@NotNull ConfigurationItem<ExpressionType> original)
super(original);
}

private ExpressionConfigItem(@NotNull ExpressionType value, @NotNull ConfigurationItemOrigin origin) {
protected ExpressionConfigItem(@NotNull ExpressionType value, @NotNull ConfigurationItemOrigin origin) {
super(value, origin);
}

Expand Down
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());
}
}
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);
}
}
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;
}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ public class MidPointConstants {
public static final String PREFIX_NS_RI = "ri";

public static final String FUNCTION_LIBRARY_BASIC_VARIABLE_NAME = "basic";
public static final String NS_FUNC_BASIC = NS_MIDPOINT_PUBLIC_PREFIX+"/function/basic-3";

public static final String FUNCTION_LIBRARY_MIDPOINT_VARIABLE_NAME = "midpoint";
public static final String NS_FUNC_MIDPOINT = NS_MIDPOINT_PUBLIC_PREFIX+"/function/midpoint-3";

public static final String FUNCTION_LIBRARY_LOG_VARIABLE_NAME = "log";
public static final String NS_FUNC_LOG = NS_MIDPOINT_PUBLIC_PREFIX+"/function/log-3";

public static final String NS_FUNC_CUSTOM = NS_MIDPOINT_PUBLIC_PREFIX+"/function/custom-3";
public static final String FUNCTION_LIBRARY_REPORT_VARIABLE_NAME = "report";

public static final String PROFILING_LOGGER_NAME = OperationExecutionLogger.PROFILING_LOGGER_NAME;
public static final String JAVA_HOME_ENVIRONMENT_VARIABLE = "JAVA_HOME";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ public Class<T> determineClass() throws SchemaException {
return typeClass;
}
} else {
Class determinedClass;
Class<?> determinedClass;
if (definition instanceof PrismReferenceDefinition) {
// Stock prism reference would return ObjectReferenceType from prism schema.
// But we have exteded type for this.
// But we have extended type for this.
// TODO: how to make this more elegant?
determinedClass = ObjectReferenceType.class;
} else {
Expand All @@ -183,7 +183,8 @@ public Class<T> determineClass() throws SchemaException {
if (determinedClass == null) {
throw new SchemaException("Cannot determine class from definition "+definition);
}
return determinedClass;
//noinspection unchecked
return (Class<T>) determinedClass;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.common.archetypes.ArchetypeManager;
import com.evolveum.midpoint.model.common.expression.functions.FunctionLibraryManager;
import com.evolveum.midpoint.model.common.mapping.metadata.MetadataMappingEvaluator;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.crypto.Protector;
Expand Down Expand Up @@ -66,4 +67,5 @@ public static ModelCommonBeans get() {
@Autowired public LightweightIdentifierGenerator lightweightIdentifierGenerator;
@Autowired public LocalizationService localizationService;
@Autowired public ArchetypeManager archetypeManager;
@Autowired public FunctionLibraryManager functionLibraryManager;
}

0 comments on commit 8438c35

Please sign in to comment.