List of usage examples for com.google.gson JsonObject entrySet
public Set<Map.Entry<String, JsonElement>> entrySet()
From source file:ExplorerPanel.java
License:Apache License
public void editWith(String editable) { try {/* ww w.j av a 2 s . com*/ JsonObject editors = RunnerRepository.getEditors(); int length = editors.entrySet().size(); Iterator iter = editors.entrySet().iterator(); Entry entry; String[] vecresult; if (editors.get("DEFAULT") != null) { vecresult = new String[length - 1]; } else { vecresult = new String[length]; } int index = 0; for (int i = 0; i < length; i++) { entry = (Entry) iter.next(); if (entry.getKey().toString().equals("DEFAULT")) { continue; } vecresult[index] = entry.getKey().toString(); index++; } JComboBox jComboBox1 = new JComboBox(); JPanel p = getEditorsPanel(jComboBox1, vecresult); Object[] message = new Object[] { p }; int r = (Integer) CustomDialog.showDialog(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, tree, "Please select an editor", null); if (r == JOptionPane.OK_OPTION) { String ID = jComboBox1.getSelectedItem().toString(); String remotefilename = tree.getSelectionPath() .getPathComponent(tree.getSelectionPath().getPathCount() - 2) + "/" + tree.getSelectionPath().getLastPathComponent(); String localfilename = RunnerRepository.temp + RunnerRepository.getBar() + "Twister" + RunnerRepository.getBar() + tree.getSelectionPath().getLastPathComponent(); if (ID.equals("Embedded")) { openEmbeddedEditor(editable, remotefilename, localfilename); } else { File file2 = copyFileLocaly(remotefilename, localfilename); String execute = RunnerRepository.getEditors().get(ID).getAsString(); executeCommand(execute, localfilename); sendFileToServer(file2, remotefilename); file2.delete(); } } } catch (Exception e) { System.out .println("There was an error in opening editors " + "window, please check configuration file"); e.printStackTrace(); } }
From source file:PanicDetect.java
License:Apache License
private void listRegex() { try {//from ww w.j ava 2s.co m String result = RunnerRepository.getRPCClient() .execute("panicDetectConfig", new Object[] { RunnerRepository.getUser(), "list" }).toString(); JsonElement jelement = new JsonParser().parse(result); JsonObject main = jelement.getAsJsonObject(); JsonObject regex = main.getAsJsonObject(RunnerRepository.getUser()); Iterator<Map.Entry<String, JsonElement>> iter = regex.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, JsonElement> n = iter.next(); String id = n.getKey(); JsonElement content = n.getValue(); JsonObject ob = content.getAsJsonObject(); String exp = ob.get("expression").getAsString(); String en = ob.get("enabled").getAsString(); MyPanel panel = new MyPanel(exp, Boolean.parseBoolean(en), id); addPanel(panel); } } catch (Exception e) { e.printStackTrace(); } }
From source file:ClearCasePanel.java
License:Apache License
public void editWith(String editable, String ctfile, boolean save) { try {/* w w w . j ava 2 s.c o m*/ JsonObject editors = RunnerRepository.getEditors(); int length = editors.entrySet().size(); Iterator iter = editors.entrySet().iterator(); Entry entry; String[] vecresult; if (editors.get("DEFAULT") != null) { vecresult = new String[length - 1]; } else { vecresult = new String[length]; } int index = 0; for (int i = 0; i < length; i++) { entry = (Entry) iter.next(); if (entry.getKey().toString().equals("DEFAULT")) { continue; } vecresult[index] = entry.getKey().toString(); index++; } JComboBox jComboBox1 = new JComboBox(); JPanel p = getEditorsPanel(jComboBox1, vecresult); Object[] message = new Object[] { p }; int r = (Integer) CustomDialog.showDialog(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, tree, "Please select an editor", null); if (r == JOptionPane.OK_OPTION) { String ID = jComboBox1.getSelectedItem().toString(); String remotefilename = tree.getSelectionPath() .getPathComponent(tree.getSelectionPath().getPathCount() - 2) + "/" + tree.getSelectionPath().getLastPathComponent(); String localfilename = RunnerRepository.temp + RunnerRepository.getBar() + "Twister" + RunnerRepository.getBar() + tree.getSelectionPath().getLastPathComponent(); if (ID.equals("Embedded")) { openEmbeddedEditor(editable, remotefilename, localfilename, ctfile, save); } else { RunnerRepository.window.mainpanel.getP5().sendCommand("cp " + remotefilename + " ~"); RunnerRepository.window.mainpanel.getP5().readOutput(null); // RunnerRepository.window.mainpanel.getP5().sendCommand("cp "+remotefilename+" ~", false); // RunnerRepository.window.mainpanel.getP5().readOutput(true); File file2 = copyFileLocaly(editable, localfilename); RunnerRepository.window.mainpanel.getP5().sendCommand("rm -f ~/" + editable); RunnerRepository.window.mainpanel.getP5().readOutput(null); // RunnerRepository.window.mainpanel.getP5().sendCommand("rm -f ~/"+editable, false); // RunnerRepository.window.mainpanel.getP5().readOutput(true); String execute = RunnerRepository.getEditors().get(ID).getAsString(); executeCommand(execute, localfilename); sendFileToServer(file2, editable, ctfile); file2.delete(); } } } catch (Exception e) { System.out .println("There was an error in opening editors " + "window, please check configuration file"); e.printStackTrace(); } }
From source file:RunnerRepository.java
License:Apache License
private static void populateLookAndFeels() { JsonObject looks = RunnerRepository.getLooks(); if (looks != null) { int length = looks.entrySet().size(); Iterator iter = looks.entrySet().iterator(); Entry entry;//w w w . jav a 2s .c om String[] vecresult; if (looks.get("DEFAULT") != null) lookAndFeels = new String[length - 1]; else lookAndFeels = new String[length]; int index = 0; for (int i = 0; i < length; i++) { entry = (Entry) iter.next(); if (entry.getKey().toString().equals("DEFAULT")) continue; lookAndFeels[index] = (String) entry.getKey(); index++; } } else { System.out.println("Error: No LooksAndFeels set, using default look"); } }
From source file:EAIJSONConverter.java
License:Open Source License
public static SiebelPropertySet JsonObjectToPropertySet(JsonObject obj, SiebelPropertySet ps) { Iterator<Entry<String, JsonElement>> iterator = obj.entrySet().iterator(); SiebelPropertySet child;//from w w w. j a v a 2 s . co m while (iterator.hasNext()) { JsonArray jsonArray = new JsonArray(); JsonObject jsonObject = new JsonObject(); Map.Entry mapEntry = (Map.Entry) iterator.next(); if (mapEntry != null) { JsonElement jsonelement = (JsonElement) mapEntry.getValue(); if (jsonelement.isJsonArray()) { jsonArray = jsonelement.getAsJsonArray(); child = new SiebelPropertySet(); child.setType("ListOf-" + mapEntry.getKey().toString()); for (int i = 0; i < jsonArray.size(); i++) { if (jsonArray.get(i).isJsonObject() || jsonArray.get(i).isJsonArray()) { SiebelPropertySet temp = new SiebelPropertySet(); temp.setType("" + i); if (jsonArray.get(i).isJsonObject()) child.addChild(JsonObjectToPropertySet(jsonArray.get(i).getAsJsonObject(), temp)); else { JsonObject aux = new JsonObject(); aux.add("" + i, jsonArray.get(i)); child.addChild(JsonObjectToPropertySet(aux, temp)); } } else child.setProperty("" + i, jsonArray.get(i).getAsString()); } ps.addChild(child); } else if (jsonelement.isJsonObject()) { jsonObject = jsonelement.getAsJsonObject(); child = new SiebelPropertySet(); child.setType(mapEntry.getKey().toString()); ps.addChild(JsonObjectToPropertySet(jsonObject, child)); } else { ps.setProperty(mapEntry.getKey().toString(), mapEntry.getValue().toString()); } } } return ps; }
From source file:Editors.java
License:Apache License
public String[] getEditors() { String[] vecresult;//from www . j av a2 s .c o m JsonObject editors = RunnerRepository.getEditors(); int length = editors.entrySet().size(); if (editors.get("DEFAULT") != null) vecresult = new String[length - 1]; else vecresult = new String[length]; int index = 0; Entry entry; Iterator iter = editors.entrySet().iterator(); for (int i = 0; i < length; i++) { entry = (Entry) iter.next(); if (entry.getKey().toString().equals("DEFAULT")) continue; vecresult[index] = entry.getKey().toString(); index++; } return vecresult; }
From source file:ProcessRequest.java
public void updateProduct(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; recordObject.remove(DbSingleton.ProductSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.ProductSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); String productID = null;//w w w .ja v a 2s. c o m //construct the SQL query from the JSON elements. //the valuesPortion String will contain the values we want to update in the record { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //System.out.println(entry.getKey()+" : "+value.getAsString()); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'"); valuesPortion += entry.getKey() + "="; valuesPortion += "'" + value.getAsString() + "'"; if (entry.getKey().equals(DbSingleton.ProductSchema.COLUMN_ID)) { productID = value.getAsString(); } } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += value.getAsString(); } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString())); if (value.getAsBoolean()) { valuesPortion += entry.getKey() + "="; valuesPortion += "1"; } else { valuesPortion += entry.getKey() + "="; valuesPortion += "0"; } } } } } //String insertQuery = "INSERT INTO "+DbSingleton.TICKET_DETAIL_TABLE_NAME+"("+columnsPortion+") VALUES ("+valuesPortion+")"; if (productID == null) { throw new SQLException("no customer id found!"); } String updateQuery = "UPDATE " + DbSingleton.PRODUCT_TABLE_NAME + " SET " + valuesPortion + " WHERE " + DbSingleton.ProductSchema.COLUMN_ID + "='" + productID + "'"; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID"; executeQuery(updateQuery); }
From source file:ProcessRequest.java
public void newProduct(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String columnsPortion = ""; recordObject.remove(DbSingleton.ProductSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.ProductSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); {/*from ww w. ja v a2 s. co m*/ Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { if (!columnsPortion.equals("")) { columnsPortion += ","; } columnsPortion += entry.getKey(); } } } //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Long(value.getAsLong()).toString(); } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } if (value.getAsBoolean()) valuesPortion += "1"; else valuesPortion += "0"; } } } } String insertQuery = "INSERT INTO " + DbSingleton.PRODUCT_TABLE_NAME + "(" + columnsPortion + ") VALUES (" + valuesPortion + ")"; String identQuery = "SELECT IDENT_CURRENT ('" + DbSingleton.PRODUCT_TABLE_NAME + "') AS ProductID"; executeQuery(insertQuery); }
From source file:ProcessRequest.java
public void updateCustomer(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String dob = null;/* www . j a v a2s . c o m*/ try { dob = mDateFormat .format(new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_DOB))); } catch (JSONException jsone) { dob = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_DOB); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_DOB, dob); } String issueDate = null; try { issueDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE))); } catch (JSONException jsone) { issueDate = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE, issueDate); } String expirationDate = null; try { expirationDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE))); } catch (JSONException jsone) { expirationDate = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE, expirationDate); } recordObject.remove(DbSingleton.CustomerSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.CustomerSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); String customerID = null; //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //System.out.println(entry.getKey()+" : "+value.getAsString()); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'"); valuesPortion += entry.getKey() + "="; valuesPortion += "'" + value.getAsString() + "'"; if (entry.getKey().equals(DbSingleton.CustomerSchema.COLUMN_ID)) { customerID = value.getAsString(); } } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += value.getAsString(); } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString())); if (value.getAsBoolean()) { valuesPortion += entry.getKey() + "="; valuesPortion += "1"; } else { valuesPortion += entry.getKey() + "="; valuesPortion += "0"; } } } } } //String insertQuery = "INSERT INTO "+DbSingleton.TICKET_DETAIL_TABLE_NAME+"("+columnsPortion+") VALUES ("+valuesPortion+")"; if (customerID == null) { throw new SQLException("no customer id found!"); } String updateQuery = "UPDATE " + DbSingleton.CUSTOMER_TABLE_NAME + " SET " + valuesPortion + " WHERE " + DbSingleton.CustomerSchema.COLUMN_ID + "='" + customerID + "'"; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID"; executeQuery(updateQuery); }
From source file:ProcessRequest.java
public void newCustomer(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String columnsPortion = ""; String dob = null;/* w w w .jav a 2s. co m*/ try { dob = mDateFormat .format(new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_DOB))); } catch (JSONException jsone) { dob = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_DOB); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_DOB, dob); } String issueDate = null; try { issueDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE))); } catch (JSONException jsone) { issueDate = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE, issueDate); } String expirationDate = null; try { expirationDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE))); } catch (JSONException jsone) { expirationDate = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE, expirationDate); } recordObject.remove(DbSingleton.CustomerSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.CustomerSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { if (!columnsPortion.equals("")) { columnsPortion += ","; } columnsPortion += entry.getKey(); } } } //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Long(value.getAsLong()).toString(); } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } if (value.getAsBoolean()) valuesPortion += "1"; else valuesPortion += "0"; } } } } String insertQuery = "INSERT INTO " + DbSingleton.CUSTOMER_TABLE_NAME + "(" + columnsPortion + ") VALUES (" + valuesPortion + ")"; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.CUSTOMER_TABLE_NAME+"') AS CustomerID"; //String customerIsHaulerQuery = "SELECT * FROM "+DbSingleton.CUSTOMER_TABLE_NAME+" " executeQuery(insertQuery); /* ResultSet identResultSet = executeQuery(identQuery); identResultSet.first(); //System.out.println(identResultSet.getRow()); int customerID = identResultSet.getInt(1); //System.out.println(ticketID); return customerID; */ }