/** * validate the mosaic and quantity * @param address * @param mosaicName * @param mosaicQuantity * @param mosaicFeeInformation * @return */ private static String validateMosaic(String address, String mosaicName, String mosaicQuantity, MosaicFeeInformation mosaicFeeInformation) { String queryResult = HttpClientUtils.get(Constants.URL_ACCOUNT_MOSAIC_OWNED + "?address=" + address); JSONObject json = JSONObject.fromObject(queryResult); JSONArray array = json.getJSONArray("data"); for(int i=0;i<array.size();i++){ JSONObject item = array.getJSONObject(i); // get mosaic id JSONObject mosaicId = item.getJSONObject("mosaicId"); String namespaceId = mosaicId.getString("namespaceId"); String name = mosaicId.getString("name"); // get mosaic quantity long quantity = item.getLong("quantity"); if(mosaicName.equals(namespaceId+":"+name)){ Double mQuantity = Double.valueOf(mosaicQuantity).doubleValue() * Math.pow(10, mosaicFeeInformation.getDivisibility()); if(mQuantity.longValue()>quantity){ return "insufficient mosaic quantity"; } else { return null; } } } return "there is no mosaic ["+mosaicName+"] in the account"; }
public void test_xml() throws Exception { XMLSerializer xmlSerializer = new XMLSerializer(); JSONObject json = new JSONObject(); json.put("id", 123); json.put("name", "jobs"); json.put("flag", true); JSONArray items = new JSONArray(); items.add("x"); items.add(234); items.add(false); json.put("items", items); String text = xmlSerializer.write(json); System.out.println(text); }
/** * @param page * @param rows * @param s_user * @param response * @return * @throws Exception */ @RequestMapping("/list") public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); if (page != null && rows != null) { PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows)); map.put("start", pageBean.getStart()); map.put("size", pageBean.getPageSize()); } map.put("userName", StringUtil.formatLike(s_user.getUserName())); List<User> userList = userService.findUser(map); Long total = userService.getTotalUser(map); JSONObject result = new JSONObject(); JSONArray jsonArray = JSONArray.fromObject(userList); result.put("rows", jsonArray); result.put("total", total); log.info("request: user/list , map: " + map.toString()); ResponseUtil.write(response, result); return null; }
/** * Converts a Map Object into JSON string. * @param hm * @return */ public static String map2jsonConverter(Map hm) { if (hm==null || hm.size()==0) { return "{}"; } JSONObject jo = new JSONObject(); for (Iterator it = hm.keySet().iterator(); it.hasNext();) { Object k = it.next(); if (hm.get(k)==null || hm.get(k) instanceof String) { jo.accumulate(k.toString(), hm.get(k)); } else if (hm.get(k) instanceof Collection || hm.get(k).getClass().isArray()) { jo.accumulate(k.toString(), JSONArray.fromObject(hm.get(k)).toString()); } else { log.debug("map2jsonConverter: "+hm.get(k).getClass().getName()); jo.accumulate(k.toString(), JSONObject.fromObject(hm.get(k)).toString()); } } return jo.toString(); }
public ArrayList<Discuss> getDiscussList(){ ArrayList<Discuss> discussesList=new ArrayList<Discuss>(); //用psessionid合成一个完整的URL并且访问它,并将结果解析为json JSONObject result=JSONObject.fromObject(utils.get(URL.URL_GET_DISCUSS_LIST.replace("[var]",credential.getPsessionID()).replace("[var1]",credential.getVfWebQQ()),new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result"); //获取讨论组列表 JSONArray discussesListInfo=result.getJSONArray("dnamelist"); //构造讨论组列表 for(int i=0;i<discussesListInfo.size();i++){ JSONObject tempDiscussInfo=JSONObject.fromObject(discussesListInfo.get(i)); //取出讨论组id,构造一个讨论组,credential用于获取成员列表 Discuss tempDiscuss=new Discuss(tempDiscussInfo.getLong("did"),credential); //设置讨论组的名称 tempDiscuss.setName(tempDiscussInfo.getString("name")); //添加到list内 discussesList.add(tempDiscuss); } return discussesList; }
/** * Convert the request parameter map to a json string. * @param request * @return */ public static String requestParams2json(ServletRequest request) { Map<String, String[]> params = request.getParameterMap(); JSONObject jo = new JSONObject(); for (Iterator<String> it=params.keySet().iterator(); it.hasNext();) { String k = it.next(); String[] v = params.get(k); if (v==null || v.length==0) { continue; } else if (v.length==1) { jo.accumulate(k, v[0]); } else { jo.accumulate(k, JSONArray.fromObject(v)); } } return jo.toString(); }
/** * 从一个JSON数组得到一个java对象数组,形如: [{"id" : idValue, "name" : nameValue}, {"id" : * idValue, "name" : nameValue}, ...] * * @param object * @param clazz * @return */ public static Object[] getDTOArray(String jsonString, Class<?> clazz) { setDataFormat2JAVA(); JSONArray array = JSONArray.fromObject(jsonString); Object[] obj = new Object[array.size()]; for (int i = 0; i < array.size(); i++) { JSONObject jsonObject = array.getJSONObject(i); obj[i] = JSONObject.toBean(jsonObject, clazz); } return obj; }
/** * 从一个JSON数组得到一个java对象数组,形如: [{"id" : idValue, "name" : nameValue}, {"id" : * idValue, "name" : nameValue}, ...] * * @param object * @param clazz * @param map * @return */ public static Object[] getDTOArray(String jsonString, Class<?> clazz, Map<?, ?> map) { setDataFormat2JAVA(); JSONArray array = JSONArray.fromObject(jsonString); Object[] obj = new Object[array.size()]; for (int i = 0; i < array.size(); i++) { JSONObject jsonObject = array.getJSONObject(i); obj[i] = JSONObject.toBean(jsonObject, clazz, map); } return obj; }
/** * 把数据对象转换成json字符串 DTO对象形如:{"id" : idValue, "name" : nameValue, ...} * 数组对象形如:[{}, {}, {}, ...] map对象形如:{key1 : {"id" : idValue, "name" : * nameValue, ...}, key2 : {}, ...} * * @param object * @return */ public static String getJSONString(Object object) throws Exception { String jsonString = null; // 日期值处理器 JsonConfig jsonConfig = new JsonConfig(); if (object != null) { if (object instanceof Collection || object instanceof Object[]) { jsonString = JSONArray.fromObject(object, jsonConfig) .toString(); } else { jsonString = JSONObject.fromObject(object, jsonConfig) .toString(); } } return jsonString == null ? "{}" : jsonString; }
@RequestMapping(value = ACTION_INSERT, method = RequestMethod.GET) public String insert(HttpServletRequest request, HttpServletResponse response, Object object) { Iterator<?> it = request.getParameterMap().entrySet().iterator(); KettleSpoon entity = new KettleSpoon(); while (it.hasNext()) { Map.Entry<?, ?> ent = (Entry<?, ?>) it.next(); entity.setValue((String) ent.getKey(), ((String[]) ent.getValue())[0]); } entity.setParams(JSONArray.fromObject(entity.getValue()).toString()); request.setAttribute(ENTITY, entity); List<?> list = service.iQuartzGroupService .selectByWhere(new QuartzGroup()); request.setAttribute(LIST, list); return VIEW_WIDGET + VIEW_QUARTZ + PAGE_INSERT; }
@RequestMapping(value = ACTION_INSERT, method = RequestMethod.POST) public String insert(HttpServletRequest request, HttpServletResponse response) throws IOException { Iterator<?> it = request.getParameterMap().entrySet().iterator(); final KettleSpoon entity = new KettleSpoon(); while (it.hasNext()) { Map.Entry<?, ?> ent = (Entry<?, ?>) it.next(); entity.setValue((String) ent.getKey(), ((String[]) ent.getValue())[0]); } entity.setParams(JSONArray.fromObject(entity.getValue()).toString()); entity.setTest(true); entity.setQueue(false); service.iKettleSpoonService.insert(entity); new Thread(new Runnable() { @Override public void run() { service.iKettleSpoonService.execute(entity); } }).start(); return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_SPOON + ACTION_LIST; }
@RequestMapping(value = ACTION_UPDATE, method = RequestMethod.POST) public String update(HttpServletRequest request, HttpServletResponse response) throws IOException { Iterator<?> it = request.getParameterMap().entrySet().iterator(); final KettleSpoon entity = new KettleSpoon(); while (it.hasNext()) { Map.Entry<?, ?> ent = (Entry<?, ?>) it.next(); entity.setValue((String) ent.getKey(), ((String[]) ent.getValue())[0]); } entity.setParams(JSONArray.fromObject(entity.getValue()).toString()); entity.setTest(true); entity.setQueue(false); service.iKettleSpoonService.update(entity); new Thread(new Runnable() { @Override public void run() { service.iKettleSpoonService.execute(entity); } }).start(); return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_SPOON + ACTION_LIST; }
@RequestMapping(value = ACTION_TREE, method = RequestMethod.POST) public void tree(HttpServletRequest request, HttpServletResponse response) throws IOException { try { Iterator<?> it = request.getParameterMap().entrySet().iterator(); KettleRepos entity = new KettleRepos(); while (it.hasNext()) { Map.Entry<?, ?> ent = (Entry<?, ?>) it.next(); entity.setValue((String) ent.getKey(), ((String[]) ent.getValue())[0]); } List<?> list = service.iKettleReposService.getJobAndTrans(entity); response.getWriter().write(JSONArray.fromObject(list).toString()); } catch (KettleException e) { e.printStackTrace(); } finally { response.getWriter().close(); } }
public int getVideoNumber(String jsonContent) throws Exception { JSONArray array = JSONArray.fromObject(jsonContent); JSONObject object = null; int l = array.size(); int videoNumber = 0; for (int i = 0; i < l; i++) { object = array.getJSONObject(i); JSONObject obj1 = (JSONObject) object.get("data"); JSONObject obj2 = (JSONObject) obj1.get("page"); videoNumber = Integer.parseInt(obj2.get("count").toString()); } return videoNumber; }
/** * 获取好友列表相当于组里的所有人 * * @param userGroupTopId * 组id * @param token * 身份 * @return */ public static List<UserData> getFriendList(String userGroupTopId, String token) { JSONObject js = new JSONObject(); js.put("hOpCode", "13"); js.put("userGroupTopId", userGroupTopId); Map<String, String> header = new HashMap<>(); header.put("hOpCode", "13"); header.put("token", token); byte[] returnByte = HttpUtil.send(js.toString(), CommonConfigChat.IDENTITY_URL, header, HttpUtil.POST); if (returnByte != null) { String str = null; try { str = new String(returnByte, "UTF-8"); } catch (UnsupportedEncodingException e) { WSManager.log.error("返回字符串解析异常", e); } JSONObject returnjs = JSONObject.fromObject(str); // 如果返回的是错误类型,说明用户中心拦截器没通过 if (returnjs.getString("hOpCode").equals("0")) { return null; } JSONArray jsArray = returnjs.getJSONArray("user"); List<UserData> list = new ArrayList<>(); for (int i = 0; i < jsArray.size(); i++) { JSONObject user = jsArray.getJSONObject(i); UserData userData = new UserData(user); list.add(userData); } return list; } return null; }
/** * 查找相应的数据集合 * * @param page * @param rows * @param article * @param response * @return * @throws Exception */ @RequestMapping("/list") public String list( @RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, Article article, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); if (page != null && rows != null) { PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows)); map.put("start", pageBean.getStart()); map.put("size", pageBean.getPageSize()); } if (article != null) { map.put("articleTitle", StringUtil.formatLike(article.getArticleTitle())); } List<Article> articleList = articleService.findArticle(map); Long total = articleService.getTotalArticle(map); JSONObject result = new JSONObject(); JSONArray jsonArray = JSONArray.fromObject(articleList); result.put("rows", jsonArray); result.put("total", total); ResponseUtil.write(response, result); log.info("request: article/list , map: " + map.toString()); return null; }
/** * @param page * @param rows * @param s_user * @param response * @return * @throws Exception */ @RequestMapping("/list") public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception { PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows)); Map<String, Object> map = new HashMap<String, Object>(); map.put("userName", StringUtil.formatLike(s_user.getUserName())); map.put("start", pageBean.getStart()); map.put("size", pageBean.getPageSize()); List<User> userList = userService.findUser(map); Long total = userService.getTotalUser(map); JSONObject result = new JSONObject(); JSONArray jsonArray = JSONArray.fromObject(userList); result.put("rows", jsonArray); result.put("total", total); log.info("request: user/list , map: " + map.toString()); ResponseUtil.write(response, result); return null; }
/** * 历史聊天人列表,会话列表,每一项都是一个人 */ @RequestMapping("hostoryChatList") public String hostoryChatList(HttpServletRequest request,Model model){ if(Global.aliyunLogUtil == null){ return error(model, "您未开启IM客服访问相关的日志服务!"); } User user = getUser(); int currentTime = DateUtil.timeForUnix10(); int startTime = currentTime - 86400*30; //30天内有效 try { AliyunLogPageUtil log = new AliyunLogPageUtil(Global.aliyunLogUtil); JSONArray jsonArray = log.listForJSONArray("receiveId = "+user.getId()+" | select max(sendId) , map_agg('array',sendUserName) as sendUserName,max(sendId) as sendIds, count(*) as count, max(__time__) as time group by sendId order by time desc limit 100", "", false, startTime, currentTime, 100, request); model.addAttribute("list", jsonArray); } catch (LogException e) { e.printStackTrace(); } return "im/hostoryChatList"; }
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("--------获取商家列表--------"); List<Seller> list=new ArrayList<Seller>(); for(int i=1;i<10;i++){ Seller seller=new Seller(); seller.setId(i); seller.setName("孟非小面第"+i+"家分店"); list.add(seller); } Response res=new Response(); res.setCode("0"); String data="{\"list\":"+JSONArray.fromObject(list).toString()+"}"; res.setData(data); CommonUtil.renderJson(response, res); }
public static MosaicFeeInformation findMosaicFeeInformationByNIS(MosaicId mosaicId){ String queryResult = HttpClientUtils.get(Constants.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString()); JSONObject json = JSONObject.fromObject(queryResult); if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){ return null; } JSONArray array = json.getJSONArray("data"); for(int i=0;i<array.size();i++){ JSONObject item = array.getJSONObject(i); JSONObject mosaic = item.getJSONObject("mosaic"); JSONObject id = mosaic.getJSONObject("id"); if(mosaicId.getName().equals(id.getString("name"))){ JSONArray properties = mosaic.getJSONArray("properties"); String initialSupply = ""; String divisibility = ""; for(int j=0;j<properties.size();j++){ JSONObject property = properties.getJSONObject(j); if("initialSupply".equals(property.getString("name"))){ initialSupply = property.getString("value"); } else if("divisibility".equals(property.getString("name"))){ divisibility = property.getString("value"); } } if(!"".equals(initialSupply) && !"".equals(divisibility)){ return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility)); } } } return null; }
@Override public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) { if (list != null && isOnlineInitiated) { try { JSONArray array = getDataToSend(list); log.info(array.toString()); apiClient.sendOnlineData(array); } catch (IOException ex) { log.warn("Failed to send active test data", ex); } try { Thread.sleep(delay); } catch (InterruptedException e) { log.warn("Backend listener client thread was interrupted"); } } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = request.getParameter("user_id"); DBcrud conn = new DBcrud(); JSONObject jsa = new JSONObject(); JSONArray um = new JSONArray(); if (AuxiliaryTools.checkValidParameter(userId)){ jsa = (conn.getUserInfor(userId)); if ((um = conn.userMachine(userId)).size()>0) { jsa.put("machine_list",um); } } response.setContentType("text/html;charset=UTF-8"); PrintWriter out; out = response.getWriter(); out.println(jsa); }
private static JSONArray calculateIntervals(List<SampleResult> list) { Map<Long, List<SampleResult>> intervals = new HashMap<>(); for (SampleResult sample : list) { long time = sample.getEndTime() / 1000; if (!intervals.containsKey(time)) { intervals.put(time, new LinkedList<SampleResult>()); } intervals.get(time).add(sample); } JSONArray result = new JSONArray(); for (Long second : intervals.keySet()) { JSONObject intervalResult = new JSONObject(); List<SampleResult> intervalValues = intervals.get(second); intervalResult.put("ts", second); intervalResult.put("n", intervalValues.size()); intervalResult.put("rc", generateResponseCodec(intervalValues)); int fails = getFails(intervalValues); intervalResult.put("ec", fails); intervalResult.put("failed", fails); intervalResult.put("na", getThreadsCount(intervalValues)); final Map<String, Object> mainMetrics = getMainMetrics(intervalValues); int intervalSize = intervalValues.size(); intervalResult.put("t", generateTimestamp(mainMetrics, intervalSize)); intervalResult.put("lt", generateLatencyTime(mainMetrics, intervalSize)); intervalResult.put("by", generateBytes(mainMetrics, intervalSize)); result.add(intervalResult); } return result; }
@Test public void testGetDataToSend() { System.out.println("addSample"); LoadosophiaClient instance = new LoadosophiaClient(); List<SampleResult> list = new LinkedList<>(); list.add(new SampleResult(System.currentTimeMillis(), 1)); list.add(new SampleResult(System.currentTimeMillis() + 1000, 1)); list.add(new SampleResult(System.currentTimeMillis() + 2000, 1)); list.add(new SampleResult(System.currentTimeMillis() + 3000, 1)); list.add(new SampleResult(System.currentTimeMillis() + 3000, 3)); list.add(new SampleResult(System.currentTimeMillis() + 3000, 2)); list.add(new SampleResult(System.currentTimeMillis() + 4000, 1)); list.add(new SampleResult(System.currentTimeMillis() + 5000, 1)); list.add(new SampleResult(System.currentTimeMillis() + 6000, 1)); String str = instance.getDataToSend(list).toString(); System.out.println("JSON: " + str); assertFalse("[]".equals(str)); assertFalse("".equals(str)); JSONArray test = JSONArray.fromObject(str); assertEquals(7, test.size()); }
@org.junit.Test public void testFlow() throws Exception { StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); JSONObject result = new JSONObject(); result.put("id", "100"); result.put("name", "NEW_TEST"); JSONObject response = new JSONObject(); response.put("result", result); Project project = new Project(emul, "10", "projectName"); emul.addEmul(response); Test test = project.createTest("NEW_WORKSPACE"); assertEquals("100", test.getId()); assertEquals("NEW_TEST", test.getName()); response.clear(); JSONArray results = new JSONArray(); results.add(result); results.add(result); response.put("result", results); emul.addEmul(response); List<Test> tests = project.getTests(); assertEquals(2, tests.size()); for (Test t :tests) { assertEquals("100", t.getId()); assertEquals("NEW_TEST", t.getName()); } }
@org.junit.Test public void testFlow() throws Exception { StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); JSONObject result = new JSONObject(); result.put("id", "999"); result.put("name", "NEW_PROJECT"); JSONObject response = new JSONObject(); response.put("result", result); Workspace workspace = new Workspace(emul, "888", "workspace_name"); emul.addEmul(response); Project project = workspace.createProject("NEW_PROJECT"); assertEquals("999", project.getId()); assertEquals("NEW_PROJECT", project.getName()); response.clear(); JSONArray results = new JSONArray(); results.add(result); results.add(result); response.put("result", results); emul.addEmul(response); List<Project> projects = workspace.getProjects(); assertEquals(2, projects.size()); for (Project p :projects) { assertEquals("999", p.getId()); assertEquals("NEW_PROJECT", p.getName()); } }
@Test public void testFlow() throws Exception { StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); JSONObject result = new JSONObject(); result.put("id", "100"); result.put("name", "NEW_WORKSPACE"); JSONObject response = new JSONObject(); response.put("result", result); Account account = new Account(emul, "777", "account_name"); emul.addEmul(response); Workspace workspace = account.createWorkspace("NEW_WORKSPACE"); assertEquals("100", workspace.getId()); assertEquals("NEW_WORKSPACE", workspace.getName()); response.clear(); JSONArray results = new JSONArray(); results.add(result); results.add(result); response.put("result", results); emul.addEmul(response); List<Workspace> workspaces = account.getWorkspaces(); assertEquals(2, workspaces.size()); for (Workspace wsp :workspaces) { assertEquals("100", wsp.getId()); assertEquals("NEW_WORKSPACE", wsp.getName()); } }
@org.junit.Test public void testFlow() throws Exception { StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); BlazeMeterReport report = new BlazeMeterReport(); BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", report); User user = new User(emul); emul.addEmul(new JSONObject()); user.ping(); JSONObject acc = new JSONObject(); acc.put("id", "accountId"); acc.put("name", "accountName"); JSONArray result = new JSONArray(); result.add(acc); result.add(acc); JSONObject response = new JSONObject(); response.put("result", result); emul.addEmul(response); List<Account> accounts = user.getAccounts(); assertEquals(2, accounts.size()); for (Account account : accounts) { assertEquals("accountId", account.getId()); assertEquals("accountName", account.getName()); } }
/** * Find mosaic fee information by NIS. * * @param mosaicId the mosaic id * @return the mosaic fee information */ public static MosaicFeeInformation findMosaicFeeInformationByNIS(MosaicId mosaicId){ String host = "alice2.nem.ninja"; String port = "7890"; NemNetworkResponse queryResult = NetworkUtils.get("http://"+host+":"+port+NemAppsLibGlobals.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString()); JSONObject json = JSONObject.fromObject(queryResult.getResponse()); if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){ return null; } JSONArray array = json.getJSONArray("data"); for(int i=0;i<array.size();i++){ JSONObject item = array.getJSONObject(i); JSONObject mosaic = item.getJSONObject("mosaic"); JSONObject id = mosaic.getJSONObject("id"); if(mosaicId.getName().equals(id.getString("name"))){ JSONArray properties = mosaic.getJSONArray("properties"); String initialSupply = ""; String divisibility = ""; for(int j=0;j<properties.size();j++){ JSONObject property = properties.getJSONObject(j); if("initialSupply".equals(property.getString("name"))){ initialSupply = property.getString("value"); } else if("divisibility".equals(property.getString("name"))){ divisibility = property.getString("value"); } } if(!"".equals(initialSupply) && !"".equals(divisibility)){ return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility)); } } } return null; }
public static MosaicFeeInformation findMosaicFeeInformationByNIS(String host, String port, MosaicId mosaicId){ NemNetworkResponse queryResult = NetworkUtils.get("http://"+host+":"+port+NemAppsLibGlobals.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString()); JSONObject json = JSONObject.fromObject(queryResult.getResponse()); if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){ return null; } JSONArray array = json.getJSONArray("data"); for(int i=0;i<array.size();i++){ JSONObject item = array.getJSONObject(i); JSONObject mosaic = item.getJSONObject("mosaic"); JSONObject id = mosaic.getJSONObject("id"); if(mosaicId.getName().equals(id.getString("name"))){ JSONArray properties = mosaic.getJSONArray("properties"); String initialSupply = ""; String divisibility = ""; for(int j=0;j<properties.size();j++){ JSONObject property = properties.getJSONObject(j); if("initialSupply".equals(property.getString("name"))){ initialSupply = property.getString("value"); } else if("divisibility".equals(property.getString("name"))){ divisibility = property.getString("value"); } } if(!"".equals(initialSupply) && !"".equals(divisibility)){ return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility)); } } } return null; }
/** * 读取日志列表,分页展示演示出来 */ @RequestMapping("list") public String list(HttpServletRequest request, Model model) throws LogException{ AliyunLogPageUtil log = new AliyunLogPageUtil(actionLog); //得到当前页面的列表数据 JSONArray jsonArray = log.list("", "", true, 10, request); //得到当前页面的分页相关数据(必须在执行了list方法获取列表数据之后,才能调用此处获取到分页) Page page = log.getPage(); //设置分页,出现得上几页、下几页跳转按钮的个数 page.setListNumber(2); model.addAttribute("list", jsonArray); model.addAttribute("page", page); return "extend/list"; }
/** * 网站访问记录日志列表 * @throws LogException */ @RequiresPermissions("adminLogList") @RequestMapping("fangwenList") public String fangwenList(HttpServletRequest request,Model model) throws LogException{ if(G.aliyunLogUtil == null){ return error(model, "您未开启网站访问相关的日志服务!无法查看网站访问日志"); } AliyunLogPageUtil log = new AliyunLogPageUtil(G.aliyunLogUtil); //得到当前页面的列表数据 JSONArray jsonArray = log.list("", "", true, 100, request); //得到当前页面的分页相关数据(必须在执行了list方法获取列表数据之后,才能调用此处获取到分页) Page page = log.getPage(); //设置分页,出现得上几页、下几页跳转按钮的个数 page.setListNumber(3); ActionLogCache.insert(request, "查看总管理后台网站访问日志列表", "第"+page.getCurrentPageNumber()+"页"); model.addAttribute("list", jsonArray); model.addAttribute("page", page); return "/admin/requestLog/fangwenList"; }
public static JSONArray buildGitData(EnvVars envVars, PrintStream printStream) { try { String gitUrl = Util.getGitRepoUrl(envVars); String gitBranch = Util.getGitBranch(envVars); String gitCommit = Util.getGitCommit(envVars); JSONObject gitInfo = new JSONObject(); gitInfo.put("GitURL" , gitUrl); gitInfo.put("GitBranch" , gitBranch); gitInfo.put("GitCommitID" , gitCommit); JSONArray gitData = new JSONArray(); gitData.add(gitInfo); return gitData; } catch (Exception e) { printStream.println("[IBM Cloud DevOps] Error: Failed to build Git data."); e.printStackTrace(printStream); throw e; } }
public static JSONObject formatDeployableMappingMessage(JSONObject org, JSONObject space, JSONObject app, String apiUrl, JSONArray gitData, PrintStream printStream) { try { JSONObject deployableMappingMessage = new JSONObject(); deployableMappingMessage.put("Org" , org); deployableMappingMessage.put("Space" , space); deployableMappingMessage.put("App" , app); deployableMappingMessage.put("ApiEndpoint" , apiUrl); deployableMappingMessage.put("Method" , "POST"); deployableMappingMessage.put("GitData" , gitData); return deployableMappingMessage; } catch (Exception e) { printStream.println("[IBM Cloud DevOps] Error: Failed to build Deployable Mapping Message."); e.printStackTrace(printStream); throw e; } }
@Test public void testInstantiateGlobalConfigData() { JSONObject json = new JSONObject(); json.put("listOfGlobalConfigData", JSONArray.fromObject("[{\"name\":\"Sonar\",\"url\":\"http://localhost:9000\",\"account\":\"admin\",\"password\":\"admin\"}]")); JSON globalDataConfig = (JSON) json.opt("listOfGlobalConfigData"); doNothing().when(spyGlobalConfigurationService).initGlobalDataConfig(globalDataConfig); assertEquals(listOfGlobalConfigData, spyGlobalConfigurationService.instantiateGlobalConfigData(json)); }
/** * @param page * @param rows * @param s_user * @param response * @return * @throws Exception */ @RequestMapping(value = "/datagrid", method = RequestMethod.POST) public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception { PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows)); Map<String, Object> map = new HashMap<String, Object>(); map.put("userName", StringUtil.formatLike(s_user.getUserName())); map.put("start", pageBean.getStart()); map.put("size", pageBean.getPageSize()); List<User> userList = userService.findUser(map); Long total = userService.getTotalUser(map); JSONObject result = new JSONObject(); JSONArray jsonArray = JSONArray.fromObject(userList); result.put("rows", jsonArray); result.put("total", total); log.info("request: user/list , map: " + map.toString()); ResponseUtil.write(response, result); return null; }
public ArrayList<String> getCategories(){ ArrayList<String> categories=new ArrayList<String>(); JSONObject r=new JSONObject(); //构造一个请求表单 r.put("vfwebqq",credential.getVfWebQQ()); //这里用到了hash r.put("hash", credential.getHash()); //访问获取好友列表的链接,取出分组信息 JSONArray result=JSONObject.fromObject(JSONObject.fromObject(utils.post(URL.URL_GET_FRIEND_LIST,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result")).getJSONArray("categories"); //取出分组的名称 for(int i=0;i<result.size();i++){ categories.add(JSONObject.fromObject(result.get(i)).getString("name")); } return categories; }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //�����ַ������ʽ req.setCharacterEncoding("utf-8"); resp.setCharacterEncoding("utf-8"); //���Ȼ�ÿͻ��˷�����������(keyword) String keyword = req.getParameter("keyword"); //��ùؼ���֮����д����õ��������� List<String> listData = getData(keyword); // System.out.println(JSONArray.fromObject(listData)); // JSONArray.fromObject(listData); //����json��ʽ resp.getWriter().write(JSONArray.fromObject(listData).toString()); }
protected String getTreeDef(final SectionInfo info, ItemNavigationTree tree, Set<String> openNodes) { List<TreeNode> nodes = addChildNodes(tree.getRootNodes(), tree, openNodes, new NodeUrlGenerator() { @Nullable @Override public String getUrlForNode(ItemNavigationNode node) { if( nodeHasAttachment(node) ) { return new BookmarkAndModify(info, events.getNamedModifier("viewNode", node.getUuid())).getHref(); } return null; } }); return JSONArray.fromObject(nodes).toString(); }