diff --git a/src/main/java/org/symphonyoss/symphony/messageml/bi/BiFields.java b/src/main/java/org/symphonyoss/symphony/messageml/bi/BiFields.java index 515dd28b..8bb11935 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/bi/BiFields.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/bi/BiFields.java @@ -36,7 +36,6 @@ public enum BiFields { CASHTAGS("cashtags", BiEventType.MESSAGEML_MESSAGE_SENT), BULLET_LIST("lists", BiEventType.MESSAGEML_MESSAGE_SENT), CARD("cards", BiEventType.MESSAGEML_MESSAGE_SENT), - EXPANDABLE_CARDS("expandablecards", BiEventType.MESSAGEML_MESSAGE_SENT), EXPANDABLE_CARDS_COLLAPSED("expandablecards_collapsed", BiEventType.MESSAGEML_MESSAGE_SENT), EXPANDABLE_CARDS_CROPPED("expandablecards_cropped", BiEventType.MESSAGEML_MESSAGE_SENT), EXPANDABLE_CARDS_EXPANDED("expandablecards_expanded", BiEventType.MESSAGEML_MESSAGE_SENT), @@ -72,6 +71,8 @@ public enum BiFields { ENTITY_JSON_SIZE("entities_json_size", BiEventType.MESSAGEML_MESSAGE_SENT), FREEMARKER("use_freemarker", BiEventType.MESSAGEML_MESSAGE_SENT), POPUPS("popups", BiEventType.MESSAGEML_MESSAGE_SENT), + OPENIM("uiactions_openim", BiEventType.MESSAGEML_MESSAGE_SENT), + OPENDIALOG("uiactions_opendialog", BiEventType.MESSAGEML_MESSAGE_SENT), COUNT("count", BiEventType.NONE); private final String value; diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/ExpandableCard.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/ExpandableCard.java index cc2d84ca..d6dcdad8 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/ExpandableCard.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/ExpandableCard.java @@ -103,7 +103,6 @@ void validate() throws InvalidInputException { @Override void updateBiContext(BiContext context) { super.updateBiContext(context); - context.updateItemCount(BiFields.EXPANDABLE_CARDS.getValue()); if (getAttribute(ATTR_STATE) == null) { return; } diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/UIAction.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/UIAction.java index 84444c7c..6fe82070 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/UIAction.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/UIAction.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.symphonyoss.symphony.messageml.MessageMLContext; import org.symphonyoss.symphony.messageml.MessageMLParser; +import org.symphonyoss.symphony.messageml.bi.BiContext; +import org.symphonyoss.symphony.messageml.bi.BiFields; import org.symphonyoss.symphony.messageml.exceptions.InvalidInputException; import org.symphonyoss.symphony.messageml.util.XmlPrintStream; @@ -153,6 +155,23 @@ public String getPresentationMLTag() { return PRESENTATIONML_TAG; } + @Override + void updateBiContext(BiContext context) { + super.updateBiContext(context); + + final String actionAttribute = getAttribute(ACTION_ATTR); + if (actionAttribute != null) { + switch (actionAttribute) { + case OPEN_IM: + context.updateItemCount(BiFields.OPENIM.getValue()); + break; + case OPEN_DIALOG: + context.updateItemCount(BiFields.OPENDIALOG.getValue()); + break; + } + } + } + private void validateUserIdsAttribute() throws InvalidInputException { String userIds = getAttribute(USER_IDS_ATTR); try { diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/ExpandableCardTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/ExpandableCardTest.java index de293661..9d675704 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/ExpandableCardTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/ExpandableCardTest.java @@ -174,7 +174,6 @@ public void testCardsBi() throws Exception { private List getExpectedCardBiItems() { List biItems = new ArrayList<>(); - biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 4))); biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS_COLLAPSED.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1))); biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS_CROPPED.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 2))); biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS_EXPANDED.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1))); diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/UIActionTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/UIActionTest.java index bb8addfb..b3f157ba 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/UIActionTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/UIActionTest.java @@ -2,12 +2,18 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertIterableEquals; import org.junit.Test; +import org.symphonyoss.symphony.messageml.bi.BiFields; +import org.symphonyoss.symphony.messageml.bi.BiItem; import org.symphonyoss.symphony.messageml.exceptions.InvalidInputException; import org.symphonyoss.symphony.messageml.exceptions.ProcessingException; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -442,6 +448,75 @@ public void testUIActionOpenDialogWithMatchingDialogId() throws Exception { assertEquals(m.group(1), m.group(2)); // assert the generated IDs are the same } + @Test + public void testBiContextOpenIm() throws Exception { + String inputMessageML = + "" + + "" + + ""; + context.parseMessageML(inputMessageML, null, MessageML.MESSAGEML_VERSION); + + List expectedBiItems = + Arrays.asList(new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()), + new BiItem(BiFields.OPENIM.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)), + new BiItem(BiFields.MESSAGE_LENGTH.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 114))); + + List biItems = context.getBiContext().getItems(); + assertIterableEquals(expectedBiItems, biItems); + } + + @Test + public void testBiContextOpenDialog() throws Exception { + String inputMessageML = + "" + + "" + + "title" + + "body" + + "" + + "" + + "" + + ""; + context.parseMessageML(inputMessageML, null, MessageML.MESSAGEML_VERSION); + + List expectedBiItems = + Arrays.asList(new BiItem(BiFields.POPUPS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)), + new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()), + new BiItem(BiFields.OPENDIALOG.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)), + new BiItem(BiFields.MESSAGE_LENGTH.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 220))); + + List biItems = context.getBiContext().getItems(); + assertIterableEquals(expectedBiItems, biItems); + } + + @Test + public void testBiContextWithMultipleUIActions() throws Exception { + String inputMessageML = + "" + + "" + + "title" + + "body" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + context.parseMessageML(inputMessageML, null, MessageML.MESSAGEML_VERSION); + + List expectedBiItems = + Arrays.asList(new BiItem(BiFields.POPUPS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)), + new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()), + new BiItem(BiFields.OPENDIALOG.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)), + new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()), + new BiItem(BiFields.OPENIM.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)), + new BiItem(BiFields.MESSAGE_LENGTH.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 311))); + + List biItems = context.getBiContext().getItems(); + assertIterableEquals(expectedBiItems, biItems); + } + private void validateMessageMLSimpleStructure() { Element messageML = context.getMessageML(); Element uiAction = messageML.getChildren().get(0);