Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Programatically creating Package using Jcrpackagemanager by translating path

Avatar

Level 2

Hi,

 

I want to programatically create package & translate the path in created package. For example '/content/dam/abc/hero.png' needs to be '/content/dam/bcd/hero.png'. Is it possible to do this using Jcrpackage manager api with filter/translate options? I tried below code but it is not working.

 

JcrPackageManager jcrPackageManager = packaging.getPackageManager(request.getResourceResolver().adaptTo(Session.class));
JcrPackage jcrPackage = jcrPackageManager.create("my_packages", "translatedpackage","1.0");
JcrPackageDefinition definition = jcrPackage.getDefinition();

DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
filter.translate(new SimplePathMapping("/content/dam/abc/", "/bcd/"));
PathFilterSet pathFilterSet = new PathFilterSet();
pathFilterSet.setRoot("/content/dam/abc/hero.png");
definition.setFilter(filter,true);
ProgressTrackerListener listener = new DefaultProgressListener();
jcrPackageManager.assemble(jcrPackage, listener);

 

I was expecting output package to have translated path but it is not working. Any suggestions?

3 Replies

Avatar

Community Advisor

You would need to run "translations" project on the particular DAM folder path. Then after, you can create content packages. Programmatically create AEM Translation Projects | by Vishal | Medium

Avatar

Community Advisor

Hi @AEMProfile ,

since the created package is not yet built I am thinking that's the reason why it isn't able to hold the filters. Try this way:

1. get a built package through package manager API,

2. get the filters' list List<PathFilterSet> getFilterSets().

3. perform the usual collections List and string operations to change the filter paths and proceed to package it.

later you can add any listeners to automate this if needed.

-Sravan

Avatar

Level 2

Hi @B_Sravan I tried with existing package but no luck, it does not translate while export. I can only translate while importing.