Build package programmatically

Avatar

Avatar

ronnyfm

Avatar

ronnyfm

ronnyfm

02-01-2017

Hello,

I am able to assemble a package using the JcrPackageManager assemble method, however in the package manager I get the package definition and the filters, but the package itself needs to be built. I am sure there should be a way, since it is possible via the HTTP interface using curl.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

ronnyfm

Avatar

ronnyfm

ronnyfm

03-01-2017

Found the issue, I was calling:

assemble(JcrPackageDefinition definition, ProgressTrackerListener listener, java.io.OutputStream out)

But that writes the file to the output stream requiring therefore an additional build step. The solution was to invoke:

assemble(JcrPackage pack, ProgressTrackerListener listener)

Thanks all for your time.

Answers (10)

Answers (10)

Avatar

Avatar

Runal_Trivedi

MVP

Avatar

Runal_Trivedi

MVP

Runal_Trivedi
MVP

02-01-2017

Here is what you need to do:

  • Get  com.day.jcr.vault.packaging.Packaging reference injection in your service.
    • Packaging API will get you access to JCRPackageManager i.e. - packaging.getPackageManager(session);
  • Now using PackageManager you can set conflict resolution policy, package name, group, version and package filters.

Below is the sample code:

final JcrPackageManager jcrPackageManager = packaging.getPackageManager(session); if (ConflictResolution.Replace.equals(conflictResolution)) { this.removePackage(jcrPackageManager, groupName, name, version); } else if (ConflictResolution.IncrementVersion.equals(conflictResolution)) { version = this.getNextVersion(jcrPackageManager, groupName, name, version).toString(); } final JcrPackage jcrPackage = jcrPackageManager.create(groupName, name, version); final JcrPackageDefinition jcrPackageDefinition = jcrPackage.getDefinition(); final DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter(); for (final PathFilterSet pathFilterSet : pathFilterSets) { workspaceFilter.add(pathFilterSet); } jcrPackageDefinition.setFilter(workspaceFilter, true); for (final Map.Entry<String, String> entry : packageDefinitionProperties.entrySet()) { jcrPackageDefinition.set(entry.getKey(), entry.getValue(), false); } session.save(); ProgressTrackerListener listener = new DefaultProgressListener(); try { jcrPackageManager.assemble(jcrPackage,listener); } catch (PackageException e) { e.printStackTrace(); }

 

jcrPackageManager.assemble(jcrPackage,listener);  is the method that build the package based on filter paths. You can also have a listener that will listen to package creation events and do further processing once package is created/built.

You will deal with following APIs when going the programmatic route for package creation.

com.day.cq.commons.jcr.JcrUtil com.day.jcr.vault.fs.api.PathFilterSet com.day.jcr.vault.fs.api.ProgressTrackerListener com.day.jcr.vault.fs.config.DefaultWorkspaceFilter com.day.jcr.vault.fs.io.ImportOptions com.day.jcr.vault.packaging.JcrPackage com.day.jcr.vault.packaging.JcrPackageDefinition com.day.jcr.vault.packaging.JcrPackageManager com.day.jcr.vault.packaging.PackageException com.day.jcr.vault.packaging.PackageId com.day.jcr.vault.packaging.Packaging com.day.jcr.vault.packaging.Version com.day.jcr.vault.util.DefaultProgressListener

 

Hope this helps.

- Runal

Avatar

Avatar

Maheswarareddy_Koppala

Avatar

Maheswarareddy_Koppala

Maheswarareddy_Koppala

13-07-2020

Hello,

JcrPackageManager.create will creates the package. You need to pass packagegroupname and packagename  as the parameters for create method.
Hope this helps.

Regards,

Mahi

Avatar

Avatar

ronnyfm

Avatar

ronnyfm

ronnyfm

02-01-2017

Thank you, I know how to do it with curl, but I want to know how to do it with the Packaging API.

Avatar

Avatar

ronnyfm

Avatar

ronnyfm

ronnyfm

02-01-2017

Thanks, that is what I said, I am invoking assemble, but the package needs to be build either manually or via curl. I get the same result that appears for example in this image  found in this article: https://helpx.adobe.com/experience-manager/using/dynamic_aem_packages.html

Package definition is OK, but still needs to be built. I want to know how to code that, not via curl, in order to have the package ready to download.

Avatar

Avatar

ankurk67503819

Avatar

ankurk67503819

ankurk67503819

02-01-2017

ronnyfm wrote...

Hello,

I am able to assemble a package using the JcrPackageManager assemble method, however in the package manager I get the package definition and the filters, but the package itself needs to be built. I am sure there should be a way, since it is possible via the HTTP interface using curl.

Thanks.

 

Hi,

 

Refer below url-

http://aemtips.blogspot.co.nz/2013/05/some-of-common-curl-commands-to-work.html

Regards

Ankur

Avatar

Avatar

smacdonald2008

Total Posts

(val/1000)?string[".0"]}K

Likes

(val/1000)?string[".0"]}K

Correct Answer

(val/1000)?string[".0"]}K

Avatar

smacdonald2008

Total Posts

(val/1000)?string[".0"]}K

Likes

(val/1000)?string[".0"]}K

Correct Answer

(val/1000)?string[".0"]}K
smacdonald2008

02-01-2017

I will double check with the team tomorrow - however - i believe they did mention in past you still needed to manually build.

Avatar

Avatar

ronnyfm

Avatar

ronnyfm

ronnyfm

02-01-2017

Exactly, I forgot to mention that I did check documentation but I didn't found a method there, still, there should be a such API functionality that builds packages.

Avatar

Avatar

smacdonald2008

Total Posts

(val/1000)?string[".0"]}K

Likes

(val/1000)?string[".0"]}K

Correct Answer

(val/1000)?string[".0"]}K

Avatar

smacdonald2008

Total Posts

(val/1000)?string[".0"]}K

Likes

(val/1000)?string[".0"]}K

Correct Answer

(val/1000)?string[".0"]}K
smacdonald2008

02-01-2017

Also - check this article and the ACS-Commons code on which it is based - it may help: 

https://helpx.adobe.com/experience-manager/using/dynamic_aem_packages.html

Avatar

Avatar

smacdonald2008

Total Posts

(val/1000)?string[".0"]}K

Likes

(val/1000)?string[".0"]}K

Correct Answer

(val/1000)?string[".0"]}K

Avatar

smacdonald2008

Total Posts

(val/1000)?string[".0"]}K

Likes

(val/1000)?string[".0"]}K

Correct Answer

(val/1000)?string[".0"]}K
smacdonald2008

02-01-2017

Looking at the Javadoc - it does not appear that there is a method of to build -- 

https://docs.adobe.com/docs/en/cq/5-5/javadoc/com/day/jcr/vault/packaging/JcrPackageManager.html

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

(val/1000)?string[".0"]}K

Likes

955

Correct Answer

(val/1000)?string[".0"]}K

Avatar

kautuk_sahni

Community Manager

Total Posts

(val/1000)?string[".0"]}K

Likes

955

Correct Answer

(val/1000)?string[".0"]}K
kautuk_sahni
Community Manager

02-01-2017

See this :- https://gist.github.com/mak18ah/b695beef449e0f29c802  (Not tested)

// package manager example

You may also use Java API to manage packages. Start with this OSGi service: com.day.jcr.vault.packaging.Packaging.

~kautuk