List of usage examples for org.apache.commons.collections.map CaseInsensitiveMap containsKey
public boolean containsKey(Object key)
From source file:com.thinkbiganalytics.nifi.feedmgr.ConfigurationPropertyReplacer.java
/** * This will replace the Map of Properties in the DTO but not persist back to Nifi. You need to call the rest client to persist the change * * @param controllerServiceDTO the controller service * @param properties the properties to set * @param propertyDescriptorTransform transformer * @return {@code true} if the properties were updated, {@code false} if not */// w ww . j a va 2s .c o m public static boolean replaceControllerServiceProperties(ControllerServiceDTO controllerServiceDTO, Map<String, String> properties, NiFiPropertyDescriptorTransform propertyDescriptorTransform) { Set<String> changedProperties = new HashSet<>(); if (controllerServiceDTO != null) { //check both Nifis Internal Key name as well as the Displayname to match the properties CaseInsensitiveMap propertyMap = new CaseInsensitiveMap(properties); Map<String, String> controllerServiceProperties = controllerServiceDTO.getProperties(); controllerServiceProperties.entrySet().stream() .filter(entry -> (propertyMap.containsKey(entry.getKey()) || (controllerServiceDTO.getDescriptors().get(entry.getKey()) != null && propertyMap.containsKey(controllerServiceDTO.getDescriptors() .get(entry.getKey()).getDisplayName().toLowerCase())))) .forEach(entry -> { boolean isSensitive = propertyDescriptorTransform .isSensitive(controllerServiceDTO.getDescriptors().get(entry.getKey())); String value = (String) propertyMap.get(entry.getKey()); if (StringUtils.isBlank(value)) { value = (String) propertyMap.get(controllerServiceDTO.getDescriptors() .get(entry.getKey()).getDisplayName().toLowerCase()); } if (!isSensitive || (isSensitive && StringUtils.isNotBlank(value))) { entry.setValue(value); changedProperties.add(entry.getKey()); } }); } return !changedProperties.isEmpty(); }
From source file:com.thinkbiganalytics.feedmgr.nifi.NifiControllerServiceProperties.java
public Map<String, String> mergeNifiAndEnvProperties(Map<String, String> nifiProperties, String serviceName) { if (nifiProperties != null) { CaseInsensitiveMap propertyMap = new CaseInsensitiveMap(nifiProperties); String servicePrefix = NifiEnvironmentProperties .getEnvironmentControllerServicePropertyPrefix(serviceName); Map<String, Object> map = environmentProperties.getPropertiesStartingWith(servicePrefix); if (map != null && !map.isEmpty()) { for (Map.Entry<String, Object> entry : map.entrySet()) { String key = NifiEnvironmentProperties .environmentPropertyToControllerServiceProperty(entry.getKey()); if (propertyMap.containsKey(key) && entry.getValue() != null) { propertyMap.put(key, entry.getValue()); }/* w w w .j ava2 s. c o m*/ } } return propertyMap; } return null; }
From source file:org.mrgeo.services.ServletUtils.java
/** * Validates the existence and type of an HTTP parameter. * @param request servlet request/*from w w w .ja v a2s . c o m*/ * @param name parameter name * @param type parameter data type * @throws Exception if the parameter does not exist or cannot be cast to the requested data type */ public static void validateParam(HttpServletRequest request, String name, String type) throws Exception { CaseInsensitiveMap params = new CaseInsensitiveMap(request.getParameterMap()); if (params.containsKey(name)) { String value = ((String[]) params.get(name))[0]; if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Missing request parameter: " + name); } if (type.equals("integer")) { try { Integer.parseInt(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid request parameter: " + name); } } if (type.equals("double")) { try { Double.parseDouble(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid request parameter: " + name); } } } else { throw new IllegalArgumentException("Missing request parameter: " + name); } }
From source file:org.mrgeo.services.ServletUtils.java
/** * Retrieves a parameter value from a servlet request * @param request servlet request//from www .j av a2 s . co m * @param name parameter name * @return parameter value */ public static String getParamValue(HttpServletRequest request, String name) { CaseInsensitiveMap params = new CaseInsensitiveMap(request.getParameterMap()); if (params.containsKey(name)) { return ((String[]) params.get(name))[0]; } return null; }
From source file:org.n52.wps.server.request.Request.java
/** * Retrieve a value from an input-map with a lookup-key * @param key The lookup-key//from w ww . j a v a2 s . co m * @param map The input-map to look in * @param required If the key-value pair must be in the map. * @return The value of the key-value pair */ public static String getMapValue(String key, CaseInsensitiveMap map, boolean required) throws ExceptionReport { if (map.containsKey(key)) { return ((String[]) map.get(key))[0]; } else if (!required) { LOGGER.warn("Parameter <" + key + "> not found."); return null; } else { //Fix for Bug 904 https://bugzilla.52north.org/show_bug.cgi?id=904 throw new ExceptionReport("Parameter <" + key + "> not specified.", ExceptionReport.MISSING_PARAMETER_VALUE, key); } }
From source file:org.n52.wps.server.request.Request.java
/** * Retrieve a value from an input-map with a lookup-key * @param key The lookup-key/*from w w w . j a v a 2 s. c o m*/ * @param map The input-map to look in * @param required If the key-value pair must be in the map. * @return The value of the key-value pair */ public static String getMapValue(String key, CaseInsensitiveMap map, boolean required, String[] supportedValues) throws ExceptionReport { if (map.containsKey(key)) { String value = ((String[]) map.get(key))[0]; for (String string : supportedValues) { if (string.equalsIgnoreCase(value)) { return value; } } throw new ExceptionReport("Invalid value for parameter <" + key + ">.", ExceptionReport.INVALID_PARAMETER_VALUE, key); } else if (!required) { LOGGER.warn("Parameter <" + key + "> not found."); return null; } else { //Fix for Bug 904 https://bugzilla.52north.org/show_bug.cgi?id=904 throw new ExceptionReport("Parameter <" + key + "> not specified.", ExceptionReport.MISSING_PARAMETER_VALUE, key); } }
From source file:org.n52.wps.server.request.Request.java
/** * Retrieve an array of values from an input-map with a lookup-key * @param key The lookup-key/*from www .j ava 2s . com*/ * @param map The input-map to look in * @param required If the key-value pair must be in the map. * @return The array of values of the key-value pair */ public static String[] getMapArray(String key, CaseInsensitiveMap map, boolean required) throws ExceptionReport { if (map.containsKey(key)) { return (String[]) map.get(key); } else if (!required) { LOGGER.warn("Parameter <" + key + "> not found."); return null; } else { //Fix for Bug 904 https://bugzilla.52north.org/show_bug.cgi?id=904 throw new ExceptionReport("Parameter <" + key + "> not specified.", ExceptionReport.MISSING_PARAMETER_VALUE, key); } }