(Map<String, String>) api.getAllValidPublishedContents().object;
//check if tag + "_" + city is present
String tagForCity = tag + "_" + city;
if (all.containsKey(tagForCity)) {
return new APIResponse(Status.SUCCESS,
all.get(tagForCity), "content tag = [" + tagForCity + "]");
}
//check if tag + "_" + region is present
String tagForRegion = tag + "_" + region;
if (all.containsKey(tagForRegion)) {
return new APIResponse(Status.SUCCESS,
all.get(tagForRegion), "content tag = [" + tagForRegion + "]");
}
//check if tag + "_" + country is present
String tagForCountry = tag + "_" + country;
if (all.containsKey(tagForCountry)) {
return new APIResponse(Status.SUCCESS,
all.get(tagForCountry), "content tag = [" + tagForCountry + "]");
}
//or tag + "_" + default is present
String defaultTag = tag + "_default";
if (all.containsKey(defaultTag)) {
return new APIResponse(Status.SUCCESS, all.get(defaultTag),
"content tag = [" + defaultTag + "]");
}
//return resource not found error
APIResponse response = new APIResponse();
response.statusCode = Status.ERROR_RESOURCE_DOES_NOT_EXIST;
response.userFriendlyMessage = "Could find neither tag for city [" +
tagForCity + "] nor tag for region [" + tagForRegion +
"] nor tag for country [" + tagForCountry +
"] nor default tag [" + defaultTag + "]. <br>" +
"It could be that tags have empty content or content is not published.";
return response;
} catch (Exception ex) {
return new APIResponse(ex);
}
}