(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));
}
//or tag + "_" + default is present
String defaultTag = tag + "_default";
if (all.containsKey(defaultTag)) {
return new APIResponse(Status.SUCCESS, all.get(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 default tag [" + defaultTag + "]. " +
"It could be that tags have empty content or content is not published.";
return response;
} catch (Exception ex) {
return new APIResponse(ex);
}
}