Comparing Adobe-Consulting-Services/acs-aem-commons 342f3ea..19d8693
View on GitHub4 changed files
with 28 additions
and 24 deletions.
+1•CHANGELOG.md
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
- #1552 - Ensure Authorizable - trim OSGi config array element whitespace for EnsureServiceUser aces property
- #1551 - ThrottledTaskRunner avoid overflow errors when comparing priority with large absolute (negative or positive) values
- #1593 - Sftp Asset Injector throws URISyntaxException if item contains special characters
- #1598 - Asset Ingestor | If user provides invalid info, nothing is happens. Erorr in report is expected
- #1597 - If 'Preserve Filename' unchecked, asset name will support only the following characters: letters, digits, hyphens, underscores, another chars will be replaced with hyphens
### Changed
+1, -3•bundle/src/main/java/com/adobe/acs/commons/mcp/impl/processes/asset/AssetIngestor.java
@@ -261,9 +261,7 @@ public abstract class AssetIngestor extends ProcessDefinition {
}
Asset asset = assetManager.createAsset(assetPath, source.getStream(), type, false);
if (asset == null) {
throw new RepositoryException("Could not create asset, see more in logs.");
} else {
if (asset != null) {
saveMigrationInfo(source, asset);
}
+19, -14•bundle/src/main/java/com/adobe/acs/commons/mcp/impl/processes/asset/FileAssetIngestor.java
@@ -99,31 +99,36 @@ public class FileAssetIngestor extends AssetIngestor {
HierarchicalElement baseFolder;
@Override
public void init() throws RepositoryException {
if (fileBasePath.toLowerCase().startsWith("sftp://")) {
public void buildProcess(ProcessInstance instance, ResourceResolver rr) throws LoginException, RepositoryException {
baseFolder = getBaseFolder(fileBasePath);
instance.getInfo().setDescription(fileBasePath + "->" + jcrBasePath);
instance.defineCriticalAction("Create Folders", rr, this::createFolders);
instance.defineCriticalAction("Import Assets", rr, this::importAssets);
}
HierarchicalElement getBaseFolder(final String url) throws RepositoryException {
HierarchicalElement baseHierarchicalElement;
if (url.toLowerCase().startsWith("sftp://")) {
try {
baseFolder = new SftpHierarchicalElement(fileBasePath);
baseFolder.isFolder(); // Forces a login and check status of base folder
baseHierarchicalElement = new SftpHierarchicalElement(url);
// Forces a login
((SftpHierarchicalElement) baseHierarchicalElement).retrieveDetails();
} catch (URISyntaxException | UnsupportedEncodingException ex) {
Logger.getLogger(FileAssetIngestor.class.getName()).log(Level.SEVERE, null, ex);
throw new RepositoryException("Unable to process URL!");
} catch (JSchException | SftpException ex) {
Logger.getLogger(FileAssetIngestor.class.getName()).log(Level.SEVERE, null, ex);
throw new RepositoryException(ex.getMessage());
}
} else {
File base = new File(fileBasePath);
File base = new File(url);
if (!base.exists()) {
throw new RepositoryException("Source folder does not exist!");
}
baseFolder = new FileHierarchicalElement(base);
baseHierarchicalElement = new FileHierarchicalElement(base);
}
super.init();
}
@Override
public void buildProcess(ProcessInstance instance, ResourceResolver rr) throws LoginException, RepositoryException {
instance.getInfo().setDescription(fileBasePath + "->" + jcrBasePath);
instance.defineCriticalAction("Create Folders", rr, this::createFolders);
instance.defineCriticalAction("Import Assets", rr, this::importAssets);
return baseHierarchicalElement;
}
void createFolders(ActionManager manager) throws IOException {
+7, -7•bundle/src/test/java/com/adobe/acs/commons/mcp/impl/processes/asset/FileAssetIngestorTest.java
@@ -131,7 +131,7 @@ public class FileAssetIngestorTest {
@Test
public void testCreateFoldersWithEmptyDirectory() throws Exception {
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
ingestor.createFolders(actionManager);
assertFalse(context.resourceResolver().hasChanges());
@@ -140,7 +140,7 @@ public class FileAssetIngestorTest {
@Test
public void testCreateFolders() throws Exception {
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
addFile(tempDirectory, "image.png", "/img/test.png");
File folder1 = mkdir(tempDirectory, "folder1");
addFile(folder1, "image.png", "/img/test.png");
@@ -166,7 +166,7 @@ public class FileAssetIngestorTest {
@Test
public void testImportAssetsWithEmptyDirectory() throws Exception {
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
ingestor.importAssets(actionManager);
assertFalse(context.resourceResolver().hasChanges());
@@ -180,7 +180,7 @@ public class FileAssetIngestorTest {
@Test
public void testImportAssetsWithDirectoryContainingJustFolders() throws Exception {
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
mkdir(tempDirectory, "folder1");
mkdir(mkdir(tempDirectory, "folder2"), "folder3");
@@ -197,7 +197,7 @@ public class FileAssetIngestorTest {
@Test
public void testImportAssets() throws Exception {
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
final File rootImage = addFile(tempDirectory, "image.png", "/img/test.png");
final File folder1 = mkdir(tempDirectory, "folder1");
final File folder1Image = addFile(folder1, "image.png", "/img/test.png");
@@ -224,7 +224,7 @@ public class FileAssetIngestorTest {
@Test
public void testImportAssetsToNewRootFolder() throws Exception {
ingestor.jcrBasePath = "/content/dam/test";
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
final File rootImage = addFile(tempDirectory, "image.png", "/img/test.png");
ingestor.importAssets(actionManager);
@@ -247,7 +247,7 @@ public class FileAssetIngestorTest {
@Test
public void testImportAssetsToExistingRootFolder() throws Exception {
ingestor.jcrBasePath = "/content/dam/test";
ingestor.init();
ingestor.baseFolder = ingestor.getBaseFolder(ingestor.fileBasePath);
context.create().resource("/content/dam/test", "jcr:primaryType", "sling:Folder", "jcr:title", "testTitle");
final File rootImage = addFile(tempDirectory, "image.png", "/img/test.png");