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

The following examples show how to use org.apache.commons.collections4.map.CaseInsensitiveMap#get() . 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: ComRecipientDaoImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private void validateCriteriaEquals(List<CriteriaEquals> criteriaEquals, CaseInsensitiveMap<String, ProfileField> customerDBProfileStructure) {
	for (CriteriaEquals criteriaEqualsElement : criteriaEquals) {
		if (!customerDBProfileStructure.containsKey(criteriaEqualsElement.getProfilefield())) {
			throw new IllegalArgumentException("The profile field " + criteriaEqualsElement.getProfilefield() + " does not exist");
		}
	
		ProfileField profileField = customerDBProfileStructure.get(criteriaEqualsElement.getProfilefield());
	
		if ("DATE".equalsIgnoreCase(profileField.getDataType()) && criteriaEqualsElement.getDateformat() == null) {
			throw new IllegalArgumentException("The \"dateformat\" is missing for a date field: " + criteriaEqualsElement.getProfilefield());
		}
	
		if (!"DATE".equalsIgnoreCase(profileField.getDataType()) && criteriaEqualsElement.getDateformat() != null) {
			throw new IllegalArgumentException("The \"dateformat\" is specified for a non-date field: " + criteriaEqualsElement.getProfilefield());
		}
	}
}
 
Example 2
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 3
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private final UserFormExecutionResult doExecuteForm(final UserForm userForm, final EmmActionOperationErrors actionOperationErrors, final CaseInsensitiveMap<String, Object> params, final HttpServletRequest request) throws Exception {
	String responseContent = userForm.evaluateForm(applicationContext, params, actionOperationErrors);
	String responseMimeType = determineSuccessResponseMimeType(userForm, params);

	final String uidString = (String) params.get("agnUID");
	responseContent = addRedirectLinks(responseContent, uidString, userForm);
	
	if (params.get("_error") == null) {
		evaluateFormEndAction(request, userForm, params, actionOperationErrors);
		responseContent = handleEndActionErrors(userForm, params, responseContent);
	} else {
		responseMimeType = userForm.getErrorMimetype();
	}

	return new UserFormExecutionResult(responseContent, responseMimeType);
}
 
Example 4
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * For user form that requires error handling adds the error messages (including velocity errors) to response context.
 *
 * @param params
 * @param responseContent html content to be sent in response (could be changed inside the method).
 * @return responseContent
 * @throws Exception
 */
protected String handleEndActionErrors(UserForm userForm, CaseInsensitiveMap<String, Object> params, String responseContent) throws Exception {
	if (userForm != null && userForm.isSuccessUseUrl()) {
		// no error handling, return original content
		return responseContent;
	}
	
	if (params.get("velocity_error") != null) {
		responseContent += "<br/><br/>";
		responseContent += params.get("velocity_error");
	}
	
	if (params.get("errors") != null) {
		responseContent += "<br/>";
		ActionErrors velocityErrors = ((ActionErrors) params.get("errors"));
		@SuppressWarnings("rawtypes")
		Iterator it = velocityErrors.get();
		while (it.hasNext()) {
			responseContent += "<br/>" + it.next();
		}
	}
	
	return responseContent;
}
 
Example 5
Source File: ActionOperationSubscribeCustomerImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private final void identifyRecipientByKeyColumn(final Recipient recipient, final ActionOperationSubscribeCustomerParameters op, final CaseInsensitiveMap<String, Object> reqParams, final EmmActionOperationErrors actionOperationErrors, final HttpServletRequest request) {
	if (op.isDoubleCheck()) {
		if (op.getKeyColumn() == null) {
			logger.error(String.format("Exception: No keyColumn (%s)", request == null ? "" : request.getQueryString()));
			actionOperationErrors.addErrorCode(ErrorCode.MISSING_KEY_COLUMN);
		} else {
			final String keyVal = (String) reqParams.get(op.getKeyColumn());
			if (keyVal == null) {
				logger.error(String.format("Exception: No keyVal for '%s' (%s)", op.getKeyColumn(), request == null ? "" : request.getQueryString()));
				for (Entry<String, Object> entry : reqParams.entrySet()) {
					logger.error(entry.getKey() + ": " + entry.getValue().toString());
				}
				actionOperationErrors.addErrorCode(ErrorCode.MISSING_KEY_VALUE);
			} else {
				recipient.findByKeyColumn(op.getKeyColumn(), keyVal);
			}
		}
	}
}
 
Example 6
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 7
Source File: RecipientServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public RecipientLightDto getRecipientDto(@VelocityCheck int companyId, int recipientId) {
	CaseInsensitiveMap<String, Object> dataFromDb = recipientDao.getCustomerDataFromDb(companyId, recipientId, DEFAULT_COLUMNS);
	int customerId = NumberUtils.toInt((String) dataFromDb.get(COLUMN_CUSTOMER_ID), 0);
	String firstName = (String) dataFromDb.get(COLUMN_FIRSTNAME);
	String lastName = (String) dataFromDb.get(COLUMN_LASTNAME);
	String email = (String) dataFromDb.get(COLUMN_EMAIL);
	return new RecipientLightDto(customerId, firstName, lastName, email);
}
 
Example 8
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 9
Source File: UserFormExecutionServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private final String determineSuccessResponseMimeType(final UserForm userForm, final CaseInsensitiveMap<String, Object> params) {
	final String formMimeType = (String)params.get(FORM_MIMETYPE_PARAM_NAME);

	
	return StringUtils.isNotBlank(formMimeType)
			? formMimeType
			: userForm.getSuccessMimetype();
}
 
Example 10
Source File: RecipientImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Updates customer data by analyzing given HTTP-Request-Parameters
 * 
 * @return true on success
 * @param suffix
 *            Suffix appended to Database-Column-Names when searching for
 *            corresponding request parameters
 * @param requestParameters
 *            Map containing all HTTP-Request-Parameters as key-value-pair.
 */
@Override
public boolean importRequestParameters(Map<String, Object> requestParameters, String suffix) {
	CaseInsensitiveMap<String, Object> caseInsensitiveParameters = new CaseInsensitiveMap<>(requestParameters);
	
	if (suffix == null) {
		suffix = "";
	}
	
	for (Entry<String, String> entry : getCustDBStructure().entrySet()) {
		String colType = entry.getValue();
		String name = entry.getKey().toUpperCase();

		if (!isAllowedName(entry.getKey())) {
			continue;
		}
		if (colType.equalsIgnoreCase("DATE")) {
			copyDate(caseInsensitiveParameters, entry.getKey(), suffix);
		} else if (caseInsensitiveParameters.get(name + suffix) != null) {
			String aValue = (String) caseInsensitiveParameters.get(name + suffix);
			if (name.equalsIgnoreCase("EMAIL")) {
				if (aValue.length() == 0) {
					aValue = " ";
				}
				aValue = aValue.toLowerCase();
				aValue = aValue.trim();
			} else if (name.length() > 4) {
				if (name.substring(0, 4).equals("SEC_")
						|| name.equals("FIRSTNAME")
						|| name.equals("LASTNAME")) {
					if (!isSecure(aValue)) {
						return false;
					}
				}
			}
			if (name.equalsIgnoreCase("DATASOURCE_ID")) {
				if (!hasCustParameter(entry.getKey())) {
					setCustParameters(entry.getKey(), aValue);
				}
			} else {
				setCustParameters(entry.getKey(), aValue);
			}
		}
	}
	return true;
}
 
Example 11
Source File: ComProfileFieldDaoImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
  public List<ComProfileField> getProfileFieldsWithIndividualSortOrder(@VelocityCheck int companyID, int adminID) throws Exception {
if (companyID <= 0) {
	return null;
} else {
	List<ComProfileField> comProfileFieldList = select(logger, SELECT_PROFILEFIELDS_BY_COMPANYID_HAVINGSORT, new ComProfileField_RowMapper(), companyID);
	CaseInsensitiveMap<String, DbColumnType> dbDataTypes = DbUtilities.getColumnDataTypes(getDataSource(), "customer_" + companyID + "_tbl");
	List<ComProfileField> returnList = new ArrayList<>();
	for (ComProfileField comProfileField : comProfileFieldList) {
		boolean found = false;
		for (String columnName : dbDataTypes.keySet()) {
			if (columnName.equalsIgnoreCase(comProfileField.getColumn())) {
				found = true;
				break;
			}
		}
		if (found) {
			DbColumnType columnType = dbDataTypes.get(comProfileField.getColumn());
			comProfileField.setDataType(columnType.getTypeName());
			comProfileField.setDataTypeLength(columnType.getCharacterLength());
			comProfileField.setNumericPrecision(columnType.getNumericPrecision());
			comProfileField.setNumericScale(columnType.getNumericScale());
			comProfileField.setNullable(columnType.isNullable());
			
			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 getProfileFieldsWithIndividualSortOrder: " + profileFieldPermissionList.size());
   			} else if (profileFieldPermissionList != null && profileFieldPermissionList.size() == 1) {
   				comProfileField.setAdminID(adminID);
   				comProfileField.setModeEdit(profileFieldPermissionList.get(0).getModeEdit());
   				returnList.add(comProfileField);
   			} else {
   				returnList.add(comProfileField);
   			}
		}
	}

	// Sort by SortingIndex or shortname
	sortCustomComProfileList(returnList);
	
	return returnList;
}
  }
 
Example 12
Source File: ComProfileFieldDaoImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
  public List<ComProfileField> getProfileFieldsWithInterest(@VelocityCheck int companyID, int adminID) throws Exception {
if (companyID <= 0) {
	return null;
} else {
	List<ComProfileField> comProfileFieldList = select(logger, SELECT_PROFILEFIELDS_BY_COMPANYID_HAVINGINTEREST, new ComProfileField_RowMapper(), companyID);
	CaseInsensitiveMap<String, DbColumnType> dbDataTypes = DbUtilities.getColumnDataTypes(getDataSource(), "customer_" + companyID + "_tbl");
	List<ComProfileField> returnList = new ArrayList<>();
	for (ComProfileField comProfileField : comProfileFieldList) {
		boolean found = false;
		for (String columnName : dbDataTypes.keySet()) {
			if (columnName.equalsIgnoreCase(comProfileField.getColumn())) {
				found = true;
				break;
			}
		}
		if (found) {
			DbColumnType columnType = dbDataTypes.get(comProfileField.getColumn());
			comProfileField.setDataType(columnType.getTypeName());
			comProfileField.setDataTypeLength(columnType.getCharacterLength());
			comProfileField.setNumericPrecision(columnType.getNumericPrecision());
			comProfileField.setNumericScale(columnType.getNumericScale());
			comProfileField.setNullable(columnType.isNullable());
			
			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 getProfileFieldsWithIndividualSortOrder: " + profileFieldPermissionList.size());
   			} else if (profileFieldPermissionList != null && profileFieldPermissionList.size() == 1) {
   				comProfileField.setAdminID(adminID);
   				comProfileField.setModeEdit(profileFieldPermissionList.get(0).getModeEdit());
   				returnList.add(comProfileField);
   			} else {
   				returnList.add(comProfileField);
   			}
		}
	}

	// Sort by SortingIndex or shortname
	sortComProfileList(returnList);
	
	return returnList;
}
  }
 
Example 13
Source File: ActionOperationIdentifyCustomerImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(AbstractActionOperationParameters operation, Map<String, Object> params, final EmmActionOperationErrors actionOperationErrors) {
	ActionOperationIdentifyCustomerParameters op =(ActionOperationIdentifyCustomerParameters) operation;
	int companyID = op.getCompanyId();
	String keyColumn = op.getKeyColumn();
	String passColumn = op.getPassColumn();
	
       Recipient aCust = beanLookupFactory.getBeanRecipient();
	String keyVal = null;
	String passVal = null;
	@SuppressWarnings("unchecked")
	CaseInsensitiveMap<String, Object> reqParams = new CaseInsensitiveMap<>((Map<String, Object>) params.get("requestParameters"));
       aCust.setCompanyID(companyID);
       aCust.loadCustDBStructure();

       keyVal=(String) reqParams.get(keyColumn.toUpperCase());

       if(passColumn.equals("none")) {
           aCust.findByKeyColumn(keyColumn, keyVal);
       } else {
           passVal=(String) reqParams.get(passColumn);
           aCust.findByUserPassword(keyColumn, keyVal, passColumn, passVal);
       }

       if(aCust.getCustomerID()!=0) {
           params.put("customerID", new Integer(aCust.getCustomerID()));
           // generate new agnUID
           try {
           	// Create new-style UID.
               
               ComCompany company = companyDao.getCompany(companyID);
               
               if( company != null) {
                   final ComExtensibleUID uid = UIDFactory.from(configService.getLicenseID(), aCust);
                   
                   String uidString = uidService.buildUIDString(uid);
                   params.put("agnUID", uidString);
                   if(!passColumn.equals("none")) {
                       params.put("authenticated", "1");
                   }
                   HttpSession session = ((HttpServletRequest)params.get("_request")).getSession();
                   @SuppressWarnings("unchecked")
				Map<String, Object> sessPar = (Map<String, Object>) session.getAttribute("agnFormParams");
				if (sessPar == null) {
					sessPar = new HashMap<>();
				}
                   sessPar.put("customerID", new Integer(aCust.getCustomerID()));
                   sessPar.put("agnUID", uidString);
				if (!passColumn.equals("none")) {
					sessPar.put("authenticated", "1");
				}
                   session.setAttribute("agnFormParams", sessPar);
               }
        
           } catch (Exception e) {
           	logger.error("problem generating new UID", e);
           }
       } else {
           if(params.containsKey("authenticated")) {
               return true;
           } else {
               return false;
           }
       }


       return true;
}