Package io.jmix.dynmodelai.modelchange
Class ModelChangeService
java.lang.Object
io.jmix.dynmodelai.modelchange.ModelChangeService
Prepares changes to a supplied Dynamic Model definition without modifying the input.
A successful MutationResult contains the changed definition after operation preconditions
have passed, without migration validation. A failed result contains issues and no definition.
Invalid operation arguments may throw IllegalArgumentException instead of returning issues.
The caller must validate migrations before installing the candidate in a workspace.
This service neither updates a workspace nor saves settings, applies migrations or changes business data.
-
Constructor Summary
ConstructorsConstructorDescriptionModelChangeService(DynamicModelEntityOperations entityOperations, DynamicModelAttributeOperations attributeOperations, DynamicModelViewOperations viewOperations) -
Method Summary
Modifier and TypeMethodDescriptionaddAttribute(DynamicModelDefinition definition, String entityName, DynamicModelDefinition baseline, @Nullable DynamicAttributeDefinition previous, String name, AttributeType type, @Nullable Caption caption, @Nullable Boolean required, @Nullable Integer length, @Nullable Boolean displayName, @Nullable Boolean unique) Adds a scalar attribute whose name is absent from the entity's current definition.addMenuItem(DynamicModelDefinition definition, String entityName, @Nullable Caption title, String parentMenu, @Nullable String insertBefore, @Nullable MenuProjection menu) Adds a menu item for an existing list view that has no menu item yet.addReference(DynamicModelDefinition definition, String entityName, DynamicModelDefinition baseline, @Nullable DynamicAttributeDefinition previous, String name, String targetEntity, @Nullable Caption caption, @Nullable Boolean required, @Nullable Boolean collection) Adds a reference to an entity present in the supplied definition or application metadata.createEntity(DynamicModelDefinition definition, String entityName, @Nullable Caption caption) Adds an entity without attributes or views.generateViews(DynamicModelDefinition definition, String entityName, ViewKind kind, @Nullable Caption title) Adds missing list/detail views of the requested kind; existing views are preserved.moveAttribute(DynamicModelDefinition definition, String entityName, String name, @Nullable String before) Moves one attribute while preserving the relative order of the others.moveMenuItem(DynamicModelDefinition definition, String entityName, String parentMenu, @Nullable String insertBefore, @Nullable MenuProjection menu) Moves an existing list-view menu item, preserving its title, view identity and role settings.removeAttribute(DynamicModelDefinition definition, String entityName, String attributeName) Removes an existing attribute from the definition without deleting stored values.removeEntity(DynamicModelDefinition definition, String entityName) Removes an existing entity and its attributes and views from the definition, not from the database.reorderAttributes(DynamicModelDefinition definition, String entityName, List<String> names) Sets the complete attribute order.updateAttributeCaption(DynamicModelDefinition definition, String entityName, String name, Caption caption) Changes an existing attribute's caption in the current user's locale, preserving other translations.
-
Constructor Details
-
ModelChangeService
public ModelChangeService(DynamicModelEntityOperations entityOperations, DynamicModelAttributeOperations attributeOperations, DynamicModelViewOperations viewOperations)
-
-
Method Details
-
createEntity
public MutationResult createEntity(DynamicModelDefinition definition, String entityName, @Nullable Caption caption) Adds an entity without attributes or views. The name must not conflict with existing metadata. The caption uses the current user's locale; an omitted or blank caption defaults to the name. -
removeEntity
Removes an existing entity and its attributes and views from the definition, not from the database. -
addAttribute
public MutationResult addAttribute(DynamicModelDefinition definition, String entityName, DynamicModelDefinition baseline, @Nullable DynamicAttributeDefinition previous, String name, AttributeType type, @Nullable Caption caption, @Nullable Boolean required, @Nullable Integer length, @Nullable Boolean displayName, @Nullable Boolean unique) Adds a scalar attribute whose name is absent from the entity's current definition. Re-creating a published attribute must preserve its settings; previous Draft captions are retained. Nullable flags default to false; length applies only to STRING and displayName excludes LOB types.- Parameters:
baseline- published definition captured before the Draft changesprevious- last definition of this attribute in the current editing sequence, or null if unknowncaption- caption in the current user's locale; null preserves captions when re-creating
-
addReference
public MutationResult addReference(DynamicModelDefinition definition, String entityName, DynamicModelDefinition baseline, @Nullable DynamicAttributeDefinition previous, String name, String targetEntity, @Nullable Caption caption, @Nullable Boolean required, @Nullable Boolean collection) Adds a reference to an entity present in the supplied definition or application metadata. Re-creating a published reference must preserve its settings and existing captions.- Parameters:
baseline- published definition captured before the Draft changesprevious- last definition of this attribute in the current editing sequence, or null if unknownrequired- true for a required reference; false or null otherwisecollection- true for a collection; false or null for a single-valued reference
-
removeAttribute
public MutationResult removeAttribute(DynamicModelDefinition definition, String entityName, String attributeName) Removes an existing attribute from the definition without deleting stored values. -
reorderAttributes
public MutationResult reorderAttributes(DynamicModelDefinition definition, String entityName, List<String> names) Sets the complete attribute order. Names must contain every current attribute exactly once. -
moveAttribute
public MutationResult moveAttribute(DynamicModelDefinition definition, String entityName, String name, @Nullable String before) Moves one attribute while preserving the relative order of the others.- Parameters:
before- attribute to place it before, or null to move it to the end
-
updateAttributeCaption
public MutationResult updateAttributeCaption(DynamicModelDefinition definition, String entityName, String name, Caption caption) Changes an existing attribute's caption in the current user's locale, preserving other translations. -
generateViews
public MutationResult generateViews(DynamicModelDefinition definition, String entityName, ViewKind kind, @Nullable Caption title) Adds missing list/detail views of the requested kind; existing views are preserved. Requires attributes and at least one missing requested view.- Parameters:
title- optional list-view title; otherwise the entity captions are used
-
addMenuItem
public MutationResult addMenuItem(DynamicModelDefinition definition, String entityName, @Nullable Caption title, String parentMenu, @Nullable String insertBefore, @Nullable MenuProjection menu) Adds a menu item for an existing list view that has no menu item yet.- Parameters:
title- optional menu-item title in the current user's localeparentMenu- existing nonadministrative menu section; new sections and root placement are unsupportedinsertBefore- sibling item identifier, or null for the default order, not necessarily lastmenu- snapshot of available application menu entries; null means unavailable
-
moveMenuItem
public MutationResult moveMenuItem(DynamicModelDefinition definition, String entityName, String parentMenu, @Nullable String insertBefore, @Nullable MenuProjection menu) Moves an existing list-view menu item, preserving its title, view identity and role settings.- Parameters:
parentMenu- existing nonadministrative menu sectioninsertBefore- sibling item identifier in the target section, or null for the default ordermenu- snapshot of available application menu entries; null means unavailable
-