Downloading and loading SDKs

An eForms application reads the files of the eForms SDK: fields, codelists, notice types, view templates and validation rules. It needs the files of every SDK version that its notices use, and the Publications Office publishes new versions regularly.

You could include one version of the SDK in your application. Your application could then read only the notices of that version, and each new SDK version would need a new release of your application. Instead, the library downloads a version the first time your application needs it, from Maven Central, where the Publications Office publishes the SDK. It keeps each version in its own folder on disk, and gives you the path to any of its files.

Downloading an SDK

The class SdkDownloader downloads a version of the SDK and unpacks it into a folder:

SdkDownloader.downloadSdk(new SdkVersion("2.0"), Path.of("eforms-sdk"));

The SDK is published on Maven Central as eu.europa.ted.eforms:eforms-sdk. The library downloads it in the same way as Maven does, unpacks it into a subfolder named after the version, here eforms-sdk/2.0, and records the exact version in the file VERSION of that subfolder. Without a folder, the library uses the folder eforms-sdk in the working directory.

The version that you give decides which version is downloaded:

  • A version with a patch number, such as 1.16.0 or 2.0.0-alpha.6, gives exactly that version. Its folder is named after the full version, for example eforms-sdk/2.0.0-alpha.6.

  • A version without a patch number, such as 1.16, gives the latest patch of that minor version. Its folder is named after the minor version, for example eforms-sdk/1.16.

A patch version of the SDK only corrects the previous one. This is why an application usually gives the minor version, and lets the library take the latest patch.

For a minor version, the library takes the latest release. It takes a pre-release, such as 2.0.0-alpha.6, only when that minor version has no release yet. Snapshot versions are taken only when you ask for them, with true as the third argument, and only from repositories that publish them (see Where the library downloads from).

When the folder already holds the version to download, the library does not download it again. Otherwise it deletes the folder and unpacks the new version into it. Keep nothing of your own in these folders.

Where the library downloads from

The library uses the Maven settings for the repositories, the logins and the proxies, as the Maven command line does, within the limits below.

The settings file

The first file that exists among:

  1. the file named by the Java system property M2_SETTINGS;

  2. .m2/settings.xml in the folder named by -Duser.home in the environment variable MAVEN_OPTS;

  3. .m2/settings.xml in your home folder;

  4. conf/settings.xml in the folder named by the environment variable M2_HOME.

    Without a settings file, the library uses Maven Central.

Repositories

The library downloads from the repositories of the profiles that are active in the settings: the profiles listed under <activeProfiles>, and the profiles marked <activeByDefault>. Other ways of activating a profile, such as by operating system or by property, are not taken into account. Without any such repository, the library uses Maven Central. When your profiles list repositories, Maven Central is not added: list it in a profile too. The library does not use the <mirrors> of the settings: to download through a mirror, list its address as a repository in an active profile.

Logins and proxies

For a repository that needs a login, the library uses the <server> with the same identifier. Encrypted passwords are decrypted with the file .m2/settings-security.xml in your home folder, as the Maven command line does. The library uses the proxies of the settings that are active.

Local repository

The library keeps the downloaded packages in a local repository, as Maven does: the folder named by the Java system property M2_LOCAL_REPO, otherwise the <localRepository> of the settings, otherwise .m2/repository in your home folder. When <offline> is true in the settings, the library uses only this local repository.

Loading a file of an SDK

The class SdkResourceLoader gives the path of a file of an SDK version that you have downloaded:

Path sdkRoot = Path.of("eforms-sdk");

Path noticeTypes = SdkResourceLoader.getResourceAsPath("2.0", SdkResource.NOTICE_TYPES_JSON, sdkRoot);

try (InputStream viewTemplate =
    SdkResourceLoader.getResourceAsStream("2.0", SdkResource.VIEW_TEMPLATES, "16.efx", sdkRoot)) {
  // read the view template of notice subtype 16
}

The version chooses the folder in the same way as for the download: 2.0 reads eforms-sdk/2.0, and 2.0.0-alpha.6 reads eforms-sdk/2.0.0-alpha.6. Use the same version for both. When the file does not exist, the method throws an IllegalArgumentException.

The enumeration SdkConstants.SdkResource names the folders and the files of the SDK, such as CODELISTS, NOTICE_TYPES_JSON, SCHEMAS_MAINDOC, TRANSLATIONS, VALIDATION_RULES_EFX and VIEW_TEMPLATES. A folder takes the name of a file inside it as third argument; without a resource, the method gives the folder of the SDK itself.

Some files differ between the major versions of the SDK. SDK 1 describes its fields and nodes in fields/fields.json (FIELDS_JSON). SDK 2 describes them in fields/fwd/fields.json (FIELDS_FWD_FIELDS_JSON) and fields/fwd/nodes.json (FIELDS_FWD_NODES_JSON). You do not need to choose: the library reads the right files for you (see Reading the SDK metadata).

SDK versions

The class SdkVersion reads a version number, with or without its patch number, and compares versions:

SdkVersion version = new SdkVersion("eforms-sdk-2.0.0-alpha.6");

version.getMajor();             // "2"
version.toStringWithoutPatch(); // "2.0"
version.isPreRelease();         // true
boolean newer = version.compareTo(new SdkVersion("1.16.0")) > 0; // true

The prefix eforms-sdk-, which notices use in the element cbc:CustomizationID, is removed. A version needs at least a major and a minor number. A version without a patch number has the patch number 0 (getPatch()).