Listing Installed Applications

Enonic version: 7.6.0
OS: Ubuntu 20.04

Hello there!

I have a project in which I intended on listing details from other projects of mine, between these details is the list of installed applications for them, like Content Studio and its version, Data toolbox and etc…

I’m trying to make the same service in each of these projects to feed these info but I’ve been having a rough time trying to get info about the applications specifically.

Is there a way to fetch this information?

I managed to solve my problem, in case anyone ever needs it, here is how I solved it:

function getApps () {
  const apps = []

  const system = repoLib.get('system-repo')
  const systemConnection = nodeLib.connect({
    repoId: system && system.id,
    branch: 'master'
  })
  const appIds = systemConnection && systemConnection.findChildren({
    parentKey: '/applications',
    count: -1
  })
  appIds && appIds.hits && appIds.hits.map(function (id) {
    const app = systemConnection.get({ key: id.id })
    apps.push({
      name: app._name,
      displayName: app.displayName,
      version: app.version,
      installDate: app._ts,
      vendor: app.vendorName
    })
  })

  return apps
}

Hi Julio.

I’m sure there is an API for applications you should use instead. Just wanted to warn you about this approach as how apps are stored etc MAY change across versions of XP.

1 Like

Oh thank you for the warning! I’ll keep on looking for an alternative method then.

Thanks again!

There is no open js api to fetch installed applications, but you can create java handler and call it from your js file.

You will need two classes.

  1. ApplicationHandler.java

     public final class ApplicationHandler implements ScriptBean {
    
         private Supplier<ApplicationService> applicationService;
    
         public List<ApplicationMapper> getInstalledApplications() {
    
             return applicationService.get().getInstalledApplications().stream()
                     .map(ApplicationMapper::new).
                     collect(Collectors.toList());
         }
    
         @Override
         public void initialize( final BeanContext context )
         {
             this.applicationService = context.getService( ApplicationService.class );
         }
     }
    

2)ApplicationMapper.java

public final class ApplicationMapper
    implements MapSerializable
{
    private final Application application;

    public ApplicationMapper(final Application application )
    {
        this.application = application;
    }

    @Override
    public void serialize( final MapGenerator gen )
    {
        gen.value( "name", application.getKey().getName() );
        gen.value( "displayName", application.getDisplayName() );
        gen.value( "version", application.getVersion().toString() );
        gen.value( "vendorName", application.getVendorName() );
        gen.value( "vendorUrl", application.getVendorUrl() );
        //any other fields you need
    }

}

And then you will be able to call it from js like this:

    var appHelper = __.newBean('com.my.package.ApplicationHelper');
    var apps = JSON.stringify(__.toNativeObject(appHelper.getInstalledApplications()));
6 Likes