Extending definition types

Next to the base types that are provided, which are document and view, it is also possible to create your own definition types. A definition type represents the data structure which its definition instances must uphold.

Defining types

Creating a definition requires two base elements, the raw definition and the definition. A raw definition simply defines that the provided definition in json/yaml is parsable to a typed object. It will not validate whether it’s content is valid. The definition is a valid typed representation of the structure based on the raw definition.

Using raw definitions as the definition object to work with is not advised. It is preferred to create a separate object that fully represents a validated definition of your custom type.

Finally, once a type configuration is registered on the DefinitionTypeConfigurationRegistry, the type is ready to be used in definitions.

Raw Definition

Before a definition is created, a raw definition will be made. A raw definition is simply a typed object converted from a given json/yaml and must implement the RawDefinition marker interface. A raw definition can hold anything and is not validated as to whether it is of the correct format.

Example raw definition
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonRootName("view-definition")
public class RawViewDefinition implements Serializable, RawDefinition
{
	private String name;
	private String type;

	@JsonDeserialize(as = ArrayList.class, contentAs = String.class)
	@Singular("property")
	@NonNull
	private List<String> properties = new ArrayList<>();

	public List<String> getProperties() {
		return properties != null ? properties : Collections.emptyList();
	}

	public static RawViewDefinition copyOf( @NonNull RawViewDefinition definition ) {
		return SerializationUtils.clone( definition );
	}
}

Definition

A Definition is the encapsulating object with strongly typed fields. These fields contains the required information of the various properties defined within the definition. Definitions should never be created directly, but through a builder that performs validation checks to ensure the definition configuration is completely valid.

Example definition
public class DynamicViewDefinition
{
    @Getter
    private final List<String> properties;

    DynamicViewDefinition(@NonNull List<String> properties){
    this.properties = Collections.unmodifiableList(properties);
}

Registering on the registry

Definitions can be converted to and from raw definitions using the RawDefinitionService. To support a custom type, a type configuration must be registered on the DynamicDefinitionTypeConfigurationRegistry.

Table 1. Type configuration information of a DefinitionType
Name Description

Name

The name of the type being registered. E.g. document for the Document type.

Raw definition

The raw definition type to and from which the json representation must be converted. The raw definition type must implement the RawDefinition interface.

Validator

The validator that should be used to validate the raw definition. If the raw definition is successfully validated, an actual definition can be created.

Example registration of a definition type.
@Autowired
public void registerBaseTypes( DynamicDefinitionTypeConfigurationRegistry typeConfigurationRegistry ) {
    typeConfigurationRegistry.register( DynamicDefinitionType.VIEW, RawViewDefinition.class, rawViewDefinitionValidator );
}

After registering the configuration, a DynamicDefinitionTypeConfiguration will be created and returned, which holds the provided parameters, as well as the corresponding DynamicDefinitionType instance.