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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void run(Migration migration, Path attachmentsDstPath) {
attachmentsDstPath.toFile().createParentDirectories()

attachmentsDstPath.toFile().withWriter { writer ->
def headers = ["id", "name", "sourcePath", "attachmentType", "targetFolder", "status", "skip", "skipPlaceholder", "skipReason", Mapping.displayHeader("originalName", true), Mapping.displayHeader("originLocations", true)]
def headers = ["id", "name", "sourcePath", "attachmentType", "targetFolder", "targetImageId", "status", "skip", "skipPlaceholder", "skipReason", Mapping.displayHeader("originalName", true), Mapping.displayHeader("originLocations", true)]
writer.writeLine(headers.join(","))
attachments.each { obj ->
def status = migration.statusTrackingRepository.findLastEventRelevantToOutput(obj.id,
Expand All @@ -40,6 +40,7 @@ static void run(Migration migration, Path attachmentsDstPath) {
builder.append("," + Csv.serialize(obj.sourcePath))
builder.append("," + Csv.serialize(obj.attachmentType))
builder.append("," + Csv.serialize(obj.targetFolder))
builder.append("," + Csv.serialize(obj.targetImageId))
builder.append("," + Csv.serialize(status.class.simpleName))
builder.append("," + Csv.serialize(obj.skip.skipped))
builder.append("," + Csv.serialize(obj.skip.placeholder))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ static void run(Migration migration, Path attachmentsFilePath) {
def newTargetFolder = Csv.deserialize(values.get("targetFolder"), String.class)
Mapping.mapProp(existingMapping, existingAttachment, "targetFolder", newTargetFolder)

def newTargetImageId = Csv.deserialize(values.get("targetImageId"), String.class)
Mapping.mapProp(existingMapping, existingAttachment, "targetImageId", newTargetImageId)

def csvStatus = values.get("status")
if (status != null && csvStatus == "Active" && status.class.simpleName != "Active") {
migration.statusTrackingRepository.active(existingAttachment.id, ResourceType.Attachment, [reason: "Manual"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void run(Migration migration, Path imagesDstPath) {
imagesDstPath.toFile().createParentDirectories()

imagesDstPath.toFile().withWriter { writer ->
def headers = ["id", "name", "sourcePath", "imageType", "targetFolder", "alternateText", "status", "skip", "skipPlaceholder", "skipReason", Mapping.displayHeader("originalName", true), Mapping.displayHeader("originLocations", true)]
def headers = ["id", "name", "sourcePath", "imageType", "targetFolder", "alternateText", "targetAttachmentId", "status", "skip", "skipPlaceholder", "skipReason", Mapping.displayHeader("originalName", true), Mapping.displayHeader("originLocations", true)]
writer.writeLine(headers.join(","))
images.each { obj ->
def status = migration.statusTrackingRepository.findLastEventRelevantToOutput(obj.id,
Expand All @@ -41,6 +41,7 @@ static void run(Migration migration, Path imagesDstPath) {
builder.append("," + Csv.serialize(obj.imageType))
builder.append("," + Csv.serialize(obj.targetFolder))
builder.append("," + Csv.serialize(obj.alternateText))
builder.append("," + Csv.serialize(obj.targetAttachmentId))
builder.append("," + Csv.serialize(status.class.simpleName))
builder.append("," + Csv.serialize(obj.skip.skipped))
builder.append("," + Csv.serialize(obj.skip.placeholder))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ static void run(Migration migration, Path imagesFilePath) {
def newAlternateText = Csv.deserialize(values.get("alternateText"), String.class)
Mapping.mapProp(existingMapping, existingImage, "alternateText", newAlternateText)

def newTargetAttachmentId = Csv.deserialize(values.get("targetAttachmentId"), String.class)
Mapping.mapProp(existingMapping, existingImage, "targetAttachmentId", newTargetAttachmentId)

def csvStatus = values.get("status")
if (status != null && csvStatus == "Active" && status.class.simpleName != "Active") {
migration.statusTrackingRepository.active(existingImage.id, ResourceType.Image, [reason: "Manual"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ class AttachmentsMappingExportTest {
def migration = Utils.mockMigration()

when(migration.attachmentRepository.listAll()).thenReturn([
new Attachment("empty", null, [], new CustomFieldMap([:]), null, null, AttachmentType.Document, emptySkipOptions()),
new Attachment("full", "full", ["foo", "bar"], new CustomFieldMap([:]), "sourcePath", "targetDir", AttachmentType.Document, new SkipOptions(true, "placeholder", "reason")),
new Attachment("overridden empty", null, [], new CustomFieldMap([:]), null, null, AttachmentType.Document, emptySkipOptions()),
new Attachment("overridden full", "full", ["foo", "bar"], new CustomFieldMap(["originalName": "originalFull"]), "sourcePath", "targetDir", AttachmentType.Attachment, emptySkipOptions()),
new Attachment("empty", null, [], new CustomFieldMap([:]), null, null, AttachmentType.Document, emptySkipOptions(), null),
new Attachment("full", "full", ["foo", "bar"], new CustomFieldMap([:]), "sourcePath", "targetDir", AttachmentType.Document, new SkipOptions(true, "placeholder", "reason"), null),
new Attachment("with-target-image", "with-target", [], new CustomFieldMap([:]), null, null, AttachmentType.Attachment, emptySkipOptions(), "img456"),
new Attachment("overridden empty", null, [], new CustomFieldMap([:]), null, null, AttachmentType.Document, emptySkipOptions(), null),
new Attachment("overridden full", "full", ["foo", "bar"], new CustomFieldMap(["originalName": "originalFull"]), "sourcePath", "targetDir", AttachmentType.Attachment, emptySkipOptions(), null),
])

when(migration.statusTrackingRepository.findLastEventRelevantToOutput(any(), any(), any())).thenReturn(new Active())

AttachmentsExport.run(migration, mappingFile)

def expected = """\
id,name,sourcePath,attachmentType,targetFolder,status,skip,skipPlaceholder,skipReason,originalName (read-only),originLocations (read-only)
empty,,,Document,,Active,false,,,,[]
full,full,sourcePath,Document,targetDir,Active,true,placeholder,reason,,[foo; bar]
overridden empty,,,Document,,Active,false,,,,[]
overridden full,full,sourcePath,Attachment,targetDir,Active,false,,,originalFull,[foo; bar]
id,name,sourcePath,attachmentType,targetFolder,targetImageId,status,skip,skipPlaceholder,skipReason,originalName (read-only),originLocations (read-only)
empty,,,Document,,,Active,false,,,,[]
full,full,sourcePath,Document,targetDir,,Active,true,placeholder,reason,,[foo; bar]
with-target-image,with-target,,Attachment,,img456,Active,false,,,,[]
overridden empty,,,Document,,,Active,false,,,,[]
overridden full,full,sourcePath,Attachment,targetDir,,Active,false,,,originalFull,[foo; bar]
""".stripIndent()
Assertions.assertEquals(expected, mappingFile.toFile().text.replaceAll("\\r\\n|\\r", "\n"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class AttachmentsMappingImportTest {
def migration = Utils.mockMigration()
Path mappingFile = Paths.get(dir.path, "testProject.csv")
def input = """\
id,name,sourcePath,attachmentType,targetFolder,status,originLocations,skip,skipPlaceholder,skipReason
attachment1,newName,newPath,Attachment,newFolder,Active,[],false,,
attachment2,,,Document,,Active,[],true,placeholder,reason
id,name,sourcePath,attachmentType,targetFolder,targetImageId,status,originLocations,skip,skipPlaceholder,skipReason
attachment1,newName,newPath,Attachment,newFolder,img123,Active,[],false,,
attachment2,,,Document,,,Active,[],true,placeholder,reason
""".stripIndent()
mappingFile.toFile().write(input)

Expand All @@ -33,14 +33,14 @@ class AttachmentsMappingImportTest {

AttachmentsImport.run(migration, mappingFile)

verify(migration.mappingRepository, times(1)).upsert("attachment1", new MappingItem.Attachment("newName", "newFolder", "newPath", AttachmentType.Attachment, new SkipOptions(false, null, null)))
verify(migration.mappingRepository, times(1)).upsert("attachment1", new MappingItem.Attachment("newName", "newFolder", "newPath", AttachmentType.Attachment, new SkipOptions(false, null, null), "img123"))
verify(migration.mappingRepository, times(1)).applyAttachmentMapping("attachment1")
verify(migration.mappingRepository, times(1)).upsert("attachment2", new MappingItem.Attachment(null, null, null, AttachmentType.Document, new SkipOptions(true, "placeholder", "reason")))
verify(migration.mappingRepository, times(1)).upsert("attachment2", new MappingItem.Attachment(null, null, null, AttachmentType.Document, new SkipOptions(true, "placeholder", "reason"), null))
verify(migration.mappingRepository, times(1)).applyAttachmentMapping("attachment2")
}

static void givenExistingAttachment(Migration mig, String id, String name, String targetFolder, String sourcePath, AttachmentType attachmentType) {
when(mig.attachmentRepository.find(id)).thenReturn(new Attachment(id, name, [], new CustomFieldMap([:]), sourcePath, targetFolder, attachmentType, new SkipOptions(false, null, null)))
when(mig.attachmentRepository.find(id)).thenReturn(new Attachment(id, name, [], new CustomFieldMap([:]), sourcePath, targetFolder, attachmentType, new SkipOptions(false, null, null), null))
}

static void givenExistingAttachmentMapping(Migration mig,
Expand All @@ -50,6 +50,6 @@ class AttachmentsMappingImportTest {
String sourcePath,
AttachmentType attachmentType) {
when(mig.mappingRepository.getAttachmentMapping(id))
.thenReturn(new MappingItem.Attachment(name, targetFolder, sourcePath, attachmentType, null))
.thenReturn(new MappingItem.Attachment(name, targetFolder, sourcePath, attachmentType, null, null))
}
}
20 changes: 11 additions & 9 deletions migration-examples/src/test/groovy/ImagesMappingExportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ class ImagesMappingExportTest {
def migration = Utils.mockMigration()

when(migration.imageRepository.listAll()).thenReturn([
new Image("empty", null, [], new CustomFieldMap([:]), null, null, null, null, [:], emptySkipOptions(), null),
new Image("full", "full", ["foo", "bar"], new CustomFieldMap([:]), "sourcePath", null, ImageType.Jpeg, "targetDir", [:], new SkipOptions(true, "placeholder", "reason"), "Alt text for full"),
new Image("overridden empty", null, [], new CustomFieldMap([:]), null, null, null, null, [:], emptySkipOptions(), null),
new Image("overridden full", "full", ["foo", "bar"], new CustomFieldMap(["originalName": "originalFull"]), "sourcePath", null, ImageType.Gif, "targetDir", [:], emptySkipOptions(), "Alt text for overridden"),
new Image("empty", null, [], new CustomFieldMap([:]), null, null, null, null, [:], emptySkipOptions(), null, null),
new Image("full", "full", ["foo", "bar"], new CustomFieldMap([:]), "sourcePath", null, ImageType.Jpeg, "targetDir", [:], new SkipOptions(true, "placeholder", "reason"), "Alt text for full", null),
new Image("with-target-attachment", "with-target", [], new CustomFieldMap([:]), null, null, ImageType.Png, null, [:], emptySkipOptions(), null, "att123"),
new Image("overridden empty", null, [], new CustomFieldMap([:]), null, null, null, null, [:], emptySkipOptions(), null, null),
new Image("overridden full", "full", ["foo", "bar"], new CustomFieldMap(["originalName": "originalFull"]), "sourcePath", null, ImageType.Gif, "targetDir", [:], emptySkipOptions(), "Alt text for overridden", null),
])

when(migration.statusTrackingRepository.findLastEventRelevantToOutput(any(), any(), any())).thenReturn(new Active())

ImagesExport.run(migration, mappingFile)

def expected = """\
id,name,sourcePath,imageType,targetFolder,alternateText,status,skip,skipPlaceholder,skipReason,originalName (read-only),originLocations (read-only)
empty,,,,,,Active,false,,,,[]
full,full,sourcePath,Jpeg,targetDir,Alt text for full,Active,true,placeholder,reason,,[foo; bar]
overridden empty,,,,,,Active,false,,,,[]
overridden full,full,sourcePath,Gif,targetDir,Alt text for overridden,Active,false,,,originalFull,[foo; bar]
id,name,sourcePath,imageType,targetFolder,alternateText,targetAttachmentId,status,skip,skipPlaceholder,skipReason,originalName (read-only),originLocations (read-only)
empty,,,,,,,Active,false,,,,[]
full,full,sourcePath,Jpeg,targetDir,Alt text for full,,Active,true,placeholder,reason,,[foo; bar]
with-target-attachment,with-target,,Png,,,att123,Active,false,,,,[]
overridden empty,,,,,,,Active,false,,,,[]
overridden full,full,sourcePath,Gif,targetDir,Alt text for overridden,,Active,false,,,originalFull,[foo; bar]
""".stripIndent()
Assertions.assertEquals(expected, mappingFile.toFile().text.replaceAll("\\r\\n|\\r", "\n"))
}
Expand Down
Loading