use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class SeqConverter method fromJSON.
@Override
public Seq fromJSON(Model mo, JSONObject o) throws JSONConverterException {
checkId(o);
List<VM> s = new ArrayList<>();
for (Object ob : (JSONArray) o.get("vms")) {
s.add(getVM(mo, (Integer) ob));
}
return new Seq(s);
}
use of net.minidev.json.JSONArray in project ddf by codice.
the class GeoNamesWebService method getLocation.
@Override
public GeoResult getLocation(String location) {
location = getUrlEncodedLocation(location);
String urlStr = String.format("%s://%s/searchJSON?q=%s&username=%s", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, location, USERNAME);
Object result = query(urlStr);
if (result != null) {
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
JSONArray geonames = (JSONArray) jsonResult.get(GEONAMES_KEY);
if (geonames != null && geonames.size() > 0) {
JSONObject firstResult = (JSONObject) geonames.get(0);
if (firstResult != null) {
double lat = Double.valueOf((String) firstResult.get(LAT_KEY));
double lon = Double.valueOf((String) firstResult.get(LON_KEY));
Long population = (Long) firstResult.get(POPULATION_KEY);
String adminCode = (String) firstResult.get(ADMIN_CODE_KEY);
return GeoResultCreator.createGeoResult((String) firstResult.get(PLACENAME_KEY), lat, lon, adminCode, population);
}
}
}
}
return null;
}
use of net.minidev.json.JSONArray in project ddf by codice.
the class GeoNamesWebService method getNearbyCity.
@Override
public NearbyLocation getNearbyCity(String locationWkt) {
notNull(locationWkt, "argument locationWkt may not be null");
Point wktCenterPoint = createPointFromWkt(locationWkt);
String urlStr = String.format("%s://%s/findNearbyPlaceNameJSON?lat=%f&lng=%f&maxRows=1&username=%s&cities=cities5000", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, wktCenterPoint.getY(), wktCenterPoint.getX(), USERNAME);
Object result = query(urlStr);
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
JSONArray geonames = (JSONArray) jsonResult.get(GEONAMES_KEY);
if (geonames != null && geonames.size() > 0) {
JSONObject firstResult = (JSONObject) geonames.get(0);
if (firstResult != null) {
double lat = Double.valueOf((String) firstResult.get(LAT_KEY));
double lon = Double.valueOf((String) firstResult.get(LON_KEY));
String cityName = (String) firstResult.get(PLACENAME_KEY);
Point cityPoint = new PointImpl(lon, lat, SpatialContext.GEO);
return new NearbyLocationImpl(wktCenterPoint, cityPoint, cityName);
}
}
}
return null;
}
use of net.minidev.json.JSONArray in project ddf by codice.
the class TestGeoCoderEndpoint method testQuery.
@Test
public void testQuery() {
JSONObject jsonObject = this.geoCoderEndpoint.doQuery("Phoenix");
JSONArray resourceSets = (JSONArray) jsonObject.get("resourceSets");
assertThat(resourceSets.size(), is(1));
JSONObject resources = (JSONObject) resourceSets.get(0);
JSONArray resourceElements = (JSONArray) resources.get("resources");
assertThat(resourceElements.size(), is(1));
JSONObject resource = (JSONObject) resourceElements.get(0);
JSONObject point = (JSONObject) resource.get("point");
JSONArray bbox = (JSONArray) resource.get("bbox");
String name = (String) resource.get("name");
assertThat(name, is("Phoenix"));
assertThat(bbox.size(), is(4));
String type = (String) point.get("type");
assertThat(type, is("Point"));
JSONArray coordinates = (JSONArray) point.get("coordinates");
assertThat(coordinates.size(), is(2));
}
use of net.minidev.json.JSONArray in project ddf by codice.
the class TestLogoutService method testLogout.
@Test
public void testLogout() throws IOException, ParseException, SecurityServiceException {
KarafLogoutAction karafLogoutActionProvider = new KarafLogoutAction();
LdapLogoutAction ldapLogoutActionProvider = new LdapLogoutAction();
Action karafLogoutAction = karafLogoutActionProvider.getAction(null);
Action ldapLogoutAction = ldapLogoutActionProvider.getAction(null);
LogoutService logoutService = new LogoutService();
logoutService.setHttpSessionFactory(sessionFactory);
logoutService.setSecurityManager(sm);
logoutService.setLogoutActionProviders(Arrays.asList(karafLogoutActionProvider, ldapLogoutActionProvider));
String responseMessage = IOUtils.toString((ByteArrayInputStream) logoutService.getActionProviders(null).getEntity());
JSONArray actionProperties = (JSONArray) new JSONParser().parse(responseMessage);
assertEquals(2, actionProperties.size());
JSONObject karafActionProperty = ((JSONObject) actionProperties.get(0));
assertEquals(karafActionProperty.get("description"), karafLogoutAction.getDescription());
assertEquals(karafActionProperty.get("realm"), karafLogoutAction.getId().substring(karafLogoutAction.getId().lastIndexOf(".") + 1));
assertEquals(karafActionProperty.get("title"), karafLogoutAction.getTitle());
assertEquals(karafActionProperty.get("url"), karafLogoutAction.getUrl().toString());
JSONObject ldapActionProperty = ((JSONObject) actionProperties.get(1));
assertEquals(ldapActionProperty.get("description"), ldapLogoutAction.getDescription());
assertEquals(ldapActionProperty.get("realm"), ldapLogoutAction.getId().substring(ldapLogoutAction.getId().lastIndexOf(".") + 1));
assertEquals(ldapActionProperty.get("title"), ldapLogoutAction.getTitle());
assertEquals(ldapActionProperty.get("url"), ldapLogoutAction.getUrl().toString());
}
Aggregations