Merge branch 'devicetype-identifier' into gpsfixstore-independent-of-race

This commit is contained in:
Fredrik Teschke committed 2014-02-02 16:26:01 +01:00
commit 8beae543ab
2 files changed
+8 -14

No files matched your search

@@ -4,14 +4,6 @@ import com.mongodb.DBObject;
import com.sap.sailing.domain.devices.DeviceIdentifier;
public interface DeviceIdentifierPersistenceHandler {
/**
* Enrich the base object with the necessary data for this specific
* device identifier type.
* @param base
* @param deviceIdentifiers
* @return
*/
DBObject enrichDBObject(DBObject base, DeviceIdentifier deviceIdentifier) throws IllegalArgumentException;
DeviceIdentifier loadFromDBObject(DBObject input);
DBObject store(DeviceIdentifier deviceIdentifier) throws IllegalArgumentException;
DeviceIdentifier load(DBObject input);
}
@@ -1,5 +1,6 @@
package com.sap.sailing.domain.smartphoneadapter.impl;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.sap.sailing.domain.devices.DeviceIdentifier;
import com.sap.sailing.domain.devices.SmartphoneImeiIdentifier;
@@ -11,19 +12,20 @@ public class SmartphoneImeiHandlerImpl implements DeviceIdentifierPersistenceHan
public static final String FIELD_IMEI = "imei";
@Override
public DBObject enrichDBObject(DBObject base, DeviceIdentifier deviceIdentifier) throws IllegalArgumentException {
public DBObject store(DeviceIdentifier deviceIdentifier) throws IllegalArgumentException {
if (!(deviceIdentifier instanceof SmartphoneImeiIdentifier)) {
throw new IllegalArgumentException(String.format(
"Unexpected device identifier of type %s while trying to persist smartphone IMEI identifier",
deviceIdentifier.getClass().getName()));
}
DBObject result = new BasicDBObject();
SmartphoneImeiIdentifier imeiIdentifier = (SmartphoneImeiIdentifier) deviceIdentifier;
base.put(FIELD_IMEI, imeiIdentifier.getImei());
return base;
result.put(FIELD_IMEI, imeiIdentifier.getImei());
return result;
}
@Override
public SmartphoneImeiIdentifier loadFromDBObject(DBObject input) {
public SmartphoneImeiIdentifier load(DBObject input) {
return new SmartphoneImeiIdentifier((String) input.get(FIELD_IMEI));
}
}