Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ itests/src/main
dependency_tree.txt
.mvn/.develocity/develocity-workspace-id
/.cursor/
/.claude/
/.local-notes/
itests/snapshots_repository/
itests/archives/
Expand Down
2 changes: 0 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -104,7 +103,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
13 changes: 13 additions & 0 deletions api/src/main/java/org/apache/unomi/api/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package org.apache.unomi.api;

import org.apache.unomi.api.conditions.ConditionValidation;
import org.apache.unomi.api.utils.YamlUtils;
import org.apache.unomi.api.utils.YamlUtils.YamlConvertible;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

import static org.apache.unomi.api.utils.YamlUtils.toYamlValue;

/**
* A representation of a condition parameter, to be used in the segment building UI to either select parameters from a
* choicelist or to enter a specific value.
Expand All @@ -39,6 +42,7 @@ public class Parameter implements Serializable, YamlConvertible {
private String type;
private boolean multivalued;
private Object defaultValue;
private ConditionValidation validation;

public Parameter() {
}
Expand Down Expand Up @@ -90,6 +94,14 @@ public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}

public ConditionValidation getValidation() {
return validation;
}

public void setValidation(ConditionValidation validation) {
this.validation = validation;
}

/**
* Converts this parameter to a Map structure for YAML output.
* Implements YamlConvertible interface.
Expand All @@ -112,6 +124,7 @@ public Map<String, Object> toYaml(Set<Object> visited, int maxDepth) {
.putIfNotNull("type", type)
.putIf("multivalued", true, multivalued)
.putIfNotNull("defaultValue", defaultValue)
.putIfNotNull("validation", validation != null ? toYamlValue(validation, visited, maxDepth - 1) : null)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.unomi.api.conditions;

import org.apache.unomi.api.utils.YamlUtils;
import org.apache.unomi.api.utils.YamlUtils.YamlConvertible;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

import static org.apache.unomi.api.utils.YamlUtils.setToSortedList;

/**
* Validation metadata for condition parameters
*/
public class ConditionValidation implements Serializable, YamlConvertible {
private static final long serialVersionUID = 1L;

public enum Type {
STRING,
INTEGER,
LONG,
FLOAT,
DOUBLE,
BOOLEAN,
DATE,
CONDITION,
OBJECT
}

private boolean required;
private Set<String> allowedValues;
private Set<String> allowedConditionTags;
private Set<String> disallowedConditionTypes;
private boolean exclusive; // Only one of the exclusive parameters in a group can have a value
private String exclusiveGroup; // Name of the exclusive group this parameter belongs to
private boolean recommended; // Parameter is recommended but not required
private transient Class<?> customType;

public ConditionValidation() {
}

public boolean isRequired() {
return required;
}

public void setRequired(boolean required) {
this.required = required;
}

public Set<String> getAllowedValues() {
return allowedValues;
}

public void setAllowedValues(Set<String> allowedValues) {
this.allowedValues = allowedValues;
}

public Set<String> getAllowedConditionTags() {
return allowedConditionTags;
}

public void setAllowedConditionTags(Set<String> allowedConditionTags) {
this.allowedConditionTags = allowedConditionTags;
}

public Set<String> getDisallowedConditionTypes() {
return disallowedConditionTypes;
}

public void setDisallowedConditionTypes(Set<String> disallowedConditionTypes) {
this.disallowedConditionTypes = disallowedConditionTypes;
}

public boolean isExclusive() {
return exclusive;
}

public void setExclusive(boolean exclusive) {
this.exclusive = exclusive;
}

public String getExclusiveGroup() {
return exclusiveGroup;
}

public void setExclusiveGroup(String exclusiveGroup) {
this.exclusiveGroup = exclusiveGroup;
}

public boolean isRecommended() {
return recommended;
}

public void setRecommended(boolean recommended) {
this.recommended = recommended;
}

public Class<?> getCustomType() {
return customType;
}

public void setCustomType(Class<?> customType) {
this.customType = customType;
}

/**
* Converts this validation to a Map structure for YAML output.
* Implements YamlConvertible interface.
*
* @param visited set of already visited objects to prevent infinite recursion (may be null)
* @return a Map representation of this validation
*/
@Override
public Map<String, Object> toYaml(Set<Object> visited, int maxDepth) {
return YamlUtils.YamlMapBuilder.create()
.putIf("required", true, required)
.putIf("recommended", true, recommended)
.putIfNotNull("allowedValues", setToSortedList(allowedValues))
.putIfNotNull("allowedConditionTags", setToSortedList(allowedConditionTags))
.putIfNotNull("disallowedConditionTypes", setToSortedList(disallowedConditionTypes))
.putIf("exclusive", true, exclusive)
.putIfNotNull("exclusiveGroup", exclusiveGroup)
.putIfNotNull("customType", customType != null ? customType.getName() : null)
.build();
}

@Override
public String toString() {
return YamlUtils.format(toYaml());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@

package org.apache.unomi.api.exceptions;

/**
* Exception thrown when a segment condition is invalid or cannot be used.
*/
public class BadSegmentConditionException extends RuntimeException {

public BadSegmentConditionException() {
super();
}

public BadSegmentConditionException(String message) {
super(message);
}

public BadSegmentConditionException(String message, Throwable cause) {
super(message, cause);
}
}
Loading
Loading