Example usage for org.apache.commons.collections.map CaseInsensitiveMap get

List of usage examples for org.apache.commons.collections.map CaseInsensitiveMap get

Introduction

In this page you can find the example usage for org.apache.commons.collections.map CaseInsensitiveMap get.

Prototype

public Object get(Object key) 

Source Link

Document

Gets the value mapped to the key specified.

Usage

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
 *///from  ww w .  ja v a  2  s  .  c om
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:kr.co.exsoft.common.service.CommonServiceImpl.java

@Override
public Map<String, Object> configVersionInfo() throws Exception {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    ConfDao confDao = sqlSession.getMapper(ConfDao.class);

    // 1.         
    List<CaseInsensitiveMap> confList = new ArrayList<CaseInsensitiveMap>();
    confList = confDao.versionConfigDetail();

    for (CaseInsensitiveMap versonMap : confList) {

        if (versonMap.get("vkey") != null && versonMap.get("vkey").toString().equals(Constant.MAP_ID_MYPAGE)) {
            resultMap.put("mypage", versonMap);
        } else {/*from w w  w . ja  v a 2s.  c  o m*/
            resultMap.put("workspace", versonMap);
        }
    }

    return resultMap;
}

From source file:org.agnitas.beans.impl.UserFormImpl.java

protected String evaluateFormResult(Map<String, Object> params, boolean actionResult) {
    if (actionResult && successUseUrl) {
        // return success URL and set flag for redirect
        params.put(TEMP_REDIRECT_PARAM, Boolean.TRUE);
        return successUrl;
    }//from  w w w .j  a  v  a2  s  .  co m
    if (!actionResult && errorUseUrl) {
        // return error URL and set flag for redirect
        params.put(TEMP_REDIRECT_PARAM, Boolean.TRUE);
        return errorUrl;
    }
    String result = null;
    StringWriter aWriter = new StringWriter();
    CaseInsensitiveMap paramsEscaped = new CaseInsensitiveMap(params);
    paramsEscaped.put("requestParameters",
            AgnUtils.escapeHtmlInValues((Map<String, Object>) paramsEscaped.get("requestParameters")));

    try {
        Velocity.setProperty("runtime.log.logsystem.class",
                "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
        Velocity.setProperty("runtime.log", AgnUtils.getDefaultValue("system.logdir") + "/velocity.log");
        Velocity.setProperty("input.encoding", "UTF-8");
        Velocity.setProperty("output.encoding", "UTF-8");
        Velocity.init();
    } catch (Exception e) {
        logger.error("Velocity init: " + e.getMessage(), e);
    }

    try {
        if (actionResult) {
            Velocity.evaluate(new VelocityContext(paramsEscaped), aWriter, null, this.successTemplate);
        } else {
            Velocity.evaluate(new VelocityContext(paramsEscaped), aWriter, null, this.errorTemplate);
        }
    } catch (Exception e) {
        logger.error("evaluateForm: " + e.getMessage(), e);
        logFormParameters(params);
    }

    result = aWriter.toString();
    if (params.get("velocity_error") != null) {
        result += "<br/><br/>" + params.get("velocity_error");
        params.remove("velocity_error");
    }
    if (params.get("errors") != null) {
        result += "<br/>";
        ActionErrors velocityErrors = (ActionErrors) params.get("errors");
        Iterator it = velocityErrors.get();
        while (it.hasNext()) {
            result += "<br/>" + it.next();
        }
    }
    return result;
}

From source file:org.agnitas.webservice.EmmWebservice.java

/**
 * Method for inserting a recipient to the customer-database
 * @param username Username from ws_admin_tbl
 * @param password Password from ws_admin_tbl
 * @param doubleCheck If true checks, if email is already in database and does not import it.
 * @param keyColumn Column on which double check is used
 * @param overwrite If true, overwrites existing data of the recipient
 * @param paramNames Names of the columns
 * @param paramValues Values of the columns
 * @return customerID//from  w  w w  .  j  a v  a  2s . c o m
 */
public int addSubscriber(java.lang.String username, java.lang.String password, boolean doubleCheck,
        java.lang.String keyColumn, boolean overwrite, StringArrayType paramNames,
        StringArrayType paramValues) {
    ApplicationContext con = getWebApplicationContext();
    CaseInsensitiveMap allParams = new CaseInsensitiveMap();
    int returnValue = 0;
    int tmpCustID = 0;
    MessageContext msct = MessageContext.getCurrentContext();

    if (!authenticateUser(msct, username, password, 1)) {
        return returnValue;
    }

    try {
        for (int i = 0; i < paramNames.getX().length; i++) {
            if (paramNames.getX(i).toLowerCase().equals("email")) {
                paramValues.setX(i, paramValues.getX(i).toLowerCase());
            }
            allParams.put(paramNames.getX(i), paramValues.getX(i));
        }

        Recipient aCust = (Recipient) con.getBean("Recipient");
        RecipientDao dao = (RecipientDao) con.getBean("RecipientDao");
        aCust.setCompanyID(1);
        aCust.setCustParameters(allParams);
        if (doubleCheck) {
            tmpCustID = dao.findByColumn(aCust.getCompanyID(), keyColumn.toLowerCase(),
                    (String) allParams.get(keyColumn.toLowerCase()));
            if (tmpCustID == 0) {
                returnValue = dao.insertNewCust(aCust);
            } else {
                returnValue = tmpCustID;
                if (overwrite) {
                    aCust.setCustomerID(tmpCustID);
                    dao.updateInDB(aCust);
                }
            }
        } else {
            returnValue = dao.insertNewCust(aCust);
        }
    } catch (Exception e) {
        AgnUtils.logger().info("soap prob new subscriber: " + e);
        returnValue = 0;
    }

    return returnValue;
}

From source file:org.mrgeo.services.ServletUtils.java

/**
 * Validates the existence and type of an HTTP parameter.
 * @param request servlet request/*from  www .  ja va  2 s .  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  w w  w  .ja  v  a2s.  c  om
 * @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.feed.FeedServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    RemoteRepository newRemoteRepo = null;

    OutputStream out = res.getOutputStream();
    try {//from  w w w.jav  a 2  s  . c  o m

        Map<String, String[]> parameters = (Map<String, String[]>) req.getParameterMap();

        CaseInsensitiveMap ciMap = new CaseInsensitiveMap(parameters);

        if (!ciMap.keySet().contains(getParamName)) {
            res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "parameter '" + getParamName + "' not found");
        } else if (!ciMap.keySet().contains(getParamFeed)) {
            res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "parameter '" + getParamFeed + "' not found");
        } else if (!ciMap.keySet().contains(getParamLocalFeedMirror)) {
            res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "parameter '" + getParamLocalFeedMirror + "' not found");

        }

        newRemoteRepo = RemoteRepository.Factory.newInstance();

        newRemoteRepo.setName(((String[]) ciMap.get(getParamName))[0]);
        newRemoteRepo.setActive(true);

        Property feedProp = newRemoteRepo.addNewProperty();

        feedProp.setName(propertyFeed);
        feedProp.setStringValue(((String[]) ciMap.get(getParamFeed))[0]);
        feedProp.setActive(true);

        Property localFeedMirrorProp = newRemoteRepo.addNewProperty();

        localFeedMirrorProp.setName(propertyLocalFeedMirror);
        localFeedMirrorProp.setStringValue(((String[]) ciMap.get(getParamLocalFeedMirror))[0]);
        localFeedMirrorProp.setActive(true);

        addNewRemoteRepository(newRemoteRepo);
        res.setStatus(HttpServletResponse.SC_OK);

    } catch (Exception e) {
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "error occured");
    }
    out.flush();
    out.close();

}

From source file:org.n52.wps.server.request.ExecuteRequest.java

private void storeRequest(CaseInsensitiveMap map) {

    BufferedWriter w = null;/*from  w  w  w .  j  av  a2 s.  c o  m*/
    ByteArrayOutputStream os = null;
    ByteArrayInputStream is = null;
    try {
        os = new ByteArrayOutputStream();
        w = new BufferedWriter(new OutputStreamWriter(os));
        for (Object key : map.keySet()) {
            Object value = map.get(key);
            String valueString = "";
            if (value instanceof String[]) {
                valueString = ((String[]) value)[0];
            } else {
                valueString = value.toString();
            }
            w.append(key.toString()).append('=').append(valueString);
            w.newLine();
        }
        w.flush();
        is = new ByteArrayInputStream(os.toByteArray());
        DatabaseFactory.getDatabase().insertRequest(getUniqueId().toString(), is, false);
    } catch (Exception e) {
        LOGGER.error("Exception storing ExecuteRequest", e);
    } finally {
        IOUtils.closeQuietly(w);
        IOUtils.closeQuietly(os);
        IOUtils.closeQuietly(is);
    }
}

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 av  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) 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  .ja v  a2s . 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, 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);
    }
}