Skip to content

Commit

Permalink
Merge pull request #562 from ehrbase/feature/1209_fix_parsing_contain…
Browse files Browse the repository at this point in the history
…s_version_without_predicate

Feature/1209 fix parsing contains version without predicate
  • Loading branch information
vmueller-vg authored Jan 29, 2024
2 parents 2a7632e + e1955c3 commit 0e92fbe
Show file tree
Hide file tree
Showing 50 changed files with 428 additions and 223 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
Note: version releases in the 0.x.y range may introduce breaking changes.

## [unreleased]
### Added
- Added `QueryResponseData.meta` additional `fetch`, `offset` and `resultsize` properties ([#559](https://github.com/ehrbase/openEHR_SDK/pull/559))
### Fixed

### Added

- Added `QueryResponseData.meta` additional `fetch`, `offset` and `resultsize`
properties ([#559](https://github.com/ehrbase/openEHR_SDK/pull/559))

### Changed

- Sealed AqlQuery
- AqlQuery: Support for VERSION without predicate

### Fixed

## [2.6.0]
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.ehrbase.openehr.sdk.aql.parser.AqlQueryParser;
import org.ehrbase.openehr.sdk.aql.render.AqlRenderer;

public class AqlQuery {
public final class AqlQuery {

private SelectClause select;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.ehrbase.openehr.sdk.aql.dto.operand.ComparisonLeftOperand;
import org.ehrbase.openehr.sdk.aql.dto.operand.Operand;

public class ComparisonOperatorCondition implements WhereCondition {
public final class ComparisonOperatorCondition implements WhereCondition {

private ComparisonLeftOperand statement;
private ComparisonOperatorSymbol symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @author Stefan Spiska
*/
public class ExistsCondition implements WhereCondition {
public final class ExistsCondition implements WhereCondition {

private IdentifiedPath value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.ehrbase.openehr.sdk.aql.dto.operand.IdentifiedPath;
import org.ehrbase.openehr.sdk.aql.dto.operand.LikeOperand;

public class LikeCondition implements WhereCondition {
public final class LikeCondition implements WhereCondition {

private IdentifiedPath statement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.ehrbase.openehr.sdk.aql.dto.LogicalOperator;
import org.ehrbase.openehr.sdk.aql.dto.condition.LogicalOperatorCondition.ConditionLogicalOperatorSymbol;

public class LogicalOperatorCondition
public final class LogicalOperatorCondition
implements WhereCondition, LogicalOperator<ConditionLogicalOperatorSymbol, WhereCondition> {

private ConditionLogicalOperatorSymbol symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.ehrbase.openehr.sdk.aql.dto.operand.IdentifiedPath;
import org.ehrbase.openehr.sdk.aql.dto.operand.MatchesOperand;

public class MatchesCondition implements WhereCondition {
public final class MatchesCondition implements WhereCondition {

private IdentifiedPath statement;
private List<MatchesOperand> values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @author Stefan Spiska
*/
public class NotCondition implements WhereCondition {
public final class NotCondition implements WhereCondition {

private WhereCondition condition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@
@JsonSubTypes.Type(value = MatchesCondition.class, name = "Matches"),
@JsonSubTypes.Type(value = NotCondition.class, name = "Not")
})
public interface WhereCondition {}
public sealed interface WhereCondition
permits ComparisonOperatorCondition,
ExistsCondition,
LikeCondition,
LogicalOperatorCondition,
MatchesCondition,
NotCondition {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.ehrbase.openehr.sdk.aql.dto.path.AndOperatorPredicate;
import org.ehrbase.openehr.sdk.aql.serializer.PredicateDeserializer;
import org.ehrbase.openehr.sdk.aql.serializer.PredicateSerializer;

/**
* @author Stefan Spiska
*/
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "identifier")
public abstract class AbstractContainmentExpression implements Containment {

protected List<AndOperatorPredicate> predicates;
public abstract sealed class AbstractContainmentExpression implements Containment
permits ContainmentClassExpression, ContainmentVersionExpression {
private Containment contains;

private String identifier;
Expand All @@ -56,39 +52,25 @@ public void setIdentifier(String identifier) {
}

@JsonSerialize(using = PredicateSerializer.class)
public List<AndOperatorPredicate> getPredicates() {
return predicates;
}
public abstract List<AndOperatorPredicate> getPredicates();

@JsonDeserialize(using = PredicateDeserializer.class)
public void setPredicates(List<AndOperatorPredicate> predicates) {
if (predicates != null) {
this.predicates = new ArrayList<>(predicates);
} else {
this.predicates = null;
}
}
public abstract boolean hasPredicates();

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbstractContainmentExpression that = (AbstractContainmentExpression) o;
return Objects.equals(predicates, that.predicates)
&& Objects.equals(contains, that.contains)
&& Objects.equals(identifier, that.identifier);
return Objects.equals(contains, that.contains) && Objects.equals(identifier, that.identifier);
}

@Override
public int hashCode() {
return Objects.hash(predicates, contains, identifier);
return Objects.hash(contains, identifier);
}

@Override
public String toString() {
return "AbstractContainmentExpression{" + "predicates="
+ predicates + ", contains="
+ contains + ", identifier='"
+ identifier + '\'' + '}';
return "AbstractContainmentExpression{contains=%s, identifier='%s'".formatted(contains, identifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
@JsonSubTypes.Type(value = ContainmentSetOperator.class, name = "LogicalOperator"),
@JsonSubTypes.Type(value = ContainmentNotOperator.class, name = "Not")
})
public interface Containment {}
public sealed interface Containment
permits AbstractContainmentExpression, ContainmentNotOperator, ContainmentSetOperator {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
*/
package org.ehrbase.openehr.sdk.aql.dto.containment;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.commons.collections4.CollectionUtils;
import org.ehrbase.openehr.sdk.aql.dto.path.AndOperatorPredicate;
import org.ehrbase.openehr.sdk.aql.serializer.PredicateDeserializer;
import org.ehrbase.openehr.sdk.aql.serializer.PredicateSerializer;

public class ContainmentClassExpression extends AbstractContainmentExpression {
@JsonPropertyOrder({"type", "predicates", "contains"})
public final class ContainmentClassExpression extends AbstractContainmentExpression {

private String type;

protected List<AndOperatorPredicate> predicates;

public String getType() {
return type;
}
Expand All @@ -31,22 +43,42 @@ public void setType(String type) {
this.type = type;
}

@JsonSerialize(using = PredicateSerializer.class)
@Override
public List<AndOperatorPredicate> getPredicates() {
return predicates;
}

@JsonDeserialize(using = PredicateDeserializer.class)
public void setPredicates(List<AndOperatorPredicate> predicates) {
if (predicates != null) {
this.predicates = new ArrayList<>(predicates);
} else {
this.predicates = null;
}
}

@Override
public boolean hasPredicates() {
return CollectionUtils.isNotEmpty(this.predicates);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ContainmentClassExpression that = (ContainmentClassExpression) o;
return Objects.equals(type, that.type);
return Objects.equals(type, that.type) && Objects.equals(predicates, that.predicates);
}

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

@Override
public String toString() {
return "ContainmentClassExpression{" + "type='" + type + '\'' + "} " + super.toString();
return "ContainmentClassExpression{type='%s', predicates=%s, %s}".formatted(type, predicates, super.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @author Stefan Spiska
*/
public class ContainmentNotOperator implements Containment {
public final class ContainmentNotOperator implements Containment {
private Containment containmentExpression;

public Containment getContainmentExpression() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.Objects;
import org.ehrbase.openehr.sdk.aql.dto.LogicalOperator;

public class ContainmentSetOperator implements Containment, LogicalOperator<ContainmentSetOperatorSymbol, Containment> {
public final class ContainmentSetOperator
implements Containment, LogicalOperator<ContainmentSetOperatorSymbol, Containment> {
ContainmentSetOperatorSymbol symbol;
List<Containment> values;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,93 @@
*/
package org.ehrbase.openehr.sdk.aql.dto.containment;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.List;
import java.util.Objects;
import org.ehrbase.openehr.sdk.aql.dto.path.AndOperatorPredicate;
import org.ehrbase.openehr.sdk.aql.dto.path.ComparisonOperatorPredicate;
import org.ehrbase.openehr.sdk.aql.serializer.VersionPredicateDeserializer;
import org.ehrbase.openehr.sdk.aql.serializer.VersionPredicateSerializer;

/**
* @author Stefan Spiska
*/
public class ContainmentVersionExpression extends AbstractContainmentExpression {
@JsonPropertyOrder({"versionPredicateType", "predicate", "contains"})
public final class ContainmentVersionExpression extends AbstractContainmentExpression {

public enum VersionPredicateType {
NONE,
LATEST_VERSION,
ALL_VERSIONS,
STANDARD_PREDICATE;
STANDARD_PREDICATE
}

private VersionPredicateType versionPredicateType;
private VersionPredicateType versionPredicateType = VersionPredicateType.NONE;

private ComparisonOperatorPredicate predicate;

public VersionPredicateType getVersionPredicateType() {
return versionPredicateType;
}

public void setVersionPredicateType(VersionPredicateType versionPredicateType) {
this.versionPredicateType = versionPredicateType;

if (versionPredicateType.equals(VersionPredicateType.ALL_VERSIONS)
|| versionPredicateType.equals(VersionPredicateType.LATEST_VERSION)) {
setPredicates(null);
if (versionPredicateType != VersionPredicateType.STANDARD_PREDICATE) {
this.predicate = null;
}
}

@Override
public void setPredicates(List<AndOperatorPredicate> predicates) {
super.setPredicates(predicates);
@JsonSerialize(using = VersionPredicateSerializer.class)
public ComparisonOperatorPredicate getPredicate() {
return predicate;
}

@JsonDeserialize(using = VersionPredicateDeserializer.class)
public void setPredicate(ComparisonOperatorPredicate predicate) {
this.predicate = predicate;

if (predicates != null) {
if (predicate != null) {
versionPredicateType = VersionPredicateType.STANDARD_PREDICATE;
} else if (versionPredicateType == VersionPredicateType.STANDARD_PREDICATE) {
versionPredicateType = VersionPredicateType.NONE;
}
}

@JsonIgnore
@Override
public List<AndOperatorPredicate> getPredicates() {
if (predicate == null) {
return null;
} else {
return List.of(new AndOperatorPredicate(List.of(predicate)));
}
}

@Override
public boolean hasPredicates() {
return predicate != null;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ContainmentVersionExpression that = (ContainmentVersionExpression) o;
return versionPredicateType == that.versionPredicateType;
return versionPredicateType == that.versionPredicateType && Objects.equals(predicate, that.predicate);
}

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

@Override
public String toString() {
return "ContainmentVersionExpression{" + "versionPredicateType="
+ versionPredicateType + "} "
+ super.toString();
return "ContainmentVersionExpression{versionPredicateType=%s, predicate=%s, %s}"
.formatted(versionPredicateType, predicate, super.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @author Stefan Spiska
*/
public class AggregateFunction implements ColumnExpression {
public sealed class AggregateFunction implements ColumnExpression permits CountDistinctAggregateFunction {

private AggregateFunctionName functionName;
private IdentifiedPath identifiedPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* @author Stefan Spiska
*/
public class BooleanPrimitive extends Primitive<Boolean, BooleanPrimitive> {
public final class BooleanPrimitive extends Primitive<Boolean, BooleanPrimitive> {

public BooleanPrimitive() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
@JsonSubTypes.Type(value = TemporalPrimitive.class, name = "Temporal"),
@JsonSubTypes.Type(value = TerminologyFunction.class, name = "TerminologyFunction")
})
public interface ColumnExpression {}
public sealed interface ColumnExpression permits AggregateFunction, FunctionCall, IdentifiedPath, Primitive {}
Loading

0 comments on commit 0e92fbe

Please # to comment.