timestamp.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package java
  2. const timestampConstTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  3. {{- if $r.Const }}
  4. private final com.google.protobuf.Timestamp {{ constantName . "Const" }} = {{ tsLit $r.GetConst }};
  5. {{- end -}}
  6. {{- if $r.Lt }}
  7. private final com.google.protobuf.Timestamp {{ constantName . "Lt" }} = {{ tsLit $r.GetLt }};
  8. {{- end -}}
  9. {{- if $r.Lte }}
  10. private final com.google.protobuf.Timestamp {{ constantName . "Lte" }} = {{ tsLit $r.Lte }};
  11. {{- end -}}
  12. {{- if $r.Gt }}
  13. private final com.google.protobuf.Timestamp {{ constantName . "Gt" }} = {{ tsLit $r.GetGt }};
  14. {{- end -}}
  15. {{- if $r.Gte }}
  16. private final com.google.protobuf.Timestamp {{ constantName . "Gte" }} = {{ tsLit $r.GetGte }};
  17. {{- end -}}
  18. {{- if $r.Within }}
  19. private final com.google.protobuf.Duration {{ constantName . "Within" }} = {{ durLit $r.GetWithin }};
  20. {{- end -}}`
  21. const timestampTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  22. {{- template "required" . -}}
  23. {{- if $r.Const }}
  24. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ConstantValidation.constant("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Const" }});
  25. {{- end -}}
  26. {{- if and (or $r.Lt $r.Lte) (or $r.Gt $r.Gte)}}
  27. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.range("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ if $r.Lt }}{{ constantName . "Lt" }}{{ else }}null{{ end }}, {{ if $r.Lte }}{{ constantName . "Lte" }}{{ else }}null{{ end }}, {{ if $r.Gt }}{{ constantName . "Gt" }}{{ else }}null{{ end }}, {{ if $r.Gte }}{{ constantName . "Gte" }}{{ else }}null{{ end }}, com.google.protobuf.util.Timestamps.comparator());
  28. {{- else -}}
  29. {{- if $r.Lt }}
  30. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.lessThan("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Lt" }}, com.google.protobuf.util.Timestamps.comparator());
  31. {{- end -}}
  32. {{- if $r.Lte }}
  33. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.lessThanOrEqual("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Lte" }}, com.google.protobuf.util.Timestamps.comparator());
  34. {{- end -}}
  35. {{- if $r.Gt }}
  36. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.greaterThan("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Gt" }}, com.google.protobuf.util.Timestamps.comparator());
  37. {{- end -}}
  38. {{- if $r.Gte }}
  39. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.greaterThanOrEqual("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Gte" }}, com.google.protobuf.util.Timestamps.comparator());
  40. {{- end -}}
  41. {{- end -}}
  42. {{- if $r.LtNow }}
  43. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.lessThan("{{ $f.FullyQualifiedName }}", {{ accessor . }}, io.envoyproxy.pgv.TimestampValidation.currentTimestamp(), com.google.protobuf.util.Timestamps.comparator());
  44. {{- end -}}
  45. {{- if $r.GtNow }}
  46. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.greaterThan("{{ $f.FullyQualifiedName }}", {{ accessor . }}, io.envoyproxy.pgv.TimestampValidation.currentTimestamp(), com.google.protobuf.util.Timestamps.comparator());
  47. {{- end -}}
  48. {{- if $r.Within }}
  49. if ({{ hasAccessor . }}) io.envoyproxy.pgv.TimestampValidation.within("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Within" }}, io.envoyproxy.pgv.TimestampValidation.currentTimestamp());
  50. {{- end -}}
  51. `