mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
moved image and video URL stuff from Event to EventBase so it can be included in REST API serialization/deserialization
This commit is contained in:
1 parent
a9eefe1622
commit
1bab76b12a
6 files changed
+146
-101
No files matched your search
+31
-1
@@ -1,7 +1,12 @@
|
||||
package com.sap.sailing.server.gateway.deserialization.impl;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
@@ -31,8 +36,33 @@ public class EventBaseJsonDeserializer implements JsonDeserializer<EventBase> {
|
||||
} else {
|
||||
venue = null;
|
||||
}
|
||||
return new EventBaseImpl(name, startDate == null ? null : new MillisecondsTimePoint(startDate.longValue()),
|
||||
EventBaseImpl result = new EventBaseImpl(name, startDate == null ? null : new MillisecondsTimePoint(startDate.longValue()),
|
||||
endDate == null ? null : new MillisecondsTimePoint(endDate.longValue()), venue, true, id);
|
||||
if (object.get(EventJsonSerializer.FIELD_IMAGE_URLS) != null) {
|
||||
try {
|
||||
result.setImageURLs(getURLsFromStrings(Helpers.getNestedArraySafe(object, EventJsonSerializer.FIELD_IMAGE_URLS)));
|
||||
} catch (MalformedURLException e) {
|
||||
throw new JsonDeserializationException("Error deserializing image URLs for event "+name, e);
|
||||
}
|
||||
}
|
||||
if (object.get(EventJsonSerializer.FIELD_VIDEO_URLS) != null) {
|
||||
try {
|
||||
result.setVideoURLs(getURLsFromStrings(Helpers.getNestedArraySafe(object, EventJsonSerializer.FIELD_VIDEO_URLS)));
|
||||
} catch (MalformedURLException e) {
|
||||
throw new JsonDeserializationException("Error deserializing video URLs for event "+name, e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Iterable<URL> getURLsFromStrings(JSONArray strings) throws MalformedURLException {
|
||||
List<URL> result = new ArrayList<URL>();
|
||||
if (strings != null) {
|
||||
for (Object string : strings) {
|
||||
result.add(new URL(string.toString()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+15
-2
@@ -1,5 +1,8 @@
|
||||
package com.sap.sailing.server.gateway.serialization.impl;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
@@ -12,6 +15,8 @@ public class EventJsonSerializer implements JsonSerializer<EventBase> {
|
||||
public static final String FIELD_START_DATE = "startDate";
|
||||
public static final String FIELD_END_DATE = "endDate";
|
||||
public static final String FIELD_VENUE = "venue";
|
||||
public static final String FIELD_IMAGE_URLS = "imageURLs";
|
||||
public static final String FIELD_VIDEO_URLS = "videoURLs";
|
||||
|
||||
private final JsonSerializer<Venue> venueSerializer;
|
||||
|
||||
@@ -22,13 +27,21 @@ public class EventJsonSerializer implements JsonSerializer<EventBase> {
|
||||
|
||||
public JSONObject serialize(EventBase event) {
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put(FIELD_ID, event.getId().toString());
|
||||
result.put(FIELD_NAME, event.getName());
|
||||
result.put(FIELD_START_DATE, event.getStartDate() != null ? event.getStartDate().asMillis() : null);
|
||||
result.put(FIELD_END_DATE, event.getStartDate() != null ? event.getEndDate().asMillis() : null);
|
||||
result.put(FIELD_VENUE, venueSerializer.serialize(event.getVenue()));
|
||||
|
||||
result.put(FIELD_IMAGE_URLS, getURLsAsStringArray(event.getImageURLs()));
|
||||
result.put(FIELD_VIDEO_URLS, getURLsAsStringArray(event.getVideoURLs()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private JSONArray getURLsAsStringArray(Iterable<URL> urls) {
|
||||
JSONArray jsonImageURLs = new JSONArray();
|
||||
for (URL url : urls) {
|
||||
jsonImageURLs.add(url.toString());
|
||||
}
|
||||
return jsonImageURLs;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user