4.2.1.1 Additional Risk Factor and High Risk Entities

This example shows how to add an additional risk factor, which shows the count of high-risk entities, where entities are either Customers or Accounts.

To update, follow these steps:
  1. Add a query to get the count: Add a method in GraphPgqlQueries#getHighRiskEntitiesCount() as given below.
    public String getHighRiskEntityCount( 
            boolean forVisibleGraph,
            long minRiskBoundary, 
            PgxGraph resultGraph, 
            GetInfoFromGraph getInfo) {
    if (getInfo.verifyIfNodeProviderExist(
            List.of("Account", "Customer"), resultGraph, false, false)) { 
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder
            .append("SELECT ")
            .append("count(n.\"Original Id\")")
            .append(" MATCH (n) ")
            .append(
                    "WHERE n.Label in ('Account', 'Customer') ")
            .append("and n.\"Risk\" > ")
            .append(minRiskBoundary); 
    if (forVisibleGraph) {
    queryBuilder.append(" and id(n) in ? ");
    }
    return queryBuilder.toString();
    } else {
     return null;
    }
    }
  2. To add a row in Risk Factors, either modify the IHub#getRiskFactormethod or add a new method and then call that method inside the getRiskFactormethod as given below.

    Add the following lines at the end of the method to add new rows, before the line printStatement(report.printTable(true));

    log("Fetching high risk entity count.");
            long highRiskEntityCaseGraph =
                    getCountBasedOnQuery(
                            false,
                            graphPgqlQueries.getHighRiskEntityCount(
                                    true,
                                    config.HIGH_RISK_MIN_SCORE_BOUNDARY,
                                    resultGraph,
                                    (GetInfoFromGraph) getInfo),
                            null);
            long highRiskEntityVisibleGraph =
                    getCountBasedOnQuery(
                            true,
                            graphPgqlQueries.getHighRiskEntityCount( 
                                    true,
                                    config.HIGH_RISK_MIN_SCORE_BOUNDARY,
                                    resultGraph,
                                    GetInfoFromGraph) getInfo),
                            List.of(visibleNodeList)); 
                    report.addRow(
                            "High Risk entity present", 
                            formatScore(highRiskEntityCaseGraph), 
                            formatScore(highRiskEntityVisibleGraph)); 

After all the changes are done, the Risk Factors section will show additional row as shown in the following figure
Description of risk-factors.png follows
Description of the illustration risk-factors.png

.