BusinessObjectDefinitionDescriptionSuggestionChangeMessageBuilder extends AbstractNotificationMessageBuilder implements NotificationMessageBuilder { @Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The NotificationEvent is cast to a BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent which is always the case since" + " we manage the event type to a builder in a map defined in NotificationMessageManager") public Map<String, Object> getNotificationMessageVelocityContextMap(NotificationEvent notificationEvent) { BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent event = (BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent) notificationEvent; List<String> notificationList = new ArrayList<>(); notificationList.add(event.getBusinessObjectDefinitionDescriptionSuggestion().getCreatedByUserId()); NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(event.getNamespace()); Assert.notNull(namespaceEntity, String.format("namespaceEntity must not be null for namespace code \"%s\"", event.getNamespace())); notificationList.addAll(userNamespaceAuthorizationDao.getUserIdsWithWriteOrWriteDescriptiveContentPermissionsByNamespace(namespaceEntity)); BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestionWithJson = escapeJsonBusinessObjectDefinitionDescriptionSuggestion(event.getBusinessObjectDefinitionDescriptionSuggestion()); BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestionWithXml = escapeXmlBusinessObjectDefinitionDescriptionSuggestion(event.getBusinessObjectDefinitionDescriptionSuggestion()); List<String> notificationListWithJson = new ArrayList<>(); List<String> notificationListWithXml = new ArrayList<>(); for (String userId : notificationList) { notificationListWithJson.add(escapeJson(userId)); notificationListWithXml.add(escapeXml(userId)); } Map<String, Object> velocityContextMap = new HashMap<>(); addObjectPropertyToContext(velocityContextMap, "businessObjectDefinitionDescriptionSuggestion", event.getBusinessObjectDefinitionDescriptionSuggestion(), businessObjectDefinitionDescriptionSuggestionWithJson, businessObjectDefinitionDescriptionSuggestionWithXml); addObjectPropertyToContext(velocityContextMap, "businessObjectDefinitionDescriptionSuggestionKey", event.getBusinessObjectDefinitionDescriptionSuggestion().getBusinessObjectDefinitionDescriptionSuggestionKey(), businessObjectDefinitionDescriptionSuggestionWithJson.getBusinessObjectDefinitionDescriptionSuggestionKey(), businessObjectDefinitionDescriptionSuggestionWithXml.getBusinessObjectDefinitionDescriptionSuggestionKey()); addStringPropertyToContext(velocityContextMap, "lastUpdatedByUserId", event.getLastUpdatedByUserId()); velocityContextMap.put("lastUpdatedOn", event.getLastUpdatedOn()); addObjectPropertyToContext(velocityContextMap, "notificationList", notificationList, notificationListWithJson, notificationListWithXml); addStringPropertyToContext(velocityContextMap, "namespace", event.getNamespace()); return velocityContextMap; }  @Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The NotificationEvent is cast to a BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent which is always the case since" + " we manage the event type to a builder in a map defined in NotificationMessageManager") Map<String, Object> getNotificationMessageVelocityContextMap(NotificationEvent notificationEvent);  }
@Test public void testGetBusinessObjectDefinitionDescriptionSuggestionChangeMessageVelocityContextMap() { BusinessObjectDefinitionDescriptionSuggestionKey businessObjectDefinitionDescriptionSuggestionKey = new BusinessObjectDefinitionDescriptionSuggestionKey(BDEF_NAMESPACE + SUFFIX_UNESCAPED, BDEF_NAME + SUFFIX_UNESCAPED, USER_ID + SUFFIX_UNESCAPED); BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion = new BusinessObjectDefinitionDescriptionSuggestion(ID, businessObjectDefinitionDescriptionSuggestionKey, DESCRIPTION_SUGGESTION + SUFFIX_UNESCAPED, BDEF_DESCRIPTION_SUGGESTION_STATUS + SUFFIX_UNESCAPED, USER_ID + SUFFIX_UNESCAPED, CREATED_ON); NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(businessObjectDefinitionDescriptionSuggestionKey.getNamespace()); Map<String, Object> result = businessObjectDefinitionDescriptionSuggestionChangeMessageBuilder.getNotificationMessageVelocityContextMap( new BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent(businessObjectDefinitionDescriptionSuggestion, USER_ID_2 + SUFFIX_UNESCAPED, UPDATED_ON, namespaceEntity.getCode())); BusinessObjectDefinitionDescriptionSuggestionKey expectedBusinessObjectDefinitionDescriptionSuggestionKeyWithJson = new BusinessObjectDefinitionDescriptionSuggestionKey(BDEF_NAMESPACE + SUFFIX_ESCAPED_JSON, BDEF_NAME + SUFFIX_ESCAPED_JSON, USER_ID + SUFFIX_ESCAPED_JSON); BusinessObjectDefinitionDescriptionSuggestion expectedBusinessObjectDefinitionDescriptionSuggestionWithJson = new BusinessObjectDefinitionDescriptionSuggestion(ID, expectedBusinessObjectDefinitionDescriptionSuggestionKeyWithJson, DESCRIPTION_SUGGESTION + SUFFIX_ESCAPED_JSON, BDEF_DESCRIPTION_SUGGESTION_STATUS + SUFFIX_ESCAPED_JSON, USER_ID + SUFFIX_ESCAPED_JSON, CREATED_ON); BusinessObjectDefinitionDescriptionSuggestionKey expectedBusinessObjectDefinitionDescriptionSuggestionKeyWithXml = new BusinessObjectDefinitionDescriptionSuggestionKey(BDEF_NAMESPACE + SUFFIX_ESCAPED_XML, BDEF_NAME + SUFFIX_ESCAPED_XML, USER_ID + SUFFIX_ESCAPED_XML); BusinessObjectDefinitionDescriptionSuggestion expectedBusinessObjectDefinitionDescriptionSuggestionWithXml = new BusinessObjectDefinitionDescriptionSuggestion(ID, expectedBusinessObjectDefinitionDescriptionSuggestionKeyWithXml, DESCRIPTION_SUGGESTION + SUFFIX_ESCAPED_XML, BDEF_DESCRIPTION_SUGGESTION_STATUS + SUFFIX_ESCAPED_XML, USER_ID + SUFFIX_ESCAPED_XML, CREATED_ON); List<String> expectedNotificationList = Lists.newArrayList(USER_ID + SUFFIX_UNESCAPED); List<String> expectedNotificationListWithJson = Lists.newArrayList(USER_ID + SUFFIX_ESCAPED_JSON); List<String> expectedNotificationListWithXml = Lists.newArrayList(USER_ID + SUFFIX_ESCAPED_XML); assertEquals(16, CollectionUtils.size(result)); assertEquals(businessObjectDefinitionDescriptionSuggestion, result.get("businessObjectDefinitionDescriptionSuggestion")); assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestionWithJson, result.get("businessObjectDefinitionDescriptionSuggestionWithJson")); assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestionWithXml, result.get("businessObjectDefinitionDescriptionSuggestionWithXml")); assertEquals(businessObjectDefinitionDescriptionSuggestionKey, result.get("businessObjectDefinitionDescriptionSuggestionKey")); assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestionKeyWithJson, result.get("businessObjectDefinitionDescriptionSuggestionKeyWithJson")); assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestionKeyWithXml, result.get("businessObjectDefinitionDescriptionSuggestionKeyWithXml")); assertEquals(USER_ID_2 + SUFFIX_UNESCAPED, result.get("lastUpdatedByUserId")); assertEquals(USER_ID_2 + SUFFIX_ESCAPED_JSON, result.get("lastUpdatedByUserIdWithJson")); assertEquals(USER_ID_2 + SUFFIX_ESCAPED_XML, result.get("lastUpdatedByUserIdWithXml")); assertEquals(UPDATED_ON, result.get("lastUpdatedOn")); assertEquals(expectedNotificationList, result.get("notificationList")); assertEquals(expectedNotificationListWithJson, result.get("notificationListWithJson")); assertEquals(expectedNotificationListWithXml, result.get("notificationListWithXml")); assertEquals(BDEF_NAMESPACE + SUFFIX_UNESCAPED, result.get("namespace")); assertEquals(BDEF_NAMESPACE + SUFFIX_ESCAPED_JSON, result.get("namespaceWithJson")); assertEquals(BDEF_NAMESPACE + SUFFIX_ESCAPED_XML, result.get("namespaceWithXml")); }