List of usage examples for org.json JSONObject getBoolean
public boolean getBoolean(String key) throws JSONException
From source file:net.dv8tion.jda.core.handle.GuildDeleteHandler.java
@Override protected Long handleInternally(JSONObject content) { final long id = content.getLong("id"); GuildImpl guild = (GuildImpl) api.getGuildMap().get(id); //If the event is attempting to mark the guild as unavailable, but it is already unavailable, // ignore the event if ((guild == null || !guild.isAvailable()) && content.has("unavailable") && content.getBoolean("unavailable")) return null; if (api.getGuildLock().isLocked(id)) return id; if (content.has("unavailable") && content.getBoolean("unavailable")) { guild.setAvailable(false);//from w ww.j a v a 2 s .c o m api.getEventManager().handle(new GuildUnavailableEvent(api, responseNumber, guild)); return null; } final TLongObjectMap<AudioManagerImpl> audioManagerMap = api.getAudioManagerMap(); final AudioManagerImpl manager = audioManagerMap.remove(id); // remove manager from central map to avoid old guild references if (manager != null) // close existing audio connection if needed manager.closeAudioConnection(ConnectionStatus.DISCONNECTED_REMOVED_FROM_GUILD); //cleaning up all users that we do not share a guild with anymore // Anything left in memberIds will be removed from the main userMap //Use a new HashSet so that we don't actually modify the Member map so it doesn't affect Guild#getMembers for the leave event. TLongSet memberIds = new TLongHashSet(guild.getMembersMap().keySet()); for (Guild guildI : api.getGuilds()) { GuildImpl g = (GuildImpl) guildI; if (g.equals(guild)) continue; for (TLongIterator it = memberIds.iterator(); it.hasNext();) { if (g.getMembersMap().containsKey(it.next())) it.remove(); } } //If we are a client account, be sure to not remove any users from the cache that are Friends. // Remember, everything left in memberIds is removed from the userMap if (api.getAccountType() == AccountType.CLIENT) { TLongObjectMap<Relationship> relationships = ((JDAClientImpl) api.asClient()).getRelationshipMap(); for (TLongIterator it = memberIds.iterator(); it.hasNext();) { Relationship rel = relationships.get(it.next()); if (rel != null && rel.getType() == RelationshipType.FRIEND) it.remove(); } } long selfId = api.getSelfUser().getIdLong(); memberIds.forEach(memberId -> { if (memberId == selfId) return true; // don't remove selfUser from cache UserImpl user = (UserImpl) api.getUserMap().remove(memberId); if (user.hasPrivateChannel()) { PrivateChannelImpl priv = (PrivateChannelImpl) user.getPrivateChannel(); user.setFake(true); priv.setFake(true); api.getFakeUserMap().put(user.getIdLong(), user); api.getFakePrivateChannelMap().put(priv.getIdLong(), priv); } else if (api.getAccountType() == AccountType.CLIENT) { //While the user might not have a private channel, if this is a client account then the user // could be in a Group, and if so we need to change the User object to be fake and // place it in the FakeUserMap for (Group grp : api.asClient().getGroups()) { if (grp.getNonFriendUsers().contains(user)) { user.setFake(true); api.getFakeUserMap().put(user.getIdLong(), user); break; //Breaks from groups loop, not memberIds loop } } } return true; }); api.getGuildMap().remove(guild.getIdLong()); guild.getTextChannels().forEach(chan -> api.getTextChannelMap().remove(chan.getIdLong())); guild.getVoiceChannels().forEach(chan -> api.getVoiceChannelMap().remove(chan.getIdLong())); api.getEventManager().handle(new GuildLeaveEvent(api, responseNumber, guild)); return null; }
From source file:com.aselalee.trainschedule.GetResultsFromSiteV2.java
private JSONObject GetResultsObject(String strJSON) { JSONObject jObject = null; JSONObject jObjectResults = null;/*from w w w . ja va2 s .c om*/ boolean bIsSuccess = false; String strStatusMsg = ""; int iStatusCode = 0; try { jObject = new JSONObject(strJSON); bIsSuccess = jObject.getBoolean("SUCCESS"); strStatusMsg = jObject.getString("MESSAGE"); iStatusCode = jObject.getInt("STATUSCODE"); jObjectResults = jObject.getJSONObject("RESULTS"); } catch (JSONException e) { errorCode = Constants.ERR_JSON_ERROR; errorString = "JSONObjectERROR : Error Parsing JSON string : " + e; Log.e(Constants.LOG_TAG, errorString); return null; } if (bIsSuccess == false) { errorCode = Constants.ERR_SERVER_ERROR; errorString = "Server status message: " + strStatusMsg; Log.e(Constants.LOG_TAG, errorString); return null; } if (iStatusCode != 2000) { errorCode = Constants.ERR_NO_RESULTS_FOUND_ERROR; errorString = "No results found. Server status message: " + strStatusMsg; Log.e(Constants.LOG_TAG, errorString); return null; } return jObjectResults; }
From source file:nl.b3p.viewer.stripes.IbisReportsActionBean.java
public Resolution download() throws Exception { JSONObject json = new JSONObject(); if (unauthorized) { json.put("success", Boolean.FALSE); json.put("message", "Not authorized"); return new StreamingResolution("application/json", new StringReader(json.toString(4))); }/* w w w.j av a 2 s . c om*/ File output = null; try { SimpleFeatureType sft = attrSource.getFeatureType(report); Filter f = this.createFilters(sft); List<AttributeDescriptor> attrs = sft.getAttributes(); SimpleFeatureSource fs = (SimpleFeatureSource) sft.openGeoToolsFeatureSource(); final Query q = new Query(fs.getName().toString()); q.setFilter(createFilters(sft)); log.debug(q); // cannot forward to download action bean as that uses layers/appLayers // while we use an attributesource Map<String, AttributeDescriptor> featureTypeAttributes = new HashMap(); List<ConfiguredAttribute> attributes = new ArrayList(); ConfiguredAttribute ca; for (AttributeDescriptor ad : attrs) { featureTypeAttributes.put(ad.getName(), ad); ca = new ConfiguredAttribute(); ca.setVisible(true); ca.setAttributeName(ad.getName()); attributes.add(ca); } output = convert(sft, fs, q, attributes, featureTypeAttributes); json.put("success", true); } catch (Exception e) { log.error("Error loading features", e); json.put("success", false); String message = "Fout bij ophalen features: " + e.toString(); Throwable cause = e.getCause(); while (cause != null) { message += "; " + cause.toString(); cause = cause.getCause(); } json.put("message", message); } if (json.getBoolean("success")) { final FileInputStream fis = new FileInputStream(output); try { StreamingResolution res = new StreamingResolution( MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(output)) { @Override public void stream(HttpServletResponse response) throws Exception { OutputStream out = response.getOutputStream(); IOUtils.copy(fis, out); fis.close(); } }; String name = output.getName(); String extension = name.substring(name.lastIndexOf(".")); SimpleDateFormat today = new SimpleDateFormat("yyyy_MM_dd"); String newName = "download-" + report + "-" + today.format(new Date()) + extension; res.setFilename(newName); res.setAttachment(true); return res; } finally { output.delete(); } } else { return new ErrorMessageResolution(json.getString("message")); } }
From source file:org.achtern.AchternEngine.core.resource.loader.json.MaterialLoader.java
@Override public Material get() throws Exception { final JSONObject json = getJsonObject(); final Material material = new Material(); // Start with the simplest one if (json.has("wireframe")) { material.asWireframe(json.getBoolean("wireframe")); }// www. j a v a 2 s .c o m // All Floats if (json.has("float")) { JSONObject floats = json.getJSONObject("float"); for (Object oKey : floats.keySet()) { String key = (String) oKey; material.addFloat(key, (float) floats.getDouble(key)); } } // All Colors if (json.has("Color")) { JSONObject colors = json.getJSONObject("Color"); for (Object oKey : colors.keySet()) { String key = (String) oKey; material.addColor(key, getColor(colors.getJSONObject(key))); } } if (json.has("Texture")) { // All Textures JSONObject textures = json.getJSONObject("Texture"); for (Object oKey : textures.keySet()) { String key = (String) oKey; material.addTexture(key, getTexture(textures.getJSONObject(key))); } } return material; }
From source file:com.lhings.java.http.WebServiceCom.java
public static List<Device> deviceList(LhingsDevice lhingsDevice) throws LhingsException, IOException { String url = LHINGS_V1_API_PREFIX + "devices/?verbose"; String json = executeGet(url, lhingsDevice.apiKey()); JSONArray deviceArray = new JSONArray(json); List<Device> deviceList = new ArrayList<Device>(); for (int j = 0; j < deviceArray.length(); j++) { JSONObject jsonObj = deviceArray.getJSONObject(j); Device device = new Device(); device.setUuidString(jsonObj.getString("uuid")); device.setName(jsonObj.getString("name")); device.setType(jsonObj.getString("type")); device.setIsonline((jsonObj.getBoolean("online"))); deviceList.add(device);/*from w ww . ja v a 2s. co m*/ } return deviceList; }
From source file:com.lhings.java.http.WebServiceCom.java
public static Map<String, Object> getStatus(LhingsDevice lhingsDevice, String uuid) throws LhingsException, IOException { String url = LHINGS_V1_API_PREFIX + "devices/" + uuid + "/states"; String json = executeGet(url, lhingsDevice.apiKey()); Map<String, Object> returnValue = new HashMap<String, Object>(); JSONArray array = new JSONArray(json); for (int j = 0; j < array.length(); j++) { JSONObject statusComponent = array.getJSONObject(j); String statusCompName = statusComponent.getString("name"); String statusCompType = statusComponent.getString("type"); Object statusCompValue;// ww w. j a v a 2 s .c o m if (statusCompType.equals("integer")) statusCompValue = statusComponent.getInt("value"); else if (statusCompType.equals("float")) statusCompValue = (float) statusComponent.getDouble("value"); else if (statusCompType.equals("timestamp")) statusCompValue = new Date((long) statusComponent.getInt("value") * 1000); else if (statusCompType.equals("boolean")) statusCompValue = statusComponent.getBoolean("value"); else statusCompValue = statusComponent.getString("value"); returnValue.put(statusCompName, statusCompValue); } return returnValue; }
From source file:com.nextgis.maplib.map.Layer.java
@Override public void fromJSON(JSONObject jsonObject) throws JSONException { mLayerType = jsonObject.getInt(JSON_TYPE_KEY); mName = jsonObject.getString(JSON_NAME_KEY); if (jsonObject.has(JSON_MAXLEVEL_KEY)) { mMaxZoom = jsonObject.getInt(JSON_MAXLEVEL_KEY); } else {/*from www . j a v a 2 s . com*/ mMaxZoom = DEFAULT_MAX_ZOOM; } if (jsonObject.has(JSON_MINLEVEL_KEY)) { mMinZoom = jsonObject.getInt(JSON_MINLEVEL_KEY); } else { mMinZoom = DEFAULT_MIN_ZOOM; } mIsVisible = jsonObject.getBoolean(JSON_VISIBILITY_KEY); }
From source file:org.collectionspace.chain.storage.TestServiceThroughWebapp.java
@Test public void testCollectionObjectBasic() throws Exception { UTF8SafeHttpTester out = tester.jettyDoUTF8(jetty, "POST", "/tenant/core/cataloging/", tester.makeSimpleRequest(tester.getResourceString("obj3.json"))); String id = out.getHeader("Location"); assertEquals(201, out.getStatus());/*ww w . j a v a 2s. c o m*/ out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + id, null); JSONObject content = new JSONObject(out.getContent()); content = tester.getFields(content); JSONObject one = new JSONObject(tester.getResourceString("obj3.json")); //log.info(one.toString()); //log.info(content.toString()); // Haven't yet identified whether JSONObject can use dot-delimited path notation - Aron //assertEquals(one.get("titleGroup.0.titleLanguage"),content.get("titleGroup.0.titleLanguage")); assertEquals(one.get("distinguishingFeatures"), content.get("distinguishingFeatures")); //assertTrue(JSONUtils.checkJSONEquivOrEmptyStringKey(new JSONObject(tester.getResourceString("obj3.json")),content)); out = tester.jettyDoUTF8(jetty, "PUT", "/tenant/core" + id, tester.makeSimpleRequest(tester.getResourceString("obj4.json"))); assertEquals(200, out.getStatus()); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + id, null); content = new JSONObject(out.getContent()); content = tester.getFields(content); JSONObject oneb = new JSONObject(tester.getResourceString("obj4.json")); // assertEquals(oneb.get("titleGroup.0.titleLanguage"),content.get("titleGroup.0.titleLanguage")); assertEquals(oneb.get("distinguishingFeatures"), content.get("distinguishingFeatures")); //assertTrue(JSONUtils.checkJSONEquivOrEmptyStringKey(new JSONObject(tester.getResourceString("obj4.json")),content)); out = tester.jettyDoUTF8(jetty, "DELETE", "/tenant/core" + id, null); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + id, null); JSONObject bob = new JSONObject(out.getContent()); assertTrue(bob.getBoolean("isError")); }
From source file:org.collectionspace.chain.storage.TestServiceThroughWebapp.java
@Test public void testIntake() throws Exception { UTF8SafeHttpTester out = tester.jettyDoUTF8(jetty, "POST", "/tenant/core/intake/", tester.makeSimpleRequest(tester.getResourceString("int3.json"))); assertEquals(201, out.getStatus());//ww w.j a va 2 s . co m String path = out.getHeader("Location"); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + path, null); //log.info(out.getContent()); JSONObject content = new JSONObject(out.getContent()); content = tester.getFields(content); JSONObject one = new JSONObject(tester.getResourceString("int3.json")); //XXX we have a utf8 issue so lets not test this //assertEquals(one.get("packingNote"),content.get("packingNote")); //assertTrue(JSONUtils.checkJSONEquivOrEmptyStringKey(new JSONObject(tester.getResourceString("int3.json")),content)); out = tester.jettyDoUTF8(jetty, "PUT", "/tenant/core" + path, tester.makeSimpleRequest(tester.getResourceString("int4.json"))); assertEquals(200, out.getStatus()); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + path, null); content = new JSONObject(out.getContent()); content = tester.getFields(content); JSONObject oneb = new JSONObject(tester.getResourceString("int4.json")); //XXX we have a utf8 issue so lets not test this //assertEquals(oneb.get("packingNote"),content.get("packingNote")); //assertTrue(JSONUtils.checkJSONEquivOrEmptyStringKey(new JSONObject(tester.getResourceString("int4.json")),content)); out = tester.jettyDoUTF8(jetty, "DELETE", "/tenant/core" + path, null); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + path, null); JSONObject bob = new JSONObject(out.getContent()); assertTrue(bob.getBoolean("isError")); }
From source file:org.collectionspace.chain.storage.TestServiceThroughWebapp.java
@Test public void testAcquisition() throws Exception { UTF8SafeHttpTester out = tester.jettyDoUTF8(jetty, "POST", "/tenant/core/acquisition/", tester.makeSimpleRequest(tester.getResourceString("create_acquistion.json"))); assertEquals(201, out.getStatus());//w w w . j a v a 2 s . c o m String path = out.getHeader("Location"); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + path, null); JSONObject content = new JSONObject(out.getContent()); content = tester.getFields(content); log.info(content.toString()); JSONObject one = new JSONObject(tester.getResourceString("create_acquistion.json")); assertEquals(one.get("acquisitionProvisos"), content.get("acquisitionProvisos")); //assertTrue(JSONUtils.checkJSONEquivOrEmptyStringKey(new JSONObject(tester.getResourceString("int5.json")),content)); out = tester.jettyDoUTF8(jetty, "PUT", "/tenant/core" + path, tester.makeSimpleRequest(tester.getResourceString("update_acquistion.json"))); assertEquals(200, out.getStatus()); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + path, null); content = new JSONObject(out.getContent()); content = tester.getFields(content); JSONObject oneb = new JSONObject(tester.getResourceString("update_acquistion.json")); assertEquals(oneb.get("acquisitionProvisos"), content.get("acquisitionProvisos")); //assertTrue(JSONUtils.checkJSONEquivOrEmptyStringKey(new JSONObject(tester.getResourceString("int6.json")),content)); out = tester.jettyDoUTF8(jetty, "DELETE", "/tenant/core" + path, null); out = tester.jettyDoUTF8(jetty, "GET", "/tenant/core" + path, null); JSONObject bob = new JSONObject(out.getContent()); assertTrue(bob.getBoolean("isError")); }