Skip to content

Commit

Permalink
#2386 - Bulk Asset Import Overwrites Existing Folder Titles (#2387)
Browse files Browse the repository at this point in the history
* Added option to not overwrite the destination folder title when creating the folder hierarchy.
* Added tests.
  • Loading branch information
rbotha78 authored Aug 5, 2020
1 parent 3a7a2b5 commit e121a02
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
- #2316 - @ChildResourceFromRequest uses incomplete request wrapper
- #2383 - [trivial] fix exception message in MarketoFieldDataSource
- #2384 - Fix resource service manager NPEs when service content nodes are missing
- #2386 - Make folder titles overwrite optional for asset ingestor

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public AssetIngestor(MimeTypeService mimeTypeService) {
options = "checked"
)
boolean preserveFileName = true;
@FormField(
name = "Preserve Folder Titles",
description = "If checked, existing folder titles will not be changed.",
component = CheckboxComponent.class,
options = "checked"
)
boolean preserveFolderTitles = true;

@FormField(
name = "Target JCR Folder",
Expand Down Expand Up @@ -388,12 +395,12 @@ protected boolean createFolderNode(HierarchicalElement el, ResourceResolver r) t
&& folderContentNode.hasProperty(JcrConstants.JCR_TITLE)
&& folderContentNode.getProperty(JcrConstants.JCR_TITLE).getString().equals(name))) {
return false;
} else {
} else if (!preserveFolderTitles) {
setFolderTitle(folderNode, name);
r.commit();
r.refresh();
return true;
}
return true;
} else {
HierarchicalElement parent = el.getParent();
String parentPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ public void testImportFile() throws IOException, RepositoryException {
assertEquals(1, importProcess.getCount(importProcess.createdFolders));
}

@Test
public void testFolderTitlePreserve() throws IOException, RepositoryException {
context.load().json("/com/adobe/acs/commons/mcp/impl/processes/asset-ingestor.json", "/content/dam/testfolder");
importProcess.init();
importProcess.preserveFolderTitles = true;
URL testImg = getClass().getResource("/img/test.png");
addImportRow(testImg.toString(), "/content/dam/testfolder/test");
addImportRow(testImg.toString(), "/content/dam/testfolder/test", "rendition", "test.png");
importProcess.files = importProcess.extractFilesAndFolders(importProcess.fileData.getDataRowsAsCompositeVariants());
importProcess.createFolders(actionManager);
assertEquals(1, importProcess.getCount(importProcess.createdFolders));
context.currentResource("/content/dam/testfolder/jcr:content");
ValueMap vm = context.currentResource().getValueMap();
assertEquals("Test Folder", vm.get("jcr:title"));
}

@Test
public void testFolderNoTitlePreserve() throws IOException, RepositoryException {
context.load().json("/com/adobe/acs/commons/mcp/impl/processes/asset-ingestor.json", "/content/dam/testfolder");
importProcess.init();
importProcess.preserveFolderTitles = false;
URL testImg = getClass().getResource("/img/test.png");
addImportRow(testImg.toString(), "/content/dam/testfolder/test");
addImportRow(testImg.toString(), "/content/dam/testfolder/test", "rendition", "test.png");
importProcess.files = importProcess.extractFilesAndFolders(importProcess.fileData.getDataRowsAsCompositeVariants());
importProcess.createFolders(actionManager);
assertEquals(1, importProcess.getCount(importProcess.createdFolders));
context.currentResource("/content/dam/testfolder/jcr:content");
ValueMap vm = context.currentResource().getValueMap();
assertEquals("testfolder", vm.get("jcr:title"));
}

@Test
public void testImportFile404() throws IOException, RepositoryException {
importProcess.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jcr:primaryType": "sling:Folder",
"jcr:createdBy": "admin",
"jcr:created": "Wed Aug 05 2020 14:22:27 GMT+0100",
"jcr:content": {
"jcr:primaryType": "nt:unstructured",
"jcr:title": "Test Folder",
"sourcing": "false"
}
}

0 comments on commit e121a02

Please sign in to comment.