-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCustomConfiguration.java
More file actions
52 lines (42 loc) · 1.5 KB
/
CustomConfiguration.java
File metadata and controls
52 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package models;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.inject.Inject;
import play.Configuration;
import java.lang.reflect.Type;
import java.util.List;
/**
* Wrapper around normal Play Configuration with some convenience methods for
* parsing some application-specific objects, like:
* 1. the json list of initial lot capacities
* 2. the redis key that all our fields are namespaced to
*/
public class CustomConfiguration {
private Configuration configuration;
private Gson gson;
@Inject
public CustomConfiguration(Configuration configuration, Gson gson) {
this.configuration = configuration;
this.gson = gson;
}
public Configuration getConfiguration() {
return configuration;
}
public String getRedisKey() {
return configuration.getString("redis.hashmapkey");
}
public List<ParkingLot> getParkingLots() {
// Super hacky, stupid Play Framework api doesn't let you parse config easily
String jsonString = gson.toJson(configuration.asMap().get("lots"));
Type type = new TypeToken<List<ParkingLot>>() {
}.getType();
return gson.fromJson(jsonString, type);
}
public String getRedisPatternChannelsWildcard() {
return getRedisPatternChannelsPrefix() + "*";
}
public String getRedisPatternChannelsPrefix() {
return "__keyspace@" + String.valueOf(configuration.getInt("redis.database"))
+ "__:" + getRedisKey();
}
}