citerus / dddsample-core

This is the new home of the original DDD Sample app (previously hosted at sf.net)..
MIT License
4.92k stars 1.47k forks source link

Date parsing failure when assigning cargo to route #99

Closed wsargent closed 3 months ago

wsargent commented 1 year ago

I can get the application to error when booking cargo:

  1. Go to http://localhost:8080/dddsample/admin/list
  2. Click on book new cargo http://localhost:8080/dddsample/admin/registration
  3. Origin JNTKO Destination AUMEL, Select arrival deadline a couple of months out "03/06/2023" (not US-locale, it uses Europe Locale)
  4. Click book http://localhost:8080/dddsample/admin/show?trackingId=7FEB8AEE
  5. Says Not routed - so click "Route this cargo" - http://localhost:8080/dddsample/admin/selectItinerary?trackingId=7FEB8AEE
  6. Click first button, "assign cargo to this route"

See page with exception:

Sun Apr 23 14:13:04 PDT 2023
There was an unexpected error (type=Bad Request, status=400).
Validation failed for object='routeAssignmentCommand'. Error count: 10

The logs show:

Field error in object 'routeAssignmentCommand' on field 'legs[1].toDate': rejected value [2023-04-29 07:05]; codes [typeMismatch.routeAssignmentCommand.legs[1].toDate,typeMismatch.routeAssignmentCommand.legs.toDate,typeMismatch.legs[1].toDate,typeMismatch.legs.toDate,typeMismatch.toDate,typeMismatch.java.time.Instant,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [routeAssignmentCommand.legs[1].toDate,legs[1].toDate]; arguments []; default message [legs[1].toDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.Instant' for property 'legs[1].toDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.Instant] for value '2023-04-29 07:05'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2023-04-29 07:05]]

Running on Ubuntu 18, JDK 11

❱ java -version                 
Picked up JAVA_TOOL_OPTIONS: -XX:-UseBiasedLocking -Djdk.nio.maxCachedBufferSize=262144 -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints
openjdk version "11.0.14.1" 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)
wsargent commented 1 year ago

Looks like it's probably https://github.com/citerus/dddsample-core/blob/3f87e2ddbb27b7c62f174ebbc4ee588f52875b7c/src/main/resources/templates/admin/selectItinerary.html#L47

orende commented 1 year ago

Hi @wsargent ! I had a look at the PR but would like to see a test verifying the fix.

wsargent commented 1 year ago

Okay I will add thatOn May 11, 2023, at 5:28 AM, orende @.***> wrote: Hi @wsargent ! I had a look at the PR but would like to see a test verifying the fix.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

MakenChan commented 8 months ago

image public class InstDateEditor extends PropertyEditorSupport {

@Override
public void setAsText(@Nullable String text) throws IllegalArgumentException {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
    LocalDateTime dateTime = LocalDateTime.parse(text, formatter);
    setValue(dateTime.toInstant(ZoneOffset.UTC));
}

/**
 * Format the Date as String, using the specified DateFormat.
 */
@Override
public String getAsText() {
    Instant value = (Instant) getValue();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
    String formattedDateTime = formatter.format(value.atZone(ZoneOffset.UTC));
    return (value != null ? formattedDateTime : "");
}