/** * Creates a JSON escaped copy of the specified business object format key. * * @param businessObjectFormatKey the business object format key * * @return the JSON escaped business object format key */ private BusinessObjectFormatKey escapeJsonBusinessObjectFormatKey(final BusinessObjectFormatKey businessObjectFormatKey) { // Build and return a JSON escaped business object format key. return new BusinessObjectFormatKey(escapeJson(businessObjectFormatKey.getNamespace()), escapeJson(businessObjectFormatKey.getBusinessObjectDefinitionName()), escapeJson(businessObjectFormatKey.getBusinessObjectFormatUsage()), escapeJson(businessObjectFormatKey.getBusinessObjectFormatFileType()), businessObjectFormatKey.getBusinessObjectFormatVersion()); }
/** * Validates the business object format key. This method also trims the key parameters. * * @param key the business object format key * @param businessObjectFormatVersionRequired specifies if business object format version parameter is required or not * * @throws IllegalArgumentException if any validation errors were found */ public void validateBusinessObjectFormatKey(BusinessObjectFormatKey key, Boolean businessObjectFormatVersionRequired) throws IllegalArgumentException { Assert.notNull(key, "A business object format key must be specified."); key.setNamespace(alternateKeyHelper.validateStringParameter("namespace", key.getNamespace())); key.setBusinessObjectDefinitionName( alternateKeyHelper.validateStringParameter("business object definition name", key.getBusinessObjectDefinitionName())); key.setBusinessObjectFormatUsage(alternateKeyHelper.validateStringParameter("business object format usage", key.getBusinessObjectFormatUsage())); key.setBusinessObjectFormatFileType( alternateKeyHelper.validateStringParameter("business object format file type", key.getBusinessObjectFormatFileType())); if (businessObjectFormatVersionRequired) { Assert.notNull(key.getBusinessObjectFormatVersion(), "A business object format version must be specified."); } }
/** * Asserts that a format exists and gets the {@link BusinessObjectFormatEntity} from the given request. * * @param request {@link BusinessObjectDataInvalidateUnregisteredRequest} with format information * * @return {@link BusinessObjectFormatEntity} * @throws ObjectNotFoundException when the format does not exist */ private BusinessObjectFormatEntity getBusinessObjectFormatEntity(BusinessObjectDataInvalidateUnregisteredRequest request) { BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(); businessObjectFormatKey.setNamespace(request.getNamespace()); businessObjectFormatKey.setBusinessObjectDefinitionName(request.getBusinessObjectDefinitionName()); businessObjectFormatKey.setBusinessObjectFormatUsage(request.getBusinessObjectFormatUsage()); businessObjectFormatKey.setBusinessObjectFormatFileType(request.getBusinessObjectFormatFileType()); businessObjectFormatKey.setBusinessObjectFormatVersion(request.getBusinessObjectFormatVersion()); return businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey); }
private String getLatestPartitionValueNotFoundErrorMessage(String boundType, String boundPartitionValue, String partitionKey, BusinessObjectFormatKey businessObjectFormatKey, Integer businessObjectDataVersion, List<String> storageNames) { return String.format("Failed to find partition value which is the latest %s partition value = \"%s\" for partition key = \"%s\" due to " + "no available business object data in \"%s\" storage that satisfies the search criteria. " + "Business object data {namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d, businessObjectDataVersion: %d}", boundType, boundPartitionValue, partitionKey, StringUtils.join(storageNames, ","), businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion(), businessObjectDataVersion); }
/** * Creates a business object format key from the relative values in the business object format create request. Please note that the key will contain a null * for the business object format version value. * * @param businessObjectFormatCreateRequest the business object format create request * * @return the business object format key */ private BusinessObjectFormatKey getBusinessObjectFormatKey(BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest) { BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(); businessObjectFormatKey.setNamespace(businessObjectFormatCreateRequest.getNamespace()); businessObjectFormatKey.setBusinessObjectDefinitionName(businessObjectFormatCreateRequest.getBusinessObjectDefinitionName()); businessObjectFormatKey.setBusinessObjectFormatUsage(businessObjectFormatCreateRequest.getBusinessObjectFormatUsage()); businessObjectFormatKey.setBusinessObjectFormatFileType(businessObjectFormatCreateRequest.getBusinessObjectFormatFileType()); return businessObjectFormatKey; }
/** * Create an instance of {@link BusinessObjectFormatKey } * */ public BusinessObjectFormatKey createBusinessObjectFormatKey() { return new BusinessObjectFormatKey(); }
@Test public void testBuildBusinessObjectFormatVersionChangeMessagesJsonPayloadNoMessageHeaders() throws Exception { // Create a business object format key. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, NO_MESSAGE_HEADER_DEFINITIONS))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, FORMAT_VERSION_2.toString())); // Validate the results. assertEquals(1, CollectionUtils.size(result)); validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectFormatKey, businessObjectFormatKey.getBusinessObjectFormatVersion().toString(), FORMAT_VERSION_2.toString(), NO_MESSAGE_HEADERS, result.get(0)); }
@Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The NotificationEvent is cast to a BusinessObjectFormatVersionChangeNotificationEvent 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) { BusinessObjectFormatVersionChangeNotificationEvent event = (BusinessObjectFormatVersionChangeNotificationEvent) notificationEvent; Map<String, Object> velocityContextMap = new HashMap<>(); addObjectPropertyToContext(velocityContextMap, "businessObjectFormatKey", event.getBusinessObjectFormatKey(), escapeJsonBusinessObjectFormatKey(event.getBusinessObjectFormatKey()), escapeXmlBusinessObjectFormatKey(event.getBusinessObjectFormatKey())); velocityContextMap.put("newBusinessObjectFormatVersion", event.getBusinessObjectFormatKey().getBusinessObjectFormatVersion()); velocityContextMap.put("oldBusinessObjectFormatVersion", event.getOldBusinessObjectFormatVersion()); addStringPropertyToContext(velocityContextMap, "namespace", event.getBusinessObjectFormatKey().getNamespace()); return velocityContextMap; }
/** * Validate the business object format parents * * @param businessObjectFormatParents business object format parents */ private void validateBusinessObjectFormatParents(List<BusinessObjectFormatKey> businessObjectFormatParents) { // Validate parents business object format. if (!CollectionUtils.isEmpty(businessObjectFormatParents)) { for (BusinessObjectFormatKey parentBusinessObjectFormatKey : businessObjectFormatParents) { Assert.notNull(parentBusinessObjectFormatKey, "Parent object format must be specified."); businessObjectFormatHelper.validateBusinessObjectFormatKey(parentBusinessObjectFormatKey, false); Assert.isNull(parentBusinessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified."); } } }
businessObjectFormatKey.setBusinessObjectFormatVersion(null); latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); businessObjectFormatParent.setBusinessObjectFormatVersion(null); businessObjectFormatParents.add(businessObjectFormatParent); businessObjectFormatChild.setBusinessObjectFormatVersion(null); businessObjectFormatChildren.add(businessObjectFormatChild);
/** * Create an instance of {@link BusinessObjectFormatKey } * */ public BusinessObjectFormatKey createBusinessObjectFormatKey() { return new BusinessObjectFormatKey(); }
@Test public void testBuildBusinessObjectFormatVersionChangeMessagesJsonPayload() throws Exception { // Create a business object format key. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, FORMAT_VERSION_2.toString())); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectFormatKey, businessObjectFormatKey.getBusinessObjectFormatVersion().toString(), FORMAT_VERSION_2.toString(), getExpectedMessageHeaders(uuid), result.get(0)); }
@Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The NotificationEvent is cast to a BusinessObjectFormatVersionChangeNotificationEvent 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) { BusinessObjectFormatVersionChangeNotificationEvent event = (BusinessObjectFormatVersionChangeNotificationEvent) notificationEvent; Map<String, Object> velocityContextMap = new HashMap<>(); addObjectPropertyToContext(velocityContextMap, "businessObjectFormatKey", event.getBusinessObjectFormatKey(), escapeJsonBusinessObjectFormatKey(event.getBusinessObjectFormatKey()), escapeXmlBusinessObjectFormatKey(event.getBusinessObjectFormatKey())); velocityContextMap.put("newBusinessObjectFormatVersion", event.getBusinessObjectFormatKey().getBusinessObjectFormatVersion()); velocityContextMap.put("oldBusinessObjectFormatVersion", event.getOldBusinessObjectFormatVersion()); addStringPropertyToContext(velocityContextMap, "namespace", event.getBusinessObjectFormatKey().getNamespace()); return velocityContextMap; }
/** * Validate the business object format parents * * @param businessObjectFormatParents business object format parents */ private void validateBusinessObjectFormatParents(List<BusinessObjectFormatKey> businessObjectFormatParents) { // Validate parents business object format. if (!CollectionUtils.isEmpty(businessObjectFormatParents)) { for (BusinessObjectFormatKey parentBusinessObjectFormatKey : businessObjectFormatParents) { Assert.notNull(parentBusinessObjectFormatKey, "Parent object format must be specified."); businessObjectFormatHelper.validateBusinessObjectFormatKey(parentBusinessObjectFormatKey, false); Assert.isNull(parentBusinessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified."); } } }
businessObjectFormatKey.setBusinessObjectFormatVersion(null); latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); businessObjectFormatParent.setBusinessObjectFormatVersion(null); businessObjectFormatParents.add(businessObjectFormatParent); businessObjectFormatChild.setBusinessObjectFormatVersion(null); businessObjectFormatChildren.add(businessObjectFormatChild);
private String getLatestPartitionValueNotFoundErrorMessage(String boundType, String boundPartitionValue, String partitionKey, BusinessObjectFormatKey businessObjectFormatKey, Integer businessObjectDataVersion, List<String> storageNames) { return String.format("Failed to find partition value which is the latest %s partition value = \"%s\" for partition key = \"%s\" due to " + "no available business object data in \"%s\" storage that satisfies the search criteria. " + "Business object data {namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d, businessObjectDataVersion: %d}", boundType, boundPartitionValue, partitionKey, StringUtils.join(storageNames, ","), businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion(), businessObjectDataVersion); }
/** * Validates the business object format key. This method also trims the key parameters. * * @param key the business object format key * @param businessObjectFormatVersionRequired specifies if business object format version parameter is required or not * * @throws IllegalArgumentException if any validation errors were found */ public void validateBusinessObjectFormatKey(BusinessObjectFormatKey key, Boolean businessObjectFormatVersionRequired) throws IllegalArgumentException { Assert.notNull(key, "A business object format key must be specified."); key.setNamespace(alternateKeyHelper.validateStringParameter("namespace", key.getNamespace())); key.setBusinessObjectDefinitionName( alternateKeyHelper.validateStringParameter("business object definition name", key.getBusinessObjectDefinitionName())); key.setBusinessObjectFormatUsage(alternateKeyHelper.validateStringParameter("business object format usage", key.getBusinessObjectFormatUsage())); key.setBusinessObjectFormatFileType( alternateKeyHelper.validateStringParameter("business object format file type", key.getBusinessObjectFormatFileType())); if (businessObjectFormatVersionRequired) { Assert.notNull(key.getBusinessObjectFormatVersion(), "A business object format version must be specified."); } }
/** * Creates a business object format key from the relative values in the business object format create request. Please note that the key will contain a null * for the business object format version value. * * @param businessObjectFormatCreateRequest the business object format create request * * @return the business object format key */ private BusinessObjectFormatKey getBusinessObjectFormatKey(BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest) { BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(); businessObjectFormatKey.setNamespace(businessObjectFormatCreateRequest.getNamespace()); businessObjectFormatKey.setBusinessObjectDefinitionName(businessObjectFormatCreateRequest.getBusinessObjectDefinitionName()); businessObjectFormatKey.setBusinessObjectFormatUsage(businessObjectFormatCreateRequest.getBusinessObjectFormatUsage()); businessObjectFormatKey.setBusinessObjectFormatFileType(businessObjectFormatCreateRequest.getBusinessObjectFormatFileType()); return businessObjectFormatKey; }
/** * Create an instance of {@link BusinessObjectFormatKey } * */ public BusinessObjectFormatKey createBusinessObjectFormatKey() { return new BusinessObjectFormatKey(); }
@Test public void testBuildBusinessObjectFormatVersionChangeMessagesJsonPayloadNoOldBusinessObjectFormatVersion() throws Exception { // Create a business object format key. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, NO_MESSAGE_HEADER_DEFINITIONS))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, NO_OLD_BUSINESS_OBJECT_FORMAT_VERSION)); // Validate the results. assertEquals(1, CollectionUtils.size(result)); validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectFormatKey, businessObjectFormatKey.getBusinessObjectFormatVersion().toString(), NO_OLD_BUSINESS_OBJECT_FORMAT_VERSION, NO_MESSAGE_HEADERS, result.get(0)); }