Skip to main content

Feature Model, Tree, and Validation

This module serves the feature model, derives the tree and the default selection from it, and validates selections. Read it when you change a validation rule or the model response.

What the model endpoint returns​

GET /api/feature-model returns everything the client needs to show and configure the model:

FieldContent
modelId, name, version, and status of the model
features, relations, constraintsThe model as it is stored
treeThe same features arranged as a tree
defaultSelectedFeatureIdsThe starting selection
warningsModel warnings, such as constraints the server cannot evaluate

The server sends both the flat lists and the tree, so the client never builds the tree itself.

Tree and default selection​

FeatureModelTreeService builds the tree from the root and the relations. Children appear in the order of their relation, and each tree node carries the relation that connects it to its parent. The same order is used everywhere the server returns feature ids, so lists are stable.

The default selection is every selectable feature whose default state is enabled, in tree order. FeatureModelCatalogService computes it, and the Configurator starts from it.

Validating a selection​

POST /api/feature-model/validate takes a list of feature ids and checks them against the loaded model:

curl -X POST http://localhost:8090/api/feature-model/validate \
-H 'Content-Type: application/json' \
-d '{"selectedFeatureIds": ["mysql", "postgresql"]}'

The answer says whether the selection is valid, returns the known ids in tree order as normalizedSelection, and lists violations and warnings. FeatureModelValidationService applies these rules:

CodeRule
UNKNOWN_SELECTED_FEATUREEvery selected id exists in the model.
MANDATORY_FEATURE_MISSINGWhen a parent is active, its mandatory selectable children are selected. Root and group nodes always count as active.
ALTERNATIVE_GROUP_SELECTION_MISSINGAn active alternative group has at least one selected child.
REQUIRES_CONSTRAINT_VIOLATEDA selected source of a requires constraint has its target selected.
EXCLUDES_CONSTRAINT_VIOLATEDThe two features of an excludes constraint are not both selected.
UNSUPPORTED_EXPRESSION_CONSTRAINTA warning: expression constraints are reported but not evaluated.

An alternative group allows at most one child because the model pairs it with excludes constraints, such as mysql excludes postgresql.

Every violation carries a message, the affected featureIds, and a suggestion such as "Enable 'modeling' or disable 'apollon'." The client shows these texts as they are, so a new rule needs no client change.

Model integrity​

Before the model is used, FeatureModelIntegrityService checks that it is well formed: unique ids, exactly one root, relations and constraints that point to existing features, artifact mappings with a known source, and no two environment mappings that produce the same variable name. These checks also run at startup as part of loading the runtime bundle. A model that fails them never reaches a user.

Add a validation rule​

  1. Add a code to ValidationCode.
  2. Add a small method to FeatureModelValidationService that returns violations for the rule, and call it from validationViolations.
  3. Write a clear message and a suggestion that tells the user what to change.
  4. Test the rule in FeatureModelValidationServiceTest with a synthetic model from TestFeatureModels.

Where it lives in the code​

PathResponsibility
catalog/service/FeatureModelCatalogServiceBuilds the model response and the default selection
catalog/service/FeatureModelIntegrityServiceChecks that the model is well formed
catalog/repository/FeatureModelStoreGives services the loaded model
visualization/service/FeatureModelTreeServiceBuilds the tree and the tree order
validation/service/FeatureModelValidationServiceValidates a selection
validation/domain/ValidationCodeAll integrity and validation codes

Paths are relative to src/main/java/de/tum/cit/aet/artemis/featuremodel/.

Search documentation