Example usage for com.liferay.portal.kernel.util StringPool COLON

List of usage examples for com.liferay.portal.kernel.util StringPool COLON

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool COLON.

Prototype

String COLON

To view the source code for com.liferay.portal.kernel.util StringPool COLON.

Click Source Link

Usage

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public List<MyResult> getBondsByYldToMaturity(String index, String portfolioIds) {

    String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
            "[$FING_BOND_WHERE_CLAUSE$]" };

    StringBuilder sb = new StringBuilder();
    sb.append(" and a.assetId = f.assetId");

    String[] parts = index.split(StringPool.COLON);
    int i = Integer.parseInt(parts[0]);
    int j = Integer.parseInt(parts[1]);

    sb.append(" and yld_ytm_bid > ").append(yldToMaturityRange[i][0]).append(" and yld_ytm_bid <= ")
            .append(yldToMaturityRange[i][1]);
    sb.append(" and dur_mid > ").append(durationRange[j][0]).append(" and dur_mid <= ")
            .append(durationRange[j][1]);

    String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", sb.toString() };

    List<MyResult> myResults = myResultFinder.findResults(portfolioIds, tokens, replacements);

    return myResults;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public List<MyResult> getBondsByCpnTypVsMtyTyp(String combo, String portfolioIds) {

    String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
            "[$FING_BOND_WHERE_CLAUSE$]" };

    StringBuilder sb = new StringBuilder();
    sb.append(" and a.assetId = f.assetId");

    String[] parts = combo.split(StringPool.COLON);
    String mtyTyp = parts[0];//from  w ww . j a va 2  s  .c om
    String cpnTyp = parts[1];

    sb.append(" and mty_typ ='").append(mtyTyp).append("'");
    sb.append(" and cpn_typ ='").append(cpnTyp).append("'");

    String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", sb.toString() };

    List<MyResult> myResults = myResultFinder.findResults(portfolioIds, tokens, replacements);

    return myResults;
}

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 {/*  w w w.ja  v  a2 s  .c  o 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 w ww. j av a 2  s. c  om
        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.liferay.adaptive.media.image.internal.configuration.AdaptiveMediaImageConfigurationEntryParser.java

License:Open Source License

public String getConfigurationString(AdaptiveMediaImageConfigurationEntry configurationEntry) {

    StringBundler sb = new StringBundler();

    sb.append(_http.encodeURL(configurationEntry.getName()));
    sb.append(StringPool.COLON);
    sb.append(_http.encodeURL(configurationEntry.getDescription()));
    sb.append(StringPool.COLON);/*from ww w .j  a v a2  s .  co m*/
    sb.append(configurationEntry.getUUID());
    sb.append(StringPool.COLON);

    Map<String, String> properties = configurationEntry.getProperties();

    if (properties.get("max-height") != null) {
        int height = GetterUtil.getInteger(properties.get("max-height"));

        sb.append("max-height=");
        sb.append(height);

        if (properties.get("max-width") != null) {
            sb.append(StringPool.SEMICOLON);
        }
    }

    if (properties.get("max-width") != null) {
        int width = GetterUtil.getInteger(properties.get("max-width"));

        sb.append("max-width=");
        sb.append(width);
    }

    sb.append(StringPool.COLON);

    sb.append("enabled=");
    sb.append(String.valueOf(configurationEntry.isEnabled()));

    return sb.toString();
}

From source file:com.liferay.adaptive.media.image.web.html.AdaptiveMediaImageHTMLTagFactoryImpl.java

License:Open Source License

private Optional<String> _getMediaQueryString(MediaQuery mediaQuery) {
    List<Condition> conditions = mediaQuery.getConditions();

    if (conditions.isEmpty()) {
        return Optional.empty();
    }// w w w.j a  v a 2 s . co  m

    String[] conditionStrings = new String[conditions.size()];

    for (int i = 0; i < conditionStrings.length; i++) {
        Condition condition = conditions.get(i);

        StringBundler sb = new StringBundler(5);

        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(condition.getAttribute());
        sb.append(StringPool.COLON);
        sb.append(condition.getValue());
        sb.append(StringPool.CLOSE_PARENTHESIS);

        conditionStrings[i] = sb.toString();
    }

    return Optional.of(String.join(" and ", conditionStrings));
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getAddresses(User user) throws Exception {
    List<Address> addresses = AddressLocalServiceUtil.getAddresses(user.getCompanyId(), Contact.class.getName(),
            user.getContactId());/*  ww  w . j a v  a2 s .c  o m*/

    StringBundler sb = new StringBundler(addresses.size() * 19);

    for (Address address : addresses) {
        sb.append("ADR;TYPE=");

        ListType listType = address.getType();

        sb.append(StringUtil.toUpperCase(_getVCardListTypeName(listType)));

        sb.append(StringPool.COLON);
        sb.append(StringPool.SEMICOLON);
        sb.append(StringPool.SEMICOLON);

        if (Validator.isNotNull(address.getStreet1())) {
            sb.append(address.getStreet1());
        }

        if (Validator.isNotNull(address.getStreet2())) {
            sb.append("\\n");
            sb.append(address.getStreet2());
        }

        if (Validator.isNotNull(address.getStreet3())) {
            sb.append("\\n");
            sb.append(address.getStreet3());
        }

        sb.append(StringPool.SEMICOLON);

        if (Validator.isNotNull(address.getCity())) {
            sb.append(address.getCity());
        }

        sb.append(StringPool.SEMICOLON);

        long regionId = address.getRegionId();

        if (regionId > 0) {
            Region region = RegionServiceUtil.getRegion(regionId);

            sb.append(region.getName());
        }

        sb.append(StringPool.SEMICOLON);

        if (Validator.isNotNull(address.getZip())) {
            sb.append(address.getZip());
        }

        sb.append(StringPool.SEMICOLON);

        long countryId = address.getCountryId();

        if (countryId > 0) {
            Country country = CountryServiceUtil.getCountry(countryId);

            sb.append(country.getName());
        }

        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getEmailAddresses(User user) throws Exception {
    List<EmailAddress> emailAddresses = EmailAddressLocalServiceUtil.getEmailAddresses(user.getCompanyId(),
            Contact.class.getName(), user.getContactId());

    StringBundler sb = new StringBundler(3 + (emailAddresses.size() * 5));

    sb.append("EMAIL;TYPE=INTERNET;TYPE=HOME:");
    sb.append(user.getEmailAddress());//from w ww . j  a v a 2s .c o m
    sb.append(StringPool.NEW_LINE);

    for (EmailAddress emailAddress : emailAddresses) {
        sb.append("EMAIL;TYPE=INTERNET;TYPE=");

        ListType listType = emailAddress.getType();

        sb.append(StringUtil.toUpperCase(listType.getName()));

        sb.append(StringPool.COLON);
        sb.append(emailAddress.getAddress());
        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getPhones(User user) throws Exception {
    List<Phone> phones = PhoneLocalServiceUtil.getPhones(user.getCompanyId(), Contact.class.getName(),
            user.getContactId());/*w w w .  java2  s  .c  o m*/

    StringBundler sb = new StringBundler(phones.size() * 7);

    for (Phone phone : phones) {
        sb.append("TEL;TYPE=");

        ListType listType = phone.getType();

        sb.append(StringUtil.toUpperCase(_getVCardListTypeName(listType)));

        sb.append(StringPool.COLON);
        sb.append(phone.getNumber());
        sb.append(StringPool.SPACE);
        sb.append(phone.getExtension());
        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getWebsites(User user) throws Exception {
    List<Website> websites = WebsiteLocalServiceUtil.getWebsites(user.getCompanyId(), Contact.class.getName(),
            user.getContactId());// w ww. j av  a  2 s  .  com

    StringBundler sb = new StringBundler(websites.size() * 5);

    for (Website website : websites) {
        sb.append("URL;TYPE=");

        ListType listType = website.getType();

        sb.append(StringUtil.toUpperCase(_getVCardListTypeName(listType)));

        sb.append(StringPool.COLON);

        String url = website.getUrl();

        sb.append(url.replaceAll(StringPool.COLON, "\\:"));

        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}