From 5210055db2f00f42fea4717b2726dda52e1c1a59 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 15 May 2020 14:46:15 -0400 Subject: Cannot parse finishTime in legacy SO responses Adding the actual sample responses to the SO simulator broke the drools-apps junit for usecases. Fixed (in theory) by updating the legacy SO actor to properly decode the finishTime. Refactored the new SO actor, extracting the type adapter into its own class file so it could be shared between the new and legacy actors. Issue-ID: POLICY-2570 Change-Id: I061b603172440b1a91da16d09b4f2a0d289dfc41 Signed-off-by: Jim Hahn --- .../policy/controlloop/actor/so/SoOperation.java | 47 +--------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'models-interactions/model-actors/actor.so/src/main') diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java index 2a00edda4..a26f6a77f 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java @@ -22,15 +22,7 @@ package org.onap.policy.controlloop.actor.so; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -68,6 +60,7 @@ import org.onap.policy.so.SoRequestInfo; import org.onap.policy.so.SoRequestParameters; import org.onap.policy.so.SoRequestStatus; import org.onap.policy.so.SoResponse; +import org.onap.policy.so.util.SoLocalDateTimeTypeAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -498,44 +491,6 @@ public abstract class SoOperation extends HttpOperation { return coder; } - /* - * TODO: combine this adapter with existing LocalDateTimeTypeAdapter and eliminate the - * following two classes. - */ - - /** - * GSON Type Adapter for "LocalDateTime" fields, that uses the standard - * RFC_1123_DATE_TIME formatter. - */ - private static class SoLocalDateTimeTypeAdapter extends TypeAdapter { - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.RFC_1123_DATE_TIME; - - @Override - public LocalDateTime read(JsonReader in) throws IOException { - try { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } else { - return LocalDateTime.parse(in.nextString(), FORMATTER); - } - - } catch (DateTimeParseException e) { - throw new JsonParseException("invalid date", e); - } - } - - @Override - public void write(JsonWriter out, LocalDateTime value) throws IOException { - if (value == null) { - out.nullValue(); - } else { - String text = value.format(FORMATTER); - out.value(text); - } - } - } - private static class SoCoder extends StandardCoder { /** -- cgit 1.2.3-korg