response.setContentType("text/plain");
MemcacheService ms = MemcacheServiceFactory.getMemcacheService();
ms.clearAll();
String chapterId = request.getParameter("id");
Chapter chapter = retrieveChapter(chapterId);
if (chapter == null) {
response.getWriter().println("Geocode update failed: chapter not found");
return;
}
response.getWriter().println(chapter.getName());
Point point = mapsService.getCoordinates(chapter.getCity(),
chapter.getState(), chapter.getCountry());
if (point == null) {
response.getWriter().println("Geocode update failed: point not found");
return;
} else {
chapter.setLatitude(point.getLatitude());
chapter.setLongitude(point.getLongitude());
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(chapter);
} catch (Exception e) {
response.getWriter().println("Geocode update failed: JDO error");
return;
} finally {
pm.close();
}
}
chapter = null;
chapter = retrieveChapter(chapterId);
if (chapter == null) {
response.getWriter().println("Geocode update failed: chapter not found");
return;
}
response.getWriter().println("Geocode update succeeded");
response.getWriter().println(point.getLatitude() + ", " + point.getLongitude());
response.getWriter().println(chapter.getLatitude() + ", " + chapter.getLongitude());
}