// no available locations = no locations
if (asu.getLocations() == null || asu.getLocations().isEmpty()) {
StringBuilder msg = new StringBuilder("No location is configured for the asset ");
msg.append(asu.toLog());
msg.append(". Please add at least one location in the corresponding JSON file.");
throw new DandelionException(msg.toString());
}
// Selecting location key
String locationKey = null;
if (asu.getLocations().size() == 1) {
// use the unique location if needed
locationKey = asu.getLocations().entrySet().iterator().next().getKey();
}
else {
// otherwise search for the first matching location key among the
// configured ones
for (String searchedLocationKey : context.getConfiguration().getAssetLocationsResolutionStrategy()) {
if (asu.getLocations().containsKey(searchedLocationKey)) {
String location = asu.getLocations().get(searchedLocationKey);
if (location != null && !location.isEmpty()) {
locationKey = searchedLocationKey;
break;
}
}
}
}
LOG.trace("Location key '{}' selected for the asset {}", locationKey, asu.toString());
Map<String, AssetLocator> locators = context.getAssetLocatorsMap();
if (!locators.containsKey(locationKey)) {
StringBuilder msg = new StringBuilder("The location key '");
msg.append(locationKey);
msg.append("' is not valid. Please choose a valid one among ");
msg.append(locators.keySet());
msg.append(".");
throw new DandelionException(msg.toString());
}
// Otherwise check for the locator
String location = null;
AssetLocator locator = locators.get(locationKey);