List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:com.fujitsu.dc.test.utils.CellUtils.java
/** * __event/{boxName}?POST?.//from w w w.ja va 2 s .c om * @param authorization Authorization?(auth-shema?) * @param cellName ?? * @param boxName ?? * @param level * @param action ? * @param object ? * @param result ?? * @return ? * @throws DcException */ @SuppressWarnings("unchecked") public static DcResponse eventUnderBox(String authorization, String cellName, String boxName, String level, String action, String object, String result) throws DcException { JSONObject body = new JSONObject(); body.put("level", level); body.put("action", action); body.put("object", object); body.put("result", result); DcRestAdapter adaper = new DcRestAdapter(); HashMap<String, String> header = new HashMap<String, String>(); header.put(HttpHeaders.AUTHORIZATION, authorization); return adaper.post(UrlUtils.cellRoot(cellName) + "__event/" + boxName, body.toJSONString(), header); }
From source file:io.personium.test.utils.CellUtils.java
/** * __event/{boxName}?POST?.//from ww w . j a va 2 s . c o m * @param authorization Authorization?(auth-shema?) * @param cellName ?? * @param boxName ?? * @param level * @param action ? * @param object ? * @param result ?? * @return ? * @throws PersoniumException */ @SuppressWarnings("unchecked") public static PersoniumResponse eventUnderBox(String authorization, String cellName, String boxName, String level, String action, String object, String result) throws PersoniumException { JSONObject body = new JSONObject(); body.put("level", level); body.put("action", action); body.put("object", object); body.put("result", result); PersoniumRestAdapter adaper = new PersoniumRestAdapter(); HashMap<String, String> header = new HashMap<String, String>(); header.put(HttpHeaders.AUTHORIZATION, authorization); return adaper.post(UrlUtils.cellRoot(cellName) + "__event/" + boxName, body.toJSONString(), header); }
From source file:fileoperations.FileOperations.java
public static JSONObject SupToReportsPropsToJSObj(String fileName) { BufferedReader fileReader = null; final String DELIMITER = ":"; final String VALUEDELIMITER = "="; JSONObject SupToReportsPropsJSObj = new JSONObject(); JSONObject urlparams = new JSONObject(); JSONObject supDetails = new JSONObject(); JSONObject repDetails = new JSONObject(); supDetails.put(URLPARAMS, urlparams); SupToReportsPropsJSObj.put("supDetails", supDetails); SupToReportsPropsJSObj.put("repDetails", repDetails); try {/*from w ww . j a va 2s . com*/ String line = ""; //Create the file reader fileReader = new BufferedReader(new FileReader(fileName)); //Read the file line by line while ((line = fileReader.readLine()) != null) { //Get all tokens available in line String[] tokens = line.split(DELIMITER); if (tokens.length == 0) { continue; } if (tokens[0].equals("sup")) { if (tokens[1].contains("authtoken")) { urlparams.put(AUTHTOKEN, tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("portal")) { urlparams.put(PORTAL, tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("department")) { urlparams.put(DEPARTMENT, tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("columns")) { String columnsStr = tokens[1].split(VALUEDELIMITER)[1].trim(); String[] columnsArr = columnsStr.split(","); supDetails.put(COLUMNS, columnsArr); } else if (tokens[1].contains("SearchCriteria")) { String searchCriteria = tokens[1].split(VALUEDELIMITER)[1].trim(); String[] searchParams = searchCriteria.split("@"); supDetails.put(SEARCHPARAMS, searchParams); } } else if (tokens[0].equals("rep")) { if (tokens[1].contains("URLEmail")) { repDetails.put("URLEmail", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("DBName")) { repDetails.put("DBName", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("TableName")) { repDetails.put("TableName", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("authToken")) { repDetails.put(AUTHTOKEN, tokens[1].split(VALUEDELIMITER)[1].trim()); } if (tokens[1].contains("ZOHO_IMPORT_TYPE")) { repDetails.put("ZOHO_IMPORT_TYPE", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("ZOHO_ON_IMPORT_ERROR")) { repDetails.put("ZOHO_ON_IMPORT_ERROR", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("ZOHO_MATCHING_COLUMNS")) { repDetails.put("ZOHO_MATCHING_COLUMNS", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("ZOHO_DATE_FORMAT")) { repDetails.put("ZOHO_DATE_FORMAT", tokens[1].split(VALUEDELIMITER)[1].trim()); } else if (tokens[1].contains("ZOHO_SELECTED_COLUMNS")) { // repDetails.put("ZOHO_DATE_FORMAT",tokens[1].split(VALUEDELIMITER)[1].trim()); repDetails.put("ZOHO_SELECTED_COLUMNS", tokens[1].split(VALUEDELIMITER)[1].trim()); } } else if (tokens[0].equals("sup_rep")) { String Sup_rep_Columns = tokens[1].trim(); if (Sup_rep_Columns != null && !Sup_rep_Columns.equals("")) { repDetails.put("supTorepColumnHeader", Sup_rep_Columns); } } else if (tokens[0].equals("rep_extra")) { String extraColumns = tokens[1].trim(); if (extraColumns != null && !extraColumns.equals("")) { repDetails.put("newColumnHeader", extraColumns); } } } } catch (Exception e) { loggerObj.log(Level.SEVERE, "Exception while parsing the file " + fileName + "\n Exception is: ", e); return null; } finally { try { fileReader.close(); } catch (IOException e) { loggerObj.log(Level.SEVERE, "Exception while Closing the file " + fileName + "\n Exception is: ", e); return null; } } return SupToReportsPropsJSObj; }
From source file:com.jts.rest.profileservice.utils.RestServiceHelper.java
/** * Gets the recent challenges and splits them to active and past challenges * Maximum 3 past challenges and all active challenges will be returned * @param sessionId/* ww w . j a v a 2 s . c o m*/ * @param username * @return * @throws MalformedURLException * @throws IOException */ @SuppressWarnings("unchecked") public static JSONObject getProcessedChallengesM2(String sessionId, String username) throws MalformedURLException, IOException { JSONArray recentChallenges = getRecentParticipantChallengesByUsername(sessionId, username); JSONArray activeChallenges = new JSONArray(); JSONArray pastChallenges = new JSONArray(); Iterator<JSONObject> iterator = recentChallenges.iterator(); while (iterator.hasNext()) { JSONObject participantChallenge = iterator.next(); JSONObject challenge = (JSONObject) participantChallenge.get("Challenge__r"); if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) { //active challenge activeChallenges.add(participantChallenge); JSONArray categories = getCategoriesByChallenge(sessionId, (String) participantChallenge.get("Challenge__c")); participantChallenge.put("categories", categories); } else { //past challenges if (pastChallenges.size() < 3) { pastChallenges.add(participantChallenge); JSONArray categories = getCategoriesByChallenge(sessionId, (String) participantChallenge.get("Challenge__c")); participantChallenge.put("categories", categories); } } } JSONObject challenges = new JSONObject(); challenges.put("activeChallenges", activeChallenges); challenges.put("pastChallenges", pastChallenges); challenges.put("totalChallenges", getChallengeCountByUser(sessionId, username)); return challenges; }
From source file:com.iitb.cse.Utils.java
/** * genetated and returns the String in Json format. String contains * information that the experiment has been stopped by experimenter This * string is later sent to filtered devices. *//*from w w w. j a v a 2s. c o m*/ @SuppressWarnings("unchecked") static String getStopSignalJson() { JSONObject obj = new JSONObject(); obj.put(Constants.action, Constants.stopExperiment); String jsonString = obj.toJSONString(); System.out.println(jsonString); return jsonString; }
From source file:com.iitb.cse.Utils.java
/** * genetated and returns the String in Json format. String contains * information that the experimentee wants to ping the devices and refresh * the list of registered devices This string is later sent to registered * devices.// w w w . ja va 2 s . c om */ @SuppressWarnings("unchecked") static String getRefreshRegistrationJson() { JSONObject obj = new JSONObject(); obj.put(Constants.action, Constants.refreshRegistration); String jsonString = obj.toJSONString(); System.out.println(jsonString); return jsonString; }
From source file:com.iitb.cse.Utils.java
/** * genetated and returns the String in Json format. String contains * information that all the registration has been cleared by experimenter * This string is later sent to filtered devices. *///www . j a v a2 s . c o m @SuppressWarnings("unchecked") static String getClearRegistrationJson() { JSONObject obj = new JSONObject(); obj.put(Constants.action, Constants.clearRegistration); String jsonString = obj.toJSONString(); System.out.println(jsonString); return jsonString; }
From source file:com.iitb.cse.Utils.java
@SuppressWarnings("unchecked") static String getHeartBeatDuration(String duration) { JSONObject obj = new JSONObject(); obj.put(Constants.action, "hbDuration"); obj.put("heartbeat_duration", duration); obj.put("hbDuration", duration); String jsonString = obj.toJSONString(); System.out.println(jsonString); return jsonString; }
From source file:com.iitb.cse.Utils.java
/** * genetated and returns the String in Json format. String contains * information about the action for sending AP settings file This string is * later sent to filtered devices.//from ww w . ja v a 2s . c o m */ @SuppressWarnings("unchecked") static String getControlFileJson(String message, String timeout, String logBgTraffic) { JSONObject obj = new JSONObject(); obj.put(Constants.action, Constants.sendControlFile); obj.put(Constants.textFileFollow, Boolean.toString(true)); obj.put(Constants.serverTime, Long.toString(Calendar.getInstance().getTimeInMillis())); obj.put(Constants.message, message); obj.put(Constants.timeout, timeout); obj.put("selectiveLog", logBgTraffic); String jsonString = obj.toJSONString(); Date obj1 = new Date(Long.parseLong((String) obj.get(Constants.serverTime))); System.out.println(jsonString + obj1); return jsonString; }
From source file:com.intbit.dao.ScheduleSocialPostDAO.java
public static JSONArray getScheduledActionsfacebook(int userid) throws SQLException { JSONObject json_action_facebook = new JSONObject(); JSONArray json_array_facebook = new JSONArray(); String query = "Select * from tbl_scheduled_entity_list" + " where entity_id=?" + " and entity_type =?" + " and user_id = ?"; try (Connection conn = connectionManager.getConnection(); PreparedStatement ps = conn.prepareStatement(query)) { ps.setInt(1, 0);// w w w . j ava 2s . c om ps.setString(2, "facebook"); ps.setInt(3, userid); try (ResultSet result_set = ps.executeQuery()) { while (result_set.next()) { JSONObject json_object = new JSONObject(); Integer id = result_set.getInt("id"); String schedule_title = result_set.getString("schedule_title"); String schedule_desc = result_set.getString("schedule_desc"); Timestamp scheduleTimestamp = result_set.getTimestamp("schedule_time"); long scheduleTime = scheduleTimestamp.getTime(); json_object.put("id", id); json_object.put("schedule_title", schedule_title); json_object.put("schedule_desc", schedule_desc); json_object.put("schedule_time", scheduleTime); json_array_facebook.add(json_object); } } } return json_array_facebook; }