/** * 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."); } } }
/** * 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."); } } }
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); }
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); }
private String getPartitionValueNotFoundErrorMessage(String partitionValueType, String partitionKey, BusinessObjectFormatKey businessObjectFormatKey, Integer businessObjectDataVersion, List<String> storageNames) { return String.format("Failed to find %s partition value for partition key = \"%s\" due to " + "no available business object data in \"%s\" storage(s) that is registered using that partition. " + "Business object data {namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d, businessObjectDataVersion: %d}", partitionValueType, partitionKey, StringUtils.join(storageNames, ","), businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion(), businessObjectDataVersion); }
private String getPartitionValueNotFoundErrorMessage(String partitionValueType, String partitionKey, BusinessObjectFormatKey businessObjectFormatKey, Integer businessObjectDataVersion, List<String> storageNames) { return String.format("Failed to find %s partition value for partition key = \"%s\" due to " + "no available business object data in \"%s\" storage(s) that is registered using that partition. " + "Business object data {namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d, businessObjectDataVersion: %d}", partitionValueType, partitionKey, StringUtils.join(storageNames, ","), businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion(), businessObjectDataVersion); }
/** * Gets a business object format for the specified key. * * @param businessObjectFormatKey the business object format key * * @return the business object format */ protected BusinessObjectFormat getBusinessObjectFormatImpl(BusinessObjectFormatKey businessObjectFormatKey) { // Perform validation and trim the alternate key parameters. businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false); // Retrieve and ensure that a business object format exists. BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey); boolean checkLatestVersion = false; //need to check latest version if the format key does not have the version if (businessObjectFormatKey.getBusinessObjectFormatVersion() != null) { checkLatestVersion = true; } // Create and return the business object format object from the persisted entity. return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity, checkLatestVersion); }
/** * Gets a business object format for the specified key. * * @param businessObjectFormatKey the business object format key * * @return the business object format */ protected BusinessObjectFormat getBusinessObjectFormatImpl(BusinessObjectFormatKey businessObjectFormatKey) { // Perform validation and trim the alternate key parameters. businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false); // Retrieve and ensure that a business object format exists. BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey); boolean checkLatestVersion = false; //need to check latest version if the format key does not have the version if (businessObjectFormatKey.getBusinessObjectFormatVersion() != null) { checkLatestVersion = true; } // Create and return the business object format object from the persisted entity. return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity, checkLatestVersion); }
@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; }
@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; }
/** * Returns a string representation of the business object format key. * * @param businessObjectFormatKey the business object format key * * @return the string representation of the business object format key */ public String businessObjectFormatKeyToString(BusinessObjectFormatKey businessObjectFormatKey) { return businessObjectFormatKeyToString(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion()); }
/** * Returns a string representation of the business object format key. * * @param businessObjectFormatKey the business object format key * * @return the string representation of the business object format key */ public String businessObjectFormatKeyToString(BusinessObjectFormatKey businessObjectFormatKey) { return businessObjectFormatKeyToString(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion()); }
/** * Gets a business object format entity based on the alternate key and makes sure that it exists. If a format version isn't specified in the business object * format alternate key, the latest available format version will be used. * * @param businessObjectFormatKey the business object format key * * @return the business object format entity * @throws ObjectNotFoundException if the business object format entity doesn't exist */ public BusinessObjectFormatEntity getBusinessObjectFormatEntity(BusinessObjectFormatKey businessObjectFormatKey) throws ObjectNotFoundException { BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); if (businessObjectFormatEntity == null) { throw new ObjectNotFoundException(String.format("Business object format with namespace \"%s\", business object definition name \"%s\", " + "format usage \"%s\", format file type \"%s\", and format version \"%d\" doesn't exist.", businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion())); } return businessObjectFormatEntity; }
/** * 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()); }
/** * 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()); }
/** * Creates an XML escaped copy of the specified business object format key. * * @param businessObjectFormatKey the business object format key * * @return the XML escaped business object format key */ private BusinessObjectFormatKey escapeXmlBusinessObjectFormatKey(final BusinessObjectFormatKey businessObjectFormatKey) { // Build and return an XML escaped business object format key. return new BusinessObjectFormatKey(escapeXml(businessObjectFormatKey.getNamespace()), escapeXml(businessObjectFormatKey.getBusinessObjectDefinitionName()), escapeXml(businessObjectFormatKey.getBusinessObjectFormatUsage()), escapeXml(businessObjectFormatKey.getBusinessObjectFormatFileType()), businessObjectFormatKey.getBusinessObjectFormatVersion()); }
/** * Creates an XML escaped copy of the specified business object format key. * * @param businessObjectFormatKey the business object format key * * @return the XML escaped business object format key */ private BusinessObjectFormatKey escapeXmlBusinessObjectFormatKey(final BusinessObjectFormatKey businessObjectFormatKey) { // Build and return an XML escaped business object format key. return new BusinessObjectFormatKey(escapeXml(businessObjectFormatKey.getNamespace()), escapeXml(businessObjectFormatKey.getBusinessObjectDefinitionName()), escapeXml(businessObjectFormatKey.getBusinessObjectFormatUsage()), escapeXml(businessObjectFormatKey.getBusinessObjectFormatFileType()), businessObjectFormatKey.getBusinessObjectFormatVersion()); }
/** * Creates and persists a new business object format entity. * * @return the newly created business object format entity. */ public BusinessObjectFormatEntity createBusinessObjectFormatEntity(BusinessObjectFormatKey businessObjectFormatKey, String businessObjectFormatDescription, String businessObjectFormatDocumentSchema, Boolean businessObjectFormatLatestVersion, String businessObjectFormatPartitionKey) { return createBusinessObjectFormatEntity(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion(), businessObjectFormatDescription, businessObjectFormatDocumentSchema, businessObjectFormatLatestVersion, businessObjectFormatPartitionKey); }
@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)); }
@Test public void testGetBusinessObjectFormatsUpperCaseParameters() { // Create and persist the relative business object definitions. businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, null); businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, null); businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE_2, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, null); businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, null); // Create and persist business object format entities. for (BusinessObjectFormatKey key : businessObjectFormatDaoTestHelper.getTestBusinessObjectFormatKeys()) { businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(key.getNamespace(), key.getBusinessObjectDefinitionName(), key.getBusinessObjectFormatUsage(), key.getBusinessObjectFormatFileType(), key.getBusinessObjectFormatVersion(), FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA, false, PARTITION_KEY); } // Retrieve a list of business object format keys for the specified business object definition using upper case input parameters BusinessObjectFormatKeys resultKeys = businessObjectFormatService.getBusinessObjectFormats(new BusinessObjectDefinitionKey(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase()), false); // Validate the returned object. assertEquals(businessObjectFormatDaoTestHelper.getExpectedBusinessObjectFormatKeys(), resultKeys.getBusinessObjectFormatKeys()); }