List of usage examples for org.apache.commons.collections4 MapUtils emptyIfNull
public static <K, V> Map<K, V> emptyIfNull(final Map<K, V> map)
null
, or the argument itself otherwise. From source file:com.kumarvv.setl.model.Row.java
public Row(Map<String, Integer> columns, Map<String, Object> data) { this.columns = MapUtils.emptyIfNull(columns); this.data = MapUtils.emptyIfNull(data); }
From source file:com.kumarvv.setl.core.Loader.java
/** * initialize load TO columns - from datasource if not found already * * @param load/*from ww w. j a va 2s . c o m*/ * @param jrs */ protected void initLoadToColumns(Load load, JdbcRowSet jrs) { if (load == null || MapUtils.isNotEmpty(load.getToColumns())) { return; } Map<String, Integer> mcs = rowSetUtil.getMetaColumns(jrs); Map<String, Integer> lcs = new HashMap<>(); for (String c : MapUtils.emptyIfNull(mcs).keySet()) { lcs.put(c, mcs.get(c)); } load.setToColumns(lcs); }
From source file:org.apache.metron.profiler.bolt.KafkaEmitter.java
/** * Appends triage values obtained from a {@code ProfileMeasurement} to the * outgoing message.// w w w . j av a 2s . c o m * * @param measurement The measurement that may contain triage values. * @param message The message that the triage values are appended to. */ private void appendTriageValues(ProfileMeasurement measurement, JSONObject message) { // for each triage value... Map<String, Object> triageValues = MapUtils.emptyIfNull(measurement.getTriageValues()); triageValues.forEach((key, value) -> { // append the triage value to the message if (isValidType(value)) { message.put(key, value); } else { LOG.error(String.format( "triage expression must result in primitive type, skipping; type=%s, profile=%s, entity=%s, expr=%s", ClassUtils.getShortClassName(value, "null"), measurement.getDefinition().getProfile(), measurement.getEntity(), key)); } }); }
From source file:org.apache.metron.profiler.DefaultProfileBuilder.java
/** * Executes a set of expressions whose results need to be assigned to a variable. * * @param expressions Maps the name of a variable to the expression whose result should be assigned to it. * @param transientState Additional transient state provided to the expression. * @param expressionType The type of expression; init, update, result. Provides additional context if expression execution fails. */// www . ja v a 2 s. c o m private void assign(Map<String, String> expressions, Map<String, Object> transientState, String expressionType) { // for each expression... for (Map.Entry<String, String> entry : MapUtils.emptyIfNull(expressions).entrySet()) { String var = entry.getKey(); String expr = entry.getValue(); try { // assign the result of the expression to the variable executor.assign(var, expr, transientState); } catch (Throwable e) { // in-scope variables = persistent state maintained by the profiler + the transient state Set<String> variablesInScope = new HashSet<>(); variablesInScope.addAll(transientState.keySet()); variablesInScope.addAll(executor.getState().keySet()); String msg = format( "Bad '%s' expression: error='%s', expr='%s', profile='%s', entity='%s', variables-available='%s'", expressionType, e.getMessage(), expr, profileName, entity, variablesInScope); LOG.error(msg, e); throw new ParseException(msg, e); } } }
From source file:org.apache.metron.profiler.ProfileBuilder.java
/** * Executes a set of expressions whose results need to be assigned to a variable. * @param expressions Maps the name of a variable to the expression whose result should be assigned to it. * @param transientState Additional transient state provided to the expression. * @param expressionType The type of expression; init, update, result. Provides additional context if expression execution fails. */// ww w .j a v a2 s. co m private void assign(Map<String, String> expressions, Map<String, Object> transientState, String expressionType) { try { // execute each of the 'update' expressions MapUtils.emptyIfNull(expressions).forEach((var, expr) -> executor.assign(var, expr, transientState)); } catch (ParseException e) { // make it brilliantly clear that one of the 'update' expressions is bad String msg = format("Bad '%s' expression: %s, profile=%s, entity=%s", expressionType, e.getMessage(), profileName, entity); throw new ParseException(msg, e); } }
From source file:org.apache.syncope.core.misc.security.AuthContextUtils.java
public static Map<String, Set<String>> getAuthorizations() { Map<String, Set<String>> result = null; final SecurityContext ctx = SecurityContextHolder.getContext(); if (ctx != null && ctx.getAuthentication() != null && ctx.getAuthentication().getAuthorities() != null) { result = new HashMap<>(); for (GrantedAuthority authority : ctx.getAuthentication().getAuthorities()) { if (authority instanceof SyncopeGrantedAuthority) { result.put(SyncopeGrantedAuthority.class.cast(authority).getAuthority(), SyncopeGrantedAuthority.class.cast(authority).getRealms()); }//from w ww .jav a 2 s .co m } } return MapUtils.emptyIfNull(result); }
From source file:org.ligoj.app.plugin.security.fortify.FortifyPluginResource.java
@SuppressWarnings("unchecked") @Override//from ww w. j a v a 2 s .c o m public String getVersion(final Map<String, String> parameters) throws Exception { final FortifyCurlProcessor processor = newFortifyCurlProcessor(parameters); final String url = StringUtils.appendIfMissing(parameters.get(PARAMETER_URL), "/") + "api/v1/userSession/info"; final CurlRequest request = new CurlRequest("POST", url, "{}", "Accept: application/json"); request.setSaveResponse(true); processor.process(request); processor.close(); final String content = ObjectUtils.defaultIfNull(request.getResponse(), "{}"); final Map<String, ?> data = MapUtils .emptyIfNull((Map<String, ?>) objectMapper.readValue(content, Map.class).get("data")); return (String) data.get("webappVersion"); }
From source file:org.ligoj.app.plugin.security.fortify.FortifyPluginResource.java
/** * Validate the project configuration.//from ww w .j a v a2s . c o m * * @param parameters * The project parameters. * @return true if the project exists. */ protected FortifyProject validateProject(final Map<String, String> parameters) throws IOException { final FortifyCurlProcessor processor = newFortifyCurlProcessor(parameters); try { // Check the project exists and get the name @SuppressWarnings("unchecked") final Map<String, Object> projectMap = MapUtils .emptyIfNull((Map<String, Object>) getFortifyResource(parameters, API_PROJECTS + parameters.get(PARAMETER_KEY) + "?fields=id,name", processor)); if (projectMap.isEmpty()) { // Project does not exist throw new ValidationJsonException(PARAMETER_KEY, "fortify-project"); } final FortifyProject project = toProject(projectMap); // Check the projectVersion is within this project final String version = parameters.get(PARAMETER_VERSION); @SuppressWarnings("unchecked") final List<Map<String, Object>> versions = (List<Map<String, Object>>) getFortifyResource(parameters, API_PROJECTS + parameters.get(PARAMETER_KEY) + "/versions?fields=id,name", processor); project.setVersion(versions.stream().filter(map -> map.get("id").toString().equals(version)).findFirst() .orElseThrow(() -> new ValidationJsonException(PARAMETER_VERSION, "fortify-version")) .get("name").toString()); // Get the project versions measures @SuppressWarnings("unchecked") final List<Map<String, Object>> measures = (List<Map<String, Object>>) getFortifyResource(parameters, API_PROJECT_VERSIONS + version + "/performanceIndicatorHistories", processor); measures.forEach( map -> project.getMeasures().put(map.get("id").toString(), map.get("value").toString())); return project; } finally { processor.close(); } }