Refine search
protected void addSkus(final HttpServletRequest request, final Product product, final JSONObject productData, final String url) throws JSONException { final JSONArray offers = new JSONArray(); final String currency = product.getRetailPrice().getCurrency().getCurrencyCode(); BigDecimal highPrice = BigDecimal.ZERO; final JSONObject offer = new JSONObject(); offer.put("@type", "Offer"); offer.put("sku", sku.getId()); offer.put("priceCurrency", currency); offer.put("availability", determineAvailability(sku)); offers.put(offer); if (offers.length() > 1) { final JSONObject aggregateOffer = new JSONObject(); aggregateOffer.put("@type", "AggregateOffer"); aggregateOffer.put("lowPrice", lowPrice.doubleValue()); aggregateOffer.put("priceCurrency", currency); aggregateOffer.put("offerCount", offers.length()); aggregateOffer.put("offers", offers);
private Map<Integer, JSONObject> listSessions() throws IOException { String sessionsUrl = livyUrl + "/sessions"; int numSessions; JSONObject sessionsInfo; Map<Integer, JSONObject> sessionsMap = new HashMap<>(); Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", APPLICATION_JSON); headers.put("X-Requested-By", USER); try { sessionsInfo = readJSONFromUrl(sessionsUrl, headers); numSessions = sessionsInfo.getJSONArray("sessions").length(); for (int i = 0; i < numSessions; i++) { int currentSessionId = sessionsInfo.getJSONArray("sessions").getJSONObject(i).getInt("id"); JSONObject currentSession = sessionsInfo.getJSONArray("sessions").getJSONObject(i); sessionsMap.put(currentSessionId, currentSession); } } catch (JSONException e) { throw new IOException(e); } return sessionsMap; }
@Override public void removeProperty(Object obj, Object key) { try { if( obj instanceof org.codehaus.jettison.json.JSONArray ) { int index = key instanceof Integer? (Integer) key : Integer.parseInt(key.toString()); if( index<length(obj) ) { Object temp = new Object(); // Need FIX: JSONArray.remove(int) ((org.codehaus.jettison.json.JSONArray)obj).put(index, temp); ((org.codehaus.jettison.json.JSONArray)obj).remove(temp); } } if( obj instanceof org.codehaus.jettison.json.JSONObject ) { ((org.codehaus.jettison.json.JSONObject)obj).remove(String.valueOf(key)); } } catch( org.codehaus.jettison.json.JSONException jsonException ) { throw new IllegalStateException(jsonException); } }
protected JSONArray addContactData(final HttpServletRequest request) throws JSONException { final JSONArray contactList = new JSONArray(); final JSONObject contact = new JSONObject(); contact.put("@type", "ContactPoint"); contact.put("telephone", getSiteCustomerServiceNumber()); contact.put("contactType", "customerService"); extensionManager.getProxy().addContactData(request, contact); contactList.put(contact); return contactList; }
@GET @Path("/compactionstats") public Response compactionStats() throws IOException, ExecutionException, InterruptedException, JSONException { return Response.status(503).entity("JMXConnectionException").build(); JSONObject rootObj = new JSONObject(); CompactionManagerMBean cm = nodeTool.getCompactionManagerProxy(); rootObj.put("pending tasks", cm.getPendingTasks()); JSONArray compStats = new JSONArray(); for (Map<String, String> c : cm.getCompactions()) { JSONObject cObj = new JSONObject(); cObj.put("id", c.get("id")); cObj.put("keyspace", c.get("keyspace")); + "%"; cObj.put("progress", percentComplete); compStats.put(cObj); rootObj.put("compaction stats", compStats);
@GET @Path("/version") public Response version() throws IOException, ExecutionException, InterruptedException { JMXNodeTool nodeTool; try { nodeTool = JMXNodeTool.instance(config); } catch (JMXConnectionException e) { logger.error( "Exception in fetching c* jmx tool . Msgl: {}", e.getLocalizedMessage(), e); return Response.status(503).entity("JMXConnectionException").build(); } return Response.ok( new JSONArray().put(nodeTool.getReleaseVersion()), MediaType.APPLICATION_JSON) .build(); }
/** * Returns a list of colours as a JSON array. * @param filter If not empty, constrains the list of colours to only * those that contain this substring * @return the list of colours matching the filter */ @GET @Produces("application/json") public JSONArray getColourListAsJSON(@QueryParam("match") String filter) { return new JSONArray(getMatchingColours(filter)); }
@GET @Path("test") @Produces(MediaType.TEXT_PLAIN) public String test() { try { _logger.info("WMS:test\n"); JSONArray id = successResponse(Main.getWorkMgr().getStatusJson()); return id.toString(); // return Response.ok() // .entity(id) // // .header("Access-Control-Allow-Origin","*") // .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT") // .allow("OPTIONS") // .build(); } catch (Exception e) { String stackTrace = Throwables.getStackTraceAsString(e); _logger.errorf("WMS:test exception: %s", stackTrace); // return Response.serverError().build(); return "got error"; } }
@Override public List<SModelCheckerInstance> getAllRepositoryModelCheckers() throws ServerException, UserException { requireRealUserAuthentication(); try { List<SModelCheckerInstance> modelCheckers = new ArrayList<SModelCheckerInstance>(); String content = NetUtils.getContent(new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/modelcheckers"), 5000); JSONObject root = new JSONObject(new JSONTokener(content)); JSONArray modelCheckersJson = root.getJSONArray("modelcheckers"); for (int i = 0; i < modelCheckersJson.length(); i++) { JSONObject modelCheckerJson = modelCheckersJson.getJSONObject(i); SModelCheckerInstance sModelChecker = new SModelCheckerInstance(); sModelChecker.setName(modelCheckerJson.getString("name")); sModelChecker.setCode(modelCheckerJson.getString("code")); sModelChecker.setDescription(modelCheckerJson.getString("description")); sModelChecker.setModelCheckerPluginClassName(modelCheckerJson.getString("modelCheckerPluginClassName")); modelCheckers.add(sModelChecker); } return modelCheckers; } catch (Exception e) { return handleException(e); } }
URL url = new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/services.json"); String content = NetUtils.getContent(url, 5000); JSONObject root = new JSONObject(new JSONTokener(content)); JSONArray services = root.getJSONArray("services"); for (int i = 0; i < services.length(); i++) { JSONObject service = services.getJSONObject(i); SServiceDescriptor sServiceDescriptor = new SServiceDescriptor(); sServiceDescriptor.setName(service.getString("name")); sServiceDescriptor.setIdentifier(service.getString("identifier")); sServiceDescriptor.setDescription(service.getString("description"));
public Set<String> getSubmittedYarnApps() throws Exception { String rmHost = PhoenixMRJobUtil.getActiveResourceManagerHost(conf, zkQuorum); Map<String, String> urlParams = new HashMap<String, String>(); urlParams.put(YarnApplication.APP_STATES_ELEMENT, YarnApplication.state.NEW.toString() + "," + YarnApplication.state.ACCEPTED + "," + YarnApplication.state.SUBMITTED + "," + YarnApplication.state.RUNNING); int rmPort = PhoenixMRJobUtil.getRMPort(conf); String response = PhoenixMRJobUtil.getJobsInformationFromRM(rmHost, rmPort, urlParams); LOG.debug("Already Submitted/Running Apps = " + response); JSONObject jobsJson = new JSONObject(response); JSONObject appsJson = jobsJson.optJSONObject(YarnApplication.APPS_ELEMENT); Set<String> yarnApplicationSet = new HashSet<String>(); if (appsJson == null) { return yarnApplicationSet; } JSONArray appJson = appsJson.optJSONArray(YarnApplication.APP_ELEMENT); if (appJson == null) { return yarnApplicationSet; } for (int i = 0; i < appJson.length(); i++) { Gson gson = new GsonBuilder().create(); YarnApplication yarnApplication = gson.fromJson(appJson.getJSONObject(i).toString(), new TypeToken<YarnApplication>() { }.getType()); yarnApplicationSet.add(yarnApplication.getName()); } return yarnApplicationSet; }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }
@Override protected JSONArray getLinkedDataJsonInternal(final String url, final HttpServletRequest request, final JSONArray schemaObjects) throws JSONException { final JSONObject categoryData = new JSONObject(); categoryData.put("@context", getStructuredDataContext()); categoryData.put("@type", "ItemList"); addCategoryProductData(request, categoryData); extensionManager.getProxy().addCategoryData(request, categoryData); schemaObjects.put(categoryData); return schemaObjects; }
public void verifyJobAttempts(JSONObject info, Job job) throws JSONException { JSONArray attempts = info.getJSONArray("jobAttempt"); assertEquals("incorrect number of elements", 2, attempts.length()); for (int i = 0; i < attempts.length(); i++) { JSONObject attempt = attempts.getJSONObject(i); verifyJobAttemptsGeneric(job, attempt.getString("nodeHttpAddress"), attempt.getString("nodeId"), attempt.getInt("id"), attempt.getLong("startTime"), attempt.getString("containerId"), attempt.getString("logsLink")); } }
public static Map<String, String> toStringMap(final JSONArray names, final JSONObject values) throws JSONException { final Map<String, String> result = Maps.newHashMap(); for (int i = 0; i < names.length(); i++) { final String key = names.getString(i); result.put(key, values.getString(key)); } return result; } }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
/** * Produce a JSONArray containing the names of the elements of this * JSONObject. * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
private void initVpcOptions(JSONObject vpcOptions) throws JSONException { _vpcId = vpcOptions.getString(JSON_KEY_ES_VPC_ID); JSONArray securityGroupIds = vpcOptions.getJSONArray(JSON_KEY_SECURITY_GROUP_IDS); for (int i = 0; i < securityGroupIds.length(); i++) { _securityGroups.add(securityGroupIds.getString(i)); } JSONArray subnetIds = vpcOptions.getJSONArray(JSON_KEY_SUBNET_IDS); for (int i = 0; i < subnetIds.length(); i++) { _subnets.add(subnetIds.getString(i)); } }