use same logic to strip off "random" parameter from TracTrac paramsURL when computing restore key

Change-Id: I6cf45ec159830af0b5e2d273a12cfadccdbe955d
This commit is contained in:
Axel Uhl committed 2017-12-20 00:55:01 +01:00
1 parent de70631ede
commit 3cdcbb15b3
5 files changed
+22 -10

No files matched your search

@@ -1,6 +1,7 @@
package com.sap.sailing.domain.persistence;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
@@ -167,7 +168,7 @@ public interface MongoObjectFactory {
*
* @see #addConnectivityParametersForRaceToRestore(RaceTrackingConnectivityParameters)
*/
void removeConnectivityParametersForRaceToRestore(RaceTrackingConnectivityParameters params);
void removeConnectivityParametersForRaceToRestore(RaceTrackingConnectivityParameters params) throws MalformedURLException;
/**
* Updates the database such that the next call to
@@ -1,6 +1,7 @@
package com.sap.sailing.domain.persistence.impl;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -1590,7 +1591,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
}
@Override
public void removeConnectivityParametersForRaceToRestore(RaceTrackingConnectivityParameters params) {
public void removeConnectivityParametersForRaceToRestore(RaceTrackingConnectivityParameters params) throws MalformedURLException {
if (raceTrackingConnectivityParamsServiceFinder != null) {
final String typeIdentifier = params.getTypeIdentifier();
final RaceTrackingConnectivityParametersHandler paramsPersistenceService = raceTrackingConnectivityParamsServiceFinder.findService(typeIdentifier);
@@ -1620,11 +1621,13 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
DBObject key = new BasicDBObject();
key.putAll(paramsPersistenceService.getKey(params));
DBObject dbObject = new BasicDBObject();
dbObject.putAll(paramsPersistenceService.mapFrom(params)); // TODO bug 4402: should we use the Tracker ID as key here to avoid duplicates?
dbObject.putAll(paramsPersistenceService.mapFrom(params));
collection.update(key, dbObject, /* upsert */ true, /* multi */ false, WriteConcern.SAFE);
} catch (NoCorrespondingServiceRegisteredException e) {
logger.log(Level.WARNING, "Couldn't find a persistence service for connectivity parameters of type "+typeIdentifier+
". Couldn't store race "+params.getTrackerID()+" for restoring.", e);
} catch (MalformedURLException e) {
logger.log(Level.WARNING, "Issue with reading a URL from the tracking params for tracker "+params.getTrackerID()+" for restoring.", e);
}
}
}
@@ -1,5 +1,6 @@
package com.sap.sailing.domain.tractracadapter.persistence.impl;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
@@ -12,6 +13,7 @@ import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
import com.sap.sailing.domain.tracking.impl.AbstractRaceTrackingConnectivityParametersHandler;
import com.sap.sailing.domain.tractracadapter.DomainFactory;
import com.sap.sailing.domain.tractracadapter.impl.RaceTrackingConnectivityParametersImpl;
import com.sap.sailing.domain.tractracadapter.impl.TracTracRaceTrackerImpl;
import com.sap.sse.common.TypeBasedServiceFinder;
import com.sap.sse.common.impl.MillisecondsDurationImpl;
import com.sap.sse.common.impl.MillisecondsTimePoint;
@@ -52,7 +54,7 @@ public class TracTracConnectivityParamsHandler extends AbstractRaceTrackingConne
}
@Override
public Map<String, Object> mapFrom(RaceTrackingConnectivityParameters params) {
public Map<String, Object> mapFrom(RaceTrackingConnectivityParameters params) throws MalformedURLException {
assert params instanceof RaceTrackingConnectivityParametersImpl;
final RaceTrackingConnectivityParametersImpl ttParams = (RaceTrackingConnectivityParametersImpl) params;
final Map<String, Object> result = getKey(params);
@@ -94,12 +96,12 @@ public class TracTracConnectivityParamsHandler extends AbstractRaceTrackingConne
}
@Override
public Map<String, Object> getKey(RaceTrackingConnectivityParameters params) {
public Map<String, Object> getKey(RaceTrackingConnectivityParameters params) throws MalformedURLException {
assert params instanceof RaceTrackingConnectivityParametersImpl;
final RaceTrackingConnectivityParametersImpl ttParams = (RaceTrackingConnectivityParametersImpl) params;
final Map<String, Object> result = new HashMap<>();
result.put(TypeBasedServiceFinder.TYPE, params.getTypeIdentifier());
result.put(PARAM_URL, ttParams.getParamURL().toString());
result.put(PARAM_URL, TracTracRaceTrackerImpl.getParamURLStrippedOfRandomParam(new URL(ttParams.getParamURL().toString())));
return result;
}
}
@@ -462,7 +462,12 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl
return trackedRegatta;
}
public static Object createID(URL paramURL, URI liveURI, URI storedURI) {
public static Object createID(URL paramURL, final URI liveURI, final URI storedURI) {
URL paramURLStrippedOfRandomParam = getParamURLStrippedOfRandomParam(paramURL);
return new Util.Triple<URL, URI, URI>(paramURLStrippedOfRandomParam, liveURI, storedURI);
}
public static URL getParamURLStrippedOfRandomParam(URL paramURL) {
URL paramURLStrippedOfRandomParam;
if (paramURL == null) {
paramURLStrippedOfRandomParam = null;
@@ -498,7 +503,7 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl
}
}
}
return new Util.Triple<URL, URI, URI>(paramURLStrippedOfRandomParam, liveURI, storedURI);
return paramURLStrippedOfRandomParam;
}
@Override
@@ -1,5 +1,6 @@
package com.sap.sailing.domain.tracking;
import java.net.MalformedURLException;
import java.util.Map;
import java.util.UUID;
@@ -26,7 +27,7 @@ public interface RaceTrackingConnectivityParametersHandler {
* The types of the value objects must be restricted to thos types that MongoDB can handle as field values,
* in particular {@link String}, {@link Number} and {@link UUID}.
*/
Map<String, Object> mapFrom(RaceTrackingConnectivityParameters params);
Map<String, Object> mapFrom(RaceTrackingConnectivityParameters params) throws MalformedURLException;
/**
* Produces a {@link RaceTrackingConnectivityParameters} object from the contents of {@code map}, ignoring the
@@ -45,5 +46,5 @@ public interface RaceTrackingConnectivityParametersHandler {
* {@link RaceTrackingConnectivityParameters#getTypeIdentifier()} as well as a non-empty set of further
* entries that uniquely identify the {@code params} object in the database, in particular for removing.
*/
Map<String, Object> getKey(RaceTrackingConnectivityParameters params);
Map<String, Object> getKey(RaceTrackingConnectivityParameters params) throws MalformedURLException;
}