Skip to content

Commit

Permalink
flattening CrmFieldToCommunicationTag
Browse files Browse the repository at this point in the history
  • Loading branch information
brmeyer committed Aug 21, 2024
1 parent 3c8e6d1 commit a13af14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,11 @@ public static class CrmFieldToCommunicationField implements Serializable {
public String communicationFieldName;
}

public static class CrmFieldToCommunicationTagCondition implements Serializable {
public Operator operator;
public String value;
}

public static class CrmFieldToCommunicationTag implements Serializable {
public String crmFieldName;
// conjunction
public List<CrmFieldToCommunicationTagCondition> crmConditions;
public Operator operator;
public String value;
public String communicationTagName;
public boolean isAppend;
}

public static class CommunicationPlatform extends Platform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,23 @@ protected Set<String> buildContactTags(CrmContact crmContact, List<String> conta
}

protected String getTagName(CrmContact crmContact, EnvironmentConfig.CrmFieldToCommunicationTag mapping) {
Object value = crmContact.fieldFetcher != null ? crmContact.fieldFetcher.apply(mapping.crmFieldName) : null;
String valueString = value == null ? "" : value.toString();
if (mapping.crmConditions.stream().allMatch(condition -> evaluate(valueString, condition))) {
String tagName = mapping.communicationTagName;
if (mapping.isAppend) {
tagName = tagName + Utils.toSlug(valueString);
}
return tagName;
Object crmFieldValue = crmContact.fieldFetcher != null ? crmContact.fieldFetcher.apply(mapping.crmFieldName) : null;
String crmFieldValueString = crmFieldValue == null ? "" : crmFieldValue.toString();
if (evaluate(crmFieldValueString, mapping.operator, mapping.value)) {
return mapping.communicationTagName;
} else {
return null;
}
}

protected boolean evaluate(String crmFieldValue, EnvironmentConfig.CrmFieldToCommunicationTagCondition crmFieldToCommunicationTagCondition) {
if (Strings.isNullOrEmpty(crmFieldValue)
|| crmFieldToCommunicationTagCondition == null
|| crmFieldToCommunicationTagCondition.operator == null) {
protected boolean evaluate(String crmFieldValueString, EnvironmentConfig.Operator operator, String value) {
if (Strings.isNullOrEmpty(crmFieldValueString) || operator == null) {
return false;
}
return switch(crmFieldToCommunicationTagCondition.operator) {
case NOT_EMPTY -> Strings.isNullOrEmpty(crmFieldValue);
case EQUAL_TO -> crmFieldValue.equalsIgnoreCase(crmFieldToCommunicationTagCondition.value);
case NOT_EQUAL_TO -> !crmFieldValue.equalsIgnoreCase(crmFieldToCommunicationTagCondition.value);
return switch(operator) {
case NOT_EMPTY -> Strings.isNullOrEmpty(crmFieldValueString);
case EQUAL_TO -> crmFieldValueString.equalsIgnoreCase(value);
case NOT_EQUAL_TO -> !crmFieldValueString.equalsIgnoreCase(value);
};
}

Expand Down

0 comments on commit a13af14

Please sign in to comment.