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

This commit is contained in:
Fredrik Teschke committed 2014-02-02 16:32:16 +01:00
commit 169b88f028
2 files changed
+6 -13

No files matched your search

@@ -1,9 +1,8 @@
package com.sap.sailing.domain.persistence.devices;
import com.mongodb.DBObject;
import com.sap.sailing.domain.devices.DeviceIdentifier;
public interface DeviceIdentifierPersistenceHandler {
DBObject store(DeviceIdentifier deviceIdentifier) throws IllegalArgumentException;
DeviceIdentifier load(DBObject input);
Object store(DeviceIdentifier deviceIdentifier) throws IllegalArgumentException;
DeviceIdentifier load(Object input);
}
@@ -1,7 +1,5 @@
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;
import com.sap.sailing.domain.persistence.devices.DeviceIdentifierPersistenceHandler;
@@ -9,23 +7,19 @@ import com.sap.sailing.domain.persistence.devices.DeviceIdentifierPersistenceHan
public class SmartphoneImeiHandlerImpl implements DeviceIdentifierPersistenceHandler {
// private static final Logger logger = Logger.getLogger(SmartphoneImeiHandlerImpl.class.getName());
public static final String FIELD_IMEI = "imei";
@Override
public DBObject store(DeviceIdentifier deviceIdentifier) throws IllegalArgumentException {
public Object 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;
result.put(FIELD_IMEI, imeiIdentifier.getImei());
return result;
return imeiIdentifier.getImei();
}
@Override
public SmartphoneImeiIdentifier load(DBObject input) {
return new SmartphoneImeiIdentifier((String) input.get(FIELD_IMEI));
public SmartphoneImeiIdentifier load(Object input) {
return new SmartphoneImeiIdentifier((String) input);
}
}