in src/main/java/com/amazonaws/partners/saasfactory/metering/common/TenantConfiguration.java [156:207]
public static TenantConfiguration getTenantConfiguration(String tenantID, TableConfiguration tableConfig, DynamoDbClient ddb, Logger logger) {
Map<String, AttributeValue> compositeKey = new HashMap<>();
AttributeValue primaryKeyValue = AttributeValue.builder()
.s(formatTenantEntry(tenantID))
.build();
compositeKey.put(PRIMARY_KEY_NAME, primaryKeyValue);
AttributeValue sortKeyValue = AttributeValue.builder()
.s(CONFIG_SORT_KEY_VALUE)
.build();
compositeKey.put(SORT_KEY_NAME, sortKeyValue);
GetItemRequest request = GetItemRequest.builder()
.tableName(tableConfig.getTableName())
.key(compositeKey)
.build();
Map<String, AttributeValue> item;
try {
item = ddb.getItem(request).item();
} catch (ResourceNotFoundException e) {
logger.error("Table {} does not exist", tableConfig.getTableName());
return new TenantConfiguration();
} catch (InternalServerErrorException e) {
logger.error(e.getMessage());
return new TenantConfiguration();
}
TenantConfiguration tenant;
if (!item.isEmpty()) {
String externalSubscriptionIdentifier = item.get(EXTERNAL_SUBSCRIPTION_IDENTIFIER_ATTRIBUTE_NAME).s();
String invoiceClosingTime = item.getOrDefault(
CLOSING_INVOICE_TIME_ATTRIBUTE_NAME,
AttributeValue.builder()
.nul(true)
.build())
.s();
try {
tenant = new TenantConfiguration(
tenantID,
externalSubscriptionIdentifier,
invoiceClosingTime);
} catch (DateTimeParseException e) {
logger.error("Could not parse the invoice closing date for tenant {}", tenantID);
return new TenantConfiguration();
}
} else {
return new TenantConfiguration();
}
return tenant;
}