@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@Cacheable(lifetime = DefaultDynamo.LIFETIME, unit = TimeUnit.MINUTES)
public ConcurrentMap<URN, Domains> load() {
final ConcurrentMap<URN, Domains> domains =
new ConcurrentHashMap<URN, Domains>(0);
final AmazonDynamoDB amazon = this.client.get();
final ScanResult result = amazon.scan(new ScanRequest(this.table));
for (final Map<String, AttributeValue> item : result.getItems()) {
final String syslog;
if (item.containsKey(DefaultDynamo.SYSLOG)) {
syslog = item.get(DefaultDynamo.SYSLOG).getS();
} else {
syslog = "syslog.s3auth.com:514";
}
final String bucket;
if (item.containsKey(DefaultDynamo.BUCKET)) {
bucket = item.get(DefaultDynamo.BUCKET).getS();
} else {
bucket = item.get(DefaultDynamo.NAME).getS();
}
final URN user = URN.create(item.get(DefaultDynamo.USER).getS());
domains.putIfAbsent(user, new Domains());
domains.get(user).add(
new DefaultDomain(
item.get(DefaultDynamo.NAME).getS(),
item.get(DefaultDynamo.KEY).getS(),
item.get(DefaultDynamo.SECRET).getS(),
bucket,
item.get(DefaultDynamo.REGION).getS(),
syslog
)
);
}
amazon.shutdown();
return domains;
}