@Override public Item insert(Item i) { if (!ItemDaoValidator.save(i)) { log.error("insert item failed:"); log.error(i); throw new IllegalParameterException(); } return dao.insert(i); }
// @RequestMapping(value = "queryAllRoleList", method = { RequestMethod.POST }) public String queryAllRoleList(HttpServletRequest request, HttpServletResponse response) { int page = Integer.parseInt(request.getParameter("page")); // 当前页数 int rows = Integer.parseInt(request.getParameter("rows")); // 每页多少行 int startNum = page * rows - rows; // 分页查询开始位置 String roleJsonStr = ""; Datagrid datagrid = new Datagrid(); int roleTotalCount = roleService.queryRoleTotalCount(); // 统计角色数量 List<Role> roleList = roleService.quryAllRoleList(startNum, rows); // 查询角色列表 datagrid.setRows(roleList); datagrid.setTotal(roleTotalCount); try { // 将查询的角色集合list转换成json格式字符串 roleJsonStr = Json.toJson(datagrid); // JsonUtils.objectToJackson(datagrid, Datagrid.class); PrintWriter out = response.getWriter(); out.print(roleJsonStr); out.flush(); out.close(); request.setAttribute("roleJsonStr", roleJsonStr); } catch (Exception e) { log.error("处理json数据报错:" + e.getStackTrace()); } log.info(roleJsonStr); return null; }
// @RequestMapping(value="getRoleByRoleName",method={RequestMethod.POST}) public String getRoleByRoleName( HttpServletRequest request, HttpServletResponse response, String roleName) { int page = Integer.parseInt(request.getParameter("page")); // 当前页数 int rows = Integer.parseInt(request.getParameter("rows")); // 每页多少行 int startNum = page * rows - rows; // 分页查询开始位置 List<Role> roles = roleService.getRoleByRoleName(roleName, startNum, rows); int rolesTotalCountByRoleName = roleService.getRolesTotalCountByRoleName(roleName); Datagrid datagrid = new Datagrid(); datagrid.setRows(roles); datagrid.setTotal(rolesTotalCountByRoleName); String rolesJsonStr = ""; try { rolesJsonStr = Json.toJson( datagrid); // JsonUtils.objectToJackson(datagrid, Datagrid.class);// 将对象转换成json字符串 PrintWriter out = response.getWriter(); out.print(rolesJsonStr); out.flush(); out.close(); } catch (Exception e) { log.error("处理json数据报错:" + e.getStackTrace()); } return null; }
@SuppressWarnings({"unchecked"}) public void init() throws FileNotFoundException { File config = Files.findFile("auth.json"); if (null == config) { log.error("Can not find path:[classpath:auth.json]"); throw new FileNotFoundException("[classpath:auth.json]"); } FileReader reader = new FileReader(config); authMap = new LinkedHashMap<String, Integer>(); authMap = Json.fromJson(authMap.getClass(), reader); log.info("Get url mapping:[" + authMap + "]"); patternMap = new LinkedHashMap<String, Pattern>(); if (!authMap.isEmpty()) { for (String url : authMap.keySet()) { patternMap.put(url, Pattern.compile(url)); } } excludePaths = new HashSet<String>(); Collections.addAll( excludePaths, PropertiesReader.getProperties("doe.url.pass").trim().split(",")); // System.out.println(Json.toJson(excludePaths)); }
@At("/?/json") @Ok("raw") public ObjectNode getEditorJson(String modelId) { ObjectNode modelNode = null; Model model = repositoryService.getModel(modelId); if (model != null) { try { ObjectMapper objectMapper = new ObjectMapper(); if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); } else { modelNode = objectMapper.createObjectNode(); modelNode.put(ModelDataJsonConstants.MODEL_NAME, model.getName()); } modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId()); ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree( new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")); modelNode.put("model", editorJsonNode); } catch (Exception e) { log.error("Error creating model JSON", e); throw new ActivitiException("Error creating model JSON", e); } } return modelNode; }
// @RequestMapping(value = "validataRoleName", method = { RequestMethod.POST }) public void validataRoleName(HttpServletResponse response, String roleName) { int i = roleService.valiedateRoleName(roleName); String ok = i + ""; try { PrintWriter out = response.getWriter(); out.write(ok); out.flush(); out.close(); } catch (IOException e) { log.error("处理数据报错:" + e.getStackTrace()); } }
// @RequestMapping(value = "deleteRoles", method = { RequestMethod.GET }) public String deleteRoles(HttpServletResponse response, String ids) { String msg = ""; try { roleService.deleteRoles(ids); msg = "1"; } catch (Exception e) { msg = "0"; log.error("删除角色失败:" + e.getStackTrace()); } // ResponseUtils.renderText(response, msg); return null; }
@SuppressWarnings("unchecked") public <T extends CommonManager> T copy() { String clazzName = this.getClass().getName().replace(ClassAgent.CLASSNAME_SUFFIX, ""); try { Mirror<T> mirror = (Mirror<T>) Mirror.me(Class.forName(clazzName)); return ClassUtil.copySameProperties(mirror.born(), this); } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); return null; } }
@At("/?/save") @PUT @Ok("http:200") public void saveModel(String modelId, HttpServletRequest req) { try { Map<String, Object> map = new HashMap<String, Object>(); String body = urlUtil.readStreamParameter(req.getInputStream()); String[] str = StringUtils.split(body, "&"); for (int i = 0; i < str.length; i++) { String[] temp = StringUtils.split(str[i], "="); if (temp.length > 1) { map.put(temp[0], URLDecoder.decode(temp[1], "utf-8")); } else { map.put(temp[0], ""); } } Model model = repositoryService.getModel(modelId); ObjectMapper objectMapper = new ObjectMapper(); ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); modelJson.put(ModelDataJsonConstants.MODEL_NAME, Strings.sNull(map.get("name"))); modelJson.put( ModelDataJsonConstants.MODEL_DESCRIPTION, Strings.sNull(map.get("description"))); model.setMetaInfo(modelJson.toString()); model.setName(Strings.sNull(map.get("name"))); repositoryService.saveModel(model); repositoryService.addModelEditorSource( model.getId(), Strings.sNull(map.get("json_xml")).getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(Strings.sNull(map.get("svg_xml")).getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); } catch (Exception e) { log.error("Error saving model", e); throw new ActivitiException("Error saving model", e); } }
// @RequestMapping(value = "saveRole", method = { RequestMethod.POST }) public String saveRole( HttpServletRequest request, HttpServletResponse response, Role role, String selectAuthIds) { String msg = ""; try { roleService.saveRole(request, role, selectAuthIds); // 保存角色 msg = "1"; // 保存角色成功 } catch (Exception e) { msg = "0"; // 保存角色失败 log.error("保存角色失败:" + e.getStackTrace()); } // ResponseUtils.renderText(response, msg); return null; }
// @RequestMapping(value = "loadAllAuthTree", method = { RequestMethod.POST }) public String loadAllAuthTree(HttpServletRequest request, HttpServletResponse response) { String id = request.getParameter("id"); List<Authority> checkedAuthList = roleService.getCheckedAuthIds(id); String authTreeJson = menusService.createAuthTree(checkedAuthList); log.info(authTreeJson); PrintWriter out; try { out = response.getWriter(); out.print(authTreeJson); out.flush(); out.close(); } catch (IOException e) { log.error("处理json数据报错:" + e.getStackTrace()); } return null; }