boolean entityExists = false;
String entityKey = subscription.getSubscriptionKey();
if (entityKey == null || entityKey.length() == 0) {
KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
entityKey = keyGen.generate();
subscription.setSubscriptionKey(entityKey);
}
else {
// Per section 4.4: keys must be case-folded
entityKey = entityKey.toLowerCase();