public HashMap<String, HashMap<String, Object>> execute( HashMap<String, Object> params, HttpServletRequest request, HttpServletResponse response) throws Exception { Session session = loginUtil.getSessionFromRequestCookie(request); if (session == null) { return DBFluteUtil.setErrorMessage("セッションがありません。再度ログインして下さい。", params); } Login login = loginUtil.getLoginFromSession(session); HashMap<String, HashMap<String, Object>> res = loginUtil.checkLogin(session, params); if (res != null) { return res; } String op = (String) params.get("operationType"); if (op.equals("fetch")) { return fetchProc(params, request, session, login); } if (op.equals("update")) { return updateProc(params, request, session, login); } if (op.equals("remove")) { return deleteProc(params, request, session, login); } if (op.equals("add")) { return insertProc(params, request, session, login); } return null; }
private HashMap<String, HashMap<String, Object>> updateProc( HashMap<String, Object> params, HttpServletRequest request, Session session, Login login) throws Exception { @SuppressWarnings("unused") String screen = request.getParameter("screen"); Map<String, Object> updateInput = preProc(params); UserTable upd = null; try { upd = BeanUtil.copyMapToNewBean(updateInput, UserTable.class); } catch (Exception e) { ServiceUtil.mapToNewBeanExceptionAnalyze(e); } UserTable dbUserTable = em.find(UserTable.class, upd.getId()); if (dbUserTable == null) { throw new SystemException("id:" + upd.getId().toString() + " が見つかりません"); } if (!(upd.getTableName().equals(dbUserTable.getTableName()) && upd.getKey1().equals(dbUserTable.getKey1()) && upd.getKey2().equals(dbUserTable.getKey2())) && userTableCodeDupCheck(upd)) { return DBFluteUtil.setErrorMessage("このDataは既に使用されています。", params); } BeanUtil.copyBeanToBean(upd, dbUserTable, CopyOptionsUtil.excludeNull()); em.merge(dbUserTable); Map<String, Object> map = null; map = entityToMap(upd); return DBFluteUtil.setFetchResult(map, params); }
private HashMap<String, HashMap<String, Object>> insertProc( HashMap<String, Object> params, HttpServletRequest request, Session session, Login login) throws Exception { @SuppressWarnings("unused") String screen = request.getParameter("screen"); Map<String, Object> newin = preProc(params); UserTable newEntity = null; try { newEntity = BeanUtil.copyMapToNewBean(newin, UserTable.class); } catch (Exception e) { ServiceUtil.mapToNewBeanExceptionAnalyze(e); } if (userTableCodeDupCheck(newEntity)) { return DBFluteUtil.setErrorMessage("このDataは既に使用されています。", params); } HashMap<String, HashMap<String, Object>> res; em.persist(newEntity); Map<String, Object> map = null; map = entityToMap(newEntity); res = DBFluteUtil.setFetchResult(map, params); return res; }