Skip to content

Commit

Permalink
Got rid of hibernate and java el based validations (#65)
Browse files Browse the repository at this point in the history
* Got rid of hibernate and java el based validations

* Review comment

* Addressed typos in messages
  • Loading branch information
avinashkolluru authored Dec 17, 2021
1 parent ca04d48 commit 506300c
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 112 deletions.
2 changes: 0 additions & 2 deletions document-store/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ dependencies {
api("com.typesafe:config:1.3.2")
annotationProcessor("org.projectlombok:lombok:1.18.22")
compileOnly("org.projectlombok:lombok:1.18.22")
implementation("org.hibernate:hibernate-validator:6.1.3.Final")
implementation("org.apache.commons:commons-collections4:4.4")
implementation("org.glassfish:javax.el:3.0.1-b06")
implementation("org.postgresql:postgresql:42.2.13")
implementation("org.mongodb:mongodb-driver-sync:4.1.2")
implementation("com.fasterxml.jackson.core:jackson-databind:2.11.0")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.hypertrace.core.documentstore.expression.impl;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import javax.validation.constraints.NotNull;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
Expand All @@ -23,13 +21,15 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class AggregateExpression implements SelectingExpression, SortingExpression {

@NotNull AggregationOperator aggregator;
AggregationOperator aggregator;

@NotNull SelectingExpression expression;
SelectingExpression expression;

public static AggregateExpression of(
final AggregationOperator aggregator, final SelectingExpression expression) {
return validateAndReturn(new AggregateExpression(aggregator, expression));
Preconditions.checkArgument(aggregator != null, "aggregator is null");
Preconditions.checkArgument(expression != null, "expression is null");
return new AggregateExpression(aggregator, expression);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.hypertrace.core.documentstore.expression.impl;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import com.google.common.base.Preconditions;
import java.util.List;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -44,13 +42,17 @@
public class FunctionExpression
implements GroupingExpression, SelectingExpression, SortingExpression {

@Singular @NotEmpty List<@NotNull SelectingExpression> operands;
@Singular List<SelectingExpression> operands;

@NotNull FunctionOperator operator;
FunctionOperator operator;

public static class FunctionExpressionBuilder {
public FunctionExpression build() {
return validateAndReturn(new FunctionExpression(operands, operator));
Preconditions.checkArgument(!operands.isEmpty(), "operands is empty");
Preconditions.checkArgument(
operands.stream().noneMatch(Objects::isNull), "One or more operands is null");
Preconditions.checkArgument(operator != null, "operator is null");
return new FunctionExpression(operands, operator);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.hypertrace.core.documentstore.expression.impl;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import javax.validation.constraints.NotBlank;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
Expand All @@ -23,10 +21,11 @@
public class IdentifierExpression
implements GroupingExpression, SelectingExpression, SortingExpression {

@NotBlank String name;
String name;

public static IdentifierExpression of(final String name) {
return validateAndReturn(new IdentifierExpression(name));
Preconditions.checkArgument(name != null && !name.isBlank(), "name is null or blank");
return new IdentifierExpression(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.hypertrace.core.documentstore.expression.impl;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import com.google.common.base.Preconditions;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -43,21 +41,23 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class LogicalExpression implements FilteringExpression {

@Singular
@Size(min = 2)
@NotNull
List<@NotNull FilteringExpression> operands;

@NotNull LogicalOperator operator;
@Singular List<FilteringExpression> operands;

public static class LogicalExpressionBuilder {
public LogicalExpression build() {
return validateAndReturn(new LogicalExpression(operands, operator));
}
}
LogicalOperator operator;

@Override
public <T> T visit(final FilteringExpressionVisitor visitor) {
return visitor.visit(this);
}

public static class LogicalExpressionBuilder {
public LogicalExpression build() {
Preconditions.checkArgument(operands != null, "operands is null");
Preconditions.checkArgument(operands.size() >= 2, "At least 2 operands required");
Preconditions.checkArgument(
operands.stream().noneMatch(Objects::isNull), "One or more operands is null");
Preconditions.checkArgument(operator != null, "operator is null");
return new LogicalExpression(operands, operator);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.hypertrace.core.documentstore.expression.impl;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import javax.validation.constraints.NotNull;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
Expand All @@ -25,17 +23,20 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class RelationalExpression implements FilteringExpression {

@NotNull SelectingExpression lhs;
SelectingExpression lhs;

@NotNull RelationalOperator operator;
RelationalOperator operator;

@NotNull SelectingExpression rhs;
SelectingExpression rhs;

public static RelationalExpression of(
final SelectingExpression lhs,
final RelationalOperator operator,
final SelectingExpression rhs) {
return validateAndReturn(new RelationalExpression(lhs, operator, rhs));
Preconditions.checkArgument(lhs != null, "lhs is null");
Preconditions.checkArgument(operator != null, "operator is null");
Preconditions.checkArgument(rhs != null, "rhs is null");
return new RelationalExpression(lhs, operator, rhs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.hypertrace.core.documentstore.query;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import com.google.common.base.Preconditions;
import java.util.List;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -16,11 +14,14 @@
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Aggregation {
@Singular @NotEmpty List<@NotNull GroupingExpression> expressions;
@Singular List<GroupingExpression> expressions;

public static class AggregationBuilder {
public Aggregation build() {
return validateAndReturn(new Aggregation(expressions));
Preconditions.checkArgument(!expressions.isEmpty(), "expressions is empty");
Preconditions.checkArgument(
expressions.stream().noneMatch(Objects::isNull), "One or more expressions is null");
return new Aggregation(expressions);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.hypertrace.core.documentstore.query;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import javax.validation.constraints.NotNull;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -13,11 +11,12 @@
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Filter {
@NotNull FilteringExpression expression;
FilteringExpression expression;

public static class FilterBuilder {
public Filter build() {
return validateAndReturn(new Filter(expression));
Preconditions.checkArgument(expression != null, "expression is null");
return new Filter(expression);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.hypertrace.core.documentstore.query;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import javax.validation.constraints.NotNull;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -12,12 +10,14 @@
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Pagination {
@NotNull Integer limit;
@NotNull Integer offset;
Integer limit;
Integer offset;

public static class PaginationBuilder {
public Pagination build() {
return validateAndReturn(new Pagination(limit, offset));
Preconditions.checkArgument(limit != null, "limit is null");
Preconditions.checkArgument(offset != null, "offset is null");
return new Pagination(limit, offset);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -230,14 +229,13 @@ public QueryBuilder setPagination(final Pagination pagination) {
}

public Query build() {
return validateAndReturn(
new Query(
getSelection(),
getFilter(),
getAggregation(),
getAggregationFilter(),
getSort(),
pagination));
return new Query(
getSelection(),
getFilter(),
getAggregation(),
getAggregationFilter(),
getSort(),
pagination);
}

protected Selection.SelectionBuilder getSelectionBuilder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.hypertrace.core.documentstore.query;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import com.google.common.base.Preconditions;
import java.util.List;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -15,11 +13,14 @@
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Selection {
@Singular @NotEmpty List<@NotNull SelectionSpec> selectionSpecs;
@Singular List<SelectionSpec> selectionSpecs;

public static class SelectionBuilder {
public Selection build() {
return validateAndReturn(new Selection(selectionSpecs));
Preconditions.checkArgument(!selectionSpecs.isEmpty(), "selectionSpecs is empty");
Preconditions.checkArgument(
selectionSpecs.stream().noneMatch(Objects::isNull), "One or more selectionSpecs is null");
return new Selection(selectionSpecs);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.hypertrace.core.documentstore.query;

import static org.hypertrace.core.documentstore.expression.Utils.validateAndReturn;

import javax.validation.constraints.NotNull;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
Expand All @@ -16,7 +14,7 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class SelectionSpec {

@NotNull SelectingExpression expression;
SelectingExpression expression;

// Alias is optional. Handling missing aliases can be implemented in the respective parsers
String alias;
Expand All @@ -26,6 +24,7 @@ public static SelectionSpec of(final SelectingExpression expression) {
}

public static SelectionSpec of(final SelectingExpression expression, final String alias) {
return validateAndReturn(new SelectionSpec(expression, alias));
Preconditions.checkArgument(expression != null, "expression is null");
return new SelectionSpec(expression, alias);
}
}
Loading

0 comments on commit 506300c

Please sign in to comment.