Merge remote-tracking branch 'origin/ftes-tracking-app-only-snakecase-in-urls' into ftes-file-storage

This commit is contained in:
Fredrik Teschke committed 2015-01-23 11:39:30 +01:00
commit d450693cb7
8 files changed
+66 -38

No files matched your search

@@ -1,28 +1,40 @@
package com.sap.sailing.domain.common.racelog.tracking;
/**
* Shared between GWT and Android. Used for creating and deciphering the URL encoded by the QRCode, which gives the
* tracking app all necessary information for creating the device mapping of either the race or leaderboard/regatta.
* <p>
* The field that server for mapping a device for an individual race are deprecated (see {@link DeviceMappingOnRaceQRCodeWidget}).
* The field that server for mapping a device for an individual race are deprecated (see
* {@link DeviceMappingOnRaceQRCodeWidget}).
* <p>
* The structure of the URL is documented in the <a href="http://wiki.sapsailing.com/wiki/tracking-app-api-v1-draft">Wiki</a>.
* The structure of the URL is documented in the <a
* href="http://wiki.sapsailing.com/wiki/tracking-app-api-v1-draft">Wiki</a>.
* {@code http://<host>/tracking/checkin?event_id=<e>&leaderboard_name=<l>&competitor_id=<c>}
*
* @author Fredrik Teschke
*/
public interface DeviceMappingConstants {
// According to the HTTP protocol definition (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.3), only
// schema and host are case insensitive.
// But to adhere to best practices, and due to the deficiencies of some web servers and clients,
// all URL components should be treated as case insensitive, preferring _underscores_ to CamelCase.
static final String URL_BASE = "/tracking/checkin";
static final String EVENT_ID = "event_id";
static final String LEADERBOARD_NAME = "leaderboardName";
static final String COMPETITOR_ID_AS_STRING = "competitorId";
static final String MARK_ID_AS_STRING = "markId";
static final String DEVICE_UUID = "deviceUuid";
static final String DEVICE_TYPE = "deviceType";
static final String PUSH_DEVICE_ID = "pushDeviceId";
static final String FROM_MILLIS = "fromMillis";
static final String TO_MILLIS = "toMillis";
static final String URL_EVENT_ID = "event_id";
static final String URL_LEADERBOARD_NAME = "leaderboard_name";
static final String URL_COMPETITOR_ID_AS_STRING = "competitor_id";
static final String URL_MARK_ID_AS_STRING = "mark_id";
static final String URL_FROM_MILLIS = "from_millis";
static final String URL_TO_MILLIS = "to_millis";
static final String JSON_COMPETITOR_ID_AS_STRING = "competitorId";
static final String JSON_MARK_ID_AS_STRING = "markId";
static final String JSON_DEVICE_UUID = "deviceUuid";
static final String JSON_DEVICE_TYPE = "deviceType";
static final String JSON_PUSH_DEVICE_ID = "pushDeviceId";
static final String JSON_FROM_MILLIS = "fromMillis";
static final String JSON_TO_MILLIS = "toMillis";
static final String JSON_TEAM_IMAGE_URI = "teamImageUri";
@Deprecated
static final String APK_PATH = "/apps/com.sap.sailing.android.tracking.app.apk";
}
@@ -108,13 +108,13 @@ public class AddDeviceMappingToRaceLogDialog extends DataEntryDialog<DeviceMappi
new SelectionChangedHandler() {
@Override
public void onSelectionChange(MarkDTO mark) {
qrWidget.setMappedItem(DeviceMappingConstants.MARK_ID_AS_STRING, mark.getIdAsString());
qrWidget.setMappedItem(DeviceMappingConstants.URL_MARK_ID_AS_STRING, mark.getIdAsString());
validate();
}
@Override
public void onSelectionChange(CompetitorDTO competitor) {
qrWidget.setMappedItem(DeviceMappingConstants.COMPETITOR_ID_AS_STRING,
qrWidget.setMappedItem(DeviceMappingConstants.URL_COMPETITOR_ID_AS_STRING,
competitor.getIdAsString());
validate();
}
@@ -153,8 +153,8 @@ public class AddDeviceMappingToRaceLogDialog extends DataEntryDialog<DeviceMappi
+ RaceLogServletConstants.PARAMS_LEADERBOARD_NAME + "=" + DeviceMappingQRCodeWidget.encode(leaderboardName) + "&"
+ RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME + "=" + DeviceMappingQRCodeWidget.encode(raceColumnName)
+ "&" + RaceLogServletConstants.PARAMS_RACE_FLEET_NAME + "=" + DeviceMappingQRCodeWidget.encode(fleetName)
+ "&" + mappedItemQueryParam + "&" + DeviceMappingConstants.FROM_MILLIS + "=" + fromMillis
+ "&" + DeviceMappingConstants.TO_MILLIS + "=" + toMillis;
+ "&" + mappedItemQueryParam + "&" + DeviceMappingConstants.URL_FROM_MILLIS + "=" + fromMillis
+ "&" + DeviceMappingConstants.URL_TO_MILLIS + "=" + toMillis;
}
});
qrWidget.generateQRCode();
@@ -73,13 +73,13 @@ public class AddDeviceMappingToRegattaLogDialog extends AbstractCancelableDialog
new SelectionChangedHandler() {
@Override
public void onSelectionChange(MarkDTO mark) {
qrWidget.setMappedItem(DeviceMappingConstants.MARK_ID_AS_STRING, mark.getIdAsString());
qrWidget.setMappedItem(DeviceMappingConstants.URL_MARK_ID_AS_STRING, mark.getIdAsString());
qrWidget.generateQRCode();
}
@Override
public void onSelectionChange(CompetitorDTO competitor) {
qrWidget.setMappedItem(DeviceMappingConstants.COMPETITOR_ID_AS_STRING,
qrWidget.setMappedItem(DeviceMappingConstants.URL_COMPETITOR_ID_AS_STRING,
competitor.getIdAsString());
qrWidget.generateQRCode();
}
@@ -98,8 +98,8 @@ public class AddDeviceMappingToRegattaLogDialog extends AbstractCancelableDialog
}
String eventIdAsString = events.getValue().id.toString();
return baseUrlWithoutTrailingSlash + DeviceMappingConstants.URL_BASE
+ "?" + DeviceMappingConstants.EVENT_ID + "=" + DeviceMappingQRCodeWidget.encode(eventIdAsString)
+ "&" + DeviceMappingConstants.LEADERBOARD_NAME + "=" + DeviceMappingQRCodeWidget.encode(leaderboardName)
+ "?" + DeviceMappingConstants.URL_EVENT_ID + "=" + DeviceMappingQRCodeWidget.encode(eventIdAsString)
+ "&" + DeviceMappingConstants.URL_LEADERBOARD_NAME + "=" + DeviceMappingQRCodeWidget.encode(leaderboardName)
+ "&" + mappedItemQueryParam;
}
});
@@ -13,7 +13,8 @@ Require-Bundle: org.mockito.mockito-core;bundle-version="1.9.5",
org.junit4;bundle-version="4.8.2",
com.sap.sailing.domain.racelogtrackingadapter.testsupport;bundle-version="1.0.0",
com.sap.sse.common,
com.sun.jersey
com.sun.jersey,
org.apache.commons.io;bundle-version="2.2.0"
Import-Package: com.sap.sailing.domain.common.impl,
com.sap.sailing.domain.persistence.impl,
com.sap.sailing.server.impl
@@ -4,11 +4,17 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.junit.Test;
import com.sap.sailing.domain.base.impl.BoatClassImpl;
@@ -18,6 +24,7 @@ import com.sap.sailing.domain.base.impl.DynamicTeam;
import com.sap.sailing.domain.base.impl.NationalityImpl;
import com.sap.sailing.domain.base.impl.PersonImpl;
import com.sap.sailing.domain.base.impl.TeamImpl;
import com.sap.sailing.domain.common.racelog.tracking.DeviceMappingConstants;
import com.sap.sailing.server.gateway.jaxrs.api.TeamResource;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.impl.AmazonS3FileStorageServiceImpl;
@@ -45,7 +52,7 @@ public class TeamResourceTest extends AbstractJaxRsApiTest {
}
@Test
public void storeAndRemoveTeamImage() throws URISyntaxException {
public void storeAndRemoveTeamImage() throws URISyntaxException, ParseException, MalformedURLException, IOException {
//set team image
TeamResource r = new TeamResource();
long length = new File(new URI(getClass().getResource(teamImageFile).toString())).length();
@@ -54,9 +61,14 @@ public class TeamResourceTest extends AbstractJaxRsApiTest {
FormDataContentDisposition fileDetails = FormDataContentDisposition.name("file").size(length)
.fileName(teamImageFile).build();
r.setTeamImage(id, stream, fileDetails);
String jsonString = r.setTeamImage(id, stream, fileDetails);
//now download and compare
JSONObject json = (JSONObject) JSONValue.parseWithException(jsonString);
String imageUri = (String) json.get(DeviceMappingConstants.JSON_TEAM_IMAGE_URI);
InputStream downloadStream = new URI(imageUri).toURL().openStream();
stream = getClass().getResourceAsStream(teamImageFile);
IOUtils.contentEquals(downloadStream, stream);
}
}
@@ -363,11 +363,11 @@ public class LeaderboardsResource extends AbstractSailingServerResource {
.type(MediaType.TEXT_PLAIN).build();
}
MillisecondsTimePoint now = MillisecondsTimePoint.now();
String competitorId = (String) requestObject.get(DeviceMappingConstants.COMPETITOR_ID_AS_STRING);
String deviceUuid = (String) requestObject.get(DeviceMappingConstants.DEVICE_UUID);
Long fromMillis = (Long) requestObject.get(DeviceMappingConstants.FROM_MILLIS);
String deviceType = (String) requestObject.get(DeviceMappingConstants.DEVICE_TYPE);
String pushDeviceId = (String) requestObject.get(DeviceMappingConstants.PUSH_DEVICE_ID);
String competitorId = (String) requestObject.get(DeviceMappingConstants.URL_COMPETITOR_ID_AS_STRING);
String deviceUuid = (String) requestObject.get(DeviceMappingConstants.JSON_DEVICE_UUID);
Long fromMillis = (Long) requestObject.get(DeviceMappingConstants.JSON_FROM_MILLIS);
String deviceType = (String) requestObject.get(DeviceMappingConstants.JSON_DEVICE_TYPE);
String pushDeviceId = (String) requestObject.get(DeviceMappingConstants.JSON_PUSH_DEVICE_ID);
if (competitorId == null || deviceUuid == null || fromMillis == null || deviceType == null
|| pushDeviceId == null) {
logger.warning("Invalid JSON body in request");
@@ -21,6 +21,7 @@ import org.json.simple.JSONObject;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.Team;
import com.sap.sailing.domain.common.racelog.tracking.DeviceMappingConstants;
import com.sap.sailing.server.gateway.jaxrs.AbstractSailingServerResource;
import com.sap.sailing.server.gateway.serialization.impl.NationalityJsonSerializer;
import com.sap.sailing.server.gateway.serialization.impl.PersonJsonSerializer;
@@ -90,6 +91,8 @@ public class TeamResource extends AbstractSailingServerResource {
competitor.getBoat().getSailID(), competitor.getTeam().getNationality(), imageUri);
logger.log(Level.INFO, "Set team image for competitor " + competitor.getName());
return Response.status(Status.OK).build();
JSONObject result = new JSONObject();
result.put(DeviceMappingConstants.JSON_TEAM_IMAGE_URI, imageUri.toString());
return result.toString();
}
}
@@ -139,9 +139,9 @@ public class LaunchActivity extends BaseActivity {
}
prefs.setServerURL(server);
String leaderboard = uri.getQueryParameter(DeviceMappingConstants.LEADERBOARD_NAME);
String competitorIdAsString = uri.getQueryParameter(DeviceMappingConstants.COMPETITOR_ID_AS_STRING);
String markIdAsString = uri.getQueryParameter(DeviceMappingConstants.MARK_ID_AS_STRING);
String leaderboard = uri.getQueryParameter(DeviceMappingConstants.URL_LEADERBOARD_NAME);
String competitorIdAsString = uri.getQueryParameter(DeviceMappingConstants.URL_COMPETITOR_ID_AS_STRING);
String markIdAsString = uri.getQueryParameter(DeviceMappingConstants.URL_MARK_ID_AS_STRING);
DeviceIdentifier device = new SmartphoneUUIDIdentifierImpl(UUID.fromString(prefs.getDeviceIdentifier()));
TimePoint from = MillisecondsTimePoint.now();
String itemId = null;
@@ -149,15 +149,15 @@ public class LaunchActivity extends BaseActivity {
JSONObject mappingStart = new JSONObject();
try {
mappingStart.put(DeviceMappingConstants.DEVICE_UUID, device.getStringRepresentation());
mappingStart.put(DeviceMappingConstants.FROM_MILLIS, from.asMillis());
mappingStart.put(DeviceMappingConstants.DEVICE_TYPE, "android");
mappingStart.put(DeviceMappingConstants.JSON_DEVICE_UUID, device.getStringRepresentation());
mappingStart.put(DeviceMappingConstants.JSON_FROM_MILLIS, from.asMillis());
mappingStart.put(DeviceMappingConstants.JSON_DEVICE_TYPE, "android");
if (competitorIdAsString != null) {
mappingStart.put(DeviceMappingConstants.PUSH_DEVICE_ID, "<push_device_id_not_known_on_android>");
mappingStart.put(DeviceMappingConstants.COMPETITOR_ID_AS_STRING, competitorIdAsString);
mappingStart.put(DeviceMappingConstants.JSON_PUSH_DEVICE_ID, "<push_device_id_not_known_on_android>");
mappingStart.put(DeviceMappingConstants.JSON_COMPETITOR_ID_AS_STRING, competitorIdAsString);
itemType = "competitor";
} else if (markIdAsString != null) {
mappingStart.put(DeviceMappingConstants.MARK_ID_AS_STRING, markIdAsString);
mappingStart.put(DeviceMappingConstants.JSON_MARK_ID_AS_STRING, markIdAsString);
itemType = "mark";
}
} catch (IllegalArgumentException e) {