Expand my Community achievements bar.

SOLVED

code to build a jcr package

Avatar

Level 2

Tried with :    

private void doPackaging(List<String> pagePaths) throws IOException, JSONException, RepositoryException, LoginException {
        List<org.apache.jackrabbit.vault.fs.api.PathFilterSet> pathFilterSets = new ArrayList<org.apache.jackrabbit.vault.fs.api.PathFilterSet>();
        final Map<String, String> packageDefinitionProperties = new HashMap<String, String>();
        // ACL Handling
        packageDefinitionProperties.put(JcrPackageDefinition.PN_AC_HANDLING,
                AccessControlHandling.OVERWRITE.toString());
        // Package Description
        packageDefinitionProperties.put(
                JcrPackageDefinition.PN_DESCRIPTION,
                "package" + new Date().getTime());
        final JcrPackage jcrPackage = packageHelper.createPackageForPaths(pagePaths,
                resourceResolverFactory.getAdministrativeResourceResolver(null).adaptTo(Session.class),
                "PackageGroup",
                "PackageName",
                "1.0.0",
                PackageHelper.ConflictResolution.valueOf(PackageHelper.ConflictResolution.IncrementVersion.toString()),
                packageDefinitionProperties
        );
        try {
            ProgressTrackerListener listener = new DefaultProgressListener();
            JcrPackageManager jcrPackageManager =        packaging.getPackageManager(resourceResolverFactory.getAdministrativeResourceResolver(null).adaptTo(Session.class));
            jcrPackageManager.assemble(jcrPackage, listener);

            
        } catch (Exception e) {
            log.error("ErrorHere : "+e.getMessage());
        }

        log.debug("Successfully created JCR package");
    }

Error : 
ErrorHere : JcrFS is not mounted anymore."

Any suggestions ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

This code will work:

public JcrPackage buildPackage()
  {
    JcrPackage jcrPackage = null;
    
    try
    {
      Packaging packaging  = // GET the Packaging service reference
      JcrPackageManager  m_jcrPkgMgr = packaging.getPackageManager(session); // You need a session here. You can pass the session to this method or you can use system user to get the session. Make sure this user hams permissions to create the package under /etc/packages.


      jcrPackage = m_jcrPkgMgr.create("my_packages", 
                                      "testpkg", 
                                      "1");
      
      JcrPackageDefinition jcrPackageDefinition = jcrPackage.getDefinition();
      
      DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
      
      workspaceFilter.add(new PathFilterSet("/content/geometrixx-media/en"));
      workspaceFilter.add(new PathFilterSet("/content/geometrixx/en/company");
      
      boolean autoSave = true;
      jcrPackageDefinition.setFilter(workspaceFilter, autoSave);

      ProgressTrackerListener listener = new DefaultProgressListener();
      m_jcrPkgMgr.assemble(jcrPackage, listener);
    }
    catch(Exception e)
    {
      
      // Catch exception here
    }
      
    return jcrPackage;
    
  } 

View solution in original post

5 Replies

Avatar

Level 10

Hi Phani,

Did you tried this below approach, it may help your use case:

Creating Adobe Experience Manager Packages using the JcrPackageManager.API
//https://helpx.adobe.com/experience-manager/using/dynamic_aem_packages.html

~ Ratna.

Avatar

Level 2

Yes , already tried it.

It’s just creating the package but not building it.

Avatar

Level 9

Hi,

Error indicates the attached session is not live. Is it happening intermediately when you build a large content?

Thanks,

Avatar

Level 4

Hi, Phani

Hope this Helps...

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

And, try avoiding getAdministrativeResourceResolver. Instead use getServiceResourceResolver. 

I've been facing issues previously with session while handling huge number of nodes. Try this and see. 

Thanks! 

Avatar

Correct answer by
Community Advisor

This code will work:

public JcrPackage buildPackage()
  {
    JcrPackage jcrPackage = null;
    
    try
    {
      Packaging packaging  = // GET the Packaging service reference
      JcrPackageManager  m_jcrPkgMgr = packaging.getPackageManager(session); // You need a session here. You can pass the session to this method or you can use system user to get the session. Make sure this user hams permissions to create the package under /etc/packages.


      jcrPackage = m_jcrPkgMgr.create("my_packages", 
                                      "testpkg", 
                                      "1");
      
      JcrPackageDefinition jcrPackageDefinition = jcrPackage.getDefinition();
      
      DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
      
      workspaceFilter.add(new PathFilterSet("/content/geometrixx-media/en"));
      workspaceFilter.add(new PathFilterSet("/content/geometrixx/en/company");
      
      boolean autoSave = true;
      jcrPackageDefinition.setFilter(workspaceFilter, autoSave);

      ProgressTrackerListener listener = new DefaultProgressListener();
      m_jcrPkgMgr.assemble(jcrPackage, listener);
    }
    catch(Exception e)
    {
      
      // Catch exception here
    }
      
    return jcrPackage;
    
  }