Class ModelChangeService

java.lang.Object
io.jmix.dynmodelai.modelchange.ModelChangeService

@Component("dmagent_ModelChangeService") public class ModelChangeService extends Object
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 Details

  • 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

      public MutationResult removeEntity(DynamicModelDefinition definition, String entityName)
      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 changes
      previous - last definition of this attribute in the current editing sequence, or null if unknown
      caption - 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 changes
      previous - last definition of this attribute in the current editing sequence, or null if unknown
      required - true for a required reference; false or null otherwise
      collection - 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 locale
      parentMenu - existing nonadministrative menu section; new sections and root placement are unsupported
      insertBefore - sibling item identifier, or null for the default order, not necessarily last
      menu - 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 section
      insertBefore - sibling item identifier in the target section, or null for the default order
      menu - snapshot of available application menu entries; null means unavailable