List of usage examples for com.liferay.portal.kernel.json JSONArray getJSONObject
public JSONObject getJSONObject(int index);
From source file:com.beorn.paymentapi.model.ApiPaymentMethod.java
License:Open Source License
public static List<ApiPaymentMethod> fromJSON(JSONArray jsonArray) { List<ApiPaymentMethod> results = new ArrayList<ApiPaymentMethod>(jsonArray.length()); for (int i = 0; i < jsonArray.length(); ++i) { results.add(fromJSON(jsonArray.getJSONObject(i))); }/*from w w w .j av a2s. c o m*/ return results; }
From source file:com.beorn.paymentapi.model.ApiTransaction.java
License:Open Source License
public static List<ApiTransaction> fromJSON(JSONArray jsonArray) { List<ApiTransaction> results = new ArrayList<ApiTransaction>(jsonArray.length()); for (int i = 0; i < jsonArray.length(); ++i) { results.add(fromJSON(jsonArray.getJSONObject(i))); }/* w ww . j a v a2s .c o m*/ return results; }
From source file:com.evozon.evoportal.my_account.wrapper.UserExpandoWrapper.java
private JSONObject getCurrentStatus() { JSONObject currentStatus = null;/*from www . jav a 2 s.com*/ try { JSONArray statusArray = getStatusArrayLog(); if (statusArray != null) { int statusCount = statusArray.length(); if (statusCount > 0) { currentStatus = statusArray.getJSONObject(statusCount - 1); } } } catch (JSONException e) { log.error(e); } return currentStatus; }
From source file:com.evozon.evoportal.my_account.wrapper.UserExpandoWrapper.java
public void removeCurrentStatusLog() { try {//from w w w. ja v a 2s . c o m JSONArray statusArray = getStatusArrayLog(); JSONArray newStatusArray = JSONFactoryUtil.createJSONArray(); int statusCount = statusArray.length(); if (statusCount > 1) { for (int i = 0; i < statusCount - 1; i++) { JSONObject oldStatus = statusArray.getJSONObject(i); newStatusArray.put(oldStatus); } } user.getExpandoBridge().setAttribute(MyAccountConstants.EVOZON_USER_STATUS, newStatusArray.toString()); } catch (Exception e) { log.error("Error getting current status for user: " + user.getFullName() + " in removeCurrentStatus()", e); } }
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getCollateralBreakdown(String portfolioIds) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); Connection conn = null;//from ww w .j ava 2 s . c om try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*, DATEDIFF(f.maturity_dt,now()) AS maturing_after", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalMarketValue = getTotalMarketValue(portfolioIds); double totalValueOfBonds = 0.0; while (rs.next()) { String collatTyp = rs.getString("collat_typ"); double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; JSONObject jsonObj = null; if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject _jsonObj = jsonArray.getJSONObject(i); if (_jsonObj.getString("bucket").equalsIgnoreCase(collatTyp)) { jsonObj = _jsonObj; break; } } } if (Validator.isNull(jsonObj)) { jsonObj = JSONFactoryUtil.createJSONObject(); jsonObj.put("bucket", collatTyp); jsonObj.put("market_value", 0.0); jsonObj.put("bond_holdings_percent", 0.0); jsonObj.put("total_holdings_percent", 0.0); jsonArray.put(jsonObj); } jsonObj.put("market_value", jsonObj.getDouble("market_value") + currentMarketValue); jsonObj.put("total_holdings_percent", jsonObj.getDouble("total_holdings_percent") + currentMarketValue * 100 / totalMarketValue); } rs.close(); stmt.close(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); jsonObj.put("bond_holdings_percent", jsonObj.getDouble("market_value") * 100 / totalValueOfBonds); } } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getBondsMaturing(String portfolioIds) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); // initialization of JSONArray with default values for (int i = 0; i < bucketNames.length; i++) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("bucket", bucketNames[i]); jsonObject.put("market_value", 0.0); jsonObject.put("bond_holdings_percent", 0.0); jsonObject.put("total_holdings_percent", 0.0); jsonArray.put(jsonObject);// w w w . ja va 2 s. c o m } Connection conn = null; try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*, round(mty_years_tdy * 360) AS maturing_after", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalMarketValue = getTotalMarketValue(portfolioIds); double totalValueOfBonds = 0.0; while (rs.next()) { int maturingAfter = rs.getInt("maturing_after"); double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; int index = 0; if (maturingAfter > 0 && maturingAfter <= 210) { index = 1; } else if (maturingAfter > 210 && maturingAfter <= 365) { index = 2; } else if (maturingAfter > 365 && maturingAfter <= 730) { index = 3; } else if (maturingAfter > 730 && maturingAfter <= 1825) { index = 4; } else if (maturingAfter > 1825 && maturingAfter <= 3650) { index = 5; } else if (maturingAfter > 3650) { index = 6; } JSONObject jsonObj = jsonArray.getJSONObject(index); jsonObj.put("market_value", jsonObj.getDouble("market_value") + currentMarketValue); jsonObj.put("total_holdings_percent", jsonObj.getDouble("total_holdings_percent") + currentMarketValue * 100 / totalMarketValue); } rs.close(); stmt.close(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); jsonObj.put("bond_holdings_percent", jsonObj.getDouble("market_value") * 100 / totalValueOfBonds); } } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getYldToMaturity(String portfolioIds) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (i <= 5) { jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.DASH + yldToMaturityRange[i][1]); } else {//from www. j a v a 2 s. co m jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.PLUS); } for (int j = 0; j < durationRange.length; j++) { jsonObject.put((int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1], 0.0d); jsonObject.put("index" + j, (i + StringPool.COLON + j)); } jsonArray.put(jsonObject); } Connection conn = null; try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalValueOfBonds = 0.0; while (rs.next()) { double dur_mid = rs.getDouble("dur_mid"); double yld_ytm_bid = rs.getDouble("yld_ytm_bid"); double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; for (int i = 0; i < yldToMaturityRange.length; i++) { if (yld_ytm_bid > yldToMaturityRange[i][0] && yld_ytm_bid <= yldToMaturityRange[i][1]) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { if (dur_mid > durationRange[j][0] && dur_mid <= durationRange[j][1]) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; jsonObj.put(key, jsonObj.getDouble(key) + currentMarketValue); } } } } } rs.close(); stmt.close(); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; jsonObj.put(key, jsonObj.getDouble(key) * 100 / totalValueOfBonds); } } // append a summary row JSONObject summary = JSONFactoryUtil.createJSONObject(); summary.put("summary", true); summary.put("yldToMaturityRange", "Total"); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; if (Double.isNaN(summary.getDouble(key))) { summary.put(key, jsonObj.getDouble(key)); } else { summary.put(key, summary.getDouble(key) + jsonObj.getDouble(key)); } } } jsonArray.put(summary); } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getCpnTypVsMtyTyp(String portfolioIds) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); List<String> cpnTypes = getDistinctValues("cpn_typ", portfolioIds); List<String> mtyTypes = getDistinctValues("mty_typ", portfolioIds); for (String cpnType : cpnTypes) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("cpnType", cpnType); int i = 0; for (String mtyType : mtyTypes) { jsonObject.put(mtyType, 0.0d); jsonObject.put(cpnType + ++i, mtyType + StringPool.COLON + cpnType); }/*from ww w .j av a2 s . co m*/ jsonObject.put("grandTotal", 0.0d); jsonArray.put(jsonObject); } Connection conn = null; try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalValueOfBonds = 0.0; while (rs.next()) { String cpn_typ = rs.getString("cpn_typ"); String mty_typ = rs.getString("mty_typ"); double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; for (int i = 0; i < cpnTypes.size(); i++) { if (cpn_typ.equalsIgnoreCase(cpnTypes.get(i))) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (String mtyType : mtyTypes) { if (mtyType.equalsIgnoreCase(mty_typ)) { jsonObj.put(mtyType, jsonObj.getDouble(mtyType) + currentMarketValue); } } } } } rs.close(); stmt.close(); for (int i = 0; i < cpnTypes.size(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (String mtyType : mtyTypes) { jsonObj.put(mtyType, jsonObj.getDouble(mtyType) * 100 / totalValueOfBonds); if (Double.isNaN(jsonObj.getDouble("grandTotal"))) { jsonObj.put("grandTotal", jsonObj.getDouble(mtyType)); } else { jsonObj.put("grandTotal", jsonObj.getDouble(mtyType) + jsonObj.getDouble("grandTotal")); } } } // append a summary row double grandTotal = 0.0d; JSONObject summary = JSONFactoryUtil.createJSONObject(); summary.put("summary", true); summary.put("cpnType", "Grand Total"); for (int i = 0; i < cpnTypes.size(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (String mtyType : mtyTypes) { if (Double.isNaN(summary.getDouble(mtyType))) { summary.put(mtyType, jsonObj.getDouble(mtyType)); } else { summary.put(mtyType, summary.getDouble(mtyType) + jsonObj.getDouble(mtyType)); grandTotal += summary.getDouble(mtyType); } } } summary.put("grandTotal", grandTotal); jsonArray.put(summary); } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getBondsQuality(String portfolioIds) { String[] categories = { "Investment", "Non Investment", "Others" }; JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); // initialization of JSONArray with default values for (int i = 0; i < categories.length; i++) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("category", categories[i]); jsonObject.put("children", JSONFactoryUtil.createJSONArray()); jsonArray.put(jsonObject);//from w w w. j a v a 2 s .c o m } Connection conn = null; try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalMarketValue = getTotalMarketValue(portfolioIds); double totalValueOfBonds = 0.0; while (rs.next()) { double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; String spRating = rs.getString("rtg_sp"); String moodyRating = rs.getString("rtg_moody"); Rating rating = null; try { rating = ratingPersistence.fetchBySP_Moody(spRating, moodyRating); } catch (SystemException e) { e.printStackTrace(); } // identify the object int index = 2; String description = "No Rating Available"; if (Validator.isNotNull(rating)) { String category = rating.getCategory(); description = rating.getDescription(); for (int i = 0; i < categories.length; i++) { if (categories[i].equalsIgnoreCase(category)) { index = i; } } } JSONArray children = jsonArray.getJSONObject(index).getJSONArray("children"); // identify the child within the parent JSONObject child = null; if (children.length() == 0) { child = JSONFactoryUtil.createJSONObject(); child.put("bucket", description); child.put("market_value", 0.0); child.put("bond_holdings_percent", 0.0); child.put("total_holdings_percent", 0.0); children.put(child); } for (int i = 0; i < children.length(); i++) { child = children.getJSONObject(i); if (child.getString("bucket").equalsIgnoreCase(description)) { child.put("market_value", child.getDouble("market_value") + currentMarketValue); child.put("total_holdings_percent", child.getDouble("total_holdings_percent") + currentMarketValue * 100 / totalMarketValue); } } } rs.close(); stmt.close(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject parent = jsonArray.getJSONObject(i); JSONArray children = parent.getJSONArray("children"); for (int j = 0; j < children.length(); j++) { JSONObject child = children.getJSONObject(j); child.put("bond_holdings_percent", child.getDouble("market_value") * 100 / totalValueOfBonds); } } } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.idetronic.subur.service.impl.AuthorLocalServiceImpl.java
License:Open Source License
public long[] createAuthor(JSONArray authors, ServiceContext serviceContext) throws SystemException { long[] authorIds = new long[authors.length()]; for (int i = 0; i < authors.length(); i++) { JSONObject jsonObj = authors.getJSONObject(i); String firstName = jsonObj.getString("firstName"); String lastName = jsonObj.getString("lastName"); Author author = newAuthor(firstName, null, lastName, null, null, null, serviceContext); authorIds[i] = author.getAuthorId(); }//from w w w . j a v a2 s .c o m return authorIds; }