Skip to content

Commit

Permalink
Basic reproduction of condition type with before, after, and contains…
Browse files Browse the repository at this point in the history
… fields
  • Loading branch information
acetousk committed Jul 20, 2024
1 parent 1c69844 commit b06e04b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions framework/data/EntityTypeData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ along with this software (see the LICENSE.md file). If not, see
<moqui.basic.Enumeration description="not-between" enumCode="NOT_BETWEEN" enumId="ENTCO_NOT_BETWEEN" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="like" enumCode="LIKE" enumId="ENTCO_LIKE" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="not-like" enumCode="NOT_LIKE" enumId="ENTCO_NOT_LIKE" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="begins-field" enumCode="BEGINS_FIELD" enumId="ENTCO_BEGINS_FIELD" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="ends-field" enumCode="ENDS_FIELD" enumId="ENTCO_ENDS_FIELD" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="contains-field" enumCode="CONTAINS_FIELD" enumId="ENTCO_CONTAINS_FIELD" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="is-null" enumCode="IS_NULL" enumId="ENTCO_IS_NULL" enumTypeId="ComparisonOperator"/>
<moqui.basic.Enumeration description="is-not-null" enumCode="IS_NOT_NULL" enumId="ENTCO_IS_NOT_NULL" enumTypeId="ComparisonOperator"/>
</entity-facade-xml>
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class EntityConditionFactoryImpl implements EntityConditionFactory {
EntityCondition makeConditionToField(String fieldName, ComparisonOperator operator, String toFieldName) {
return new FieldToFieldCondition(new ConditionField(fieldName), operator, new ConditionField(toFieldName))
}
@Override
EntityCondition makeConditionToField(String fieldName, ComparisonOperator operator, String toFieldName, Object value) {
// TODO: This needs some work
return null
// return new FieldToFieldCondition(new ConditionField(fieldName), operator, new ConditionField(toFieldName))
}

@Override
EntityCondition makeCondition(List<EntityCondition> conditionList) {
Expand Down Expand Up @@ -316,6 +322,9 @@ class EntityConditionFactoryImpl implements EntityConditionFactory {
case "ENTCO_NOT_BETWEEN": return EntityCondition.NOT_BETWEEN
case "ENTCO_LIKE": return EntityCondition.LIKE
case "ENTCO_NOT_LIKE": return EntityCondition.NOT_LIKE
case "ENTCO_BEGINS_FIELD": return EntityCondition.BEGINS_FIELD
case "ENTCO_ENDS_FIELD": return EntityCondition.ENDS_FIELD
case "ENTCO_CONTAINS_FIELD": return EntityCondition.CONTAINS_FIELD
case "ENTCO_IS_NULL": return EntityCondition.IS_NULL
case "ENTCO_IS_NOT_NULL": return EntityCondition.IS_NOT_NULL
default: return null
Expand Down Expand Up @@ -361,8 +370,27 @@ class EntityConditionFactoryImpl implements EntityConditionFactory {
if (efi.ecfi.resourceFacade.condition(ignore, null)) return null

if (toFieldName != null && toFieldName.length() > 0) {
EntityCondition ec = makeConditionToField(fieldName, getComparisonOperator(operator), toFieldName)
EntityCondition ec = null;
ComparisonOperator compOp = getComparisonOperator(operator)
if (compOp == ComparisonOperator.BEGINS_FIELD || compOp == ComparisonOperator.ENDS_FIELD || compOp == ComparisonOperator.CONTAINS_FIELD) {
Object condValue
if (value != null && value.length() > 0) {
// NOTE: have to convert value (if needed) later on because we don't know which entity/field this is for, or change to pass in entity?
condValue = value
} else {
condValue = fromObj
}
logger.warn(value)
logger.warn(fromObj.toString())
logger.warn(condValue.toString())

// TODO: This also needs some work!
ec = makeConditionWhere("'moc.elgoog.fdsa' LIKE prefix || '%'")
} else {
ec = makeConditionToField(fieldName, compOp, toFieldName)
}
if (ignoreCase) ec.ignoreCase()

return ec
} else {
Object condValue
Expand Down Expand Up @@ -493,6 +521,15 @@ class EntityConditionFactoryImpl implements EntityConditionFactory {
"not-like":ComparisonOperator.NOT_LIKE,
"NOT LIKE":ComparisonOperator.NOT_LIKE,

"begins-field":ComparisonOperator.BEGINS_FIELD,
"BEGINS FIELD":ComparisonOperator.BEGINS_FIELD,

"ends-field":ComparisonOperator.ENDS_FIELD,
"ENDS FIELD":ComparisonOperator.ENDS_FIELD,

"contains-field":ComparisonOperator.CONTAINS_FIELD,
"CONTAINS FIELD":ComparisonOperator.CONTAINS_FIELD,

"is-null":ComparisonOperator.IS_NULL,
"IS NULL":ComparisonOperator.IS_NULL,

Expand Down
4 changes: 4 additions & 0 deletions framework/src/main/java/org/moqui/entity/EntityCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public interface EntityCondition extends Externalizable {
ComparisonOperator NOT_BETWEEN = ComparisonOperator.NOT_BETWEEN;
ComparisonOperator LIKE = ComparisonOperator.LIKE;
ComparisonOperator NOT_LIKE = ComparisonOperator.NOT_LIKE;
ComparisonOperator BEGINS_FIELD = ComparisonOperator.BEGINS_FIELD;
ComparisonOperator ENDS_FIELD = ComparisonOperator.ENDS_FIELD;
ComparisonOperator CONTAINS_FIELD = ComparisonOperator.CONTAINS_FIELD;
ComparisonOperator IS_NULL = ComparisonOperator.IS_NULL;
ComparisonOperator IS_NOT_NULL = ComparisonOperator.IS_NOT_NULL;

Expand All @@ -45,6 +48,7 @@ public interface EntityCondition extends Externalizable {

enum ComparisonOperator { EQUALS, NOT_EQUAL,
LESS_THAN, GREATER_THAN, LESS_THAN_EQUAL_TO, GREATER_THAN_EQUAL_TO,
BEGINS_FIELD, ENDS_FIELD, CONTAINS_FIELD,
IN, NOT_IN, BETWEEN, NOT_BETWEEN, LIKE, NOT_LIKE, IS_NULL, IS_NOT_NULL }

enum JoinOperator { AND, OR }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface EntityConditionFactory {
EntityCondition makeCondition(String fieldName, EntityCondition.ComparisonOperator operator, Object value, boolean orNull);

EntityCondition makeConditionToField(String fieldName, EntityCondition.ComparisonOperator operator, String toFieldName);
EntityCondition makeConditionToField(String fieldName, EntityCondition.ComparisonOperator operator, String toFieldName, Object value);

/** Default to JoinOperator of AND */
EntityCondition makeCondition(List<EntityCondition> conditionList);
Expand Down
3 changes: 3 additions & 0 deletions framework/xsd/common-types-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ along with this software (see the LICENSE.md file). If not, see
<xs:enumeration value="not-between"/>
<xs:enumeration value="like"/>
<xs:enumeration value="not-like"/>
<xs:enumeration value="begins-field"/>
<xs:enumeration value="ends-field"/>
<xs:enumeration value="contains-field"/>
<xs:enumeration value="is-null"/>
<xs:enumeration value="is-not-null"/>
</xs:restriction></xs:simpleType>
Expand Down

0 comments on commit b06e04b

Please sign in to comment.