From 0cd244443033d832bb80ddb00efd1cff1f3cfce3 Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sat, 1 Jun 2024 23:28:27 +0700 Subject: [PATCH] :recycle: refactor: update base model #3 --- .../unify4j/model/filter/DateTimeFilter.java | 46 +++++++++++++++++++ .../model/request/IDecisionRequest.java | 6 +++ .../unify4j/model/response/WrapResponse.java | 7 +-- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 plugin/src/main/groovy/org/unify4j/model/filter/DateTimeFilter.java diff --git a/plugin/src/main/groovy/org/unify4j/model/filter/DateTimeFilter.java b/plugin/src/main/groovy/org/unify4j/model/filter/DateTimeFilter.java new file mode 100644 index 0000000..b1f2c76 --- /dev/null +++ b/plugin/src/main/groovy/org/unify4j/model/filter/DateTimeFilter.java @@ -0,0 +1,46 @@ +package org.unify4j.model.filter; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.unify4j.common.Time4j; + +import java.io.Serializable; +import java.util.Date; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class DateTimeFilter implements Serializable { + public DateTimeFilter() { + super(); + } + + public DateTimeFilter(Date from, Date to) { + super(); + this.from = from; + this.to = to; + } + + private Date from; + private Date to; + + public Date getFrom() { + return from; + } + + public void setFrom(Date from) { + this.from = from; + } + + public Date getTo() { + return to; + } + + public void setTo(Date to) { + this.to = to; + } + + @Override + public String toString() { + return String.format("DateTime filtering { from: '%s', to: '%s' }", Time4j.format(from), Time4j.format(to)); + } +} diff --git a/plugin/src/main/groovy/org/unify4j/model/request/IDecisionRequest.java b/plugin/src/main/groovy/org/unify4j/model/request/IDecisionRequest.java index 0141549..4ab710c 100644 --- a/plugin/src/main/groovy/org/unify4j/model/request/IDecisionRequest.java +++ b/plugin/src/main/groovy/org/unify4j/model/request/IDecisionRequest.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import org.unify4j.common.Json4j; import java.io.Serializable; @@ -52,4 +53,9 @@ public String getLabel() { public void setLabel(String label) { this.label = label; } + + @Override + public String toString() { + return String.format("IDecision request { label: '%s', enabled: %s, value: %s }", label, enabled, Json4j.toJson(value)); + } } diff --git a/plugin/src/main/groovy/org/unify4j/model/response/WrapResponse.java b/plugin/src/main/groovy/org/unify4j/model/response/WrapResponse.java index ab76395..88130ba 100644 --- a/plugin/src/main/groovy/org/unify4j/model/response/WrapResponse.java +++ b/plugin/src/main/groovy/org/unify4j/model/response/WrapResponse.java @@ -1,8 +1,6 @@ package org.unify4j.model.response; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import org.unify4j.common.Json4j; import org.unify4j.model.builder.HttpStatusBuilder; @@ -16,6 +14,7 @@ public WrapResponse() { super(); } + @JsonAlias({"code", "http_code", "status_http_code"}) @JsonProperty("status_code") private int statusCode; @JsonProperty("message") @@ -101,10 +100,12 @@ public void setPagination(PaginationResponse pagination) { this.pagination = pagination; } + @JsonIgnore public boolean isError() { return this.errors != null; } + @JsonIgnore public boolean isSuccess() { return this.statusCode >= HttpStatusBuilder.OK.getCode() && this.statusCode < HttpStatusBuilder.MULTIPLE_CHOICES.getCode(); }