vrijdag 22 augustus 2014

Getting the Alfresco version number programmatically

When you create an add-on to Alfresco you often want to ensure compatibility with multiple versions of Alfresco. To do this it is useful to have access to the version number of the current Alfresco server.

Here are three ways:

JavaScript

In server-side JavaScript you can use the server object.

server.version
server.versionMajor
server.versionMinor
server.versionRevision
server.edition

Java

In Java code you need to call the DescriptorService. This rarely used service allows you to access three descriptors

  1. descriptorService.getCurrentRepositoryDescriptor()
    The current repository descriptor. This information is stored in a hidden node inside the repository.
  2. descriptorService.getServerDescriptor()
    The server descriptor: this is the version of the software currently running. This should match the version of the current repository except during an upgrade.
  3. descriptorService.getInstalledRepositoryDescriptor()
    The installed Repository Descriptor: this is the version information of the repository when it was first installed, also stored as a hidden node in the repository.

The Descriptor object returned by these methods allows you to access the version number (major, minor and revision), edition (community or enterprise) and database schema version.

REST API

The third way is using the Alfresco REST API. This is needed for client applications not running inside Alfresco. Also JavaScript running in the browser as part of Share or a third-party web application can use this.

The endpoint to call is

http://<host>:<port>/alfresco/api/server

or via the Share proxy

http://<host>:<port>/share/proxy/alfresco/api/server

This returns a JSON object containing the version number, edition and schema version


{
   data: {
      edition: "Enterprise",
      version: "5.0.0",
      schema: "8002"
   }
}

Geen opmerkingen:

Een reactie posten