List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:com.fujitsu.dc.test.utils.RoleUtils.java
/** * NP?Role??.//ww w.j a va 2s . c om * @param cellName ?? * @param token * @param srcEntityName ??? * @param srcEntityKeyString ?"Name='xxx'" * @param roleName ?? * @param code ? * @return ? */ @SuppressWarnings("unchecked") public static TResponse createViaNP(final String cellName, final String token, final String srcEntityName, final String srcEntityKeyString, final String roleName, final int code) { JSONObject body = new JSONObject(); body.put("Name", roleName); return Http.request("cell/createNPWithoutQuote.txt").with("method", HttpMethod.POST) .with("token", "Bearer " + token).with("cell", cellName).with("entityType", srcEntityName) .with("id", srcEntityKeyString).with("navPropName", "_Role") .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON) .with("body", body.toJSONString()).returns().statusCode(code); }
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
/** * Convert a given ObirsQuery object into a JSON format * * @param query/* ww w .j a v a2s . c o m*/ * @return * @throws IOException */ public static String jsonifyObirsQuery(ObirsQuery query) throws IOException { JSONObject jsonObject = new JSONObject(); jsonObject.put("aggregator", query.getAggregator()); jsonObject.put("aggregatorParameter", query.getAggregatorParameter()); jsonObject.put("similarityMeasure", query.getSimilarityMeasure()); jsonObject.put("scoreThreshold", query.getScoreThreshold()); jsonObject.put("numberOfResults", query.getNumberOfResults()); StringWriter jsonQuery = new StringWriter(); JSONArray jsonConcepts = new JSONArray(); for (Map.Entry<URI, Double> queryConcept : query.getConcepts().entrySet()) { JSONObject jsonConcept = new JSONObject(); URI conceptURI = queryConcept.getKey(); jsonConcept.put("uri", conceptURI.stringValue()); jsonConcept.put("weight", queryConcept.getValue()); jsonConcepts.add(jsonConcept); } jsonObject.put("concepts", jsonConcepts); jsonObject.writeJSONString(jsonQuery); return jsonQuery.toString(); }
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
public static String buildJSONString(Set<Autocompletion_Trie.AutocompleteElement> autocomplete) throws IOException { JSONArray jsonResults = new JSONArray(); StringWriter json = new StringWriter(); for (Autocompletion_Trie.AutocompleteElement result : autocomplete) { JSONObject jsonResult = new JSONObject(); jsonResult.put("uri", result.id); jsonResult.put("label", result.label); jsonResults.add(jsonResult);/*from w w w. java 2 s.c o m*/ } JSONObject finalJSONresult = new JSONObject(); finalJSONresult.put("results", jsonResults); finalJSONresult.writeJSONString(json); return json.toString(); }
From source file:com.fujitsu.dc.test.utils.RoleUtils.java
/** * NP?Role??./*from www . j a va 2s .co m*/ * @param cellName ?? * @param authorization Authorization?(auth-schema?) * @param srcEntityName ??? * @param srcEntityKeyString ?"Name='xxx'" * @param roleName ?? * @param code ? * @return ? */ @SuppressWarnings("unchecked") public static TResponse createViaNPWithAuthSchema(final String cellName, final String authorization, final String srcEntityName, final String srcEntityKeyString, final String roleName, final int code) { JSONObject body = new JSONObject(); body.put("Name", roleName); String key = srcEntityKeyString; if (srcEntityKeyString != null && !srcEntityKeyString.contains("'")) { key = "'" + srcEntityKeyString + "'"; } return Http.request("cell/createNPWithoutQuote.txt").with("method", HttpMethod.POST) .with("token", authorization).with("cell", cellName).with("entityType", srcEntityName) .with("id", key).with("navPropName", "_Role").with("accept", MediaType.APPLICATION_JSON) .with("contentType", MediaType.APPLICATION_JSON).with("body", body.toJSONString()).returns() .statusCode(code); }
From source file:com.fujitsu.dc.test.utils.RoleUtils.java
/** * ./*ww w .ja va2 s . com*/ * @param token ? * @param cellName ?? * @param roleName ?? * @param newRoleName ?? * @param boxName ?? * @param sc * @return ? */ @SuppressWarnings("unchecked") public static TResponse update(String token, String cellName, String roleName, String newRoleName, String boxName, int sc) { JSONObject body = new JSONObject(); body.put("Name", newRoleName); String boxNameStr = null; if (boxName != null) { body.put("_Box.Name", boxName); boxNameStr = "'" + boxName + "'"; } else { boxNameStr = "null"; } TResponse res = Http.request("cell/role-update.txt").with("cellPath", cellName).with("token", token) .with("rolename", roleName).with("boxname", boxNameStr).with("body", body.toString()).returns() .statusCode(sc); return res; }
From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java
public static String getAllLists(List<String> listTypeList) { UserListBeanHelper helper = new UserListBeanHelper(); JSONArray listContainerArray = new JSONArray(); for (String listType : listTypeList) { Collection<String> myLists = new ArrayList<String>(); JSONObject listContainer = new JSONObject(); JSONArray myJSONLists = new JSONArray(); listContainer.put("listType", listType); //which do we want to display differently in the UI myLists = helper.getGenericListNames(ListType.valueOf(listType)); for (String listName : myLists) { UserList ul = helper.getUserList(listName); DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm aaa", Locale.US); if (ul != null) { String listSubType = ""; if (ul.getListSubType() != null) { listSubType = "Subtype: " + ul.getListSubType().toString() + " - "; }//from w w w. j a v a 2 s . c o m JSONObject jsonListName = new JSONObject(); String listNotes = ul.getNotes(); if (ul.getNotes() != null) { if (listNotes.length() > 100) { listNotes = listNotes.substring(0, 99); } } String style = ""; if (ul.getListOrigin() != null) { jsonListName.put("origin", ul.getListOrigin().toString()); if (ul.getListOrigin().equals(ListOrigin.Default)) { style = "color:#000000"; jsonListName.put("highlightType", style); } if (ul.getListOrigin().equals(ListOrigin.Custom)) { style = "color:#A90101"; jsonListName.put("highlightType", style); } } else { jsonListName.put("highlightType", style); } jsonListName.put("author", ul.getAuthor()); jsonListName.put("notes", listNotes); jsonListName.put("listSubType", listSubType); jsonListName.put("listName", ul.getName()); if (ul.getDateCreated() != null) { jsonListName.put("listDate", dateFormat.format(ul.getDateCreated()).toString()); } jsonListName.put("itemCount", String.valueOf(ul.getItemCount())); jsonListName.put("invalidItems", String.valueOf(ul.getInvalidList().size())); String commas = StringUtils.join(ul.getList().toArray(), ", "); jsonListName.put("listItems", commas); myJSONLists.add(jsonListName); } } listContainer.put("listItems", myJSONLists); listContainerArray.add(listContainer); } return listContainerArray.toString(); }
From source file:io.personium.test.utils.RoleUtils.java
/** * Role??./* ww w . jav a 2s . com*/ * @param cellName ?? * @param token * @param roleName ?? * @param boxName ?? * @param code ? * @return ? */ @SuppressWarnings("unchecked") public static TResponse create(final String cellName, final String token, final String roleName, final String boxName, final int code) { JSONObject body = new JSONObject(); body.put("Name", roleName); if (boxName != null) { body.put("_Box.Name", boxName); } return Http.request("role-create.txt").with("token", token).with("cellPath", cellName) .with("body", body.toString()).returns().statusCode(code); }
From source file:ch.newscron.encryption.Encryption.java
/** * Given a JSONObject, and maybe an hash, it is encoded and returned as a String. * @param inviteData is a JSONObject having the data with the keys "customerId", "rew1", "rew2" and "val" * @param md5Hash is a String that substitute the hash computed using md5 algorithm, in case it is not null and not empty * @return encoded string //from www . j av a 2 s.co m */ protected static String encode(JSONObject inviteData, String md5Hash) { try { //Check in case we want to add a given hash (having at the end a corrupt data) if (md5Hash != null && !md5Hash.isEmpty()) { //Add md5Hash to JSONObject inviteData.put("hash", md5Hash); } else { return null; } //Encode inviteData (with hash) JSONObject String params = inviteData.toString(); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(initializationVector.getBytes("UTF-8"))); return Base64.encodeBase64URLSafeString(cipher.doFinal(params.getBytes())); //to ensure valid URL characters } catch (Exception e) { } return null; }
From source file:luceneindexdemo.LuceneIndexDemo.java
public static void searchIndex(String s) throws IOException, ParseException, SQLException, FileNotFoundException, org.json.simple.parser.ParseException { Directory directory = FSDirectory.getDirectory(INDEX_DIRECTORY); IndexReader reader = IndexReader.open(directory); IndexSearcher search = new IndexSearcher(reader); Analyzer analyzer = new StandardAnalyzer(); QueryParser queryparser = new QueryParser(FIELD_CONTENTS, analyzer); Query query = queryparser.parse(s); Hits hits = search.search(query);//www.j ava 2 s . co m Iterator<Hit> it = hits.iterator(); //System.out.println("hits:"+hits.length()); float f_score; List<String> names = new ArrayList<>(); while (it.hasNext()) { Hit hit = it.next(); f_score = hit.getScore(); //System.out.println(f_score); Document document = hit.getDocument(); Field f = document.getField(FIELD_PATH); //System.out.println(f.readerValue()); //System.out.println(document.getValues(FIELD_PATH)); String path = document.get(FIELD_PATH); System.out.println(document.getValues(path)); Field con = document.getField(FIELD_PATH); //System.out.println("hit:"+path+" "+hit.getId()+" "+con); names.add(new File(path).getName()); } //ProcessBuilder pb=new ProcessBuilder(); FileReader fReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/inntell.json"); JSONParser jsParser = new JSONParser(); //System.out.println("This is an assumption that you belong to US"); FileReader freReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/location.json"); Connection con = DriverManager.getConnection("jdbc:neo4j://localhost:7474/"); System.out.println(names); if (names.get(0).equals("miss")) { System.out.println(s); StringTokenizer stringTokenizer = new StringTokenizer(s); Connection con1 = DriverManager.getConnection("jdbc:neo4j://localhost:7474/"); String querySearch = "match ()-[r:KNOWS]-() where has(r.relType) return distinct r.relType"; ResultSet rSet = con.createStatement().executeQuery(querySearch); List<String> allRels = new ArrayList<>(); while (rSet.next()) { System.out.println(); allRels.add(rSet.getString("r.relType")); } //System.out.println(rSet); while (stringTokenizer.hasMoreTokens()) { String next = stringTokenizer.nextToken(); if (allRels.contains(next)) { missOperation(next); } //System.out.println(resSet.getString("r.relType")); } System.out.println(names.get(1)); //missOperation(names.get(1)); } else { try { JSONObject jsonObj = (JSONObject) jsParser.parse(fReader); System.out.println(names.get(0)); JSONObject jsObj = (JSONObject) jsonObj.get(names.get(0)); JSONObject results = new JSONObject(); System.out.println(jsObj.get("explaination")); results.put("explaination", jsObj.get("explaination")); JSONArray reqmts = (JSONArray) jsObj.get("true"); System.out.println("Let me look out for the places that contains "); List<String> lis = new ArrayList<>(); JSONObject locObj = (JSONObject) jsParser.parse(freReader); JSONArray jsArray = (JSONArray) locObj.get("CHENNAI"); Iterator<JSONArray> ite = reqmts.iterator(); int k = 0; String resQuery = "START n=node:restaurant('withinDistance:[" + jsArray.get(0) + "," + jsArray.get(1) + ",7.5]') where"; Iterator<JSONArray> ite1 = reqmts.iterator(); while (ite1.hasNext()) System.out.println(ite1.next()); while (ite.hasNext()) { lis.add("n.type=" + "'" + ite.next() + "'"); if (k == 0) resQuery += " " + lis.get(k); else resQuery += " or " + lis.get(k); //System.out.println(attrib); k++; } resQuery += " return n.name,n.place,n.type"; File writeTo = new File( "/home/rishav12/NetBeansProjects/LuceneIndexDemo/filestoIndex1/" + names.get(0)); FileOutputStream fop = new FileOutputStream(writeTo, true); String writeTOFile = s + "\n"; fop.write(writeTOFile.getBytes()); //System.out.println(resQuery); ResultSet res = con.createStatement().executeQuery(resQuery); JSONArray resSet = new JSONArray(); while (res.next()) { System.out.println(" name:" + res.getString("n.name") + " located:" + res.getString("n.place") + " type:" + res.getString("n.type")); JSONObject jsPart = new JSONObject(); jsPart.put("name", res.getString("n.name")); jsPart.put("located", res.getString("n.place")); jsPart.put("type", res.getString("n.type")); resSet.add(jsPart); } results.put("results", resSet); File resultFile = new File("result.json"); FileOutputStream fop1 = new FileOutputStream(resultFile); System.out.println(results); fop1.write(results.toJSONString().getBytes()); //String resQuery="START n=node:restaurant('withinDistance:[40.7305991, -73.9865812,10.0]') where n.coffee=true return n.name,n.address;"; //System.out.println("Sir these results are for some coffee shops nearby NEW YORK"); //ResultSet res=con.createStatement().executeQuery(resQuery); //while(res.next()) //System.out.println("name: "+res.getString("n.name")+" address: "+res.getString("n.address")); } catch (org.json.simple.parser.ParseException ex) { Logger.getLogger(LuceneIndexDemo.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:bizlogic.Records.java
public static void list(Connection DBcon) throws IOException, ParseException, SQLException { Statement st;//from w w w . j ava 2 s. c o m ResultSet rs = null; try { st = DBcon.createStatement(); rs = st.executeQuery("SELECT userconf.log_list.sensor_id, " + "userconf.log_list.smpl_interval, " + "userconf.log_list.running, " + "userconf.log_list.name AS log_name, " + "userconf.log_list.log_id, " + "userconf.sensorlist.name AS sensor_name " + "FROM USERCONF.LOG_LIST " + "JOIN userconf.sensorlist " + "ON userconf.log_list.sensor_id=userconf.sensorlist.sensor_id"); } catch (SQLException ex) { Logger lgr = Logger.getLogger(Records.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } try { FileWriter recordsFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/records.json"); //BufferedWriter recordsFile = new BufferedWriter(_file); //recordsFile.write(""); //recordsFile.flush(); FileReader fr = new FileReader("/var/lib/tomcat8/webapps/ROOT/Records/records.json"); BufferedReader br = new BufferedReader(fr); JSONObject Records = new JSONObject(); int _total = 0; JSONArray recordList = new JSONArray(); while (rs.next()) { String isRunningStr; JSONObject sensor_Obj = new JSONObject(); int sensor_id = rs.getInt("sensor_id"); sensor_Obj.put("sensor_id", sensor_id); String smpl_interval = rs.getString("smpl_interval"); sensor_Obj.put("smpl_interval", smpl_interval); Boolean running = rs.getBoolean("running"); if (running) { //System.out.print("1"); isRunningStr = "ON"; } else { //System.out.print("0"); isRunningStr = "OFF"; } sensor_Obj.put("running", isRunningStr); String log_name = rs.getString("log_name"); sensor_Obj.put("log_name", log_name); String sensor_name = rs.getString("sensor_name"); sensor_Obj.put("sensor_name", sensor_name); int log_id = rs.getInt("log_id"); sensor_Obj.put("recid", log_id); recordList.add(sensor_Obj); _total++; } rs.close(); Records.put("total", _total); Records.put("records", recordList); recordsFile.write(Records.toJSONString()); recordsFile.flush(); recordsFile.close(); System.out.print(Records.toJSONString()); System.out.print(br.readLine()); } catch (IOException ex) { Logger.getLogger(Records.class.getName()).log(Level.SEVERE, null, ex); } }