List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:gessi.ossecos.graph.GraphModel.java
public static void IStarJsonToGraphFile(String iStarModel, String layout, String typeGraph) throws ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(iStarModel); JSONArray jsonArrayNodes = (JSONArray) jsonObject.get("nodes"); JSONArray jsonArrayEdges = (JSONArray) jsonObject.get("edges"); String modelType = jsonObject.get("modelType").toString(); // System.out.println(modelType); // System.out.println(jsonArrayNodes.toJSONString()); // System.out.println(jsonArrayEdges.toJSONString()); System.out.println(jsonObject.toJSONString()); Hashtable<String, String> nodesHash = new Hashtable<String, String>(); Hashtable<String, String> boundaryHash = new Hashtable<String, String>(); Hashtable<String, Integer> countNodes = new Hashtable<String, Integer>(); ArrayList<String> boundaryItems = new ArrayList<String>(); ArrayList<String> actorItems = new ArrayList<String>(); GraphViz gv = new GraphViz(); gv.addln(gv.start_graph());// w ww . j a v a 2s . com String nodeType; String nodeName; String nodeBoundary; for (int i = 0; i < jsonArrayNodes.size(); i++) { jsonObject = (JSONObject) jsonArrayNodes.get(i); nodeName = jsonObject.get("name").toString().replace(" ", "_"); // .replace("(", "").replace(")", ""); nodeName = nodeName.replaceAll("[\\W]|`[_]", ""); nodeType = jsonObject.get("elemenType").toString(); nodeBoundary = jsonObject.get("boundary").toString(); // TODO: Verify type of diagram // if (!nodeType.equals("actor") & !nodeBoundary.equals("boundary")) // { if (countNodes.get(nodeName) == null) { countNodes.put(nodeName, 0); } else { countNodes.put(nodeName, countNodes.get(nodeName) + 1); nodeName += "_" + countNodes.put(nodeName, 0); } gv.addln(renderNode(nodeName, nodeType)); // } nodesHash.put(jsonObject.get("id").toString(), nodeName); boundaryHash.put(jsonObject.get("id").toString(), nodeBoundary); if (nodeType.equals("actor")) { actorItems.add(nodeName); } } String edgeType = ""; String source = ""; String target = ""; String edgeSubType = ""; int subgraphCount = 0; boolean hasCluster = false; nodeBoundary = "na"; String idSource; String idTarget; for (int i = 0; i < jsonArrayEdges.size(); i++) { jsonObject = (JSONObject) jsonArrayEdges.get(i); edgeSubType = jsonObject.get("linksubtype").toString(); edgeType = renderEdge(edgeSubType, jsonObject.get("linktype").toString()); idSource = jsonObject.get("source").toString(); idTarget = jsonObject.get("target").toString(); source = nodesHash.get(idSource); target = nodesHash.get(idTarget); if (!boundaryHash.get(idSource).toString().equals("boundary") && !boundaryHash.get(idTarget).toString().equals("boundary")) { if (!boundaryHash.get(idSource).toString().equals(nodeBoundary)) { nodeBoundary = boundaryHash.get(idSource).toString(); if (hasCluster) { gv.addln(gv.end_subgraph()); hasCluster = false; } else { hasCluster = true; } gv.addln(gv.start_subgraph(subgraphCount)); gv.addln(actorItems.get(subgraphCount++)); gv.addln("style=filled;"); gv.addln("color=lightgrey;"); } gv.addln(source + "->" + target + edgeType); } else { boundaryItems.add(source + "->" + target + edgeType); } } if (subgraphCount > 0) { gv.addln(gv.end_subgraph()); } for (String boundaryE : boundaryItems) { gv.addln(boundaryE); } gv.addln(gv.end_graph()); String type = typeGraph; // String type = "dot"; // String type = "fig"; // open with xfig // String type = "pdf"; // String type = "ps"; // String type = "svg"; // open with inkscape // String type = "png"; // String type = "plain"; String repesentationType = layout; // String repesentationType= "neato"; // String repesentationType= "fdp"; // String repesentationType= "sfdp"; // String repesentationType= "twopi"; // String repesentationType= "circo"; // //File out = new File("/tmp/out"+gv.getImageDpi()+"."+ type); // // Linux File out = new File("Examples/out." + type); // Windows gv.writeGraphToFile(gv.getGraph(gv.getDotSource(), type, repesentationType), out); }
From source file:kr.co.bitnine.octopus.testutils.MemoryDatabaseTest.java
private void verifyTableEquals(JSONObject expectedTable, ResultSet actualRows) throws Exception { ResultSetMetaData actualRowsMetaData = actualRows.getMetaData(); JSONArray expectedSchema = (JSONArray) expectedTable.get("table-schema"); assertEquals(expectedSchema.size(), actualRowsMetaData.getColumnCount()); for (int i = 0; i < expectedSchema.size(); i++) assertEquals(expectedSchema.get(i), actualRowsMetaData.getColumnName(i + 1)); for (Object rowObj : (JSONArray) expectedTable.get("table-rows")) { JSONArray row = (JSONArray) rowObj; actualRows.next();//from w w w .j a v a 2s. c o m for (int i = 0; i < row.size(); i++) { Object expected = row.get(i); Object actual; int sqlType = actualRowsMetaData.getColumnType(i + 1); switch (sqlType) { case Types.INTEGER: if (expected instanceof Boolean) expected = (long) ((Boolean) expected ? 1 : 0); actual = actualRows.getLong(i + 1); break; case Types.NULL: case Types.FLOAT: case Types.VARCHAR: actual = actualRows.getObject(i + 1); break; default: throw new RuntimeException("java.sql.Types " + sqlType + " is not supported"); } assertEquals(expected, actual); } } assertFalse(actualRows.next()); }
From source file:control.ProcesoVertimientosServlets.InsertarVerificacionInfoCaracterizacion.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from ww w .j a v a 2 s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String respuestas = request.getParameter("respuestas"); Integer codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); Object obj = JSONValue.parse(respuestas); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); String checkeado = (String) jsonObject.get("checkeado"); Integer codigo = Integer.parseInt((String) jsonObject.get("codigo")); //Creamos el manager y guardamos la informacion. VerificacionInfoCaracterizacion manager = new VerificacionInfoCaracterizacion(); manager.insertar(checkeado, codigo, codigoProceso); } } catch (Exception ex) { //Logger.getLogger(InsertarActEconomica.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.des.paperbase.ManageData.java
public void update(String Tablename, Map<String, Object> Filter, Map<String, Object> updateValue, String FilterType) throws IOException, ParseException { String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json"); JSONObject json = (JSONObject) new JSONParser().parse(data); List<String> keySet = g.getKeyFromMap(updateValue); if (!data.equalsIgnoreCase("{\"data\":[]}")) { JSONArray newValue = new JSONArray(); JSONArray OldValue = (JSONArray) json.get("data"); for (int s = 0; s < OldValue.size(); s++) { JSONObject record = (JSONObject) OldValue.get(s); if (MappingRecordAndKey(Filter, record, FilterType)) { for (int i = 0; i < keySet.size(); i++) { System.out.println("replace : " + keySet.get(i) + " to " + updateValue.get(keySet.get(i))); record.replace(keySet.get(i), updateValue.get(keySet.get(i))); }//from www . ja v a 2 s . c o m } newValue.add(record); } json.put("data", newValue); System.out.println(json.toJSONString()); g.writefile(json.toJSONString(), PATH_FILE + "\\" + Tablename + ".json"); } else { g.writefile(data, PATH_FILE + "\\" + Tablename + ".json"); } }
From source file:com.des.paperbase.ManageData.java
public List<Map<String, Object>> select(String Tablename, Map<String, Object> value, String FilterType) throws ParseException { String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json"); System.out.println(PATH_FILE + "\\" + Tablename + ".json"); JSONArray output = new JSONArray(); JSONObject json = (JSONObject) new JSONParser().parse(data); List<Map<String, Object>> result = new LinkedList<Map<String, Object>>(); GenerateFile g = new GenerateFile(); if (!data.equalsIgnoreCase("{\"data\":[]}")) { JSONArray OldValue = (JSONArray) json.get("data"); for (int s = 0; s < OldValue.size(); s++) { JSONObject record = (JSONObject) OldValue.get(s); if (MappingRecordAndKey(value, record, FilterType)) { List<String> Listkey = g.getKeyFromJSONArray(record.keySet()); Map<String, Object> Maprecord = new HashMap<String, Object>(); for (int i = 0; i < Listkey.size(); i++) { System.out.println(Listkey.get(i) + "," + record.get(Listkey.get(i))); Maprecord.put(Listkey.get(i), record.get(Listkey.get(i))); }/* w w w. j ava 2 s. c o m*/ result.add(Maprecord); } } } else { } return result; }
From source file:control.ProcesoVertimientosServlets.RegistrarTasaRetibutiva.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w .jav a 2 s. c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); String cargasParam = request.getParameter("cargasParam"); String valorTasaCobrada = request.getParameter("valorTasaCobrada"); String valorTotalTasaPagar = request.getParameter("valorTotalTasaPagar"); Object obj = JSONValue.parse(cargasParam); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; for (int i = 0; i < jsonArray.size(); i++) { //Obtenemos los valores por parametro JSONObject jsonObject = (JSONObject) jsonArray.get(i); String valorTarifa = (String) jsonObject.get("valorTarifa"); String procentajeRemocion = (String) jsonObject.get("procentajeRemocion"); String valorTasa = (String) jsonObject.get("valorTasa"); String valorCarga = (String) jsonObject.get("valorCarga"); String codigoParametro = (String) jsonObject.get("codigoParametro"); try { //Creamos el manager y guardamos la informacion. ProgramarMonitoreo manager = new ProgramarMonitoreo(); manager.registrarTasaRetributiva(codigoProceso, Integer.parseInt(codigoParametro), valorTarifa, procentajeRemocion, valorTasa, valorCarga, valorTasaCobrada, valorTotalTasaPagar); } catch (Exception ex) { } } String codigoParametro = ""; String valorTarifa = request.getParameter("codigoProceso"); String procentajeRemocion = request.getParameter("codigoProceso"); String valorTasa = request.getParameter("codigoProceso"); String valorCarga = request.getParameter("codigoProceso"); }
From source file:net.sf.okapi.filters.drupal.Node.java
@SuppressWarnings("unchecked") public String getContent(String lang) { Object obj = store.get("body"); if (!(obj instanceof Map)) { return null; }//from www.j a v a2 s . com Map<String, JSONArray> map = (Map<String, JSONArray>) store.get("body"); // Look for the source JSONArray data = map.get(lang); if (data == null) { data = map.get("und"); if (data == null) { return null; } } JSONObject cnt = (JSONObject) data.get(0); String value = (String) cnt.get("value"); return value; }
From source file:net.sf.okapi.filters.drupal.Node.java
@SuppressWarnings("unchecked") public String getSummary(String lang) { Object obj = store.get("body"); if (!(obj instanceof Map)) { return null; }//from w w w.j a v a2 s . c o m Map<String, JSONArray> map = (Map<String, JSONArray>) store.get("body"); // Look for the source summary JSONArray data = map.get(lang); if (data == null) { data = map.get("und"); if (data == null) { return null; } } JSONObject cnt = (JSONObject) data.get(0); String value = (String) cnt.get("summary"); return value; }
From source file:com.noelportugal.amazonecho.AmazonEchoApi.java
public String getLatestCards() throws IOException { String output = httpGet("/api/cards"); System.out.println(output);//from ww w . java 2 s.c om // Parse JSON Object obj = JSONValue.parse(output); JSONObject jsonObject = (JSONObject) obj; JSONArray values = (JSONArray) jsonObject.get("cards"); //System.out.println(values.size()); JSONObject item = (JSONObject) values.get(0); //System.out.println(item.toString()); // Get text and itemId String text = item.get("title").toString(); String itemId = item.get("title").toString(); //System.out.println(text); if (!checkItemId(itemId)) { return text; } else { return null; } }
From source file:me.ryandowling.Followers.java
public void run() { this.latestFollower = this.username; this.numberOfFollowers = 0; this.tempLatestFollower = this.username; this.tempNumberOfFollowers = 0; while (true) { System.out.println("Getting Information From Twitch API"); try {/*from w w w . j a va 2 s . co m*/ followerInformation = Utils.urlToString("https://api.twitch.tv/kraken/channels/" + username + "/follows?direction=DESC&limit=1&offset=0"); } catch (ConnectException e) { System.err.println("Couldn't Connect To Twitch API!"); sleep(); continue; } catch (IOException e) { e.printStackTrace(); sleep(); continue; } JSONParser parser = new JSONParser(); this.tempLatestFollower = this.latestFollower; try { Object obj = parser.parse(followerInformation); JSONObject jsonObject = (JSONObject) obj; JSONArray msg = (JSONArray) jsonObject.get("follows"); this.latestFollower = (String) ((JSONObject) ((JSONObject) msg.get(0)).get("user")) .get("display_name"); this.tempNumberOfFollowers = (Long) jsonObject.get("_total"); } catch (Exception e) { e.printStackTrace(); sleep(); continue; } if (this.newStream && !this.newStreamRun) { try { // Save the number of followers at the start of the stream FileUtils.write(this.followersStartTodayTxrFile.toFile(), this.numberOfFollowers + ""); this.startNumberOfFollowers = this.numberOfFollowers; this.newStreamRun = true; } catch (IOException e) { e.printStackTrace(); } } if (this.firstFollower == null && this.latestFollower != null) { this.firstFollower = this.latestFollower; } if (!this.tempLatestFollower.equalsIgnoreCase(this.latestFollower) && this.tempNumberOfFollowers > this.numberOfFollowers) { newFollower(); } if (this.tempNumberOfFollowers > this.numberOfFollowers) { this.numberOfFollowers = this.tempNumberOfFollowers; moreFollowers(); } System.out.println("Latest follower is " + this.latestFollower); System.out.println("There are " + this.numberOfFollowers + " followers"); System.out.println("There have been " + (this.numberOfFollowers - this.startNumberOfFollowers) + " followers today"); sleep(); } }