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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<module>studymanager-core</module>
<module>studymanager-observation</module>
<module>studymanager-intervention</module>
<module>studymanager-goaltemplates</module>
<module>studymanager-services</module>
<module>studymanager</module>
</modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public ComponentFactory<C,P> init(ComponentFactoryProperties componentProperties

public abstract String getTitle();

public abstract String getDescription();

public List<Value> getProperties() {
return List.of();
}

public abstract <P extends ComponentProperties> Class<P> getPropertyClass();

public abstract String getDescription();

//TODO remove in a next step (as soon as interventions impl is done in FE for new props
public Map<String, Object> getDefaultProperties() {
HashMap<String, Object> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.properties.model;

public class ConfigSection extends Value<Void> {
public ConfigSection(String id) {
super(id);
}

@Override
public Class<Void> getValueType() {
return Void.class;
}

@Override
public String getType() {
return "GROUPING";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.redlink.more.studymanager.core.properties.model;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class IntegerRange {
Comment thread
westei marked this conversation as resolved.

// Defines the lower set value of the range
private final int lower;
// Defines the upper set value of the range
private final int upper;

@JsonCreator
public IntegerRange(
@JsonProperty("lower") @JsonAlias({"min"}) int lower,
@JsonProperty("upper") @JsonAlias({"max"}) int upper) {
this.lower = lower;
this.upper = upper;
}

public int getLower() {
return lower;
}

public int getUpper() {
return upper;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
IntegerRange that = (IntegerRange) o;
return lower == that.lower && upper == that.upper;
}

@Override
public int hashCode() {
return Objects.hash(lower, upper);
}

@Override
public String toString() {
return "IntegerRange{" +
"lower=" + lower +
", upper=" + upper +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.properties.model;

import io.redlink.more.studymanager.core.validation.ValidationIssue;

public class IntegerRangeValue extends Value<IntegerRange> {

// Defines the minimum value of the range, not equal to IntegerRange.lower which defines the user set lower bound
private int min = 0;
// Defines the maximum value of the range, not equal to IntegerRange.upper which defines the user set upper bound
private int max = Integer.MAX_VALUE;

public IntegerRangeValue(String id) {
super(id);
}

@Override
public String getType() {
return "INTEGER_RANGE";
}

@Override
public Class<IntegerRange> getValueType() {
return IntegerRange.class;
}

@Override
public ValidationIssue doValidate(IntegerRange range) {
if (range != null && range.getLower() > range.getUpper()) {
return ValidationIssue.error(this, "Lower bound of RangeValue MUST NOT be higer as the upper bound (lower:" + range.getLower() + ", upper: " + range.getUpper() + ")");
}
if (range != null && (range.getLower() < getMin() || range.getUpper() > getMax())) {
return ValidationIssue.error(this, "Value must between " + getMin() + " and " + getMax());
}
return ValidationIssue.NONE;
}

public int getMin() {
return min;
}

public IntegerRangeValue setMin(int min) {
this.min = min;
return this;
}

public int getMax() {
return max;
}

public IntegerRangeValue setMax(int max) {
this.max = max;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.redlink.more.studymanager.core.properties.model;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Objects;

public class NamedIntegerRange extends IntegerRange {

private String name;

@JsonCreator
public NamedIntegerRange(String name, int lower, int upper) {
super(lower, upper);
this.name = name;
}

public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
NamedIntegerRange that = (NamedIntegerRange) o;
return Objects.equals(name, that.name);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public String toString() {
return "NamedIntegerRange{" +
"name='" + name + '\'' +
"lower=" + getLower() +
", upper=" + getUpper() +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.properties.model;

import io.redlink.more.studymanager.core.validation.ValidationIssue;

public class NamedIntegerRangeValue extends Value<NamedIntegerRange> {

private int min = 0;
private int max = Integer.MAX_VALUE;

public NamedIntegerRangeValue(String id) {
super(id);
}

@Override
public String getType() {
return "INTEGER_RANGE";
}

@Override
public Class<NamedIntegerRange> getValueType() {
return NamedIntegerRange.class;
}

@Override
public ValidationIssue doValidate(NamedIntegerRange namedRange) {
if(namedRange != null && namedRange.getName() == null || namedRange.getName().isBlank()) {
return ValidationIssue.error(this, "The name of the RangeValue MUST NOT be blank");
}
if(namedRange != null && namedRange.getLower() > namedRange.getUpper()) {
return ValidationIssue.error(this, "Lower bound of RangeValue MUST NOT be higer as the upper bound (lower:" + namedRange.getLower() + ", upper: " + namedRange.getUpper() + ")");
}
if (namedRange != null && (namedRange.getLower() < getMin() || namedRange.getUpper() > getMax()) ) {
return ValidationIssue.error(this, "Value must between " + getMin() + " and " + getMax());
}
return ValidationIssue.NONE;
}

public int getMin() {
return min;
}

public NamedIntegerRangeValue setMin(int min) {
this.min = min;
return this;
}

public int getMax() {
return max;
}

public NamedIntegerRangeValue setMax(int max) {
this.max = max;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.redlink.more.studymanager.core.properties.model;

import io.redlink.more.studymanager.core.validation.ValidationIssue;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Type that allows to refer other values via &lt;id&gt;. Before saving those MUST BE replaced with the actual values.
* The validation will fail if the stored value contains any templates (&lt;id&gt;)
*/
public class StringTemplateValue extends StringValue {


private static final Pattern TEMPLATE_PATTERN = Pattern.compile("<[(^>)]+>");
private Set<String> allowList;

public StringTemplateValue(String id) {
this(id, null);
}

public StringTemplateValue(String id, Set<String> allowList) {
super(id);
this.allowList = allowList;
}

@Override
public String getType() {
return "STRINGTEMPLATE";
}

protected ValidationIssue doValidate(String value) {
if (value == null) {
return super.doValidate(value);
}
if (allowList != null) { //check that only allowed templates are used
int start = 0;
Matcher m = TEMPLATE_PATTERN.matcher(value);
Set<String> notAllowed = new HashSet<>();
while (m.find(start)) {
String template = m.group(1);
start = m.end();
if (!allowList.contains(template)) {
notAllowed.add(template);
}
}
if (!notAllowed.isEmpty()) {
return ValidationIssue.error(this, String.format(
"The value contains the unknown templates %s (allowed are: %s)!", notAllowed, allowList));
}
}
return super.doValidate(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
package io.redlink.more.studymanager.core.properties.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.redlink.more.studymanager.core.exception.ValueCastException;
import io.redlink.more.studymanager.core.exception.ValueNonNullException;
import io.redlink.more.studymanager.core.properties.ComponentProperties;
import io.redlink.more.studymanager.core.validation.ValidationIssue;

import java.util.function.Function;

public abstract class Value<T> {
Expand All @@ -23,6 +25,7 @@ public abstract class Value<T> {
private boolean required = false;
private boolean immutable = false;
private Function<T, ValidationIssue> validationFunction = (T t) -> ValidationIssue.NONE;
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

public Value(String id) {
this.id = id;
Expand Down Expand Up @@ -55,8 +58,8 @@ protected ValidationIssue doValidate(T t) {
public T getValue(ComponentProperties properties) {
if (properties.containsKey(id)) {
try {
return getValueType().cast(properties.get(id));
} catch (ClassCastException e) {
return OBJECT_MAPPER.convertValue(properties.get(id), getValueType());
} catch (ClassCastException | IllegalArgumentException e) {
throw new ValueCastException(this, getValueType());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright LBI-DHP and/or licensed to LBI-DHP under one or more
* contributor license agreements (LBI-DHP: Ludwig Boltzmann Institute
* for Digital Health and Prevention -- A research institute of the
* Ludwig Boltzmann Gesellschaft, Österreichische Vereinigung zur
* Förderung der wissenschaftlichen Forschung).
* Licensed under the Elastic License 2.0.
*/
package io.redlink.more.studymanager.core.properties.model;

public class ValueGroup extends Value<Void> {
public ValueGroup(String id) {
super(id);
}

@Override
public Class<Void> getValueType() {
return Void.class;
}

@Override
public String getType() {
return "GROUPING";
}
}
2 changes: 2 additions & 0 deletions studymanager-goaltemplates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# More Studymanager Goal Templates

Loading
Loading