Search in sources :

Example 1 with ConfigurationProvider

use of org.apache.nifi.minifi.c2.api.ConfigurationProvider in project nifi-minifi by apache.

the class ConfigService method initContentTypeInfo.

protected ConfigurationProviderInfo initContentTypeInfo(List<ConfigurationProvider> configurationProviders) {
    List<Pair<MediaType, ConfigurationProvider>> mediaTypeList = new ArrayList<>();
    List<String> contentTypes = new ArrayList<>();
    Set<MediaType> seenMediaTypes = new LinkedHashSet<>();
    for (ConfigurationProvider configurationProvider : configurationProviders) {
        try {
            for (String contentTypeString : configurationProvider.getContentTypes()) {
                MediaType mediaType = MediaType.valueOf(contentTypeString);
                if (seenMediaTypes.add(mediaType)) {
                    contentTypes.add(contentTypeString);
                    mediaTypeList.add(new Pair<>(mediaType, configurationProvider));
                }
            }
        } catch (ConfigurationProviderException e) {
            return new ConfigurationProviderInfo(null, null, e);
        }
    }
    return new ConfigurationProviderInfo(mediaTypeList, contentTypes, null);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) ConfigurationProvider(org.apache.nifi.minifi.c2.api.ConfigurationProvider) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) Pair(org.apache.nifi.minifi.c2.api.util.Pair)

Example 2 with ConfigurationProvider

use of org.apache.nifi.minifi.c2.api.ConfigurationProvider in project nifi-minifi by apache.

the class ConfigService method initConfigurationProviderValue.

public ConfigurationProviderValue initConfigurationProviderValue(ConfigurationProviderKey key) {
    if (logger.isDebugEnabled()) {
        logger.debug("Attempting to load and cache configuration with key " + key);
    }
    try {
        List<MediaType> acceptValues = key.getAcceptValues();
        Pair<MediaType, ConfigurationProvider> providerPair = getProvider(acceptValues);
        Map<String, List<String>> parameters = key.getParameters();
        Integer version = null;
        List<String> versionList = parameters.get("version");
        if (versionList != null && versionList.size() > 0) {
            try {
                version = Integer.parseInt(versionList.get(0));
            } catch (NumberFormatException e) {
                throw new InvalidParameterException("Unable to parse " + version + " as integer.", e);
            }
        }
        return new ConfigurationProviderValue(providerPair.getSecond().getConfiguration(providerPair.getFirst().toString(), version, parameters), providerPair.getFirst(), null);
    } catch (ConfigurationProviderException e) {
        return new ConfigurationProviderValue(null, null, e);
    }
}
Also used : ConfigurationProvider(org.apache.nifi.minifi.c2.api.ConfigurationProvider) ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) InvalidParameterException(org.apache.nifi.minifi.c2.api.InvalidParameterException) MediaType(javax.ws.rs.core.MediaType) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)2 MediaType (javax.ws.rs.core.MediaType)2 ConfigurationProvider (org.apache.nifi.minifi.c2.api.ConfigurationProvider)2 ConfigurationProviderException (org.apache.nifi.minifi.c2.api.ConfigurationProviderException)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 InvalidParameterException (org.apache.nifi.minifi.c2.api.InvalidParameterException)1 Pair (org.apache.nifi.minifi.c2.api.util.Pair)1