Example usage for java.util Map forEach

List of usage examples for java.util Map forEach

Introduction

In this page you can find the example usage for java.util Map forEach.

Prototype

default void forEach(BiConsumer<? super K, ? super V> action) 

Source Link

Document

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.

Usage

From source file:org.wso2.carbon.identity.oauth2.util.ClaimsUtil.java

/**
 * To add the missing claims that are missed in IDP and SP mapping.
 *
 * @param tokenReqMsgCtx             Token request message context.
 * @param userAttributes                 Attributes received from IDP.
 * @param claimsAfterIDPandSPMapping Claims.
 * @param idPClaimMappings           IDP Claim mappings.
 * @return Final claim map with all the claims received from the IDP.
 * @throws IdentityApplicationManagementException Identity Application Management Exception.
 *//*from   ww w .j av  a 2s. c  o m*/
private static Map<String, String> addMissingClaims(OAuthTokenReqMessageContext tokenReqMsgCtx,
        Map<String, String> userAttributes, Map<String, String> claimsAfterIDPandSPMapping,
        ClaimMapping[] idPClaimMappings) throws IdentityApplicationManagementException {

    boolean isUserClaimsLoggable = isUserClaimsInTokenLoggable();
    ServiceProvider serviceProvider = getServiceProvider(tokenReqMsgCtx);
    ClaimConfig serviceProviderClaimConfig = serviceProvider.getClaimConfig();
    AuthenticatedUser authenticatedUser = tokenReqMsgCtx.getAuthorizedUser();

    userAttributes.forEach((key, value) -> {
        boolean foundMatching = false;
        String localClaimUri = null;

        // If IDP Claim mapping is not empty.
        if (ArrayUtils.isNotEmpty(idPClaimMappings)) {
            // Go through the claim mappings to identify the missed attributes in IDP level claim mapping.
            for (ClaimMapping claimMapping : idPClaimMappings) {
                if (claimMapping.getRemoteClaim().getClaimUri().equals(key)) {
                    localClaimUri = claimMapping.getLocalClaim().getClaimUri();
                    foundMatching = true;
                    break;
                }
            }
            // If the relevant attribute is not mapped in IDP, add that.
            if (!foundMatching) {
                if (isUserClaimsLoggable) {
                    if (log.isDebugEnabled()) {
                        log.debug("IDP Claim mapping does not exist for " + key + ", hence adding value "
                                + value + " for the user : " + authenticatedUser);
                    }
                }
                claimsAfterIDPandSPMapping.put(key, value);
            } else {
                // If the relevant attribute has mapping in IDP level, check for SP level mapping.
                foundMatching = false;
                ClaimMapping[] spClaimMapping = serviceProviderClaimConfig.getClaimMappings();
                for (ClaimMapping claimMapping : spClaimMapping) {
                    if (claimMapping.getLocalClaim().getClaimUri().equals(localClaimUri)
                            && claimMapping.isRequested()) {
                        foundMatching = true;
                        break;
                    }
                }
                // If the relevant attribute has IDP level mapping but not SP level mapping, add it.
                if (!foundMatching) {
                    if (isUserClaimsLoggable) {
                        if (log.isDebugEnabled()) {
                            log.debug("IDP Claim mapping exist, but SP Claim mapping does not exist for " + key
                                    + ", hence adding value " + value + " for the user : " + authenticatedUser);
                        }
                    }
                    claimsAfterIDPandSPMapping.put(key, value);
                }
            }
        } else {
            // If the IDP level mapping is not there, all the claims coming from IDP are assumed to be local claim.
            ClaimMapping[] spClaimMapping = serviceProviderClaimConfig.getClaimMappings();
            for (ClaimMapping claimMapping : spClaimMapping) {
                if (claimMapping.getLocalClaim().getClaimUri().equals(key) && claimMapping.isRequested()) {
                    foundMatching = true;
                    break;
                }
            }
            // If the attribute does not have the specific mapping in SP level, add the mapping.
            if (!foundMatching) {
                if (isUserClaimsLoggable) {
                    if (log.isDebugEnabled()) {
                        log.debug("SP Claim mapping does not exist for " + key + ", hence adding value " + value
                                + " for the user : " + authenticatedUser);
                    }
                }
                claimsAfterIDPandSPMapping.put(key, value);
            }
        }
    });
    if (isUserClaimsLoggable) {
        if (log.isDebugEnabled()) {
            log.debug("Final set of claims for the user : " + authenticatedUser + ": "
                    + claimsAfterIDPandSPMapping.toString());
        }
    }
    return claimsAfterIDPandSPMapping;
}

From source file:ijfx.service.workflow.DefaultWorkflowStep.java

@JsonSetter
public void setParameters(Map<String, Object> parameters) {

    parameters.forEach((key, value) -> {
        if (value == null) {
            return;
        }//ww w  .j av  a  2 s.co  m
        if (ArrayUtils.contains(SAVED_TYPES, value.getClass())) {

            if (value instanceof String && value.toString().startsWith(FileSerializer.FILE_PREFIX)) {
                this.parameters.put(key, FileDeserializer.deserialize(value.toString()));
            } else {
                this.parameters.put(key, value);
            }

        }
    });
    //this.parameters = parameters;
}

From source file:org.apache.metron.profiler.bolt.KafkaEmitter.java

/**
 * Appends triage values obtained from a {@code ProfileMeasurement} to the
 * outgoing message./* ww  w . j  a v  a  2s  .com*/
 *
 * @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.codice.ddf.catalog.ui.forms.filter.TransformVisitor.java

@Override
public void visitFunctionType(VisitableElement<Map<String, Object>> visitable) {
    traceName(visitable);//from   w  w w . j  av  a 2  s  .  c o m
    Map<String, Object> args = visitable.getValue();
    if (LOGGER.isTraceEnabled()) {
        args.forEach((key, value) -> LOGGER.trace("Key: {} | Value: {}", key, value));
    }

    builder.setTemplatedValues(args);
}

From source file:org.springframework.cloud.stream.app.tasklaunchrequest.DataFlowTaskLaunchRequestAutoConfiguration.java

private List<String> evaluateArgExpressions(Message message, Map<String, String> argExpressions) {
    List<String> results = new LinkedList<>();
    argExpressions.forEach((k, v) -> {
        Expression expression = argExpressionsMap.get(k);
        Assert.notNull(expression, String.format("expression %s cannot be null!", v));
        Object val = expression.getValue(message);
        results.add(String.format("%s=%s", k, val));
    });//  ww  w .  java  2 s . c o m
    return results;
}

From source file:org.apache.nifi.csv.CSVSchemaInference.java

private RecordSchema createSchema(final Map<String, FieldTypeInference> inferences) {
    final List<RecordField> recordFields = new ArrayList<>(inferences.size());
    inferences.forEach(
            (fieldName, type) -> recordFields.add(new RecordField(fieldName, type.toDataType(), true)));
    return new SimpleRecordSchema(recordFields);
}

From source file:org.springframework.web.reactive.resource.ResourceUrlProvider.java

/**
 * Manually configure resource handler mappings.
 * <p><strong>Note:</strong> by default resource mappings are auto-detected
 * from the Spring {@code ApplicationContext}. If this property is used,
 * auto-detection is turned off.//from   ww w .j av  a 2s .co m
 */
public void registerHandlers(Map<String, ResourceWebHandler> handlerMap) {
    this.handlerMap.clear();
    handlerMap.forEach((rawPattern, resourceWebHandler) -> {
        rawPattern = prependLeadingSlash(rawPattern);
        PathPattern pattern = this.patternParser.parse(rawPattern);
        this.handlerMap.put(pattern, resourceWebHandler);
    });
}

From source file:io.github.swagger2markup.internal.document.SecurityDocument.java

private void buildSecuritySchemeDefinitionsSection(MarkupDocBuilder markupDocBuilder,
        Map<String, SecuritySchemeDefinition> securitySchemes) {
    Map<String, SecuritySchemeDefinition> securitySchemeNames = toSortedMap(securitySchemes, null); // TODO : provide a dedicated ordering configuration for security schemes
    securitySchemeNames.forEach((String securitySchemeName,
            SecuritySchemeDefinition securityScheme) -> securitySchemeDefinitionComponent.apply(
                    markupDocBuilder,/* ww w . j  a v  a 2s  .  c  o  m*/
                    SecuritySchemeDefinitionComponent.parameters(securitySchemeName, securityScheme, 2)));
}

From source file:edu.usc.irds.sparkler.solr.schema.FieldMapper.java

/**
 * Maps fields to dynamic schema//from w w w  .  j ava 2 s.  c o m
 * @param fields fields to be mapped
 * @param eval cast the value type
 * @return mapped fields
 */
public Map<String, Object> mapFields(Map<String, Object> fields, boolean eval) {
    Map<String, Object> result = new HashMap<>();
    fields.forEach((k, v) -> {
        if (k != null) {
            if (eval && evaluator.canEval(v)) {
                v = evaluator.eval(v);
            }
            result.put(mapField(k, v), v);
        }
    });
    return result;
}

From source file:gov.nasa.jpl.analytics.solr.schema.FieldMapper.java

/**
 * Maps fields to dynamic schema//from  w  w w. ja  v a2s. c  om
 * @param fields fields to be mapped
 * @param eval cast the value type
 * @return mapped fields
 */
public Map<String, Object> mapFields(Map<String, Object> fields, boolean eval) {
    Map<String, Object> result = new HashMap<>();

    fields.forEach((k, v) -> {
        if (eval && evaluator.canEval(v)) {
            v = evaluator.eval(v);
        }
        result.put(mapField(k, v), v);
    });
    return result;
}