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

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

Introduction

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

Prototype

public Object put(Object key, Object value) 

Source Link

Document

Puts a key-value mapping into this map.

Usage

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());
                }/*from   w w  w.  ja  v  a  2  s . c  om*/
            }
        }
        return propertyMap;
    }
    return null;
}

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;
    }/* w w w  .  j a  v  a 2s .  c  o  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.web.OnePixelCount.java

/**
 * Gets the id of action to be exequted on opening the mailing; if the action id > 0, executes the action with
 * parameters from the request.//from  w w w .  j  a v  a 2  s . co  m
 * @param uid ExtensibleUID object, contains parsed data from the "uid" request parameter
 * @param context application context
 * @param req  HTTP request
 */
protected void executeMailingOpenAction(ExtensibleUID uid, ApplicationContext context, HttpServletRequest req) {
    MailingDao mailingDao = (MailingDao) context.getBean("MailingDao");
    EmmActionDao actionDao = (EmmActionDao) context.getBean("EmmActionDao");
    int companyID = uid.getCompanyID();
    int mailingID = uid.getMailingID();
    int customerID = uid.getCustomerID();
    int openActionID = mailingDao.getMailingOpenAction(mailingID, companyID);
    if (openActionID != 0) {
        EmmAction emmAction = actionDao.getEmmAction(openActionID, companyID);
        if (emmAction != null) {
            // execute configured actions
            CaseInsensitiveMap params = new CaseInsensitiveMap();
            params.put("requestParameters", AgnUtils.getReqParameters(req));
            params.put("_request", req);
            params.put("customerID", customerID);
            params.put("mailingID", mailingID);
            emmAction.executeActions(context, params);
        }
    }
}

From source file:org.agnitas.web.Rdir.java

/**
 * Servlet service-method, is invoked when user calls the servlet. Logs the click to DB and redirects recipient to actual link. Also invokes link action (if there is one) and mailing default click
 * action./*www  . j av a 2 s.  c o  m*/
 * 
 * @param req
 *            HTTP request. Should contain parameter "uid" - the encoded data of link/user (contains companyID, urlID, customerID, mailingID)
 * @param res
 *            HTTP response. If everything goes ok - the response sends redirect to actual link
 * @throws IOException
 *             if an input/output error occurs
 * @throws ServletException
 *             if a servlet exception occurs
 */
@Override
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    ApplicationContext con = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());

    try {
        // validate uid
        ExtensibleUID uid = getExtensibleUIDService().newUID();

        String param = req.getParameter("uid");
        if (param != null) {
            try {
                uid = getExtensibleUIDService().parse(param);
            } catch (UIDParseException e) {
                logger.warn("Error parsing UID: " + param + " (" + e.getMessage() + ")");
                logger.debug(e);
                return;
            }
        } else {
            logger.error("service: uid missing");
        }
        if (uid == null || uid.getCompanyID() == 0) {
            return;
        }

        Company aCompany = AgnUtils.getCompanyCache(uid.getCompanyID(), con);
        if (aCompany == null) {
            return;
        }

        /* TODO: check validateUID -> didn't recognize valid UIDs (maybe unittest) */
        /*
         * // TODO: Implement Helper class to validate the very old UIDs if(uid.validateUID(aCompany.getSecret()) == false) { logger.warn("uid invalid: "+param); return; }
         */

        TrackableLink aLink = (TrackableLink) urlCache.get(uid.getUrlID());
        if (aLink == null || aLink.getCompanyID() != uid.getCompanyID()) {
            // get link and do actions
            aLink = getTrackableLinkDao().getTrackableLink(uid.getUrlID(), uid.getCompanyID());
            if (aLink != null) {
                urlCache.put(uid.getUrlID(), aLink);
            }
        }

        // link is beeing personalized, replaces AGNUID
        String fullUrl = aLink.personalizeLink(uid.getCustomerID(), param, con);
        if (fullUrl == null) {
            logger.error("service: could not personalize link");
            return;
        }

        if (AgnUtils.getDefaultValue("redirection.status") == null
                || AgnUtils.getDefaultIntValue("redirection.status") == 302) {
            res.sendRedirect(fullUrl);
            // res.sendRedirect(aLink.getFullUrl());
        } else {
            res.setStatus(AgnUtils.getDefaultIntValue("redirection.status"));
            res.setHeader("Location", fullUrl);
            res.flushBuffer();
        }

        // log click in db
        if (!getTrackableLinkDao().logClickInDB(aLink, uid.getCustomerID(), req.getRemoteAddr())) {
            return;
        }

        int companyID = uid.getCompanyID();
        int mailingID = uid.getMailingID();
        int customerID = uid.getCustomerID();
        int clickActionID = getMailingDao().getMailingClickAction(mailingID, companyID);
        if (clickActionID != 0) {
            EmmAction emmAction = getEmmActionDao().getEmmAction(clickActionID, companyID);
            if (emmAction != null) {
                // execute configured actions
                CaseInsensitiveMap params = new CaseInsensitiveMap();
                params.put("requestParameters", AgnUtils.getReqParameters(req));
                params.put("_request", req);
                params.put("customerID", customerID);
                params.put("mailingID", mailingID);
                emmAction.executeActions(con, params);
            }
        }

        // execute configured actions
        CaseInsensitiveMap params = new CaseInsensitiveMap();
        params.put("requestParameters", AgnUtils.getReqParameters(req));
        params.put("_request", req);

        aLink.performLinkAction(params, uid.getCustomerID(), con);
    } catch (Exception e) {
        logger.error(e);
    }
}

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 .  ja v  a  2 s .  co  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.agnitas.webservice.EmmWebservice.java

/**
 * Method for updating a recipient in the customer-database
 * @param username Username from ws_admin_tbl
 * @param password Password from ws_admin_tbl
 * @param customerID customerID of the customer to be updated
 * @param paramNames Names of the columns
 * @param paramValues Values of the columns
 * @return true if update was successful
 *///  w w w . j  av  a  2s  .  c o  m
public boolean updateSubscriber(java.lang.String username, java.lang.String password, int customerID,
        StringArrayType paramNames, StringArrayType paramValues) {
    ApplicationContext con = getWebApplicationContext();
    CaseInsensitiveMap allParams = new CaseInsensitiveMap();
    MessageContext msct = MessageContext.getCurrentContext();

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

    try {
        Recipient aCust = (Recipient) con.getBean("Recipient");
        RecipientDao dao = (RecipientDao) con.getBean("RecipientDao");
        aCust.setCompanyID(1);
        aCust.loadCustDBStructure();
        aCust.setCustParameters(dao.getCustomerDataFromDb(aCust.getCompanyID(), customerID));
        aCust.setCustomerID(customerID);

        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));
            String name = paramNames.getX(i);
            String value = paramValues.getX(i);
            aCust.setCustParameters(name, value);
        }

        dao.updateInDB(aCust);
    } catch (Exception e) {
        AgnUtils.logger().info("soap prob updating subscriber: " + e);
        return false;
    }

    return true;
}