Reading the SDK metadata

Most of what an eForms application does depends on the metadata of the SDK. To display a value, it needs to know the field: its data type, where it is in the XML, and the codelist of its codes. To build a form, it needs the fields and the nodes that group them. The SDK describes all this in large JSON and Genericode files: a recent SDK has more than 800 fields. Their structure also differs between SDK 1 and SDK 2.

The library reads these files into Java objects, so that your application works with fields and codelists instead of with the files, in the same way for both major versions. It keeps the objects in repositories: maps from identifiers to objects. For example, the repository of the fields maps BT-21-Procedure to an SdkField object that describes this field.

The fields and the nodes

The class SdkRepositoryFactory gives the nodes, the fields and the data types of an SDK version:

String sdkVersion = "2.0";
Path sdkPath = SdkResourceLoader.getResourceAsPath(sdkVersion, null, Path.of("eforms-sdk"));

SdkNodeRepository nodes = SdkRepositoryFactory.getSdkNodeRepository(sdkVersion, sdkPath);
SdkFieldRepository fields = SdkRepositoryFactory.getSdkFieldRepository(sdkVersion, sdkPath, nodes);
SdkDataTypeRepository dataTypes = SdkRepositoryFactory.getSdkDataTypeRepository(sdkVersion, sdkPath);

The factory knows which files each major version of the SDK uses, and reads them for you: fields/fields.json for SDK 1, and fields/fwd/fields.json and fields/fwd/nodes.json for SDK 2. It uses the components for each SDK version for this.

Read the nodes first, and give them to the fields: each field is then linked to the node it belongs to. You can give null instead of the nodes, but then getParentNode() gives null for every field.

SdkField name = fields.get("BT-21-Procedure");

name.getType();               // "text-multilingual"
name.getXpathAbsolute();      // "/*/cac:ProcurementProject/cbc:Name"
name.isRepeatable();          // false
name.getParentNode().getId(); // "ND-ProcedureProcurementScope"

A field gives, among other things:

  • its identifier, its data type, and its XPath, both absolute and relative to its node;

  • whether it repeats, and the node it belongs to;

  • the identifier of its codelist, for a field of type code;

  • the fields of its XML attributes, such as the currency of an amount, and, for an attribute field, the field it belongs to;

  • for a field that can be withheld from publication, its privacy code and the four fields that record a withholding: the privacy code of what is withheld, the reason code, the reason description, and the date of publication.

A node gives its identifier, its XPath, whether it repeats, its parent node, and its ancestry: the identifiers of the node and of all its ancestors up to the root (getAncestry()).

The constructors of SdkFieldRepository and SdkNodeRepository read only the file that you give them. They are deprecated: they cannot read the files of SDK 2 completely. Use the factory.

The differences between SDK 1 and SDK 2

The objects are the same for both major versions, so that most of your code does not need to know which version it reads. Where the SDK versions differ, the library gives the same result in the same way:

  • SDK 1 names the disclosure fields of each withheld field in that field. SDK 2 names them once for all fields. The library gives them to each withheld field in both cases (getPrivacySettings()).

  • SDK 1 uses the type measure for durations. The library gives duration for these fields, which is the type that SDK 2 uses.

  • SDK 1 publishes no data types. The library then gives its own list, in the same format as SDK 2.

Some information exists only in SDK 2, and is empty or null for SDK 1:

Stable identifiers

A stable identifier names the field or the node that plays a particular role, such as disclosureDate. It stays the same throughout a major version of the SDK, while the identifier of the field may change from one minor version to the next. Use it instead of writing the identifier of the field in your code:

String disclosureDateField = fields.getFieldIdByStableId("disclosureDate"); // "BT-198-notice"
Withholding conditions

For a field that is withheld only in some cases, getWithholdingCondition() gives the EFX expression that tells when, and getUndisclosedFieldSelector() the EFX that selects the withheld instances. The library gives the EFX as the SDK writes it; translate it with the EFX Toolkit.

The data types

The data types tell, for each type of field, how the fields of that type are handled:

SdkDataType amount = dataTypes.get("amount");

amount.getPrivacyMask();   // "-1": the value that replaces a withheld amount
amount.getAttributeName(); // "currencyID": the attribute that fields of this type carry

The codelists

The class SdkCodelistRepository gives the codelists of an SDK version, by identifier:

SdkCodelistRepository codelists = new SdkCodelistRepository(sdkVersion,
    SdkResourceLoader.getResourceAsPath(sdkVersion, SdkResource.CODELISTS, Path.of("eforms-sdk")));

SdkCodelist contractNature = codelists.get(fields.get("BT-23-Procedure").getCodelistId());

contractNature.getCodes(); // [services, supplies, works]

The repository reads the list of codelists from codelists/codelists.json, and reads a codelist file only the first time you ask for that codelist. A codelist gives its identifier, its version, and its codes. A tailored codelist, which takes a part of the codes of another codelist, also gives the identifier of that other codelist (getRootCodelistId()).

The notice subtypes

The class SdkNoticeTypeRepository gives the notice subtypes of an SDK version, by identifier, such as 16, E1 or X01:

SdkNoticeTypeRepository subtypes = new SdkNoticeTypeRepository(sdkVersion,
    SdkResourceLoader.getResourceAsPath(sdkVersion, SdkResource.NOTICE_TYPES_JSON, Path.of("eforms-sdk")));

SdkNoticeSubtype contractNotice = subtypes.get("16");

contractNotice.getDocumentType(); // "CN"
contractNotice.getType();         // "cn-standard"