BusinessObjectDataStatusChangeMessageBuilder extends AbstractNotificationMessageBuilder implements NotificationMessageBuilder { @Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The NotificationEvent is cast to a BusinessObjectDataStatusChangeNotificationEvent 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) { BusinessObjectDataStatusChangeNotificationEvent event = (BusinessObjectDataStatusChangeNotificationEvent) notificationEvent; Map<String, Object> velocityContextMap = new HashMap<>(); addObjectPropertyToContext(velocityContextMap, "businessObjectDataKey", event.getBusinessObjectDataKey(), escapeJsonBusinessObjectDataKey(event.getBusinessObjectDataKey()), escapeXmlBusinessObjectDataKey(event.getBusinessObjectDataKey())); addStringPropertyToContext(velocityContextMap, "newBusinessObjectDataStatus", event.getNewBusinessObjectDataStatus()); addStringPropertyToContext(velocityContextMap, "oldBusinessObjectDataStatus", event.getOldBusinessObjectDataStatus()); BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(event.getBusinessObjectDataKey()); velocityContextMap.put("businessObjectDataId", businessObjectDataEntity.getId()); BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat(); Map<String, BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntityMap = businessObjectFormatHelper.getAttributeDefinitionEntities(businessObjectFormatEntity); Map<String, String> businessObjectDataAttributes = new LinkedHashMap<>(); Map<String, String> businessObjectDataAttributesWithJson = new LinkedHashMap<>(); Map<String, String> businessObjectDataAttributesWithXml = new LinkedHashMap<>(); if (!attributeDefinitionEntityMap.isEmpty()) { for (BusinessObjectDataAttributeEntity attributeEntity : businessObjectDataEntity.getAttributes()) { if (attributeDefinitionEntityMap.containsKey(attributeEntity.getName().toUpperCase())) { BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity = attributeDefinitionEntityMap.get(attributeEntity.getName().toUpperCase()); if (BooleanUtils.isTrue(attributeDefinitionEntity.getPublish())) { businessObjectDataAttributes.put(attributeEntity.getName(), attributeEntity.getValue()); businessObjectDataAttributesWithJson.put(escapeJson(attributeEntity.getName()), escapeJson(attributeEntity.getValue())); businessObjectDataAttributesWithXml.put(escapeXml(attributeEntity.getName()), escapeXml(attributeEntity.getValue())); } if (BooleanUtils.isTrue(attributeDefinitionEntity.getPublishForFilter())) { String filterAttributeKey = configurationHelper.getRequiredProperty(ConfigurationValue.MESSAGE_HEADER_KEY_FILTER_ATTRIBUTE_VALUE); if (velocityContextMap.containsKey(filterAttributeKey)) { throw new IllegalStateException(String.format("Multiple attributes are marked as publishForFilter for business object format {%s}.", businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity))); } addStringPropertyToContext(velocityContextMap, filterAttributeKey, attributeEntity.getValue()); } } } } addObjectPropertyToContext(velocityContextMap, "businessObjectDataAttributes", businessObjectDataAttributes, businessObjectDataAttributesWithJson, businessObjectDataAttributesWithXml); addStringPropertyToContext(velocityContextMap, "namespace", event.getBusinessObjectDataKey().getNamespace()); return velocityContextMap; }  @Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The NotificationEvent is cast to a BusinessObjectDataStatusChangeNotificationEvent 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 testGetBusinessObjectDataStatusChangeMessageVelocityContextMap() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE + SUFFIX_UNESCAPED, BDEF_NAME + SUFFIX_UNESCAPED, FORMAT_USAGE_CODE + SUFFIX_UNESCAPED, FORMAT_FILE_TYPE_CODE + SUFFIX_UNESCAPED, FORMAT_VERSION, PARTITION_VALUE + SUFFIX_UNESCAPED, Lists .newArrayList(SUBPARTITION_VALUES.get(0) + SUFFIX_UNESCAPED, SUBPARTITION_VALUES.get(1) + SUFFIX_UNESCAPED, SUBPARTITION_VALUES.get(2) + SUFFIX_UNESCAPED, SUBPARTITION_VALUES.get(3) + SUFFIX_UNESCAPED), DATA_VERSION); List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE + SUFFIX_UNESCAPED, ATTRIBUTE_VALUE_1 + SUFFIX_UNESCAPED)); attributes.add(new Attribute(ATTRIBUTE_NAME_2_MIXED_CASE + SUFFIX_UNESCAPED, ATTRIBUTE_VALUE_2 + SUFFIX_UNESCAPED)); attributes.add(new Attribute(ATTRIBUTE_NAME_3_MIXED_CASE + SUFFIX_UNESCAPED, null)); BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID); for (Attribute attribute : attributes) { businessObjectDataAttributeDaoTestHelper .createBusinessObjectDataAttributeEntity(businessObjectDataEntity, attribute.getName(), attribute.getValue()); } for (Attribute attribute : attributes) { businessObjectFormatDaoTestHelper .createBusinessObjectDataAttributeDefinitionEntity(businessObjectDataEntity.getBusinessObjectFormat(), attribute.getName(), PUBLISH_ATTRIBUTE, NO_PUBLISH_FOR_FILTER); } Map<String, Object> result = businessObjectDataStatusChangeMessageBuilder.getNotificationMessageVelocityContextMap( new BusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BDATA_STATUS_2 + SUFFIX_UNESCAPED, BDATA_STATUS + SUFFIX_UNESCAPED)); Map<String, String> expectedBusinessObjectDataAttributes = new LinkedHashMap<>(); expectedBusinessObjectDataAttributes.put(ATTRIBUTE_NAME_1_MIXED_CASE + SUFFIX_UNESCAPED, ATTRIBUTE_VALUE_1 + SUFFIX_UNESCAPED); expectedBusinessObjectDataAttributes.put(ATTRIBUTE_NAME_2_MIXED_CASE + SUFFIX_UNESCAPED, ATTRIBUTE_VALUE_2 + SUFFIX_UNESCAPED); expectedBusinessObjectDataAttributes.put(ATTRIBUTE_NAME_3_MIXED_CASE + SUFFIX_UNESCAPED, null); Map<String, String> expectedBusinessObjectDataAttributesWithJson = new LinkedHashMap<>(); expectedBusinessObjectDataAttributesWithJson.put(ATTRIBUTE_NAME_1_MIXED_CASE + SUFFIX_ESCAPED_JSON, ATTRIBUTE_VALUE_1 + SUFFIX_ESCAPED_JSON); expectedBusinessObjectDataAttributesWithJson.put(ATTRIBUTE_NAME_2_MIXED_CASE + SUFFIX_ESCAPED_JSON, ATTRIBUTE_VALUE_2 + SUFFIX_ESCAPED_JSON); expectedBusinessObjectDataAttributesWithJson.put(ATTRIBUTE_NAME_3_MIXED_CASE + SUFFIX_ESCAPED_JSON, null); Map<String, String> expectedBusinessObjectDataAttributesWithXml = new LinkedHashMap<>(); expectedBusinessObjectDataAttributesWithXml.put(ATTRIBUTE_NAME_1_MIXED_CASE + SUFFIX_ESCAPED_XML, ATTRIBUTE_VALUE_1 + SUFFIX_ESCAPED_XML); expectedBusinessObjectDataAttributesWithXml.put(ATTRIBUTE_NAME_2_MIXED_CASE + SUFFIX_ESCAPED_XML, ATTRIBUTE_VALUE_2 + SUFFIX_ESCAPED_XML); expectedBusinessObjectDataAttributesWithXml.put(ATTRIBUTE_NAME_3_MIXED_CASE + SUFFIX_ESCAPED_XML, null); BusinessObjectDataKey expectedBusinessObjectDataKeyWithJson = new BusinessObjectDataKey(BDEF_NAMESPACE + SUFFIX_ESCAPED_JSON, BDEF_NAME + SUFFIX_ESCAPED_JSON, FORMAT_USAGE_CODE + SUFFIX_ESCAPED_JSON, FORMAT_FILE_TYPE_CODE + SUFFIX_ESCAPED_JSON, FORMAT_VERSION, PARTITION_VALUE + SUFFIX_ESCAPED_JSON, Lists .newArrayList(SUBPARTITION_VALUES.get(0) + SUFFIX_ESCAPED_JSON, SUBPARTITION_VALUES.get(1) + SUFFIX_ESCAPED_JSON, SUBPARTITION_VALUES.get(2) + SUFFIX_ESCAPED_JSON, SUBPARTITION_VALUES.get(3) + SUFFIX_ESCAPED_JSON), DATA_VERSION); BusinessObjectDataKey expectedBusinessObjectDataKeyWithXml = new BusinessObjectDataKey(BDEF_NAMESPACE + SUFFIX_ESCAPED_XML, BDEF_NAME + SUFFIX_ESCAPED_XML, FORMAT_USAGE_CODE + SUFFIX_ESCAPED_XML, FORMAT_FILE_TYPE_CODE + SUFFIX_ESCAPED_XML, FORMAT_VERSION, PARTITION_VALUE + SUFFIX_ESCAPED_XML, Lists .newArrayList(SUBPARTITION_VALUES.get(0) + SUFFIX_ESCAPED_XML, SUBPARTITION_VALUES.get(1) + SUFFIX_ESCAPED_XML, SUBPARTITION_VALUES.get(2) + SUFFIX_ESCAPED_XML, SUBPARTITION_VALUES.get(3) + SUFFIX_ESCAPED_XML), DATA_VERSION); assertEquals(16, CollectionUtils.size(result)); assertEquals(businessObjectDataKey, result.get("businessObjectDataKey")); assertEquals(expectedBusinessObjectDataKeyWithJson, result.get("businessObjectDataKeyWithJson")); assertEquals(expectedBusinessObjectDataKeyWithXml, result.get("businessObjectDataKeyWithXml")); assertEquals(BDATA_STATUS_2 + SUFFIX_UNESCAPED, result.get("newBusinessObjectDataStatus")); assertEquals(BDATA_STATUS_2 + SUFFIX_ESCAPED_JSON, result.get("newBusinessObjectDataStatusWithJson")); assertEquals(BDATA_STATUS_2 + SUFFIX_ESCAPED_XML, result.get("newBusinessObjectDataStatusWithXml")); assertEquals(BDATA_STATUS + SUFFIX_UNESCAPED, result.get("oldBusinessObjectDataStatus")); assertEquals(BDATA_STATUS + SUFFIX_ESCAPED_JSON, result.get("oldBusinessObjectDataStatusWithJson")); assertEquals(BDATA_STATUS + SUFFIX_ESCAPED_XML, result.get("oldBusinessObjectDataStatusWithXml")); assertEquals(businessObjectDataEntity.getId(), result.get("businessObjectDataId")); assertEquals(expectedBusinessObjectDataAttributes, result.get("businessObjectDataAttributes")); assertEquals(expectedBusinessObjectDataAttributesWithJson, result.get("businessObjectDataAttributesWithJson")); assertEquals(expectedBusinessObjectDataAttributesWithXml, result.get("businessObjectDataAttributesWithXml")); 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")); }