@DefaultHandler public Resolution defaultResolution() throws AjaxException { log.info("FiltersDataAction"); try { conn = EntityManager.getConnection(); Dao<Filter, String> dao = DaoManager.createDao(conn, Filter.class); String string = new ObjectMapper() .configure(Feature.DEFAULT_VIEW_INCLUSION, false) .writerWithView(JsonViews.Filters.class) .writeValueAsString(dao.queryForEq("views_id", getView().getId())); log.info(string); return new StreamingResolution("text/json", string); } catch (Exception e) { e.printStackTrace(); getContext() .getValidationErrors() .add("entity", new SimpleError("unknown exception [" + e.getMessage() + "]")); throw new AjaxException(this, "filters", "data error"); } finally { try { conn.close(); } catch (SQLException e) { } } }
public Resolution register() throws AjaxException, RegisterException { log.info("RegisterAction.register() - Creating new user / userview"); // Object nextPage = getContext().getRequest().getSession().getAttribute("nextPage"); ConnectionSource conn = null; try { conn = EntityManager.getConnection(); /** Check that the view allows creating users */ Dao<View, String> vDao = DaoManager.createDao(conn, View.class); View view = vDao.queryForId(getView().getId().toString()); if (!view.getCreateUser()) { log.info(" View does not allow creating new users"); throw new AjaxException(this, "userView", "Create User Disabled"); } Dao<UserView, String> uvDao = DaoManager.createDao(conn, UserView.class); Dao<User, String> uDao = DaoManager.createDao(conn, User.class); /** * Try to create a user and userview If this fails there is likely already a user with the * same name and account */ try { log.info(" Creating new user in system: " + getAccount().getAlias()); User user = new User(); user.setAccount(getAccount()); user.setEmail(getEmail()); user.setName(getUsername()); user.setPassword(getPassword()); uDao.create(user); log.info(" Creating new userview in for: " + getView().getAlias()); UserView userView = new UserView(); userView.setUser(user); userView.setView(getView()); uvDao.create(userView); getContext().setUser(user); getContext().setAccessLevel(MyActionBeanContext.ACCESS_LEVEL_PASSWORD); /** User exists but nextPage was not specified. Redirect to the manager page */ if (getContext().getUser() != null && nextPage == null) { log.info(" User exists but nextpage is null - redirect to ManagerAction"); RedirectResolution resolution = new RedirectResolution(ManagerAction.class).includeRequestParameters(true); return resolution; } log.info(" Login successful - redirect to " + nextPage); RedirectResolution resolution = new RedirectResolution(getNextPage()); return resolution; } catch (SQLException x) { log.error("RegisterException", x); return new ErrorResolution( HttpServletResponse.SC_PRECONDITION_FAILED, "{\"result\":\"error\",\"message\":\"" + x.getMessage() + "\"}"); } } catch (Exception x) { x.printStackTrace(); log.error("RegisterException", x); getContext().getValidationErrors().add("entity", new SimpleError("create user error")); throw new RegisterException(this, getAccount(), getView(), "Exception encountered"); } finally { try { conn.close(); } catch (SQLException e) { } } }