Java Code Examples for org.apache.commons.collections4.map.CaseInsensitiveMap#put()

The following examples show how to use org.apache.commons.collections4.map.CaseInsensitiveMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionOperationSubscribeCustomerImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private final void checkAndNormalizeMobilePhoneNumber(final int companyID, final CaseInsensitiveMap<String, Object> reqParams, final EmmActionOperationErrors actionOperationErrors) {
	final String PARAM_NAME = "SMSNUMBER";
	
	final String value = (String) reqParams.get(PARAM_NAME);
	
	if(StringUtils.isNotBlank(value)) {
		try {
			final MobilephoneNumber number = new MobilephoneNumber(value.trim());

			// If parsing was successful, check that number is allowed
			if(this.mobilephoneNumberWhitelist.isWhitelisted(number, companyID)) {
				// If number is ok, write back the number. Its in normalized form now.
				reqParams.put(PARAM_NAME, number.toString());
			} else {
				actionOperationErrors.addErrorCode(ErrorCode.MOBILEPHONE_NUMBER_NOT_ALLOWED);
			}
		} catch(final NumberFormatException e) {
			actionOperationErrors.addErrorCode(ErrorCode.MALFORMED_MOBILEPHONE_NUMBER);
		}
	}
	
}
 
Example 2
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private String createDirectLinkWithOptionalExtensions(String uidString, ComTrackableUserFormLink comTrackableUserFormLink) throws UIDParseException, InvalidUIDException, DeprecatedUIDVersionException, UnsupportedEncodingException {
	String linkString = comTrackableUserFormLink.getFullUrl();
	CaseInsensitiveMap<String, Object> cachedRecipientData = null;
	for (LinkProperty linkProperty : comTrackableUserFormLink.getProperties()) {
		if (linkProperty.getPropertyType() == PropertyType.LinkExtension) {
			String propertyValue = linkProperty.getPropertyValue();
			if (propertyValue != null && propertyValue.contains("##")) {
				if (cachedRecipientData == null && StringUtils.isNotBlank(uidString)) {
					final ComExtensibleUID uid = decodeUidString(uidString);
					cachedRecipientData = recipientDao.getCustomerDataFromDb(uid.getCompanyID(), uid.getCustomerID());
					cachedRecipientData.put("mailing_id", uid.getMailingID());
				}
				// Replace customer and form placeholders
				@SuppressWarnings("unchecked")
				String replacedPropertyValue = AgnUtils.replaceHashTags(propertyValue, cachedRecipientData);
				propertyValue = replacedPropertyValue;
			}
			// Extend link properly (watch out for html-anchors etc.)
			linkString = AgnUtils.addUrlParameter(linkString, linkProperty.getPropertyName(), propertyValue == null ? "" : propertyValue, "UTF-8");
		}
	}
	return linkString;
}
 
Example 3
Source File: RedirectServlet.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private final void executeLinkAction(final int actionID, final int deviceID, final int companyID, final int customerID, final int mailingID, final DeviceClass deviceClass, final HttpServletRequest request) throws Exception {
	if (actionID != 0) {
		// "_request" is the original unmodified request which might be needed (and used) somewhere else ...
		final Map<String, String> tmpRequestParams = AgnUtils.getReqParameters(request);
		tmpRequestParams.put("mobileDevice", String.valueOf(deviceClass == DeviceClass.MOBILE ? deviceID : 0)); // for mobile detection
		
		final EmmActionOperationErrors actionOperationErrors = new EmmActionOperationErrors();
		
		final CaseInsensitiveMap<String, Object> params = new CaseInsensitiveMap<>();
		params.put("requestParameters", tmpRequestParams);
		params.put("_request", request);
		params.put("customerID", customerID);
		params.put("mailingID", mailingID);
		params.put("actionErrors", actionOperationErrors);
		getEmmActionService().executeActions(actionID, companyID, params, actionOperationErrors);
	}
	
}
 
Example 4
Source File: ComOnePixelCount.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Get the actionid to be executed on opening the mailing.
 * If the action id > 0, execute the action with parameters from the request.
 * 
 * @param uid
 *            ExtensibleUID object, contains parsed data from the "uid"
 *            request parameter
 * @param req
 *            HTTP request
 * @throws Exception
 */
protected void executeMailingOpenAction(final ComExtensibleUID uid, final HttpServletRequest req) throws Exception {
	int companyID = uid.getCompanyID();
	int mailingID = uid.getMailingID();
	int customerID = uid.getCustomerID();
	int openActionID = getMailingDao().getMailingOpenAction(mailingID, companyID);
	if (openActionID != 0) {
		EmmAction emmAction = getActionDao().getEmmAction(openActionID, companyID);
		if (emmAction != null) {
			final EmmActionOperationErrors actionOperationErrors = new EmmActionOperationErrors();

			// execute configured actions
			CaseInsensitiveMap<String, Object> params = new CaseInsensitiveMap<>();
			params.put("requestParameters", AgnUtils.getReqParameters(req));
			params.put("_request", req);
			params.put("customerID", customerID);
			params.put("mailingID", mailingID);
			params.put("actionErrors", actionOperationErrors);
			
			ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
			EmmActionService emmActionService = (EmmActionService) applicationContext.getBean("EmmActionService");
			emmActionService.executeActions(openActionID, companyID, params, actionOperationErrors);
		}
	}
}
 
Example 5
Source File: ComProfileFieldDaoImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
public CaseInsensitiveMap<String, ComProfileField> getComProfileFieldsMap(@VelocityCheck int companyID, int adminID, final boolean noNotNullConstraintCheck) throws Exception {
     if (companyID <= 0) {
         return null;
     } else {
CaseInsensitiveMap<String, ComProfileField> comProfileFieldMap = getComProfileFieldsMap(companyID, noNotNullConstraintCheck);
CaseInsensitiveMap<String, ComProfileField> returnMap = new CaseInsensitiveMap<>();
for (ComProfileField comProfileField : comProfileFieldMap.values()) {
	List<ComProfileFieldPermission> profileFieldPermissionList = select(logger, SELECT_PROFILEFIELDPERMISSION, new ComProfileFieldPermission_RowMapper(), companyID, comProfileField.getColumn(), adminID);
         	if (profileFieldPermissionList != null && profileFieldPermissionList.size() > 1) {
 				throw new RuntimeException("Invalid number of permission entries found in getProfileFields: " + profileFieldPermissionList.size());
 			} else if (profileFieldPermissionList != null && profileFieldPermissionList.size() == 1) {
 				comProfileField.setAdminID(adminID);
 				comProfileField.setModeEdit(profileFieldPermissionList.get(0).getModeEdit());
 				returnMap.put(comProfileField.getColumn(), comProfileField);
 			} else {
 				returnMap.put(comProfileField.getColumn(), comProfileField);
 			}
}
return returnMap;
     }
 }
 
Example 6
Source File: ComRecipientDaoImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public CaseInsensitiveMap<String, CsvColInfo> readDBColumns(@VelocityCheck int companyID) {
	CaseInsensitiveMap<String, CsvColInfo> dbAllColumns = new CaseInsensitiveMap<>();

	try {
		CaseInsensitiveMap<String, DbColumnType> columnTypes = DbUtilities.getColumnDataTypes(getDataSource(), getCustomerTableName(companyID));

		for (String columnName : columnTypes.keySet()) {
			if (!columnName.equalsIgnoreCase("change_date") && !columnName.equalsIgnoreCase("creation_date") && !columnName.equalsIgnoreCase("datasource_id")) {
				DbColumnType type = columnTypes.get(columnName);
				CsvColInfo csvColInfo = new CsvColInfo();

				csvColInfo.setName(columnName);
				csvColInfo.setLength(type.getSimpleDataType() == SimpleDataType.Characters ? type.getCharacterLength() : type.getNumericPrecision());
				csvColInfo.setActive(false);
				csvColInfo.setNullable(type.isNullable());
				csvColInfo.setType(dbTypeToCsvType(type.getSimpleDataType()));

				dbAllColumns.put(columnName, csvColInfo);
			}
		}
	} catch (Exception e) {
		logger.error("readDBColumns (companyID: " + companyID + ")", e);
	}
	return dbAllColumns;
}
 
Example 7
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private final void populateRequestParametersAsVelocityParameters(final HttpServletRequest request, final CaseInsensitiveMap<String, Object> params) {
	params.put("requestParameters", AgnUtils.getReqParameters(request));
	params.put("_request", request);

	if ((request.getParameter("requestURL") != null) && (request.getParameter("queryString") != null)) {
		params.put("formURL", request.getRequestURL() + "?" + request.getQueryString());
	}
}
 
Example 8
Source File: ComColumnInfoServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CaseInsensitiveMap<String, ProfileField> getColumnInfoMap(@VelocityCheck int companyID, int adminID) throws Exception {
	CaseInsensitiveMap<String, ComProfileField> comProfileFieldMap = profileFieldDao.getComProfileFieldsMap(companyID, adminID);
	CaseInsensitiveMap<String, ProfileField> profileFieldMap = new CaseInsensitiveMap<>();
	for (ComProfileField comProfileField : comProfileFieldMap.values()) {
		profileFieldMap.put(comProfileField.getColumn(), comProfileField);
	}
	return profileFieldMap;
}
 
Example 9
Source File: ComColumnInfoServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CaseInsensitiveMap<String, ProfileField> getColumnInfoMap(@VelocityCheck int companyID) throws Exception {
	CaseInsensitiveMap<String, ComProfileField> comProfileFieldMap = profileFieldDao.getComProfileFieldsMap(companyID);
	CaseInsensitiveMap<String, ProfileField> profileFieldMap = new CaseInsensitiveMap<>();
	for (ComProfileField comProfileField : comProfileFieldMap.values()) {
		profileFieldMap.put(comProfileField.getColumn(), comProfileField);
	}
	return profileFieldMap;
}
 
Example 10
Source File: ComRecipientDaoImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Load structure of Customer-Table for the given Company-ID in member
 * variable "companyID". Load profile data into map. Has to be done before
 * working with customer-data in class instance
 *
 * @return true on success
 */
protected CaseInsensitiveMap<String, ProfileField> loadCustDBProfileStructure(@VelocityCheck int companyID) throws Exception {
	CaseInsensitiveMap<String, ProfileField> custDBStructure = new CaseInsensitiveMap<>();
	for (ProfileField fieldDescription : columnInfoService.getColumnInfos(companyID)) {
		custDBStructure.put(fieldDescription.getColumn(), fieldDescription);
	}
	return custDBStructure;
}
 
Example 11
Source File: CaseInsensitiveMapRowMapper.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CaseInsensitiveMap<String, Object> mapRow(ResultSet resultSet, int row) throws SQLException {
	CaseInsensitiveMap<String, Object> returnMap = new CaseInsensitiveMap<>();
	for (int i = 1 ; i <= resultSet.getMetaData().getColumnCount(); i++) {
		if ("TIMESTAMP".equalsIgnoreCase(resultSet.getMetaData().getColumnTypeName(i))) {
			// Avoid getting the type "oracle.sql.TIMESTAMP" which cannot be handled mostly
			returnMap.put(resultSet.getMetaData().getColumnName(i), resultSet.getTimestamp(i));
		} else {
			returnMap.put(resultSet.getMetaData().getColumnName(i), resultSet.getObject(i));
		}
	}
	return returnMap;
}
 
Example 12
Source File: ComProfileFieldDaoImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public CaseInsensitiveMap<String, ProfileField> getProfileFieldsMap(@VelocityCheck int companyID, int adminID, final boolean noNotNullConstraintCheck) throws Exception {
	if (companyID == 0) {
		return null;
	} else {
		CaseInsensitiveMap<String, ComProfileField> comProfileFieldMap = getComProfileFieldsMap(companyID, adminID, noNotNullConstraintCheck);
		CaseInsensitiveMap<String, ProfileField> returnMap = new CaseInsensitiveMap<>();

		for (Entry<String, ComProfileField> entry : comProfileFieldMap.entrySet()) {
			returnMap.put(entry.getKey(), entry.getValue());
		}
		return returnMap;
	}
}
 
Example 13
Source File: ComProfileFieldDaoImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CaseInsensitiveMap<String, ProfileField> getProfileFieldsMap(@VelocityCheck int companyID) throws Exception {
	if (companyID <= 0) {
		return null;
	} else {
		CaseInsensitiveMap<String, ComProfileField> comProfileFieldMap = getComProfileFieldsMap(companyID);
		CaseInsensitiveMap<String, ProfileField> returnMap = new CaseInsensitiveMap<>();

		for (Entry<String, ComProfileField> entry : comProfileFieldMap.entrySet()) {
			returnMap.put(entry.getKey(), entry.getValue());
		}
		
		return returnMap;
	}
}
 
Example 14
Source File: UserFormImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private final CaseInsensitiveMap<String, Object> escapeRequestParameters(final Map<String, Object> params) {
	final CaseInsensitiveMap<String, Object> paramsEscaped = new CaseInsensitiveMap<>(params);
	
	@SuppressWarnings("unchecked")
	final Map<String, Object> parameters = (Map<String, Object>) paramsEscaped.get("requestParameters");
       paramsEscaped.put("requestParameters", AgnUtils.escapeHtmlInValues(parameters));
       
       return paramsEscaped;
}
 
Example 15
Source File: Utils.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static CaseInsensitiveMap<String, Object> toCaseInsensitiveMap(Map map, final boolean extractStringFromSubXml) {
	if (map == null || map.getItem() == null) {
		return null;
	}
	CaseInsensitiveMap<String, Object> resultMap = new CaseInsensitiveMap<>(map.getItem().size());
	
	for (MapItem item : map.getItem()) {
		final String key = (item.getKey() instanceof Element && extractStringFromSubXml) ? stringFromSubXml((Element) item.getKey()) : (String) item.getKey();
		final Object value = (item.getValue() instanceof Element && extractStringFromSubXml) ? stringFromSubXml((Element) item.getValue()) : item.getValue();
		
		resultMap.put(key, value);
	}
	return resultMap;
}
 
Example 16
Source File: DbUtilities.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static CaseInsensitiveMap<String, CaseInsensitiveMap<String, DbColumnType>> getColumnDataTypes(DataSource dataSource, Set<String> tableNames) throws Exception {
	if (dataSource == null) {
		throw new Exception("Invalid empty dataSource for getColumnDataTypes");
	} else {
		CaseInsensitiveMap<String, CaseInsensitiveMap<String, DbColumnType>> resultMap = new CaseInsensitiveMap<>();
		// Return empty map for empty set
		if (tableNames.size() > 0) {
			for (String tableName : tableNames) {
				resultMap.put(tableName, getColumnDataTypes(dataSource, tableName));
			}
		}
		return resultMap;
	}
}
 
Example 17
Source File: SendServiceMailServiceImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void sendServiceMailByEmmAction(final int actionID, final int customerID, @VelocityCheck final int companyID) throws Exception {
	if(actionID <= 0) {
		logger.error("Action ID is not positive: " + actionID);
		
		throw new UnknownActionIdException(actionID);
	}
	if(customerID <= 0) {
		logger.error("Customer ID is not positive: " + actionID);

		throw new UnknownCustomerIdException(customerID);
	}
	if(companyID <= 0) {
		logger.error("Company ID is not positive: " + actionID);

		throw new UnknownCompanyIdException(companyID);
	}
	
	// Check, if action exists
   	if(!emmActionService.actionExists(actionID, companyID)) {
		logger.error(String.format("Action ID %d not found for company ID %d", actionID, companyID));

   		throw new UnknownActionIdException(actionID);
   	}
   	
	final EmmActionOperationErrors actionOperationErrors = new EmmActionOperationErrors();
	CaseInsensitiveMap<String, Object> params = new CaseInsensitiveMap<>();
	params.put("customerID", customerID);
	params.put("actionErrors", actionOperationErrors);
	
	boolean result = emmActionService.executeActions(actionID, companyID, params, actionOperationErrors);
	
	if(!result) {
		logger.error(String.format("Executing action %d failed", actionID));
		
		throw new ExecutingActionFailedException(actionID);
	}
	
	if(logger.isInfoEnabled()) {
		logger.info(String.format("Sending service mail successful (action ID %d, customer ID %d, company ID%d", actionID, customerID, companyID));
	}
}
 
Example 18
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private final void populateMobileDeviceParametersAsVelocityParameters(final int mobileID, final CaseInsensitiveMap<String, Object> params, final HttpServletRequest request) {
	params.put("mobileDevice", String.valueOf(mobileID));
	// just to be sure
	request.setAttribute("mobileDevice", String.valueOf(mobileID));
}
 
Example 19
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private void populateFormPropertiesAsVelocityParameters(UserForm userForm, CaseInsensitiveMap<String, Object> params) {
	params.put("formID", userForm.getId());
}
 
Example 20
Source File: ComRecipientDaoImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
	public List<CaseInsensitiveMap<String, Object>> getCustomers(List<Integer> customerIDs, int companyID) {
		CaseInsensitiveMap<String, ProfileField> profileMap;
		try {
			profileMap = loadCustDBProfileStructure(companyID);
		} catch (Exception e) {
			logger.error("getCustomers: Exception in getQueryProperties", e);
			return Collections.emptyList();
		}

		String query = "SELECT * FROM " + getCustomerTableName(companyID) + " WHERE customer_id IN(:ids) AND " + ComCompanyDaoImpl.STANDARD_FIELD_BOUNCELOAD + " = 0";
		MapSqlParameterSource parameters = new MapSqlParameterSource();
		parameters.addValue("ids", customerIDs);

		NamedParameterJdbcTemplate jTmpl = new NamedParameterJdbcTemplate(getDataSource());
		List<Map<String, Object>> queryResult = jTmpl.queryForList(query, parameters);
	
		List<CaseInsensitiveMap<String, Object>> results = new ArrayList<>();
	
		GregorianCalendar calendar = new GregorianCalendar();
	
//		long estimatedTime = System.nanoTime() - startTime;
//		logger.warn("getCustomers: after query before processing " + estimatedTime + "ns");

		for (Map<String, Object> row : queryResult) {
			CaseInsensitiveMap<String, Object> params = new CaseInsensitiveMap<>();
		
			for (Entry<String, ProfileField> entry : profileMap.entrySet()) {
				String columnName = entry.getKey();
				String columnType = entry.getValue().getDataType();
				Object value = row.get(columnName);
				if ("DATE".equalsIgnoreCase(columnType)) {
					if (value == null) {
						Map<String, String> dateColumnEmptyValues = SUPPLEMENTAL_DATE_COLUMN_SUFFIXES.stream()
								.map(suffix -> columnName + suffix)
								.collect(Collectors.toMap(Function.identity(), pair -> ""));
						dateColumnEmptyValues.put(columnName, "");

						params.putAll(dateColumnEmptyValues);
					} else {
						calendar.setTime((Date) value);
						params.put(columnName + ComRecipientDao.SUPPLEMENTAL_DATECOLUMN_SUFFIX_DAY, Integer.toString(calendar.get(GregorianCalendar.DAY_OF_MONTH)));
						params.put(columnName + ComRecipientDao.SUPPLEMENTAL_DATECOLUMN_SUFFIX_MONTH, Integer.toString(calendar.get(GregorianCalendar.MONTH) + 1));
						params.put(columnName + ComRecipientDao.SUPPLEMENTAL_DATECOLUMN_SUFFIX_YEAR, Integer.toString(calendar.get(GregorianCalendar.YEAR)));
						params.put(columnName + ComRecipientDao.SUPPLEMENTAL_DATECOLUMN_SUFFIX_HOUR, Integer.toString(calendar.get(GregorianCalendar.HOUR_OF_DAY)));
						params.put(columnName + ComRecipientDao.SUPPLEMENTAL_DATECOLUMN_SUFFIX_MINUTE, Integer.toString(calendar.get(GregorianCalendar.MINUTE)));
						params.put(columnName + ComRecipientDao.SUPPLEMENTAL_DATECOLUMN_SUFFIX_SECOND, Integer.toString(calendar.get(GregorianCalendar.SECOND)));
						params.put(columnName, new SimpleDateFormat(DateUtilities.YYYY_MM_DD_HH_MM_SS).format(calendar.getTime()));
					}
				} else {
					if (value == null) {
						value = "";
					}
					params.put(columnName, value.toString());
				}
			}
		
			results.add(params);
		}
	
//		estimatedTime = System.nanoTime() - startTime;
//		logger.warn("getCustomers: after processing " + estimatedTime + "ns");
		
		return results;
	}