Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)

- Added azureAI sample files
- Introduced attachment table that allows to work with static files. Export/import, path config and other support included
- Areas have flowToNextPage property (false by default) available in Area builder and import/export scripts.

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static void run(Migration migration, Path path) {
Mapping.displayHeader("pageId", false),
Mapping.displayHeader("pageName", true),
Mapping.displayHeader("interactiveFlowName", false),
Mapping.displayHeader("flowToNextPage", false),
Mapping.displayHeader("x", true),
Mapping.displayHeader("y", true),
Mapping.displayHeader("width", true),
Expand Down Expand Up @@ -85,6 +86,7 @@ static String buildArea(Migration migration, Number idx, Area area, DocumentObje
builder.append(Csv.serialize(page.id) + ",")
builder.append(Csv.serialize(page.name) + ",")
builder.append(Csv.serialize(area.interactiveFlowName) + ",")
builder.append(Csv.serialize(area.flowToNextPage) + ",")
builder.append(Csv.serialize(area.position.x) + ",")
builder.append(Csv.serialize(area.position.y) + ",")
builder.append(Csv.serialize(area.position.width) + ",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ static void run(Migration migration, Path path) {
def columnNames = Csv.parseColumnNames(fileLines.removeFirst()).collect { Mapping.normalizeHeader(it) }

DocumentObject currentPage = null
def areas = null
MappingItem.Area mapping = null
int areaIndex = 0
for (line in fileLines) {
Expand All @@ -37,24 +36,25 @@ static void run(Migration migration, Path path) {

if (currentPage?.id != pageId) {
if (currentPage != null) {
migration.mappingRepository.upsert(pageId, mapping)
migration.mappingRepository.upsert(currentPage.id, mapping)
migration.mappingRepository.applyAreaMapping(currentPage.id)
}

def pageModel = migration.documentObjectRepository.find(pageId)
if (!pageModel) {
throw new IllegalStateException("Page '${pageId}' not found.")
}

areas = pageModel.content.findAll { it instanceof Area } as List<Area>
mapping = migration.mappingRepository.getAreaMapping(pageId)
currentPage = pageModel
areaIndex = 0
}

def interactiveFlowName = Csv.deserialize(values.get("interactiveFlowName"), String.class)
if (interactiveFlowName != mapping.areas.get(areaIndex) && areas[areaIndex].interactiveFlowName != interactiveFlowName) {
mapping.areas[areaIndex] = interactiveFlowName
}
mapping.areas[areaIndex] = interactiveFlowName

def flowToNextPage = Csv.deserialize(values.get("flowToNextPage"), Boolean.class)
mapping.flowToNextPage[areaIndex] = flowToNextPage ?: false

areaIndex++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ def page = new DocumentObjectBuilder("page1", DocumentObjectType.Page)
it.width(contentWidth)
it.height(Size.ofCentimeters(2))
}
.documentObjectRef(signature.id)
.attachmentRef(exampleAttachment.id)
.documentObjectRef(signature.id)
.attachmentRef(exampleAttachment.id)
.flowToNextPage(true)
}
.variableStructureRef(variableStructure.id)
.build()
Expand Down
22 changes: 11 additions & 11 deletions migration-examples/src/test/groovy/AreasExportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ class AreasExportTest {
@Test
void export() {
Path mappingFile = Paths.get(dir.path, "testProject.csv")
when(migration.mappingRepository.getAreaMapping(any())).thenReturn(new MappingItem.Area(null, [:]))
when(migration.mappingRepository.getAreaMapping(any())).thenReturn(new MappingItem.Area(null, [:], [:]))
when((migration.documentObjectRepository as DocumentObjectRepository).list(any())).thenReturn([
new DocumentObject("empty tmpl", null, [], new CustomFieldMap([:]), DocumentObjectType.Template, [], false, null, null, null, null, null, null, null, [:], emptySkipOptions(), null),
new DocumentObject("unreferenced page", null, [], new CustomFieldMap([:]), DocumentObjectType.Page, [createArea("test flow")], false, null, null, null, null, null, null, null, [:], emptySkipOptions(), null),
new DocumentObject("unreferenced page", null, [], new CustomFieldMap([:]), DocumentObjectType.Page, [createArea("test flow", true)], false, null, null, null, null, null, null, null, [:], emptySkipOptions(), null),
new DocumentObject("full tmpl", null, [], new CustomFieldMap([:]), DocumentObjectType.Template, [new DocumentObjectRef("full page")], false, null, null, null, null, null, null, null, [:], emptySkipOptions(), null),
new DocumentObject("full page", null, [], new CustomFieldMap([:]), DocumentObjectType.Page, [createArea("test flow2"), createArea("test flow3"), createArea(null), createArea("test flow5")], false, null, null, null, null, null, null, null, [:], emptySkipOptions(), null),
new DocumentObject("full page", null, [], new CustomFieldMap([:]), DocumentObjectType.Page, [createArea("test flow2"), createArea("test flow3", true), createArea(null), createArea("test flow5")], false, null, null, null, null, null, null, null, [:], emptySkipOptions(), null),
])

AreasExport.run(migration, mappingFile)

def expected = """\
templateId (read-only),templateName (read-only),pageId,pageName (read-only),interactiveFlowName,x (read-only),y (read-only),width (read-only),height (read-only),contentPreview (read-only)
full tmpl,,full page,,test flow2,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,test flow3,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,test flow5,0.0mm,0.0mm,0.0mm,0.0mm,
,,unreferenced page,,test flow,0.0mm,0.0mm,0.0mm,0.0mm,
templateId (read-only),templateName (read-only),pageId,pageName (read-only),interactiveFlowName,flowToNextPage,x (read-only),y (read-only),width (read-only),height (read-only),contentPreview (read-only)
full tmpl,,full page,,test flow2,false,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,test flow3,true,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,,false,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,test flow5,false,0.0mm,0.0mm,0.0mm,0.0mm,
,,unreferenced page,,test flow,true,0.0mm,0.0mm,0.0mm,0.0mm,
""".stripIndent()
Assertions.assertEquals(expected, mappingFile.toFile().text.replaceAll("\\r\\n|\\r", "\n"))
}

static Area createArea(String flowName) {
return new Area([], new Position(Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0)), flowName)
static Area createArea(String flowName, Boolean flowToNextPage = false) {
return new Area([], new Position(Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0)), flowName, flowToNextPage)
}

static SkipOptions emptySkipOptions() {
Expand Down
53 changes: 33 additions & 20 deletions migration-examples/src/test/groovy/AreasImportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import org.junit.jupiter.api.io.TempDir
import java.nio.file.Path
import java.nio.file.Paths

import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when
import static org.mockito.Mockito.times

class AreasImportTest {
@TempDir
java.io.File dir
File dir

Migration migration

Expand All @@ -31,33 +29,48 @@ class AreasImportTest {
@Test
void importTest() {
Path mappingFile = Paths.get(dir.path, "testProject.csv")
when(migration.mappingRepository.getAreaMapping(any())).thenReturn(new MappingItem.Area(null, [:]))
givenPageExists("full page", ["test flow2", "test flow3", null, "test flow5"])
givenPageExists("unreferenced page", ["test flow"])

when(migration.mappingRepository.getAreaMapping("page1")).thenReturn(new MappingItem.Area(null, [:], [:]))
when(migration.mappingRepository.getAreaMapping("page2")).thenReturn(new MappingItem.Area(null, [:], [:]))
when(migration.mappingRepository.getAreaMapping("page3")).thenReturn(new MappingItem.Area(null, [:], [:]))

givenPageExists("page1", ["flow1", "flow2", "flow3"], [false, false, false])
givenPageExists("page2", ["flowA", "flowB"], [false, false])
givenPageExists("page3", [null, "beta", null, "delta"])

def input = """\
templateId,templateName,pageId,pageName,interactiveFlowName,x,y,width,height,contentPreview
,,unreferenced page,,test flow,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,test flow2,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,test flow3,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,new flow name,0.0mm,0.0mm,0.0mm,0.0mm,
full tmpl,,full page,,new test flow5,0.0mm,0.0mm,0.0mm,0.0mm,
templateId,templateName,pageId,pageName,interactiveFlowName,flowToNextPage,x,y,width,height,contentPreview
,,page1,,flow1,false,0.0mm,0.0mm,0.0mm,0.0mm,
,,page1,,new flow2,false,0.0mm,0.0mm,0.0mm,0.0mm,
,,page1,,flow3,true,0.0mm,0.0mm,0.0mm,0.0mm,
tmpl2,,page2,,flowA,true,0.0mm,0.0mm,0.0mm,0.0mm,
tmpl2,,page2,,modified flowB,false,0.0mm,0.0mm,0.0mm,0.0mm,
tmpl3,,page3,,new alpha,false,0.0mm,0.0mm,0.0mm,0.0mm,
tmpl3,,page3,,beta,true,0.0mm,0.0mm,0.0mm,0.0mm,
tmpl3,,page3,,new gamma,false,0.0mm,0.0mm,0.0mm,0.0mm,
tmpl3,,page3,,modified delta,true,0.0mm,0.0mm,0.0mm,0.0mm,
""".stripIndent()
mappingFile.toFile().write(input)

AreasImport.run(migration, mappingFile)

verify(migration.mappingRepository, times(2))
.upsert("full page", new MappingItem.Area(null, [2: "new flow name", 3: "new test flow5"]))
verify(migration.mappingRepository).applyAreaMapping("full page")
verify(migration.mappingRepository).upsert("page1", new MappingItem.Area(null, [0: "flow1", 1: "new flow2", 2: "flow3"], [0: false, 1: false, 2: true]))
verify(migration.mappingRepository).applyAreaMapping("page1")
verify(migration.mappingRepository).upsert("page2", new MappingItem.Area(null, [0: "flowA", 1: "modified flowB"], [0: true, 1: false]))
verify(migration.mappingRepository).applyAreaMapping("page2")
verify(migration.mappingRepository).upsert("page3", new MappingItem.Area(null, [0: "new alpha", 1: "beta", 2: "new gamma", 3: "modified delta"], [0: false, 1: true, 2: false, 3: true]))
verify(migration.mappingRepository).applyAreaMapping("page3")
}

static Area createArea(String flowName) {
return new Area([], new Position(Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0)), flowName)
static Area createArea(String flowName, boolean flowToNextPage) {
return new Area([], new Position(Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0), Size.ofMillimeters(0)), flowName, flowToNextPage)
}

void givenPageExists(String pageId, List<String> flowNames) {
def content = flowNames.collect { flowName -> createArea(flowName) }
void givenPageExists(String pageId, List<String> flowNames, List<Boolean> flowToNextPageValues = null) {
def values = flowToNextPageValues ?: flowNames.collect { false }
def content = [flowNames, values].transpose()
.collect { String flowName, Boolean flowToNextPage -> createArea(flowName, flowToNextPage) }
when(migration.documentObjectRepository.find(pageId))
.thenReturn(new DocumentObject(pageId, null, [], new CustomFieldMap([:]), DocumentObjectType.Page, content, false, null, null, null, null, null, null, null, [:], new SkipOptions(false, null, null), null))
.thenReturn(new DocumentObject(pageId, null, [], new CustomFieldMap([:]), DocumentObjectType.Page, content, false, null, null, null, null, null, null, null, [:], new SkipOptions(false, null, null), null))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sealed class MappingItem {
data class Area(
override var name: String?,
var areas: MutableMap<Int, String?>,
var flowToNextPage: MutableMap<Int, Boolean> = mutableMapOf(),
) : MappingItem()

data class Image(
Expand Down Expand Up @@ -102,7 +103,9 @@ sealed class MappingItem {
)
}

is MappingItem.Area -> MappingItemEntity.Area( name = this.name, areas = this.areas)
is MappingItem.Area -> MappingItemEntity.Area(
name = this.name, areas = this.areas, flowToNextPage = this.flowToNextPage
)

is MappingItem.Image -> {
MappingItemEntity.Image(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AreaBuilder : DocumentContentBuilderBase<AreaBuilder> {
override val content = mutableListOf<DocumentContent>()
private var position: Position? = null
private var interactiveFlowName: String? = null
private var flowToNextPage: Boolean = false

/**
* Sets the position of the flow area.
Expand All @@ -36,6 +37,13 @@ class AreaBuilder : DocumentContentBuilderBase<AreaBuilder> {
*/
fun interactiveFlowName(interactiveFlowName: String) = apply { this.interactiveFlowName = interactiveFlowName }

/**
* Set whether the flow area should flow to the next page.
* @param flowToNextPage Whether the flow area should flow to the next page. Default is false.
* @return The [AreaBuilder] instance for method chaining.
*/
fun flowToNextPage(flowToNextPage: Boolean) = apply { this.flowToNextPage = flowToNextPage }

/**
* Builds the [Area] instance.
* @return The constructed [Area] instance.
Expand All @@ -45,6 +53,7 @@ class AreaBuilder : DocumentContentBuilderBase<AreaBuilder> {
content = content,
position = position,
interactiveFlowName = interactiveFlowName,
flowToNextPage = flowToNextPage,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.quadient.migration.api.dto.migrationmodel
import com.quadient.migration.persistence.migrationmodel.AreaEntity
import com.quadient.migration.shared.Position

data class Area(var content: List<DocumentContent>, var position: Position?, var interactiveFlowName: String?) :
data class Area(var content: List<DocumentContent>, var position: Position?, var interactiveFlowName: String?, var flowToNextPage: Boolean = false) :
DocumentContent, RefValidatable {
override fun collectRefs(): List<Ref> {
return content.flatMap {
Expand All @@ -16,9 +16,9 @@ data class Area(var content: List<DocumentContent>, var position: Position?, var

companion object {
fun fromDb(entity: AreaEntity): Area = Area(
entity.content.map { DocumentContent.fromDbContent(it) }, entity.position, entity.interactiveFlowName
entity.content.map { DocumentContent.fromDbContent(it) }, entity.position, entity.interactiveFlowName, entity.flowToNextPage
)
}

fun toDb() = AreaEntity(content.toDb(), position, interactiveFlowName)
fun toDb() = AreaEntity(content.toDb(), position, interactiveFlowName, flowToNextPage)
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MappingRepository(

fun getAreaMapping(id: String): MappingItem.Area {
return (internalRepository.find<MappingItemEntity.Area>(id) ?: MappingItemEntity.Area(
name = null, areas = mutableMapOf()
name = null, areas = mutableMapOf(), flowToNextPage = mutableMapOf()
)).toDto() as MappingItem.Area
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ data class ParagraphEntity(

@Serializable
data class AreaEntity(
val content: List<DocumentContentEntity>, val position: Position?, val interactiveFlowName: String?
val content: List<DocumentContentEntity>, val position: Position?, val interactiveFlowName: String?, val flowToNextPage: Boolean = false
) : DocumentContentEntity
Loading