Skip to content

Commit 0b7031d

Browse files
committed
Force user to provide time stamp pattern to ensure harmonized parsing
1 parent f238fc1 commit 0b7031d

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/main/java/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSource.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class CouchbaseWeatherSource implements WeatherSource {
4646
private final CouchbaseConnector connector;
4747
private final IdCoordinateSource coordinateSource;
4848
private final String coordinateIdColumnName;
49+
private final String timeStampPattern;
4950

5051
/**
5152
* Instantiate a weather source utilising a connection to a couchbase instance obtained via the
@@ -57,13 +58,20 @@ public class CouchbaseWeatherSource implements WeatherSource {
5758
* @param coordinateSource Source to obtain actual coordinates from
5859
* @param weatherFactory Factory to transfer field to value mapping into actual java object
5960
* instances
61+
* @param timeStampPattern Pattern of time stamps to parse
6062
*/
6163
public CouchbaseWeatherSource(
6264
CouchbaseConnector connector,
6365
IdCoordinateSource coordinateSource,
64-
TimeBasedWeatherValueFactory weatherFactory) {
66+
TimeBasedWeatherValueFactory weatherFactory,
67+
String timeStampPattern) {
6568
this(
66-
connector, coordinateSource, DEFAULT_KEY_PREFIX, DEFAULT_NAMING_CONVENTION, weatherFactory);
69+
connector,
70+
coordinateSource,
71+
DEFAULT_KEY_PREFIX,
72+
DEFAULT_TIMESTAMP_PATTERN,
73+
DEFAULT_NAMING_CONVENTION,
74+
weatherFactory);
6775
}
6876

6977
/**
@@ -76,15 +84,22 @@ public CouchbaseWeatherSource(
7684
* @param weatherFactory Factory to transfer field to value mapping into actual java object
7785
* instances
7886
* @deprecated Use {@link CouchbaseWeatherSource#CouchbaseWeatherSource(CouchbaseConnector,
79-
* IdCoordinateSource, String, NamingConvention, TimeBasedWeatherValueFactory)} instead
87+
* IdCoordinateSource, String, String, NamingConvention, TimeBasedWeatherValueFactory)}
88+
* instead
8089
*/
8190
@Deprecated
8291
public CouchbaseWeatherSource(
8392
CouchbaseConnector connector,
8493
IdCoordinateSource coordinateSource,
8594
String keyPrefix,
8695
TimeBasedWeatherValueFactory weatherFactory) {
87-
this(connector, coordinateSource, keyPrefix, DEFAULT_NAMING_CONVENTION, weatherFactory);
96+
this(
97+
connector,
98+
coordinateSource,
99+
keyPrefix,
100+
DEFAULT_TIMESTAMP_PATTERN,
101+
DEFAULT_NAMING_CONVENTION,
102+
weatherFactory);
88103
}
89104

90105
/**
@@ -94,6 +109,7 @@ public CouchbaseWeatherSource(
94109
* @param connector Connector, that establishes the connection to the couchbase instance
95110
* @param coordinateSource Source to obtain actual coordinates from
96111
* @param keyPrefix Prefix of entries, that belong to weather
112+
* @param timeStampPattern Pattern of time stamps to parse
97113
* @param namingConvention the (case) convention, how columns are named
98114
* @param weatherFactory Factory to transfer field to value mapping into actual java object
99115
* instances
@@ -102,12 +118,14 @@ public CouchbaseWeatherSource(
102118
CouchbaseConnector connector,
103119
IdCoordinateSource coordinateSource,
104120
String keyPrefix,
121+
String timeStampPattern,
105122
NamingConvention namingConvention,
106123
TimeBasedWeatherValueFactory weatherFactory) {
107124
this.connector = connector;
108125
this.coordinateSource = coordinateSource;
109126
this.keyPrefix = keyPrefix;
110127
this.weatherFactory = weatherFactory;
128+
this.timeStampPattern = timeStampPattern;
111129
this.coordinateIdColumnName = weatherFactory.getCoordinateIdFieldString(namingConvention);
112130
}
113131

@@ -186,7 +204,7 @@ public Optional<TimeBasedValue<WeatherValue>> getWeather(ZonedDateTime date, Poi
186204
public String generateWeatherKey(ZonedDateTime time, Integer coordinateId) {
187205
String key = keyPrefix + "::";
188206
key += coordinateId + "::";
189-
key += time.format(DateTimeFormatter.ofPattern(DEFAULT_TIMESTAMP_PATTERN));
207+
key += time.format(DateTimeFormatter.ofPattern(timeStampPattern));
190208
return key;
191209
}
192210

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceCosmoIT.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements WeatherSour
6363
"--dataset", "file:///home/weather.json")
6464

6565
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
66-
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ssxxx"))
67-
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory)
66+
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
67+
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
68+
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
6869
}
6970

7071
def "The test container can establish a valid connection"() {

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceIconIT.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class CouchbaseWeatherSourceIconIT extends Specification implements WeatherSourc
6161
"--dataset", "file:///home/weather.json")
6262

6363
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
64-
def weatherFactory = new IconTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ssxxx"))
65-
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory)
64+
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
65+
def weatherFactory = new IconTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
66+
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
6667
}
6768

6869
def "The test container can establish a valid connection"() {

0 commit comments

Comments
 (0)