'Want to compare Timestamps in Drools
I am to receive a timestamp value and want to check it agains the current timeStamp value to make sure that the value I am getting is less of before the current time stamp.
the value being sent is in this format 2022-05-13 17:52:07
rule "effectiveTimestamp is in past "
when
$retail: DroolsDTO(pricingExecutionDetails.effectiveTimestamp != null &&
pricingExecutionDetails.effectiveTimestamp.compareTo(java.sql.Timestamp.from(Instant.now())) >= 0 )
$locale: Locale()
then
modify($retail) {
setIsValid(false),
getViolationList().add(source.getMessage(config.pastEffectiveTimestamp, null, $locale))
}
end
I think the java.sql.Timestamp.from(Instant.now()) has milli seconds attached to it - ex: 2022-05-13 19:14:21.371. am not sure if this matters when comparing
this is how the effectiveTimestamp field is defined in the DTO
@JsonProperty("effectiveTimestamp")
@JsonDeserialize(using = CustomDeserializer.class)
@JsonSerialize(using = CustomSerializer.class)
private Instant effectiveTimestamp;
this is the error I m getting
[2m2022-05-13 15:40:28.586[0;39m [33m WARN[0;39m [35m69147[0;39m [2m---[0;39m [2m[nio-8080-exec-3][0;39m [36m.w.s.m.s.DefaultHandlerExceptionResolver[0;39m [2m:[0;39m Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Text '2021-11-30 17:52:07' could not be parsed at index 10; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Text '2021-11-30 17:52:07' could not be parsed at index 10 (through reference chain: com.sams.pricing.rulesexecutor.dto.DroolsDTO["priceExecutionDetails"]->com.sams.pricing.execution.common.dto.PricingExecutionDetailsDTO["effectiveTimestamp"])]
(also I may have to change the >= 0 to < but thats just a side note still getting this parsing error )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|