Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)

### Added

- DeployBaseTemplates task that deploys base templates with pages, areas, interactive flows and other options.

### Changed

### Fixed
Expand Down
23 changes: 22 additions & 1 deletion migration-examples/hierarchy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
color: #40a02b;
}

.label.base_template {
color: #8839ef;
}

.label mark {
background: var(--hl);
padding: 0 2px;
Expand Down Expand Up @@ -247,6 +251,8 @@
<label for="images">Images</label>
<input id="attachments" type="checkbox" checked />
<label for="attachments">Attachments</label>
<input id="baseTemplates" type="checkbox" checked />
<label for="baseTemplates">Base templates</label>
</div>

<div id="content">
Expand Down Expand Up @@ -289,6 +295,7 @@
const variableStructuresChkbox = /** @type {HTMLInputElement} */ (document.getElementById("variableStructures"));
const attachmentsChkbox = /** @type {HTMLInputElement} */ (document.getElementById("attachments"));
const imagesChkbox = /** @type {HTMLInputElement} */ (document.getElementById("images"));
const baseTemplatesChkbox = /** @type {HTMLInputElement} */ (document.getElementById("baseTemplates"));

function refresh() {
indexes = buildIndexes(data);
Expand All @@ -307,6 +314,7 @@
variableStructuresChkbox.addEventListener("change", refresh);
attachmentsChkbox.addEventListener("change", refresh);
imagesChkbox.addEventListener("change", refresh);
baseTemplatesChkbox.addEventListener("change", refresh);

treeEl.addEventListener("click", onTreeClick);

Expand Down Expand Up @@ -489,6 +497,9 @@
case 'VARIABLE_STRUCTURE': {
return variableStructuresChkbox.checked;
};
case 'BASE_TEMPLATE': {
return baseTemplatesChkbox.checked;
};
}
}

Expand Down Expand Up @@ -916,6 +927,7 @@
addBucket(root.images, "IMAGE");
addBucket(root.variables, "VARIABLE");
addBucket(root.variableStructures, "VARIABLE_STRUCTURE");
addBucket(root.baseTemplates, "BASE_TEMPLATE");

return { nodeByKey, childrenByKey, parentsByKey };
}
Expand Down Expand Up @@ -967,6 +979,9 @@
case 'VARIABLE_STRUCTURE': {
return root.variableStructures[ref.id];
};
case 'BASE_TEMPLATE': {
return root.baseTemplates[ref.id];
};
}
}

Expand Down Expand Up @@ -1012,6 +1027,10 @@
label = "VS"
break;
};
case 'BASE_TEMPLATE': {
label = "BT"
break;
};
}

let eid = id;
Expand Down Expand Up @@ -1040,6 +1059,7 @@
* @property {Object.<string, Leaf>} images
* @property {Object.<string, Leaf>} variables
* @property {Object.<string, Child>} variableStructures
* @property {Object.<string, Leaf>} baseTemplates
*/

/**
Expand Down Expand Up @@ -1073,7 +1093,8 @@
* | 'ATTACHMENT'
* | 'IMAGE'
* | 'VARIABLE'
* | 'VARIABLE_STRUCTURE'} ChildType
* | 'VARIABLE_STRUCTURE'
* | 'BASE_TEMPLATE'} ChildType
*/
</script>
</body>
Expand Down
23 changes: 19 additions & 4 deletions migration-examples/layout/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,10 @@
const baseTemplateId = `bt-${templateGroupIndex + 1}`;
const baseTemplateName = `${templateGroup.templateNames[0]}BaseTemplate`;

const usedFlowNames = new Set();
/** @type {Map<string, number>} */
const firstPageGroupIndexForName = new Map();

templateGroup.pageGroups.forEach((pageGroup, pageGroupIndex) => {
const basePageId = `page-${pageGroupIndex + 1}`;
const basePageName = `Page ${pageGroupIndex + 1}`;
Expand All @@ -941,14 +945,25 @@

/** @type {string[]} */
const flowNamesByAreaGroupIndex = [];
const usedFlowNames = new Set();

representativeDrafts.forEach((draft, areaGroupIndex) => {
const flowToNextPage = draft.areaIndices.some(ai => representativePage.areas[ai]?.flowToNextPage);
let flowName = draft.name;
if (usedFlowNames.has(flowName)) {
flowName = `${flowName} (Area ${areaGroupIndex + 1})`;
const baseFlowName = `${draft.name}Flow`;
let flowName = baseFlowName;
if (usedFlowNames.has(baseFlowName)) {
flowName = firstPageGroupIndexForName.get(baseFlowName) === pageGroupIndex
? `${baseFlowName} (Area ${areaGroupIndex + 1})`
: `${baseFlowName} (${basePageName})`;
} else {
firstPageGroupIndexForName.set(baseFlowName, pageGroupIndex);
}
let uniqueFlowName = flowName;
let dedupCounter = 2;
while (usedFlowNames.has(uniqueFlowName)) {
uniqueFlowName = `${flowName} (${dedupCounter})`;
dedupCounter++;
}
flowName = uniqueFlowName;
usedFlowNames.add(flowName);
flowNamesByAreaGroupIndex.push(flowName);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! ---
//! displayName: Deploy Base Templates
//! category: Deployment
//! description: Deploys all base templates
//! ---
package com.quadient.migration.example.common

import groovy.transform.Field
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import static com.quadient.migration.example.common.util.InitMigration.initMigration

def migration = initMigration(this.binding)
def start = System.currentTimeMillis()

deploymentResult = migration.deployClient.deployBaseTemplates()
@Field static Logger log = LoggerFactory.getLogger(this.class.name)

if (!deploymentResult.deployed.empty) {
for (def item : deploymentResult.deployed) {
log.info "Deployed ${item.type.toString()} '${item.id}' to '${item.targetPath}'"
}
}

if (!deploymentResult.warnings.empty) {
for (def item : deploymentResult.warnings) {
log.warn "Item '${item.id}' deployed with warning: ${item.message}"
}
}

if (!deploymentResult.errors.empty) {
for (def item : deploymentResult.errors) {
log.error "Item '${item.id}' failed to deploy with error: ${item.message}"
}
}
log.info "Deployment finished. Deployed ${deploymentResult.deployed.size()} items with ${deploymentResult.warnings.size()} warnings and ${deploymentResult.errors.size()} errors"
log.info "Deployment took ${System.currentTimeMillis() - start} ms"
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ static void run(Migration migration, Path documentObjFilePath) {
Mapping.mapProp(existingMapping, existingDocObject, "type", newType)

def varStructureRef = Csv.deserialize(values.get("variableStructureId"), String.class)
if (varStructureRef != existingDocObject.variableStructureRef?.id && varStructureRef != existingMapping.variableStructureRef) {
existingMapping.variableStructureRef = varStructureRef
}
existingMapping.variableStructureRef = varStructureRef

def csvStatus = values.get("status")
if (status != null && csvStatus == "Active" && status.class.simpleName != "Active") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ static void run(Migration migration, Path path) {
areasFile.withWriter { writer ->
def headers = [
Mapping.displayHeader("templateId", false),
Mapping.displayHeader("templateName", true),
Mapping.displayHeader("templateName", false),
Mapping.displayHeader("pageId", false),
Mapping.displayHeader("pageName", true),
Mapping.displayHeader("pageName", false),
Mapping.displayHeader("type", false),
Mapping.displayHeader("baseTemplateTargetId", false),
Mapping.displayHeader("interactiveFlowName", false),
Mapping.displayHeader("flowToNextPage", false),
Mapping.displayHeader("areaIndex", true),
Mapping.displayHeader("x", true),
Mapping.displayHeader("y", true),
Mapping.displayHeader("width", true),
Mapping.displayHeader("height", true),
Mapping.displayHeader("pageWidth", true),
Mapping.displayHeader("pageHeight", true),
Mapping.displayHeader("areaIndex", false),
Mapping.displayHeader("x", false),
Mapping.displayHeader("y", false),
Mapping.displayHeader("width", false),
Mapping.displayHeader("height", false),
Mapping.displayHeader("pageWidth", false),
Mapping.displayHeader("pageHeight", false),
Mapping.displayHeader("contentPreview", true),
]
writer.writeLine(headers.join(","))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def attachments = migration.attachmentRepository.listAll()
def images = migration.imageRepository.listAll()
def variables = migration.variableRepository.listAll()
def variableStructures = migration.variableStructureRepository.listAll()
def baseTemplates = migration.baseTemplateRepository.listAll()

def root = new Root()

Expand Down Expand Up @@ -87,6 +88,12 @@ for (variableStructure in variableStructures) {
root.variableStructures[node.id] = node
}

for (baseTemplate in baseTemplates) {
def node = new Leaf(id: baseTemplate.id, name: baseTemplate.name, type: ChildType.BASE_TEMPLATE)

root.baseTemplates[node.id] = node
}

// Collect parents
for (node in root.documentObjects.values()) {
def parentNode = new Reference(id: node.id, type: ChildType.DOCUMENT_OBJECT)
Expand Down Expand Up @@ -121,6 +128,7 @@ static void collectParents(Root root, Node node, Reference parentNode) {
case ChildType.IMAGE -> root.images
case ChildType.VARIABLE -> root.variables
case ChildType.VARIABLE_STRUCTURE -> root.variableStructures
case ChildType.BASE_TEMPLATE -> root.baseTemplates
default -> throw new IllegalStateException("Unknown parent type: ${child.type}")
}

Expand All @@ -139,6 +147,7 @@ static void collectChildren(Node node, Set<Ref> refs) {
case ImageRef -> ChildType.IMAGE
case VariableRef -> ChildType.VARIABLE
case VariableStructureRef -> ChildType.VARIABLE_STRUCTURE
case BaseTemplateRef -> ChildType.BASE_TEMPLATE
default -> throw new IllegalStateException("Unknown reference type: ${child.class}")
}

Expand All @@ -155,6 +164,7 @@ class Root {
Map<String, Leaf> images = [:]
Map<String, Leaf> variables = [:]
Map<String, Child> variableStructures = [:]
Map<String, Leaf> baseTemplates = [:]
}

class Node {
Expand Down Expand Up @@ -186,4 +196,5 @@ enum ChildType {
IMAGE,
VARIABLE,
VARIABLE_STRUCTURE,
BASE_TEMPLATE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def mainFlow = new DocumentObjectBuilder("mainFlow", DocumentObjectType.Block)
.build()
migration.documentObjectRepository.upsert(mainFlow)

def page = new DocumentObjectBuilder("page1", DocumentObjectType.Page)
def page = new DocumentObjectBuilder("page", DocumentObjectType.Page)
.internal(true)
.options(new PageOptions(Size.ofMillimeters(210), Size.ofMillimeters(297)))
.area {
it.position {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def displayAddressRule = new DisplayRuleBuilder("displayAddressRule")
.internal(false)
.subject("External display rule")
.metadata("key") { it.string("value") }
.variableStructureRef(variableStructure)
.group {
it.operator(GroupOp.Or)
it.comparison { it.variable(nameVariable).notEquals().value("") }
Expand Down Expand Up @@ -403,15 +402,13 @@ def address = new DocumentObjectBuilder("address", DocumentObjectType.Block)
.paragraph { it.styleRef(compactParagraphStyle).text { it.styleRef(normalStyle).variableRef(addressVariable) } }
.paragraph { it.styleRef(compactParagraphStyle).text { it.styleRef(normalStyle).variableRef(cityVariable) } }
.paragraph { it.styleRef(compactParagraphStyle).text { it.styleRef(normalStyle).variableRef(stateVariable) } }
.variableStructureRef(variableStructure)
.build()

// Footer of the document containing a signature.
def signature = new DocumentObjectBuilder("signature", DocumentObjectType.Block)
.paragraph { it.styleRef(compactParagraphStyle).text { it.styleRef(normalStyle).string("Sincerely,") } }
.paragraph { it.styleRef(compactParagraphStyle).text { it.styleRef(normalStyle).string("John Migration") } }
.paragraph { it.styleRef(compactParagraphStyle).text { it.styleRef(normalStyle).string("CEO of Lorem ipsum") } }
.variableStructureRef(variableStructure)
.build()

// Sample paragraph containing a heading using headingStyle style,
Expand Down Expand Up @@ -490,7 +487,6 @@ def conditionalParagraph = new DocumentObjectBuilder("conditionalParagraph", Doc
it.styleRef(normalStyle).string("Integer quis quam semper, accumsan neque at, pellentesque diam. Etiam in blandit dolor. Maecenas sit amet interdum augue, vel pellentesque erat. Suspendisse ut sem in justo rhoncus placerat vitae ut lacus. Etiam consequat bibendum justo ut posuere. Donec aliquam posuere nibh, vehicula pulvinar lectus dictum et. Nullam rhoncus ultrices ipsum et consectetur. Nam tincidunt id purus ac viverra. ")
}
}
.variableStructureRef(variableStructure)
.build()

def firstMatchBlock = new DocumentObjectBuilder("firstMatch", DocumentObjectType.Block)
Expand Down Expand Up @@ -534,7 +530,6 @@ def snippet = new SnippetBuilder("snippet")
.simple()
.string("Lorem ipsum: ")
.variableRef(nameVariable)
.variableStructureRef(variableStructure)
.build()

// A simple first match snippet example
Expand All @@ -551,7 +546,6 @@ def fmSnippet = new SnippetBuilder("firstMatchSnippet")
}
.defaultString("For more information visit ")
}
.variableStructureRef(variableStructure)
.build()


Expand All @@ -574,6 +568,7 @@ def separator = new ShapeBuilder()
def paragraph1TopMargin = topMargin + Size.ofMillimeters(25)
def signatureTopMargin = pageHeight - Size.ofCentimeters(3)
def page = new DocumentObjectBuilder("page1", DocumentObjectType.Page)
.internal(true)
.options(new PageOptions(pageWidth, pageHeight))
.shape(separator)
.area {
Expand Down Expand Up @@ -649,7 +644,6 @@ def page = new DocumentObjectBuilder("page1", DocumentObjectType.Page)
.attachmentRef(exampleAttachment)
.flowToNextPage(true)
}
.variableStructureRef(variableStructure)
.build()

def sms = new SmsObjectBuilder("sms")
Expand Down Expand Up @@ -720,15 +714,10 @@ def email = new EmailObjectBuilder("email")
}
.build()

def templateEmailSms = new DocumentObjectBuilder("templateEmailSms", DocumentObjectType.Template)
.documentObjectRef(sms)
.documentObjectRef(email)
.baseTemplate("vcs://Interactive/StandardPackage/BaseTemplates/ResponsiveEmailBaseTemplate.wfd")
.variableStructureRef(variableStructure)
.build()

def template = new DocumentObjectBuilder("template", DocumentObjectType.Template)
.documentObjectRef(page)
.documentObjectRef(sms)
.documentObjectRef(email)
.subject("Document example template")
.pdfMetadata {
it.author(new VariableRef(nameVariable.id))
Expand All @@ -741,7 +730,7 @@ def template = new DocumentObjectBuilder("template", DocumentObjectType.Template
.build()

// Insert all content into the database to be used in the deploy task
for (item in [address, signature, paragraph1, paragraph2, conditionalParagraph, page, template, firstMatchBlock, selectByLanguageBlock, jobListBlock, snippet, fmSnippet, sms, email, templateEmailSms]) {
for (item in [address, signature, paragraph1, paragraph2, conditionalParagraph, page, template, firstMatchBlock, selectByLanguageBlock, jobListBlock, snippet, fmSnippet, sms, email]) {
migration.documentObjectRepository.upsert(item)
}
for (item in [headingStyle, normalStyle]) {
Expand Down
Loading
Loading