Skip to content

Move RequiredIdOptionPolicy and RequiredIdOptionPolicy to McJava #135

@alexander-yevsyukov

Description

@alexander-yevsyukov

Validation has an ability to generate the code for implicitly required fields. Such fields are IDs of corresponding message types.

For example, a command message must have an ID, or an entity state must have an ID, and we do not want to force the user to apply (required)=true all the time. We want to make such rules assumed.

To support this feature we have the MessageMarkers type which allows to filter out message types into the following categories:

  1. Entity states by using the repeated field entity_option_name.
  2. Signal messages (commands, events, rejections) using the fields with FilePattern type.

McJava fills in MessageMarkers (as a part of ValidationConfig) from its settings when passing settings to ValidationPlugin executed by ProtoData.

The problem

The problem with this approach is that it breaks the level of abstraction. Validation should not know about entity states or signals. It's the job of Model Compilers, and McJava in particular.

Validation should have the notion of implicitly required fields and provide API for being informed about such fields from the tools that deal with custom message types. But it should not be organised via passing settings because:

  1. It leaks the abstraction back to Validation.
  2. Supporting more types requires extending MessageMarkers and therefore re-building Validation.

We need to resolve this issue and reduce the coupling between Validation and McJava. Fortunately, we already have the basis for such separation of abstractions: the abstract class RequiredIdPolicy. It has two descendants that handle entity states and signals. These descendants are RequiredIdOptionPolicy and RequiredIdPatternPolicy classes.

Suggested course of actions

  1. Make RequiredIdPolicy public.
  2. Make RequiredIdOptionPolicy a part of EntityPlugin in McJava. The policy would fire the events as it does now under Validation, but taking options directly from McJava.
  3. Similarly to the item above, make RequiredIdPatternPolicy a part of SignalPlugin in McJava.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions