BusinessObjectFormatExternalInterfaceDescriptiveInformationHelper { public BusinessObjectFormatExternalInterfaceDescriptiveInformation createBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities( BusinessObjectFormatEntity businessObjectFormatEntity, ExternalInterfaceEntity externalInterfaceEntity) { BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity); BusinessObjectFormatExternalInterfaceKey businessObjectFormatExternalInterfaceKey = new BusinessObjectFormatExternalInterfaceKey(businessObjectFormat.getNamespace(), businessObjectFormat.getBusinessObjectDefinitionName(), businessObjectFormat.getBusinessObjectFormatUsage(), businessObjectFormat.getBusinessObjectFormatFileType(), externalInterfaceEntity.getCode()); Map<String, Object> velocityContext = Maps.newHashMap(); velocityContext.put("StringUtils", StringUtils.class); velocityContext.put("CollectionUtils", CollectionUtils.class); velocityContext.put("Collections", Collections.class); velocityContext.put("namespace", businessObjectFormat.getNamespace()); velocityContext.put("businessObjectDefinitionName", businessObjectFormat.getBusinessObjectDefinitionName()); velocityContext.put("businessObjectFormatUsage", businessObjectFormat.getBusinessObjectFormatUsage()); velocityContext.put("businessObjectFormatFileType", businessObjectFormat.getBusinessObjectFormatFileType()); Map<String, String> businessObjectFormatAttributes = Maps.newLinkedHashMap(); for (Attribute attribute : businessObjectFormat.getAttributes()) { businessObjectFormatAttributes.put(attribute.getName(), attribute.getValue()); } velocityContext.put("businessObjectFormatAttributes", businessObjectFormatAttributes); List<String> partitionColumnNames = Lists.newLinkedList(); if (businessObjectFormat.getSchema() != null) { for (SchemaColumn schemaColumn : businessObjectFormat.getSchema().getPartitions()) { partitionColumnNames.add(schemaColumn.getName()); } } velocityContext.put("partitionColumnNames", partitionColumnNames); if (businessObjectFormatEntity.getPartitionKeyGroup() != null) { velocityContext.put("partitionKeyGroup", businessObjectFormatEntity.getPartitionKeyGroup().getPartitionKeyGroupName()); } else { velocityContext.put("partitionKeyGroup", ""); } String velocityEvaluatedExternalInterfaceDescription; try { velocityEvaluatedExternalInterfaceDescription = velocityHelper.evaluate(externalInterfaceEntity.getDescription(), velocityContext, "External Interface Description", false); } catch (ParseErrorException parseErrorException) { String exceptionMessage = String .format("Failed to evaluate velocity template in the external interface with name \"%s\". Reason: %s", externalInterfaceEntity.getCode(), parseErrorException.getMessage()); LOGGER.error(exceptionMessage, parseErrorException); throw new IllegalArgumentException(exceptionMessage); } return new BusinessObjectFormatExternalInterfaceDescriptiveInformation(businessObjectFormatExternalInterfaceKey, externalInterfaceEntity.getDisplayName(), velocityEvaluatedExternalInterfaceDescription); }  BusinessObjectFormatExternalInterfaceDescriptiveInformation createBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities(
        BusinessObjectFormatEntity businessObjectFormatEntity, ExternalInterfaceEntity externalInterfaceEntity);  }
@Test public void testCreateBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities() { String velocityTemplateDescription = "${namespace}#${businessObjectDefinitionName}#${businessObjectFormatUsage}#${businessObjectFormatFileType}#" + "${businessObjectFormatAttributes}#${partitionColumnNames}#${partitionKeyGroup}#$StringUtils.isNotEmpty($namespace)"; List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns(); assertTrue(CollectionUtils.size(partitionColumns) > BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1); List<SchemaColumn> regularColumns = schemaColumnDaoTestHelper.getTestSchemaColumns(); List<Attribute> attributes = Lists.newArrayList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE), new Attribute(ATTRIBUTE_NAME_2, ATTRIBUTE_VALUE_2)); BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, NO_FORMAT_DOCUMENT_SCHEMA, NO_FORMAT_DOCUMENT_SCHEMA_URL, LATEST_VERSION_FLAG_SET, partitionColumns.get(0).getName(), PARTITION_KEY_GROUP, attributes, SCHEMA_DELIMITER_PIPE, SCHEMA_COLLECTION_ITEMS_DELIMITER_COMMA, SCHEMA_MAP_KEYS_DELIMITER_HASH, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, null, null, SCHEMA_NULL_VALUE_BACKSLASH_N, regularColumns, partitionColumns); ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDaoTestHelper.createExternalInterfaceEntity(EXTERNAL_INTERFACE); externalInterfaceEntity.setDisplayName(DISPLAY_NAME_FIELD); externalInterfaceEntity.setDescription(velocityTemplateDescription); businessObjectFormatExternalInterfaceDaoTestHelper .createBusinessObjectFormatExternalInterfaceEntity(businessObjectFormatEntity, externalInterfaceEntity); BusinessObjectFormatExternalInterfaceDescriptiveInformation result = businessObjectFormatExternalInterfaceDescriptiveInformationHelper .createBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities(businessObjectFormatEntity, externalInterfaceEntity); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getNamespace(), NAMESPACE); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectDefinitionName(), BDEF_NAME); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatUsage(), FORMAT_USAGE_CODE); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatFileType(), FORMAT_FILE_TYPE_CODE); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getExternalInterfaceName(), EXTERNAL_INTERFACE); assertEquals(result.getExternalInterfaceDisplayName(), DISPLAY_NAME_FIELD); String[] descriptionTemplateReplacementValues = result.getExternalInterfaceDescription().split("#"); assertEquals("Namespace not equal to replacement.", descriptionTemplateReplacementValues[0], NAMESPACE); assertEquals("Business object definition name not equal to replacement.", descriptionTemplateReplacementValues[1], BDEF_NAME); assertEquals("Usage not equal to replacement.", descriptionTemplateReplacementValues[2], FORMAT_USAGE_CODE); assertEquals("File type not equal to replacement.", descriptionTemplateReplacementValues[3], FORMAT_FILE_TYPE_CODE); Map<String, String> attributesMap = Maps.newLinkedHashMap(); for (Attribute attribute : attributes) { attributesMap.put(attribute.getName(), attribute.getValue()); } assertEquals("Attributes not equal to replacement.", descriptionTemplateReplacementValues[4], attributesMap.toString()); List<String> partitionColumnNames = Lists.newArrayList(); for (SchemaColumnEntity schemaColumn : businessObjectFormatEntity.getSchemaColumns()) { if (schemaColumn.getPartitionLevel() != null) { partitionColumnNames.add(schemaColumn.getName()); } } assertEquals("Partitions not equal to replacement.", descriptionTemplateReplacementValues[5], partitionColumnNames.toString()); assertEquals("Partition key group not equal to replacement.", descriptionTemplateReplacementValues[6], PARTITION_KEY_GROUP); assertEquals("StringUtils not equal to replacement.", descriptionTemplateReplacementValues[7], "true"); }
@Test public void testCreateBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntitiesWithNullPartitionKeyGroup() { String velocityTemplateDescription = "${partitionKeyGroup}"; BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, NO_FORMAT_DOCUMENT_SCHEMA, NO_FORMAT_DOCUMENT_SCHEMA_URL, LATEST_VERSION_FLAG_SET, NO_PARTITION_KEY, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_COLLECTION_ITEMS_DELIMITER_COMMA, SCHEMA_MAP_KEYS_DELIMITER_HASH, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, null, null, SCHEMA_NULL_VALUE_BACKSLASH_N, NO_COLUMNS, NO_PARTITION_COLUMNS); ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDaoTestHelper.createExternalInterfaceEntity(EXTERNAL_INTERFACE); externalInterfaceEntity.setDescription(velocityTemplateDescription); businessObjectFormatExternalInterfaceDaoTestHelper .createBusinessObjectFormatExternalInterfaceEntity(businessObjectFormatEntity, externalInterfaceEntity); BusinessObjectFormatExternalInterfaceDescriptiveInformation result = businessObjectFormatExternalInterfaceDescriptiveInformationHelper .createBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities(businessObjectFormatEntity, externalInterfaceEntity); assertEquals("Partition key group not equal to replacement.", result.getExternalInterfaceDescription(), ""); }
@Test public void testCreateBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntitiesWithException() { String velocityTemplateDescription = "#elseif"; BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, NO_FORMAT_DOCUMENT_SCHEMA, NO_FORMAT_DOCUMENT_SCHEMA_URL, LATEST_VERSION_FLAG_SET, NO_PARTITION_KEY, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_COLLECTION_ITEMS_DELIMITER_COMMA, SCHEMA_MAP_KEYS_DELIMITER_HASH, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, null, null, SCHEMA_NULL_VALUE_BACKSLASH_N, NO_COLUMNS, NO_PARTITION_COLUMNS); ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDaoTestHelper.createExternalInterfaceEntity(EXTERNAL_INTERFACE); externalInterfaceEntity.setDescription(velocityTemplateDescription); businessObjectFormatExternalInterfaceDaoTestHelper .createBusinessObjectFormatExternalInterfaceEntity(businessObjectFormatEntity, externalInterfaceEntity); String parseErrorExceptionMessage = String.format( "Encountered \"#elseif\" at External Interface Description[line 1, column 1]%n" + "Was expecting one of:%n" + " <EOF> %n" + " \"(\" ...%n" + " <RPAREN> ...%n" + " <ESCAPE_DIRECTIVE> ...%n" + " <SET_DIRECTIVE> ...%n" + " \"##\" ...%n" + " \"\\\\\\\\\" ...%n" + " \"\\\\\" ...%n" + " <TEXT> ...%n" + " \"*#\" ...%n" + " \"*#\" ...%n" + " \"]]#\" ...%n" + " <STRING_LITERAL> ...%n" + " <IF_DIRECTIVE> ...%n" + " <INTEGER_LITERAL> ...%n" + " <FLOATING_POINT_LITERAL> ...%n" + " <WORD> ...%n" + " <BRACKETED_WORD> ...%n" + " <IDENTIFIER> ...%n" + " <DOT> ...%n" + " \"{\" ...%n" + " \"}\" ...%n" + " <EMPTY_INDEX> ...%n" + " "); String illegalArgumentExceptionMessage = String .format("Failed to evaluate velocity template in the external interface with name \"%s\". Reason: %s", externalInterfaceEntity.getCode(), parseErrorExceptionMessage); try { businessObjectFormatExternalInterfaceDescriptiveInformationHelper .createBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities(businessObjectFormatEntity, externalInterfaceEntity); fail(); } catch (IllegalArgumentException illegalArgumentException) { assertEquals("Actual illegal argument exception message not equal to expected illegal argument exception message.", illegalArgumentExceptionMessage, illegalArgumentException.getMessage()); } }