Skip to content

Commit

Permalink
Backport Adding Bi Items for Custom entities (#334) and release (#335)
Browse files Browse the repository at this point in the history
* Adding Bi Items for Custom entities (#334)
Goal of this implementation is to add BiItems in the BiContext for custom entities as well.
For each custom entity found in the entityJson payload we
- create a BiItem containing the type of entity found
- increase the total count of entities found in the message

* bump 0.10.2 version
  • Loading branch information
symphony-mariacristina authored May 16, 2022
1 parent 0f18731 commit 2d94d67
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.symphonyoss.symphony</groupId>
<artifactId>messageml</artifactId>
<version>0.10.1</version>
<version>0.10.2</version>
<name>MessageML Utils</name>
<url>https://github.com/finos/messageml-utils</url>
<description>A set of utilities for parsing, processing and rendering of MessageML messages</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.symphonyoss.symphony.messageml.bi.BiContext;
import org.symphonyoss.symphony.messageml.bi.BiFields;
import org.symphonyoss.symphony.messageml.bi.BiItem;
import org.symphonyoss.symphony.messageml.elements.Bold;
import org.symphonyoss.symphony.messageml.elements.BulletList;
import org.symphonyoss.symphony.messageml.elements.Button;
Expand Down Expand Up @@ -89,6 +90,7 @@
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -214,6 +216,7 @@ private void parseEntityJson(String entityJson) throws InvalidInputException {
} else {
throw new InvalidInputException("Error parsing EntityJSON: provided content is not a JSON object");
}
addCustomEntitiesToBiContext(jsonNode);
} catch (JsonProcessingException e) {
throw new InvalidInputException("Error parsing EntityJSON: " + e.getMessage());
}
Expand All @@ -222,6 +225,19 @@ private void parseEntityJson(String entityJson) throws InvalidInputException {
}
}

/**
* For each custom entity found in the entityJson payload we:
* - create a BiItem containing the type of entity found
* - increase the total count of entities found in the message
*/
private void addCustomEntitiesToBiContext(JsonNode entityNode) {
entityNode.findValues(Entity.TYPE_FIELD).forEach(entityType -> {
biContext.updateItemCount(BiFields.ENTITIES.getValue());
biContext.addItem(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), entityType.asText())));
});
}

/**
* Retrieve a JSON representation of entity data (EntityJSON).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void testGetBiContextFromMessageMLWithStyles() throws Exception {
List<BiItem> expectedBiItems = getExpectedBiItems();

List<BiItem> biItems = context.getBiContext().getItems();
assertEquals(biItems.size(), expectedBiItems.size());
assertEquals(expectedBiItems.size(), biItems.size());
assertTrue(biItems.containsAll(expectedBiItems));
assertTrue(expectedBiItems.containsAll(biItems));
}
Expand All @@ -535,7 +535,7 @@ private List<BiItem> getExpectedBiItems() {
biItems.add(
new BiItem(BiFields.MENTIONS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)));
biItems.add(new BiItem(BiFields.CARD.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)));
biItems.add(new BiItem(BiFields.ENTITIES.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)));
biItems.add(new BiItem(BiFields.ENTITIES.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 10)));
biItems.add(
new BiItem(BiFields.STYLES_CUSTOM.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)));
biItems.add(new BiItem(BiFields.STYLES_CLASS_OTHER.getValue(),
Expand All @@ -549,6 +549,24 @@ private List<BiItem> getExpectedBiItems() {
Collections.singletonMap(BiFields.COUNT.getValue(), 2984)));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.user.mention")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.jira.event.v2.state")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.user")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.jira.label")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.jira.issue")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.icon")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.jira.priority")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.user")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.jira.issueType")));
biItems.add(new BiItem(BiFields.ENTITY.getValue(),
Collections.singletonMap(BiFields.ENTITY_TYPE.getValue(), "com.symphony.integration.jira.label")));
return biItems;
}

Expand Down

0 comments on commit 2d94d67

Please sign in to comment.