use persisted string representation when loading from mongodb

This commit is contained in:
Papick Garcia Taboada committed 2017-02-02 17:23:51 +01:00
1 parent bcabc7b592
commit f7a9c64ab8
2 files changed
+26 -3

No files matched your search

@@ -24,7 +24,7 @@ public class TrackFileImportDeviceIdentifierMongoHandler implements DeviceIdenti
String trackName = (String) dbObject.get(Fields.TRACK_NAME.name());
TimePoint uploaded = TrackFileImportDeviceIdentifierJsonHandler.
loadTimePoint(dbObject.get(Fields.UPLOADED_MILLIS.name()));
return new TrackFileImportDeviceIdentifierImpl(uuid, fileName, trackName, uploaded);
return new TrackFileImportDeviceIdentifierImpl(uuid, stringRepresentation, fileName, trackName, uploaded);
}
@Override
@@ -15,6 +15,7 @@ public class TrackFileImportDeviceIdentifierImpl implements TrackFileImportDevic
private final String fileName;
private final String trackName;
private final TimePoint timePoint;
private final String stringRepresentation;
private static final ConcurrentMap<UUID, TrackFileImportDeviceIdentifier> cache = new ConcurrentHashMap<>();
@@ -30,10 +31,18 @@ public class TrackFileImportDeviceIdentifierImpl implements TrackFileImportDevic
}
public TrackFileImportDeviceIdentifierImpl(UUID id, String fileName, String trackName, TimePoint timePoint) {
this(id, computeStringRepresentation(id, trackName, fileName, timePoint), fileName,
trackName, timePoint);
cache.put(id, this);
}
public TrackFileImportDeviceIdentifierImpl(UUID id, String stringRepresentation, String fileName, String trackName,
TimePoint timePoint) {
this.id = id;
this.fileName = fileName;
this.trackName = trackName;
this.timePoint = timePoint;
this.stringRepresentation = stringRepresentation;
cache.put(id, this);
}
@@ -54,8 +63,7 @@ public class TrackFileImportDeviceIdentifierImpl implements TrackFileImportDevic
@Override
public String getStringRepresentation() {
return String.format("%s: %s\n @%s(uploaded %s)",
id.toString(), trackName, fileName, timePoint);
return stringRepresentation;
}
@Override
@@ -92,4 +100,19 @@ public class TrackFileImportDeviceIdentifierImpl implements TrackFileImportDevic
}
return (TrackFileImportDeviceIdentifier) deviceIdentifier;
}
/**
* Computes unique string representation for this device identifier. This string representaion should be human
* readable.
*
* @param id
* @param fileName
* @param trackName
* @param timePoint
* @return
*/
private static final String computeStringRepresentation(UUID id, String fileName, String trackName,
TimePoint timePoint) {
return String.format("%s: %s\n @%s(uploaded %s)", id.toString(), trackName, fileName, timePoint);
}
}