* @param delegator
* @param context
* @return
*/
public static EntityCondition createSingleCondition(ModelField modelField, String operation, Object fieldValue, boolean ignoreCase, Delegator delegator, Map<String, ?> context) {
EntityCondition cond = null;
String fieldName = modelField.getName();
EntityComparisonOperator<?, ?> fieldOp = null;
if (operation != null) {
if (operation.equals("contains")) {
fieldOp = EntityOperator.LIKE;
fieldValue = "%" + fieldValue + "%";
} else if ("not-contains".equals(operation) || "notContains".equals(operation)) {
fieldOp = EntityOperator.NOT_LIKE;
fieldValue = "%" + fieldValue + "%";
} else if (operation.equals("empty")) {
return EntityCondition.makeCondition(fieldName, EntityOperator.EQUALS, null);
} else if (operation.equals("like")) {
fieldOp = EntityOperator.LIKE;
fieldValue = fieldValue + "%";
} else if ("not-like".equals(operation) || "notLike".equals(operation)) {
fieldOp = EntityOperator.NOT_LIKE;
fieldValue = fieldValue + "%";
} else if ("opLessThan".equals(operation)) {
fieldOp = EntityOperator.LESS_THAN;
} else if ("upToDay".equals(operation)) {
fieldOp = EntityOperator.LESS_THAN;
} else if ("upThruDay".equals(operation)) {
fieldOp = EntityOperator.LESS_THAN_EQUAL_TO;
} else if (operation.equals("greaterThanFromDayStart")) {
String timeStampString = (String) fieldValue;
Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context);
return EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue);
} else if (operation.equals("sameDay")) {
String timeStampString = (String) fieldValue;
Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context);
EntityCondition startCond = EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue);
Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1), delegator, context);
EntityCondition endCond = EntityCondition.makeCondition(fieldName, EntityOperator.LESS_THAN, endValue);
return EntityCondition.makeCondition(startCond, endCond);
} else {
fieldOp = entityOperators.get(operation);
}
} else {