Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 16 additions & 74 deletions config/libraries.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# Configurations for libraries, folders and content assets. CustomAttributes are not supported yet. There is a main
# library defined by "libraryConfig:". This library can contain additional further customized custom libraries under
# "libraries:" and customized folders under "folders:".
# If the library "ComdagenSharedLibrary" exists and contains a content asset named "ComdagenSummary" then this will be
# rendered in a central content slot on the store front.
# Configurations for folders and content assets. CustomAttributes are not supported yet. The defined content assets and
# content folders will be spliced into the SiteGenesisSharedLibrary.
libraryConfig:
# root folder for libraries
outputDir: "libraries"
# Top level seed
initialSeed: 1234

# Id and name of the content library. If no libraryId is defined it will be determined in an incremental
# fashion e.g. Library_0, Library_1,...
libraryId: "ComdagenSharedLibrary"

# Total of libraries to be generated. First this library will be generated and then the custom libraries up to
# "libraryCount"
libraryCount: 5
# Total number of generated content assets
generatedContentAssetCount: 30

# Total number of generated content assets per library
contentAssetCount: 30

# Total number of generated folders per library. Custom specified folders are generated first followed by default
# generated folders up to "folderCount" folders
folderCount: 10
# Total number of generated folders. Custom specified folders are generated first followed by default
# generated folders up to "generatedFolderCount" folders
generatedFolderCount: 10

# Generates a content asset containing the top level seeds and names of all generated libraries and
# sites if generateSummaryContentAsset is set to true or is left out in the config. Additionally display
# product count for sites and content asset count for libraries. This content asset counts towards
# contentAssetCount meaning, if generateSummaryContentAsset is set to true or is left out in the config,
# there will be 9 normally generated content assets.
# sites if generateSummaryContentAsset is set to true or is left out in the config. Additionally it displays
# the product count for sites. This content asset counts towards
# generatedContentAssetCount. If generateSummaryContentAsset is set to true or is left out in the config,
# there will be generatedContentAssetCount-1 normally generated content assets.
generateSummaryContentAsset: true


Expand All @@ -44,61 +34,13 @@ libraryConfig:
# Use randomly generated folderIds instead of Folder_<index>
randomFolderIds: false
# Parent folder
parent: "ComdagenContentAssets"


#------------------------
# Customized generation
#------------------------

# Custom libraries generation. Note: Libraries that are defined here can not generate additional libraries that are
# defined in their own custom library generation section "libraries:".
libraries:
# root folder for libraries
- libraryId: "Custom_test_library"
initialSeed: 9876

# Total generated content assets per library
contentAssetCount: 50

# Total generated folders per library
folderCount: 4

# Renders a summary about the comdagen run
renderSummary: false

# This overrides default settings for content asset generation
contentAssetDefaults:
classificationFolder: "root"

# This overrides default settings for folder generation
folderDefaults:
# Parent folder
parent: "root"

folders:
- folderId: "root"
displayName: "Root folder"
description: "Offers comdagen generated content"
# The content of folders marked with onlineFlag false is disabled
onlineFlag: true
parent: "root"

# Creating a custom folder for each entry
folders:
# If no folderId is given a randomized generated one is being used
- folderId: "root"
displayName: "Root folder"
description: "Offers comdagen generated content"
onlineFlag: true

- folderId: "ComdagenContent"
displayName: "Custom comdagen folder"
description: "Content folder for Comdagen generated content"
onlineFlag: true
parent: "root"

- folderId: "ComdagenContentAssets"
displayName: "Custom comdagen folder"
description: "Content folder for Comdagen generated content"
- folderId: "test1"
displayName: "Comdagen test folder"
description: "Generated folder by comdagen"
onlineFlag: true
parent: "ComdagenContent"
parent: "root"
2 changes: 1 addition & 1 deletion config/sites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sitesConfig:
# pseudo randomization seed, could be overwritten in generator config files
initialSeed: 1234
customCartridges: ["sitegenesis_storefront_pipelines", "sitegenesis_storefront_core"]
staticFiles: ["payment-methods.xml", "payment-processors.xml", "tax.xml", "url-rules.xml", "slots.xml"]
staticFiles: ["payment-methods.xml", "payment-processors.xml", "tax.xml", "url-rules.xml"]

# MFRA site import
- regions: [Generic, German, Chinese]
Expand Down
43 changes: 33 additions & 10 deletions src/main/java/com/salesforce/comdagen/Comdagen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,43 @@ class Comdagen {
)
}


/*
* load library configuration
* This is done before site generation because it is required to know if the comdagen summary content asset
* will be created in order to determine the content asset to be loaded in the central content asset slot on
* home page.
*/
val librariesConfFile = File(configDir, "libraries.yaml")
val librariesConf: LibraryConfiguration? =
if (librariesConfFile.isFile && librariesConfFile.canRead()) OBJECT_MAPPER.readValue(
librariesConfFile,
LibraryConfiguration::class.java
) else null


// load sites configuration
val sitesConfig = OBJECT_MAPPER.readValue(sitesConfigFile, SitesConfig::class.java)

// render generated data as xml files
outputProducer.render(SiteGenerator(sitesConfig, configDir))

// load library configuration
val librariesConfFile = File(configDir, "libraries.yaml")
val librariesConf: LibraryConfiguration?
// render generated data as xml files; if the library config couldn't be read, don't set the content slot to
// the comdagen summary content asset
outputProducer.render(
SiteGenerator(
sitesConfig,
configDir,
librariesConf?.renderComdagenSummaryContentAsset ?: false
)
)


// render libraries
if (librariesConfFile.isFile && librariesConfFile.canRead()) {
librariesConf = OBJECT_MAPPER.readValue(librariesConfFile, LibraryConfiguration::class.java)
outputProducer.render(LibraryGenerator(librariesConf, configDir))
}
if (librariesConf != null) outputProducer.render(
LibraryGenerator(
librariesConf,
configDir
)
) else LOGGER.warn("Could not read in library configuration \"library.yaml\".")

// zip generated output directory if cmd option is set
if (zip) {
Expand All @@ -118,7 +140,8 @@ class Comdagen {
if (xltExport) {
LOGGER.info("Start exporting product names.")

val siteGenerator = SiteGenerator(sitesConfig, configDir)
val siteGenerator =
SiteGenerator(sitesConfig, configDir, librariesConf?.renderComdagenSummaryContentAsset ?: false)

val allRegions = siteGenerator.configuration.sites.flatMap { it.regions.toList() }.toSet()

Expand Down
33 changes: 30 additions & 3 deletions src/main/java/com/salesforce/comdagen/XMLOutputProducer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ constructor(
val gatheredLibraryStatistics: Map<String, String> = mapOf(
"Library id" to it.libraryId,
"Library seed" to it.seed.toString(),
"Content asset count" to generator.configuration.contentAssetCount.toString()
"Content asset count" to generator.configuration.generatedContentAssetCount.toString()
)
comdagenStatistics.mergeIntoStatisticsMap(
it.libraryId,
Expand All @@ -178,7 +178,7 @@ constructor(
)
}
comdagenStatistics.generalStatistics["Libraries top level seed"] =
generator.configuration.initialSeed.toString()
generator.configuration.initialSeed.toString()

// For each library
libraries.forEach { library ->
Expand Down Expand Up @@ -216,7 +216,7 @@ constructor(
// Adding top level seed for statistics
comdagenStatistics.generalStatistics["Sites top level seed"] = generator.configuration.initialSeed.toString()

generator.objects.forEach {
generator.objects.forEachIndexed { index, it ->
// render site.xml
LOGGER.info("Start rendering site ${it.id} with template $siteTemplateName")
val siteModelData = mapOf("site" to it)
Expand Down Expand Up @@ -256,6 +256,33 @@ constructor(
"${generator.configuration.outputDir}/${it.id}/preferences.xml", preferencesModelData
)

/*
* render slots.xml
* This is dependent on the library.yaml generateSummaryContentAsset boolean. If a comdagen summary content
* asset gets generated, place it on the main page in a central slot. Otherwise use a default content asset
* there.
*/
LOGGER.info("Start rendering slots for site ${it.id} with template $preferencesTemplateName")


// Use the configuration on the first x sites since those are the custom defined sites which could provde
// different slots.ftlx
if (index < generator.configuration.sites.size && generator.configuration.sites[index].slotsConfig != null) {
produce(
generator.configuration.sites[index].slotsConfig!!,
"${generator.configuration.outputDir}/${it.id}/slots.xml",
mapOf("generateComdagenSummary" to generator.generateComdagenSummaryContentAsset)
)
} else {
// Render non custom specified sites by using the default slots.ftlx
produce(
"slots.ftlx",
"${generator.configuration.outputDir}/${it.id}/slots.xml",
mapOf("generateComdagenSummary" to generator.generateComdagenSummaryContentAsset)
)
}


// copy site specific static files to site output directory
if (it.staticFiles.isNotEmpty()) {
copyStaticFiles(it.staticFiles, File(outputDir, "sites/${it.id}/"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,18 @@ import com.salesforce.comdagen.RenderConfig
@JsonIgnoreProperties(ignoreUnknown = true)
data class LibraryConfiguration(
override val initialSeed: Long = 1234,
val libraryId: String?,
val contentAssetCount: Int = 3,
val generatedContentAssetCount: Int = 3,
val folders: List<FolderConfiguration> = listOf(),
@JsonProperty("folderDefaults")
val defaultFolderConfigs: FolderConfiguration,
val folderCount: Int = 6,
val defaultFolderConfigs: FolderConfiguration = FolderConfiguration(initialSeed, null, null, null, parent = null),
val generatedFolderCount: Int = 6,
@JsonProperty("generateSummaryContentAsset")
val renderComdagenSummaryContentAsset: Boolean = true,

val libraries: List<LibraryConfiguration> = listOf(),
@JsonProperty("contentAssetDefaults")
val defaultContentAssetConfig: ContentConfiguration,
val defaultContentAssetConfig: ContentConfiguration = ContentConfiguration(initialSeed, null, null),

@JsonProperty("libraryCount")
override val elementCount: Int = 3,
override val elementCount: Int = 1,
override val outputFilePattern: String = "",
override val outputDir: String = "libraries",
override val templateName: String = "library.ftlx"
) : RenderConfig {

/**
* Returns the number of content assets that will be generated by this library and its custom libraries.
*/
fun totalContentAssetCount() =
/* Number of default generated content assets */ contentAssetCount +
/* Number of content assets generated by custom libraries */ libraries.sumBy { it.contentAssetCount }

/**
* Returns the number of folders that will be rendered in the template.
*/
fun totalFolderCount(): Int {
val x = /* Number of default generated folders */ folderCount +
/* Number of folders generated by custom libraries */ libraries.sumBy { it.folderCount }
return if (renderComdagenSummaryContentAsset) x + 1 else x
}

}
) : RenderConfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ data class SiteConfiguration(

val redirectUrlConfig: String? = null,

val slotsConfig: String? = null,

override val outputFilePattern: String = "site.xml",

override val outputDir: String = "sites",
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/salesforce/comdagen/config/SlotConfiguration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.salesforce.comdagen.config


import com.salesforce.comdagen.RenderConfig

/**
* Configuration for slots.xml files. This currently is only used for template and output file specification. Therefore
* it does not back a yaml config.
*/
class SlotConfiguration : RenderConfig {

override val elementCount: Int = 1

override val initialSeed: Long = 1234

override val outputFilePattern: String = "slots.xml"
override val outputDir: String = "sites"
override val templateName: String = "slots.ftlx"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,13 @@ data class LibraryGenerator(
val configDir: File
) : Generator<LibraryConfiguration, Library> {

private val rng: Random
get() = Random(configuration.initialSeed)

/**
* First the library from the main library configuration file gets created. Following are custom libraries and
* generated libraries up to the defined number of libraries elementCount.
*/
override val objects: Sequence<Library>
get() {
val maxNumberOfLibraries = configuration.elementCount

if (maxNumberOfLibraries <= 0)
return emptySequence()
var x = emptySequence<Library>()

// Adding one library with the configured libraryId. If libraryId is null the internId will be 0
x += creatorFunc(
0,
configuration.initialSeed
)
// Adding custom libraries
x += (0 until Math.min(maxNumberOfLibraries - x.count(), configuration.libraries.size)).map { index ->
Library(index + 1, configuration.libraries[index].initialSeed, configuration.libraries[index])
}

// Adding generated libraries to fill up
x += rng.longs(
Math.max(
maxNumberOfLibraries - configuration.libraries.size - 1,
0
).toLong()
).toList().mapIndexed { index, randomLong ->
creatorFunIndexedLibrary(
index + x.count(),
randomLong
)
}.asSequence()
return x
}

get() = sequenceOf(Library(configuration.initialSeed, configuration))

/**
* Creates a library according to the configuration of the generator.
*/
override val creatorFunc = { idx: Int, seed: Long -> Library(idx, seed, configuration) }

/**
* Generates a library according to the configuration of the generator but ignores the libraryId
*/
val creatorFunIndexedLibrary =
{ idx: Int, seed: Long -> Library(idx, seed, configuration.copy(libraryId = null)) }

// TODO: Implement metadata
override val metadata: Map<String, Set<AttributeDefinition>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import kotlin.streams.toList
* @property configDir directory where linked configuration files are stored
* @property generatorTemplate site configuration happens in this template
*/
data class SiteGenerator(override val configuration: SitesConfig, private val configDir: File) :
data class SiteGenerator(
override val configuration: SitesConfig,
private val configDir: File,
val generateComdagenSummaryContentAsset: Boolean
) :
Generator<SitesConfig, Site> {

private val rng: Random
Expand Down
Loading