List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject(String memberName)
From source file:com.inmind.restful.testcases.Org.java
@Test public void PostOrgsList() { try {//from w w w .j a v a 2s. c o m LOGGER.info("*****************Test case: Post Orgs List Started*****************"); String uri = APITest.getValue("baseuri"); String cookievalue = cookies.get(0); String payload = "{\"orgName\":\"Test for Automation\"}"; APIResponse response = APIRequest.POST(uri).path("/orgs/list/").type(MediaType.APPLICATION_JSON_TYPE) .header("cookie", cookievalue).body(payload).invoke(); response.assertBodyContains("200"); String responsbody = response.getBody(); JsonObject jsonObject = new JsonParser().parse(responsbody).getAsJsonObject(); JsonObject body = jsonObject.getAsJsonObject("_body"); int type = body.get("type").getAsInt(); long updatedBy = body.get("updatedBy").getAsLong(); String description = body.get("description").getAsString(); long ownerId = body.get("ownerId").getAsLong(); long createdAt = body.get("createdAt").getAsLong(); long createdBy = body.get("createdBy").getAsLong(); String simpleName = body.get("simpleName").getAsString(); String englishName = body.get("englishName").getAsString(); int source = body.get("source").getAsInt(); String aliases = body.get("aliases").getAsString(); String phoneNo = body.get("phoneNo").getAsString(); String logoUrl = body.get("logoUrl").getAsString(); String siteUrl = body.get("siteUrl").getAsString(); int finacingStatus = body.get("finacingStatus").getAsInt(); double finacingAmount = body.get("finacingAmount").getAsDouble(); String legalPerson = body.get("legalPerson").getAsString(); double registedCapital = body.get("registedCapital").getAsDouble(); long registedAt = body.get("registedAt").getAsLong(); double turnover = body.get("turnover").getAsDouble(); String registedNo = body.get("registedNo").getAsString(); String registedAuthority = body.get("registedAuthority").getAsString(); int natureCode = body.get("natureCode").getAsInt(); int empScale = body.get("empScale").getAsInt(); int empMeanSalary = body.get("empMeanSalary").getAsInt(); String wxPublicNo = body.get("wxPublicNo").getAsString(); String facebookUrl = body.get("facebookUrl").getAsString(); String linkedinUrl = body.get("linkedinUrl").getAsString(); String weiboUrl = body.get("weiboUrl").getAsString(); String twitterUrl = body.get("twitterUrl").getAsString(); String qccUnique = body.get("qccUnique").getAsString(); String orgCode = body.get("orgCode").getAsString(); String licenseNo = body.get("licenseNo").getAsString(); String imgUrls = body.get("imgUrls").getAsString(); String finacingDetail = body.get("finacingDetail").getAsString(); JsonObject shareholdings = body.getAsJsonObject("shareholdings"); long shareholdings_id = shareholdings.get("id").getAsLong(); long shareholdings_org_id = shareholdings.get("orgId").getAsLong(); long shareholdings_hold_id = shareholdings.get("holdId").getAsLong(); double shareholdings_hold_rate = shareholdings.get("holdRate").getAsDouble(); double shareholdings_invest_amount = shareholdings.get("investMount").getAsDouble(); String shareholdings_invest_detail = shareholdings.get("investDetail").getAsString(); long shareholdings_created_by = shareholdings.get("createdBy").getAsLong(); long shareholdings_updated_by = shareholdings.get("updatedBy").getAsLong(); long shareholdings_created_at = shareholdings.get("createdAt").getAsLong(); ; long shareholdings_updated_at = shareholdings.get("updatedAt").getAsLong(); JsonObject createdByAccount = body.getAsJsonObject("createdByAccount"); //String createdByAccount_password=createdByAccount.get("password").getAsString(); String createdByAccount_nickname = createdByAccount.get("nickname").getAsString(); String createdByAccount_mobile = createdByAccount.get("mobile").getAsString(); long createdByAccount_id = createdByAccount.get("id").getAsLong(); String createdByAccount_email = createdByAccount.get("email").getAsString(); String createdByAccount_username = createdByAccount.get("username").getAsString(); String createdByAccountsql = "SELECT * FROM account WHERE id" + createdBy + ";"; ResultSet createdByAccountResultSet = dbCtrl.query(conn, createdByAccountsql); commonutil.AssertEqualsCustomize(createdByAccount_nickname, createdByAccountResultSet.getString("nickname")); commonutil.AssertEqualsCustomize(createdByAccount_email, createdByAccountResultSet.getString("email")); commonutil.AssertEqualsCustomize(createdByAccount_mobile, createdByAccountResultSet.getString("mobile")); commonutil.AssertEqualsCustomize(createdByAccount_username, createdByAccountResultSet.getString("username")); commonutil.AssertEqualsCustomize(createdByAccount_id, createdByAccountResultSet.getLong("id")); JsonObject updatedByAccount = body.getAsJsonObject("updatedByAccount"); //String updatedByAccount_password=updatedByAccount.get("password").getAsString(); String updatedByAccount_nickname = updatedByAccount.get("nickname").getAsString(); String updatedByAccount_mobile = updatedByAccount.get("mobile").getAsString(); long updatedByAccount_id = updatedByAccount.get("id").getAsLong(); String updatedByAccount_email = updatedByAccount.get("email").getAsString(); String updatedByAccount_username = updatedByAccount.get("username").getAsString(); String updatedByAccountsql = "SELECT * FROM account WHERE id" + createdBy + ";"; ResultSet UpdatedByAccountResultSet = dbCtrl.query(conn, updatedByAccountsql); commonutil.AssertEqualsCustomize(updatedByAccount_nickname, UpdatedByAccountResultSet.getString("nickname")); commonutil.AssertEqualsCustomize(updatedByAccount_email, UpdatedByAccountResultSet.getString("email")); commonutil.AssertEqualsCustomize(updatedByAccount_mobile, UpdatedByAccountResultSet.getString("mobile")); commonutil.AssertEqualsCustomize(updatedByAccount_username, UpdatedByAccountResultSet.getString("username")); commonutil.AssertEqualsCustomize(updatedByAccount_id, UpdatedByAccountResultSet.getLong("id")); JsonObject shareholders = body.getAsJsonObject("shareholders"); long shareholders_id = shareholders.get("id").getAsLong(); long shareholders_org_id = shareholders.get("orgId").getAsLong(); long shareholders_hold_id = shareholders.get("holdId").getAsLong(); double shareholders_hold_rate = shareholders.get("holdRate").getAsDouble(); double shareholders_invest_amount = shareholders.get("investAmount").getAsDouble(); String shareholders_invest_detail = shareholders.get("investDetail").getAsString(); long shareholders_created_by = shareholders.get("createdBy").getAsLong(); long shareholders_updated_by = shareholders.get("updatedBy").getAsLong(); long shareholders_created_at = shareholders.get("createdAt").getAsLong(); long shareholders_updated_at = shareholders.get("updatedAt").getAsLong(); JsonObject orgStocks = body.getAsJsonObject("orgStocks"); long orgStocks_id = orgStocks.get("id").getAsLong(); long orgStocks_org_id = orgStocks.get("orgId").getAsLong(); int orgStocks_stock_exchange = orgStocks.get("stockExchange").getAsInt(); String orgStocks_stock_code = orgStocks.get("stockCode").getAsString(); long orgStocks_created_by = orgStocks.get("createdBy").getAsLong(); long orgStocks_updated_by = orgStocks.get("updatedBy").getAsLong(); long orgStocks_created_at = orgStocks.get("createdAt").getAsLong(); long orgStocks_updated_at = orgStocks.get("updatedAt").getAsLong(); JsonArray industrialModeDicts = body.get("industrialModeDicts").getAsJsonArray(); for (int i = 0; i < industrialModeDicts.size(); i++) { JsonObject subObject = industrialModeDicts.get(i).getAsJsonObject(); String industrialModeDicts_sql = "SELECT * FROM organization WHERE target_id=" + orgid + ";"; ResultSet industrialModeDictsResultSet = dbCtrl.query(conn, industrialModeDicts_sql); commonutil.AssertEqualsCustomize(subObject.get("type").getAsString(), industrialModeDictsResultSet.getString("dict_type")); commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(), industrialModeDictsResultSet.getString("dict_type")); String dicttype = industrialModeDictsResultSet.getString("dict_type"); String dict_code = subObject.get("code").getAsString(); ResultSet dictResultSet = dbCtrl.query(conn, "SELECT * FROM dict WHERE type=" + dicttype + " AND code=" + dict_code + ";"); Long dict_title = dictResultSet.getLong("title"); commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(), dict_title); commonutil.AssertEqualsCustomize(subObject.get("generated").getAsLong(), industrialModeDictsResultSet.getLong("generated")); } JsonArray industryDicts = body.get("industryDicts").getAsJsonArray(); for (int i = 0; i < industryDicts.size(); i++) { JsonObject subObject = industryDicts.get(i).getAsJsonObject(); String industryDicts_sql = "SELECT * FROM organization WHERE target_id=" + orgid + ";"; ResultSet industryDictsResultSet = dbCtrl.query(conn, industryDicts_sql); commonutil.AssertEqualsCustomize(subObject.get("type").getAsString(), industryDictsResultSet.getString("dict_type")); commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(), industryDictsResultSet.getString("dict_type")); String dicttype = industryDictsResultSet.getString("dict_type"); String dict_code = subObject.get("code").getAsString(); ResultSet dictResultSet = dbCtrl.query(conn, "SELECT * FROM dict WHERE type=" + dicttype + " AND code=" + dict_code + ";"); Long dict_title = dictResultSet.getLong("title"); commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(), dict_title); commonutil.AssertEqualsCustomize(subObject.get("generated").getAsLong(), industryDictsResultSet.getLong("generated")); } JsonArray highlightDicts = body.get("highlightDicts").getAsJsonArray(); for (int i = 0; i < highlightDicts.size(); i++) { JsonObject subObject = highlightDicts.get(i).getAsJsonObject(); String industryDicts_sql = "SELECT * FROM organization WHERE target_id=" + orgid + ";"; ResultSet highlightDictsResultSet = dbCtrl.query(conn, industryDicts_sql); commonutil.AssertEqualsCustomize(subObject.get("type").getAsString(), highlightDictsResultSet.getString("dict_type")); commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(), highlightDictsResultSet.getString("dict_type")); String dicttype = highlightDictsResultSet.getString("dict_type"); String dict_code = subObject.get("code").getAsString(); ResultSet dictResultSet = dbCtrl.query(conn, "SELECT * FROM dict WHERE type=" + dicttype + " AND code=" + dict_code + ";"); Long dict_title = dictResultSet.getLong("title"); commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(), dict_title); commonutil.AssertEqualsCustomize(subObject.get("generated").getAsLong(), highlightDictsResultSet.getLong("generated")); } JsonObject orgContactWays = body.getAsJsonObject("orgContactWays"); long orgContactWays_id = orgContactWays.get("id").getAsLong(); long orgContactWays_org_id = orgContactWays.get("orgId").getAsLong(); String orgContactWays_phone_number = orgContactWays.get("phoneNumber").getAsString(); long orgContactWays_created_by = orgContactWays.get("createdBy").getAsLong(); long orgContactWays_updated_by = orgContactWays.get("updatedBy").getAsLong(); long orgContactWays_created_at = orgContactWays.get("createdAt").getAsLong(); long orgContactWays_updated_at = orgContactWays.get("updatedAt").getAsLong(); String orgContactWays_fax_number = orgContactWays.get("faxNumber").getAsString(); long orgContactWays_address_id = orgContactWays.get("addressId").getAsLong(); String name = body.get("name").getAsString(); JsonObject orgBrands = body.getAsJsonObject("orgBrands"); int orgBrands_type = orgBrands.get("type").getAsInt(); String orgBrands_description = orgBrands.get("description").getAsString(); String orgBrands_title = orgBrands.get("title").getAsString(); long orgBrands_created_by = orgBrands.get("createdBy").getAsLong(); long orgBrands_updated_by = orgBrands.get("updatedBy").getAsLong(); long orgBrands_id = orgBrands.get("id").getAsLong(); long orgBrands_created_at = orgBrands.get("createdAt").getAsLong(); long orgBrands_updated_at = orgBrands.get("updatedAt").getAsLong(); String orgBrands_siteUrl = orgBrands.get("siteUrl").getAsString(); String orgBrands_imgUrl = orgBrands.get("imgUrl").getAsString(); long orgBrands_org_id = orgBrands.get("orgId").getAsLong(); String orgHistories_sql = "SELECT * FROM organization WHERE org_id=" + orgid + ";"; ResultSet orghHistoriesResultSet = dbCtrl.query(conn, orgHistories_sql); JsonObject orgHistories = body.getAsJsonObject("orgHistories"); commonutil.AssertEqualsCustomize(orgHistories.get("description").getAsString(), orghHistoriesResultSet.getString("description")); commonutil.AssertEqualsCustomize(orgHistories.get("title").getAsString(), orghHistoriesResultSet.getString("title")); commonutil.AssertEqualsCustomize(orgHistories.get("createdBy").getAsLong(), orghHistoriesResultSet.getLong("created_by")); commonutil.AssertEqualsCustomize(orgHistories.get("createdAt").getAsLong(), orghHistoriesResultSet.getLong("created_at")); commonutil.AssertEqualsCustomize(orgHistories.get("UpdatedAt").getAsLong(), orghHistoriesResultSet.getLong("updated_at")); commonutil.AssertEqualsCustomize(orgHistories.get("UpdatedBy").getAsLong(), orghHistoriesResultSet.getLong("updated_by")); commonutil.AssertEqualsCustomize(orgHistories.get("timeAt").getAsLong(), orghHistoriesResultSet.getLong("time_at")); commonutil.AssertEqualsCustomize(orgHistories.get("linkUrl").getAsLong(), orghHistoriesResultSet.getLong("link_url")); long updatedAt = body.get("updatedAt").getAsLong(); String sql = "SELECT * FROM organization WHERE org_id=;" + orgid; ResultSet organization = dbCtrl.query(conn, sql); commonutil.AssertEqualsCustomize(orgid, organization.getLong("id")); commonutil.AssertEqualsCustomize(name, organization.getString("name")); commonutil.AssertEqualsCustomize(createdAt, organization.getLong("created_at")); commonutil.AssertEqualsCustomize(updatedAt, organization.getLong("updated_at")); commonutil.AssertEqualsCustomize(createdBy, organization.getLong("created_by")); commonutil.AssertEqualsCustomize(updatedBy, organization.getLong("updated_by")); commonutil.AssertEqualsCustomize(ownerId, organization.getLong("owner_id")); commonutil.AssertEqualsCustomize(registedAt, organization.getLong("registed_at")); commonutil.AssertEqualsCustomize(source, organization.getInt("source")); commonutil.AssertEqualsCustomize(description, organization.getString("description")); commonutil.AssertEqualsCustomize(englishName, organization.getString("english_name")); commonutil.AssertEqualsCustomize(type, organization.getInt("type")); commonutil.AssertEqualsCustomize(phoneNo, organization.getString("phone_no")); commonutil.AssertEqualsCustomize(simpleName, organization.getString("simple_name")); commonutil.AssertEqualsCustomize(aliases, organization.getString("aliases")); commonutil.AssertEqualsCustomize(logoUrl, organization.getString("logo_url")); commonutil.AssertEqualsCustomize(siteUrl, organization.getString("site_url")); commonutil.AssertEqualsCustomize(finacingDetail, organization.getString("finacing_detail")); commonutil.AssertEqualsCustomize(finacingAmount, organization.getDouble("finacing_amount")); commonutil.AssertEqualsCustomize(legalPerson, organization.getString("legal_person")); commonutil.AssertEqualsCustomize(registedCapital, organization.getString("registed_capital")); commonutil.AssertEqualsCustomize(registedAt, organization.getString("registed_at")); commonutil.AssertEqualsCustomize(turnover, organization.getDouble("turnover")); commonutil.AssertEqualsCustomize(registedNo, organization.getString("registedNo")); commonutil.AssertEqualsCustomize(registedAuthority, organization.getString("registed_authority")); commonutil.AssertEqualsCustomize(natureCode, organization.getInt("natureCode")); commonutil.AssertEqualsCustomize(empScale, organization.getInt("empScale")); commonutil.AssertEqualsCustomize(empMeanSalary, organization.getInt("empMean_salary")); commonutil.AssertEqualsCustomize(wxPublicNo, organization.getString("wxPublic_no")); commonutil.AssertEqualsCustomize(facebookUrl, organization.getString("facebook_url")); commonutil.AssertEqualsCustomize(linkedinUrl, organization.getString("linkedin_url")); commonutil.AssertEqualsCustomize(weiboUrl, organization.getString("weibo_url")); commonutil.AssertEqualsCustomize(twitterUrl, organization.getString("twitter_url")); commonutil.AssertEqualsCustomize(qccUnique, organization.getString("qcc_unique")); commonutil.AssertEqualsCustomize(orgCode, organization.getString("org_code")); commonutil.AssertEqualsCustomize(licenseNo, organization.getString("license_no")); commonutil.AssertEqualsCustomize(imgUrls, organization.getString("img_urls")); commonutil.AssertEqualsCustomize(finacingDetail, organization.getString("finacing_detail")); commonutil.AssertEqualsCustomize(finacingStatus, organization.getString("finacing_status")); String shareholders_sql = "SELECT * FROM automind_test.org_shareholder WHERE org_id=;" + orgid; ResultSet shareholdersResultSet = dbCtrl.query(conn, shareholders_sql); commonutil.AssertEqualsCustomize(shareholders_id, shareholdersResultSet.getLong("id")); commonutil.AssertEqualsCustomize(shareholders_org_id, shareholdersResultSet.getLong("org_id")); commonutil.AssertEqualsCustomize(shareholders_hold_id, shareholdersResultSet.getLong("hold_id")); commonutil.AssertEqualsCustomize(shareholders_hold_rate, shareholdersResultSet.getDouble("hold_rate")); commonutil.AssertEqualsCustomize(shareholders_invest_amount, shareholdersResultSet.getInt("invest_amount")); commonutil.AssertEqualsCustomize(shareholders_invest_detail, shareholdersResultSet.getString("invest_detail")); commonutil.AssertEqualsCustomize(shareholders_created_at, shareholdersResultSet.getLong("created_at")); commonutil.AssertEqualsCustomize(shareholders_created_by, shareholdersResultSet.getLong("created_by")); commonutil.AssertEqualsCustomize(shareholders_updated_by, shareholdersResultSet.getLong("updated_by")); commonutil.AssertEqualsCustomize(shareholders_updated_at, shareholdersResultSet.getLong("updated_at")); String shareholdings_sql = "SELECT * FROM org_shareholder WHERE org_id=;" + orgid; ResultSet shareholdingsResultSet = dbCtrl.query(conn, shareholdings_sql); commonutil.AssertEqualsCustomize(shareholdings_created_at, shareholdings.get("created_at").getAsLong()); commonutil.AssertEqualsCustomize(shareholdings_created_by, shareholdings.get("created_by").getAsLong()); commonutil.AssertEqualsCustomize(shareholdings_id, shareholdingsResultSet.getLong("id")); commonutil.AssertEqualsCustomize(shareholdings_org_id, shareholdingsResultSet.getLong("org_id")); commonutil.AssertEqualsCustomize(shareholdings_hold_id, shareholdingsResultSet.getLong("hold_id")); commonutil.AssertEqualsCustomize(shareholdings_hold_rate, shareholdingsResultSet.getDouble("hold_rate")); commonutil.AssertEqualsCustomize(shareholdings_invest_amount, shareholdingsResultSet.getInt("invest_amount")); commonutil.AssertEqualsCustomize(shareholdings_invest_detail, shareholdingsResultSet.getString("invest_detail")); commonutil.AssertEqualsCustomize(shareholdings_updated_by, shareholdingsResultSet.getLong("updated_by")); commonutil.AssertEqualsCustomize(shareholdings_updated_at, shareholdingsResultSet.getLong("updated_at")); String stock_sql = "SELECT * FROM org_stock WHERE org_id=;" + orgid; ResultSet stockResultSet = dbCtrl.query(conn, stock_sql); commonutil.AssertEqualsCustomize(orgStocks_id, stockResultSet.getLong("id")); commonutil.AssertEqualsCustomize(orgStocks_org_id, stockResultSet.getLong("org_id")); commonutil.AssertEqualsCustomize(orgStocks_stock_code, stockResultSet.getString("stock_code")); commonutil.AssertEqualsCustomize(orgStocks_stock_exchange, stockResultSet.getInt("stock_exchange")); commonutil.AssertEqualsCustomize(orgStocks_created_at, stockResultSet.getLong("created_at")); commonutil.AssertEqualsCustomize(orgStocks_created_by, stockResultSet.getLong("created_by")); commonutil.AssertEqualsCustomize(orgStocks_updated_at, stockResultSet.getLong("updated_at")); commonutil.AssertEqualsCustomize(orgStocks_updated_by, stockResultSet.getLong("updated_by")); String brand_sql = "SELECT * FROM org_brand WHERE org_id=;" + orgid; ResultSet brandResultSet = dbCtrl.query(conn, brand_sql); commonutil.AssertEqualsCustomize(orgBrands_type, brandResultSet.getInt("type")); commonutil.AssertEqualsCustomize(orgBrands_id, brandResultSet.getLong("id")); commonutil.AssertEqualsCustomize(orgBrands_description, brandResultSet.getString("description")); commonutil.AssertEqualsCustomize(orgBrands_created_by, brandResultSet.getLong("created_by")); commonutil.AssertEqualsCustomize(orgBrands_created_at, brandResultSet.getLong("created_at")); commonutil.AssertEqualsCustomize(orgBrands_updated_at, brandResultSet.getLong("updated_at")); commonutil.AssertEqualsCustomize(orgBrands_updated_by, brandResultSet.getLong("updated_by")); commonutil.AssertEqualsCustomize(orgBrands_imgUrl, brandResultSet.getString("img_Url")); commonutil.AssertEqualsCustomize(orgBrands_siteUrl, brandResultSet.getString("site_Url")); commonutil.AssertEqualsCustomize(orgBrands_title, brandResultSet.getString("title")); commonutil.AssertEqualsCustomize(orgBrands_org_id, brandResultSet.getLong("org_id")); String contacWays_sql = "SELECT * FROM org_brand WHERE org_id=;" + orgid; ResultSet contactWaysResultSet = dbCtrl.query(conn, contacWays_sql); commonutil.AssertEqualsCustomize(orgContactWays_id, contactWaysResultSet.getInt("id")); commonutil.AssertEqualsCustomize(orgContactWays_created_at, contactWaysResultSet.getLong("created_at")); commonutil.AssertEqualsCustomize(orgContactWays_created_by, contactWaysResultSet.getLong("created_by")); commonutil.AssertEqualsCustomize(orgContactWays_address_id, contactWaysResultSet.getLong("address_id")); commonutil.AssertEqualsCustomize(orgContactWays_fax_number, contactWaysResultSet.getString("fax_number")); commonutil.AssertEqualsCustomize(orgContactWays_org_id, contactWaysResultSet.getLong("org_id")); commonutil.AssertEqualsCustomize(orgContactWays_phone_number, contactWaysResultSet.getString("phone_number")); commonutil.AssertEqualsCustomize(orgContactWays_updated_at, contactWaysResultSet.getLong("updated_at")); commonutil.AssertEqualsCustomize(orgContactWays_updated_by, contactWaysResultSet.getLong("updated_by")); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { LOGGER.info("*****************Test case: Post Orgs List Ended*****************"); } }
From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java
License:Apache License
static void COMPUTE_COUNT(JsonObject jsonObject) { jsonObject.remove("jointProgress"); jsonObject.remove("actionProgress"); jsonObject.remove("experimentProgress"); jsonObject.remove("jointActionRate"); jsonObject.remove("actionRates"); JsonObject cur = jsonObject.getAsJsonObject("buckets"); for (Map.Entry<String, JsonElement> entry : cur.entrySet()) { entry.getValue().getAsJsonObject().remove("actionRates"); entry.getValue().getAsJsonObject().remove("jointActionRate"); entry.getValue().getAsJsonObject().remove("bucketComparisons"); }//from www . jav a 2 s. com JsonObject experimentStatistics = jsonObject.getAsJsonObject("buckets"); for (String label : new String[] { "red", "blue" }) { JsonObject bucket = experimentStatistics.getAsJsonObject(label); if (bucket.getAsJsonObject("actionCounts").entrySet().size() == 0) { experimentStatistics.remove(label); } } }
From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java
License:Apache License
/** * @param jsonObject/* www . jav a 2 s. co m*/ */ static void COMPUTE_DAILY_COUNT(JsonObject jsonObject) { for (JsonElement element : jsonObject.getAsJsonArray("days")) { element.getAsJsonObject().remove("cumulative"); element.getAsJsonObject().remove("jointProgress"); element.getAsJsonObject().remove("actionProgress"); element.getAsJsonObject().remove("experimentProgress"); element.getAsJsonObject().remove("jointActionRate"); element.getAsJsonObject().remove("actionRates"); JsonObject experimentStatistics = element.getAsJsonObject().getAsJsonObject("perDay"); experimentStatistics.remove("jointActionRate"); experimentStatistics.remove("actionRates"); JsonObject buckets = experimentStatistics.getAsJsonObject("buckets"); for (String label : new String[] { "red", "blue" }) { JsonObject bucket = buckets.getAsJsonObject(label); bucket.remove("actionRates"); bucket.remove("jointActionRate"); } } }
From source file:com.jaspervanriet.huntingthatproduct.Activities.CollectionActivity.java
License:Open Source License
private void getProducts() { Ion.with(this).load(Constants.API_URL + "collections/" + mCollection.id) .setHeader("Authorization", "Bearer " + Constants.CLIENT_TOKEN).asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override/* www.ja va 2 s . com*/ public void onCompleted(Exception e, JsonObject result) { if (e != null && e instanceof TimeoutException) { Toast.makeText(CollectionActivity.this, getResources().getString(R.string.error_connection), Toast.LENGTH_SHORT).show(); return; } if (result != null && result.has("collection")) { int i; result = result.getAsJsonObject("collection"); JsonArray products = result.getAsJsonArray("posts"); for (i = 0; i < products.size(); i++) { JsonObject obj = products.get(i).getAsJsonObject(); Product product = new Product(obj); mProducts.add(product); } mListAdapter.notifyDataSetChanged(); mProgressWheel.stopSpinning(); mProgressWheel.setVisibility(View.INVISIBLE); checkEmpty(); } } }); }
From source file:com.kaltura.client.types.ObjectBase.java
License:Open Source License
public ObjectBase(JsonObject jsonObject) throws APIException { if (jsonObject == null) return;/*from w w w . j a v a 2s . c o m*/ // set members values: relatedObjects = GsonParser.parseMap(jsonObject.getAsJsonObject("relatedObjects"), ListResponse.class); }
From source file:com.kurtraschke.amtkgtfsrealtime.AMTKRealtimeProvider.java
License:Apache License
/** * This method downloads the latest vehicle data, processes each vehicle in * turn, and create a GTFS-realtime feed of trip updates and vehicle * positions as a result./* w ww . j a v a 2 s.c o m*/ */ private void refreshVehicles() throws IOException, ParseException { URL trainPositions = new URL( "https://www.googleapis.com/mapsengine/v1/tables/01382379791355219452-08584582962951999356/features?version=published&maxResults=250&key=" + _mapsEngineKey); JsonParser parser = new JsonParser(); JsonObject o = (JsonObject) parser.parse(new InputStreamReader(trainPositions.openStream())); JsonArray trains = o.getAsJsonArray("features"); for (JsonElement e : trains) { try { JsonObject train = e.getAsJsonObject(); JsonArray coordinates = train.getAsJsonObject("geometry").getAsJsonArray("coordinates"); JsonObject trainProperties = train.getAsJsonObject("properties"); String trainState = trainProperties.get("TrainState").getAsString(); if (!(trainState.equals("Active") || trainState.equals("Predeparture"))) { continue; } String trainNumber = trainProperties.get("TrainNum").getAsString(); String originTimestamp = trainProperties.get("OrigSchDep").getAsString(); String originTimezone = trainProperties.get("OriginTZ").getAsString(); String updateTimestamp = trainProperties.get("LastValTS").getAsString(); String updateTimezone = trainProperties.has("EventTZ") ? trainProperties.get("EventTZ").getAsString() : originTimezone; ServiceDate trainServiceDate = DateUtils.serviceDateForTimestamp(originTimestamp, originTimezone); String key = String.format("%s(%s)", trainNumber, trainServiceDate.getDay()); Date updateDate = DateUtils.parseTimestamp(updateTimestamp, updateTimezone); if (!lastUpdateByVehicle.containsKey(key) || updateDate.after(lastUpdateByVehicle.get(key))) { long updateTime = updateDate.getTime() / 1000L; /** * We construct a TripDescriptor and VehicleDescriptor, * which will be used in both trip updates and vehicle * positions to identify the trip and vehicle. */ TripDescriptor.Builder tripDescriptor = TripDescriptor.newBuilder(); String tripId = tripForTrainAndDate(trainNumber, trainServiceDate); if (tripId == null) { continue; } tripDescriptor.setTripId(tripId); tripDescriptor.setStartDate(String.format("%04d%02d%02d", trainServiceDate.getYear(), trainServiceDate.getMonth(), trainServiceDate.getDay())); VehicleDescriptor.Builder vehicleDescriptor = VehicleDescriptor.newBuilder(); vehicleDescriptor.setId(key); vehicleDescriptor.setLabel(trainNumber); TripUpdate.Builder tripUpdate = TripUpdate.newBuilder(); for (Entry<String, JsonElement> propEntry : trainProperties.entrySet()) { if (propEntry.getKey().startsWith("Station")) { StopTimeUpdate stu = stopTimeUpdateForStation(propEntry.getValue().getAsString()); if (stu != null) { tripUpdate.addStopTimeUpdate(stu); } } } tripUpdate.setTrip(tripDescriptor); tripUpdate.setVehicle(vehicleDescriptor); tripUpdate.setTimestamp(updateTime); /** * Create a new feed entity to wrap the trip update and add * it to the GTFS-realtime trip updates feed. */ FeedEntity.Builder tripUpdateEntity = FeedEntity.newBuilder(); tripUpdateEntity.setId(key); tripUpdateEntity.setTripUpdate(tripUpdate); /** * To construct our VehiclePosition, we create a position * for the vehicle. We add the position to a VehiclePosition * builder, along with the trip and vehicle descriptors. */ Position.Builder position = Position.newBuilder(); position.setLatitude(coordinates.get(1).getAsFloat()); position.setLongitude(coordinates.get(0).getAsFloat()); if (trainProperties.has("Heading") && !trainProperties.get("Heading").getAsString().equals("")) { position.setBearing(degreesForHeading(trainProperties.get("Heading").getAsString())); } if (trainProperties.has("Velocity") && !trainProperties.get("Velocity").getAsString().equals("")) { position.setSpeed(trainProperties.get("Velocity").getAsFloat() * 0.44704f); } VehiclePosition.Builder vehiclePosition = VehiclePosition.newBuilder(); vehiclePosition.setTimestamp(updateTime); vehiclePosition.setPosition(position); vehiclePosition.setTrip(tripDescriptor); vehiclePosition.setVehicle(vehicleDescriptor); /** * Create a new feed entity to wrap the vehicle position and * add it to the GTFS-realtime vehicle positions feed. */ FeedEntity.Builder vehiclePositionEntity = FeedEntity.newBuilder(); vehiclePositionEntity.setId(key); vehiclePositionEntity.setVehicle(vehiclePosition); GtfsRealtimeIncrementalUpdate tripUpdateUpdate = new GtfsRealtimeIncrementalUpdate(); tripUpdateUpdate.addUpdatedEntity(tripUpdateEntity.build()); _tripUpdatesSink.handleIncrementalUpdate(tripUpdateUpdate); GtfsRealtimeIncrementalUpdate vehiclePositionUpdate = new GtfsRealtimeIncrementalUpdate(); vehiclePositionUpdate.addUpdatedEntity(vehiclePositionEntity.build()); _vehiclePositionsSink.handleIncrementalUpdate(vehiclePositionUpdate); if (trainProperties.has("StatusMsg")) { String statusMessage = trainProperties.get("StatusMsg").getAsString().trim(); Alert.Builder alert = Alert.newBuilder(); alert.setDescriptionText(GtfsRealtimeLibrary.getTextAsTranslatedString(statusMessage)); EntitySelector.Builder informedEntity = EntitySelector.newBuilder(); informedEntity.setTrip(tripDescriptor); alert.addInformedEntity(informedEntity); FeedEntity.Builder alertEntity = FeedEntity.newBuilder(); alertEntity.setId(key); alertEntity.setAlert(alert); GtfsRealtimeIncrementalUpdate alertUpdate = new GtfsRealtimeIncrementalUpdate(); alertUpdate.addUpdatedEntity(alertEntity.build()); _alertsSink.handleIncrementalUpdate(alertUpdate); } lastUpdateByVehicle.put(key, updateDate); } } catch (Exception ex) { _log.warn("Exception processing vehicle", ex); } } }
From source file:com.kyloth.serleena.synchronization.kylothcloud.EmergencyDataDeserializer.java
License:Open Source License
@Override public EmergencyDataEntity deserialize(JsonElement json, Type typeOfEd, JsonDeserializationContext context) throws JsonParseException { EmergencyDataEntity ede = new EmergencyDataEntity(); JsonObject boundingRect = json.getAsJsonObject().get("boundingRect").getAsJsonObject(); JsonObject topLeft = boundingRect.getAsJsonObject("topLeft"); JsonObject bottomRight = boundingRect.getAsJsonObject("bottomRight"); GeoPoint tl = new GeoPoint(topLeft.getAsJsonObject().get("latitude").getAsDouble(), topLeft.get("longitude").getAsDouble()); GeoPoint br = new GeoPoint(bottomRight.getAsJsonObject().get("latitude").getAsDouble(), bottomRight.get("longitude").getAsDouble()); ede.rect = new Region(tl, br); ede.name = json.getAsJsonObject().get("name").getAsString(); ede.number = json.getAsJsonObject().get("number").getAsString(); return ede;/*ww w. j a va2 s .c o m*/ }
From source file:com.licensetokil.atypistcalendar.gcal.Syncer.java
private int getCorrespondingLocalTaskId(JsonObject remoteTask) { if (privateExtendedPropertiesExist(remoteTask)) { return remoteTask.getAsJsonObject(EVENT_RESOURCE_LABEL_EXTENDED_PROPERTIES) .getAsJsonObject(EVENT_EXTENDED_PROPERTIES_RESOURCE_LABEL_PRIVATE) .get(EVENT_EXTENDED_PROPERTIES_PRIVATE_RESOURCE_LABEL_ATC_LOCAL_TASK_ID).getAsInt(); }//from ww w.ja v a2 s. co m return NULL_CORRESPONDING_LOCAL_TASK_ID; }
From source file:com.licensetokil.atypistcalendar.gcal.Syncer.java
private boolean privateExtendedPropertiesExist(JsonObject remoteTask) { if (remoteTask.getAsJsonObject(EVENT_RESOURCE_LABEL_EXTENDED_PROPERTIES) == null) { return false; }/*from ww w .j av a 2s. c o m*/ if (remoteTask.getAsJsonObject(EVENT_RESOURCE_LABEL_EXTENDED_PROPERTIES) .getAsJsonObject(EVENT_EXTENDED_PROPERTIES_RESOURCE_LABEL_PRIVATE) == null) { return false; } if (remoteTask.getAsJsonObject(EVENT_RESOURCE_LABEL_EXTENDED_PROPERTIES) .getAsJsonObject(EVENT_EXTENDED_PROPERTIES_RESOURCE_LABEL_PRIVATE) .get(EVENT_EXTENDED_PROPERTIES_PRIVATE_RESOURCE_LABEL_ATC_LOCAL_TASK_ID) == null) { return false; } return true; }
From source file:com.licensetokil.atypistcalendar.gcal.Syncer.java
private void updateLocalTaskFromRemoteTask(JsonObject remoteTask, Task currentLocalTask) { // Extracting the (common) fields from the RemoteTask object. String remoteTaskId = Utilities.getJsonObjectValueOrEmptyString(remoteTask, EVENT_RESOURCE_LABEL_ID); String description = Utilities.getJsonObjectValueOrEmptyString(remoteTask, EVENT_RESOURCE_LABEL_SUMMARY); String location = Utilities.getJsonObjectValueOrEmptyString(remoteTask, EVENT_RESOURCE_LABEL_LOCATION); Calendar lastModifiedDate = SyncManager.getLastModifiedDateOrTimeNow(remoteTask); if (currentLocalTask instanceof Todo) { logger.info("currentLocalTask is of type Todo."); updateLocalTodo((Todo) currentLocalTask, description, location, remoteTaskId, lastModifiedDate); } else {/*from w w w .j a va2 s .c o m*/ // Extract the start and end time of the RemoteTask object. Calendar startTime = null; Calendar endTime = null; try { startTime = Utilities .parseGoogleDateTimeObject(remoteTask.getAsJsonObject(EVENT_RESOURCE_LABEL_START)); endTime = Utilities.parseGoogleDateTimeObject(remoteTask.getAsJsonObject(EVENT_RESOURCE_LABEL_END)); } catch (ParseException e) { logger.severe( "Unable to parse Google DateTime object (this is unexpected as Google only returns a standardised format). Failing quietly."); e.printStackTrace(); assert false; return; } if (currentLocalTask instanceof Deadline) { logger.info("currentLocalTask is of type Deadline."); updateLocalDeadline((Deadline) currentLocalTask, remoteTaskId, description, location, lastModifiedDate, endTime); } else if (currentLocalTask instanceof Schedule) { logger.info("currentLocalTask is of type Schedule."); updateLocalSchedule((Schedule) currentLocalTask, remoteTaskId, description, location, lastModifiedDate, startTime, endTime); } else { logger.severe("Unknown Task sub-type detected."); assert false; } } }