private void delete(HttpServletRequest request, HttpServletResponse response) throws IOException { String id = null; Integer idIndex = 0; final AccessLevelManager layerManager = new AccessLevelManager(HibernateUtil.getCurrentSession()); boolean rollback = false; while ((id = request.getParameter("ids[" + idIndex + "][id]")) != null) { try { layerManager.delete(id); } catch (ObjectNotFoundException e) { response.getWriter().print(NOTFOUND_MESSAGE); rollback = true; break; } catch (RuntimeException e) { rollback = true; response.getWriter().print(ERROR_MESSAGE); break; } finally { idIndex++; } } if (rollback == true) { HibernateUtil.getCurrentSession().getTransaction().rollback(); } else { response.getWriter().print(OK_MESSAGE); } response.getWriter().flush(); }
private void update(HttpServletRequest request, HttpServletResponse response) throws IOException { final AccessLevelManager accessLevelManager = new AccessLevelManager(HibernateUtil.getCurrentSession()); try { AccessLevel accessLevel = this.retrieveObjectFromRequest(request); accessLevelManager.update(accessLevel); response.getWriter().print(OK_MESSAGE); } catch (ObjectNotFoundException e) { response.getWriter().print(NOTFOUND_MESSAGE); } catch (RuntimeException e) { response.getWriter().print(ERROR_MESSAGE); } finally { response.getWriter().flush(); } }
public AccessLevel loadObject(HttpServletRequest request, AccessLevelManager accessLevelManager) { String name = request.getParameter("name"); if (name == null || name.equals("")) { throw new RuntimeException("No name attribute specified"); } final AccessLevel accessLevel = accessLevelManager.getById(name); return accessLevel; }
private void readAll(HttpServletRequest request, HttpServletResponse response) throws IOException { final AccessLevelManager accessLevelManager = new AccessLevelManager(HibernateUtil.getCurrentSession()); final List<AccessLevel> accessLevels = accessLevelManager.readAll(); JSONSerializer serializer = new JSONSerializer(); final StringBuilder jsonLayersBuilder = new StringBuilder(); serializer .rootName("objects") .include("layers") .exclude("*.class") .serialize(accessLevels, jsonLayersBuilder); response.setContentType("application/json"); response.getWriter().println(jsonLayersBuilder.toString()); response.getWriter().flush(); }
private void create(HttpServletRequest request, HttpServletResponse response) throws IOException { final String name = request.getParameter("name"); if (name != null) { final AccessLevelManager accessLevelManager = new AccessLevelManager(HibernateUtil.getCurrentSession()); try { AccessLevel accessLevel = this.retrieveObjectFromRequest(request); accessLevelManager.create(accessLevel); response.getWriter().print(OK_MESSAGE); } catch (ObjectDuplicateException e) { response.getWriter().print(DUPLICATE_MESSAGE); } catch (RollbackException e) { response.getWriter().print(ERROR_MESSAGE); } finally { response.getWriter().flush(); } } }