}
private HashMap<String, Object> getDataFromCache(Long courseId, Locale locale) throws Exception {
HashMap<Long, HashMap<String, Object>> courses = null;
HashMap<String, Object> courseData = null;
MemcacheService syncCache = null;
boolean cached = false;
try {
syncCache = MemcacheServiceFactory.getMemcacheService("test-"+locale.getLanguage());
} catch(Exception e) {
LOGGER.severe("Error getting cache for towns by name map: ");
LOGGER.severe(StackTraceUtil.getStackTrace(e));
}
try {
courses = (HashMap<Long, HashMap<String, Object>>)syncCache.get("coursesData");
} catch(InvalidValueException e) {
LOGGER.severe(StackTraceUtil.getStackTrace(e));
}
if(courses == null) {
courses = new HashMap<Long, HashMap<String, Object>>();
}
courseData = courses.get(courseId);
if(courseData == null) {
courseData = new HashMap<String, Object>();
Course course = this.serviceLocator.getCourseService().getCourse(courseId, locale);
School school = this.serviceLocator.getSchoolService().getSchool(course.getSchool(), locale);
Provider provider = this.serviceLocator.getProviderService().getProviderById(school.getProvider(), locale);
String townName = school.getContactInfo() != null &&
school.getContactInfo().getCity() != null ?
school.getContactInfo().getCity() : "";
//Town town = this.getTownByName(townName, locale);
Town town = this.serviceLocator.getTerritorialService().getTownsMap(locale).get(townName);
Province province = new Province();
Region region = new Region();
if(town != null && town.getId() != null) {
region = this.serviceLocator.getTerritorialService().getRegionsMap(locale).get(town.getRegion());
province = this.serviceLocator.getTerritorialService().getProvincesMap(locale).get(town.getProvince());
} else {
town = new Town();
}
// Metadata
StringBuffer keyWords = new StringBuffer();
for(Category tag : course.getTags()) {
keyWords.append(tag.getCategory()).append(",");
}
// Create courseData
courseData.put("provider", provider);
courseData.put("school", school);
courseData.put("course", course);
courseData.put("province", province);
courseData.put("region", region);
courseData.put("town", town);
courseData.put("tags", keyWords.toString());
courses.put(courseId, courseData);
//Store in cache
syncCache.put("coursesData", courses);
} else {
LOGGER.log(Level.INFO, "CourseData from cache!!!!!!!");
}