### Build Project with Maven Wrapper Source: https://github.com/contextmapper/context-mapper-dsl/wiki/Build This command cleans and installs the project using the Maven Wrapper. It's the primary command for building the project and its artifacts, including the Eclipse plugin update site. ```bash ./mvnw clean install ``` -------------------------------- ### Execute Integration Tests with Maven Wrapper Source: https://github.com/contextmapper/context-mapper-dsl/wiki/Build This command cleans and executes integration tests for the Xtext grammar. These tests require an additional Maven goal beyond the standard 'test' goal and are crucial for verifying grammar correctness. ```bash ./mvnw clean integration-test ``` -------------------------------- ### Java: Context Mapper DSL Standalone Application Example Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt This Java code demonstrates the complete lifecycle of using the Context Mapper DSL standalone API. It includes initializing the API, loading a CML model, generating PlantUML diagrams, context maps, and MDSL contracts, applying a refactoring, saving changes, and creating a new CML model programmatically. Dependencies include the Context Mapper DSL libraries. Input is a CML file path; output includes generated diagrams and contracts, and a saved CML file. ```java import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; import org.contextmapper.dsl.cml.CMLResource; import org.contextmapper.dsl.contextMappingDSL.*; import org.contextmapper.dsl.generator.*; import org.contextmapper.dsl.generator.contextmap.ContextMapFormat; import org.contextmapper.dsl.refactoring.*; import org.eclipse.xtext.resource.SaveOptions; public class ContextMapperExample { public static void main(String[] args) { try { // Initialize API StandaloneContextMapperAPI api = ContextMapperStandaloneSetup.getStandaloneAPI(); // Load existing model CMLResource cml = api.loadCML("./models/insurance-system.cml"); System.out.println("Loaded model with " + cml.getContextMappingModel().getBoundedContexts().size() + " contexts"); // Generate PlantUML diagrams PlantUMLGenerator plantUML = new PlantUMLGenerator(); api.callGenerator(cml, plantUML, "./output/diagrams"); System.out.println("✓ PlantUML diagrams generated"); // Generate context maps ContextMapGenerator contextMapGen = new ContextMapGenerator(); contextMapGen.setContextMapFormats(ContextMapFormat.PNG, ContextMapFormat.SVG); contextMapGen.setWidth(2500); contextMapGen.printAdditionalLabels(true); api.callGenerator(cml, contextMapGen, "./output/context-maps"); System.out.println("✓ Context maps generated"); // Generate MDSL contracts MDSLContractsGenerator mdsl = new MDSLContractsGenerator(); api.callGenerator(cml, mdsl, "./output/contracts"); System.out.println("✓ MDSL contracts generated"); // Apply architectural refactoring SplitBoundedContextByOwner splitRefactoring = new SplitBoundedContextByOwner("PolicyManagementContext"); api.applyRefactoring(cml, splitRefactoring); System.out.println("✓ Refactoring applied: split by owner"); // Save modified model cml.save(SaveOptions.defaultOptions().toOptionsMap()); System.out.println("✓ Model saved"); // Create new model programmatically CMLResource newModel = api.createCML("./models/new-system.cml"); ContextMappingModel model = newModel.getContextMappingModel(); BoundedContext bc = ContextMappingDSLFactory.eINSTANCE.createBoundedContext(); bc.setName("PaymentContext"); model.getBoundedContexts().add(bc); Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate(); aggregate.setName("PaymentAggregate"); bc.getAggregates().add(aggregate); newModel.save(SaveOptions.defaultOptions().toOptionsMap()); System.out.println("✓ New model created and saved"); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); } } } ``` -------------------------------- ### Create New CML Models Programmatically in Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Illustrates how to programmatically create and persist new Context Mapper DSL (CML) models using the factory pattern in Java. This example demonstrates creating a CML resource, defining a bounded context, an aggregate, and an entity with attributes. The new model is then saved to a specified file path. ```java import org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory; import org.contextmapper.dsl.contextMappingDSL.Aggregate; import org.contextmapper.dsl.tactic.dsl.tacticdsl.TacticdslFactory; import org.contextmapper.dsl.tactic.dsl.tacticdsl.Entity; import org.eclipse.xtext.resource.SaveOptions; // Create new CML resource CMLResource newCml = contextMapper.createCML("./model/new-system.cml"); ContextMappingModel model = newCml.getContextMappingModel(); // Create bounded context BoundedContext customerContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext(); customerContext.setName("CustomerManagementContext"); model.getBoundedContexts().add(customerContext); // Create aggregate Aggregate customerAggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate(); customerAggregate.setName("CustomerAggregate"); customerContext.getAggregates().add(customerAggregate); // Create entity Entity customer = TacticdslFactory.eINSTANCE.createEntity(); customer.setName("Customer"); customer.setAggregateRoot(true); customerAggregate.getDomainObjects().add(customer); // Create attributes org.contextmapper.dsl.tactic.dsl.tacticdsl.Attribute nameAttr = TacticdslFactory.eINSTANCE.createAttribute(); nameAttr.setName("name"); nameAttr.setType("String"); customer.getAttributes().add(nameAttr); // Save the model newCml.save(SaveOptions.defaultOptions().toOptionsMap()); System.out.println("Model saved to: ./model/new-system.cml"); ``` -------------------------------- ### Generate Graphical Context Maps with Graphviz Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Generates visual context maps in PNG, SVG, and DOT formats using Graphviz. This requires Graphviz to be installed. Configuration options include label spacing, fixed width, and showing relationship names. ```java import org.contextmapper.dsl.generator.ContextMapGenerator; import org.contextmapper.dsl.generator.contextmap.ContextMapFormat; // Load model with context map CMLResource cml = contextMapper.loadCML("./model/insurance-context-map.cml"); // Create context map generator ContextMapGenerator contextMapGen = new ContextMapGenerator(); // Configure output formats (PNG, SVG, DOT) contextMapGen.setContextMapFormats( ContextMapFormat.PNG, ContextMapFormat.SVG, ContextMapFormat.DOT ); // Configure visual appearance contextMapGen.setLabelSpacingFactor(5); // 1-20, controls label spacing contextMapGen.setWidth(3000); // Fix width, height adjusts dynamically // contextMapGen.setHeight(2000); // Alternative: fix height instead contextMapGen.printAdditionalLabels(true); // Show relationship names contextMapGen.clusterTeams(true); // Cluster team BCs together // Check if Graphviz is installed if (contextMapGen.isGraphvizInstalled()) { // Generate context maps contextMapper.callGenerator(cml, contextMapGen, "./diagrams/context-maps"); System.out.println("Context maps generated: PNG, SVG, and DOT formats"); } else { System.err.println("Graphviz not installed. Please install from https://graphviz.org/"); } ``` -------------------------------- ### Trigger ContextMapper DSL Release on Travis CI Source: https://github.com/contextmapper/context-mapper-dsl/wiki/Releasing Steps to trigger the release process for the ContextMapper DSL. This involves installing the Travis CI gem, logging in, navigating to the .travis directory, and executing the releaseTrigger.sh script. The release is performed automatically on Travis. ```bash gem install travis travis login --com cd .travis ./releaseTrigger.sh ``` -------------------------------- ### Deploy Libraries to Local Maven Repository (Gradle) Source: https://github.com/contextmapper/context-mapper-dsl/blob/master/README.md Gradle command to publish the standalone libraries to the local Maven repository. This requires GPG keys for signing artifacts and specifies the key ID, passphrase, and keyring file path. ```bash ./gradlew clean publishToMavenLocal -Psigning.keyId= -Psigning.password= -Psigning.secretKeyRingFile= ``` -------------------------------- ### Build Standalone Projects (Gradle) Source: https://github.com/contextmapper/context-mapper-dsl/blob/master/README.md Command to build only the standalone projects (DSL and IDE) using the Gradle Wrapper. This command cleans the build directory and compiles the standalone artifacts. ```bash ./gradlew clean build ``` -------------------------------- ### Loading CML Models Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt This section details how to load existing Context Mapper DSL models from the filesystem using either string paths or File objects. ```APIDOC ## Loading CML Models ### Description Load existing Context Mapper DSL models from the filesystem. ### Method `contextMapper.loadCML(String path)` or `contextMapper.loadCML(File file)` ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Initialize the API StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); // Load CML file using string path CMLResource cml = contextMapper.loadCML("./model/insurance-context-map.cml"); // Or load using File object File cmlFile = new File("./model/insurance-context-map.cml"); CMLResource cml2 = contextMapper.loadCML(cmlFile); // Access the model ContextMappingModel model = cml.getContextMappingModel(); // Iterate through bounded contexts for (BoundedContext bc : model.getBoundedContexts()) { System.out.println("Bounded Context: " + bc.getName()); bc.getAggregates().forEach(agg -> System.out.println(" - Aggregate: " + agg.getName()) ); } // Access context map relationships if (model.getMap() != null) { System.out.println("Context Map: " + model.getMap().getName()); model.getMap().getRelationships().forEach(rel -> System.out.println(" Relationship: " + rel.getName()) ); } ``` ### Response #### Success Response (200) Returns a `CMLResource` object representing the loaded model. #### Response Example ```json { "message": "CML model loaded successfully." } ``` ``` -------------------------------- ### Load CML Models Programmatically in Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Demonstrates how to load existing Context Mapper DSL (CML) models from the filesystem using a Java API. It covers initializing the ContextMapperStandaloneSetup, loading CML files by path or File object, accessing the model, and iterating through bounded contexts and their aggregates. It also shows how to access context map relationships. ```java import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; import org.contextmapper.dsl.cml.CMLResource; import org.contextmapper.dsl.contextMappingDSL.ContextMappingModel; import org.contextmapper.dsl.contextMappingDSL.BoundedContext; import java.io.File; // Initialize the API StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); // Load CML file using string path CMLResource cml = contextMapper.loadCML("./model/insurance-context-map.cml"); // Or load using File object File cmlFile = new File("./model/insurance-context-map.cml"); CMLResource cml2 = contextMapper.loadCML(cmlFile); // Access the model ContextMappingModel model = cml.getContextMappingModel(); // Iterate through bounded contexts for (BoundedContext bc : model.getBoundedContexts()) { System.out.println("Bounded Context: " + bc.getName()); bc.getAggregates().forEach(agg -> System.out.println(" - Aggregate: " + agg.getName()) ); } // Access context map relationships if (model.getMap() != null) { System.out.println("Context Map: " + model.getMap().getName()); model.getMap().getRelationships().forEach(rel -> System.out.println(" Relationship: " + rel.getName()) ); } ``` -------------------------------- ### Creating New CML Models Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt This section explains how to programmatically create and persist new CML models using the factory pattern. ```APIDOC ## Creating New CML Models ### Description Create and persist new CML models programmatically using the factory pattern. ### Method `contextMapper.createCML(String path)` ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory; import org.contextmapper.dsl.contextMappingDSL.Aggregate; import org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory; import org.contextmapper.tactic.dsl.tacticdsl.Entity; import org.eclipse.xtext.resource.SaveOptions; // Initialize the API (assuming contextMapper is already initialized as in the previous example) // StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); // Create new CML resource CMLResource newCml = contextMapper.createCML("./model/new-system.cml"); ContextMappingModel model = newCml.getContextMappingModel(); // Create bounded context BoundedContext customerContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext(); customerContext.setName("CustomerManagementContext"); model.getBoundedContexts().add(customerContext); // Create aggregate Aggregate customerAggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate(); customerAggregate.setName("CustomerAggregate"); customerContext.getAggregates().add(customerAggregate); // Create entity Entity customer = TacticdslFactory.eINSTANCE.createEntity(); customer.setName("Customer"); customer.setAggregateRoot(true); customerAggregate.getDomainObjects().add(customer); // Create attributes org.contextmapper.tactic.dsl.tacticdsl.Attribute nameAttr = TacticdslFactory.eINSTANCE.createAttribute(); nameAttr.setName("name"); nameAttr.setType("String"); customer.getAttributes().add(nameAttr); // Save the model newCml.save(SaveOptions.defaultOptions().toOptionsMap()); System.out.println("Model saved to: ./model/new-system.cml"); ``` ### Response #### Success Response (200) Returns a `CMLResource` object representing the newly created and saved model. #### Response Example ```json { "message": "New CML model created and saved successfully.", "filePath": "./model/new-system.cml" } ``` ``` -------------------------------- ### Generate Custom Content with Freemarker Templates Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Generates custom text output, such as documentation or configuration files, using Freemarker templates. It requires a CML model, a Freemarker template file, and a GenericContentGenerator instance. Custom data can be registered and accessed within the template. ```java import org.contextmapper.dsl.generator.GenericContentGenerator; import java.util.HashMap; import java.util.Map; // Load model CMLResource cml = contextMapper.loadCML("./model/system.cml"); // Create Freemarker template file (template.ftl) // Example template content: // # System Documentation // // ## Bounded Contexts // <#list boundedContexts as bc> // ### ${bc.name} // <#list bc.aggregates as agg> // - Aggregate: ${agg.name} // // // Create generic content generator GenericContentGenerator genericGen = new GenericContentGenerator(); genericGen.setFreemarkerTemplateFile(new File("./templates/documentation.ftl")); genericGen.setTargetFileName("system-documentation.md"); // Register custom properties accessible in template Map customData = new HashMap<>(); customData.put("projectName", "Insurance System"); customData.put("version", "1.0.0"); customData.put("author", "Development Team"); genericGen.registerCustomModelProperty("metadata", customData); // Generate output contextMapper.callGenerator(cml, genericGen, "./docs"); System.out.println("Custom documentation generated from template"); ``` -------------------------------- ### Bump Version with Maven Wrapper Source: https://github.com/contextmapper/context-mapper-dsl/wiki/Releasing Commands to update the project's version using the Maven wrapper. The first command sets the new version, and the second updates Eclipse-specific metadata files. Ensure to commit changes after successful builds. ```bash ./mvnw versions:set -DgenerateBackupPoms=false -DnewVersion=1.0.0-SNAPSHOT ./mvnw org.eclipse.tycho:tycho-versions-plugin:1.2.0:update-eclipse-metadata ``` -------------------------------- ### Split Bounded Context by Owner using Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Splits a single bounded context into multiple contexts based on aggregate ownership. It loads a CML model, applies the SplitBoundedContextByOwner refactoring, and then saves the modified model. Dependencies include the Context Mapper DSL library. ```java import org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner; // Load model CMLResource cml = contextMapper.loadCML("./model/monolithic-context.cml"); // Show original state System.out.println("Original bounded contexts: " + cml.getContextMappingModel().getBoundedContexts().size()); // Apply refactoring - splits the context by aggregate owner SplitBoundedContextByOwner refactoring = new SplitBoundedContextByOwner("PolicyManagementContext"); contextMapper.applyRefactoring(cml, refactoring); // Show results System.out.println("After split: " + cml.getContextMappingModel().getBoundedContexts().size() + " bounded contexts"); cml.getContextMappingModel().getBoundedContexts().forEach(bc -> System.out.println(" - " + bc.getName()) ); // Persist changes cml.save(SaveOptions.defaultOptions().toOptionsMap()); ``` -------------------------------- ### Generate MDSL Service Contracts from Bounded Contexts Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Generates MDSL (Micro-service Domain-Specific Language) service contracts from bounded contexts within a CML model. The generator produces one .mdsl file per exposed service, including API endpoints, data types, and operation signatures. ```java import org.contextmapper.dsl.generator.MDSLContractsGenerator; // Load CML model CMLResource cml = contextMapper.loadCML("./model/online-shop.cml"); // Create MDSL generator MDSLContractsGenerator mdslGen = new MDSLContractsGenerator(); // Generate MDSL contracts contextMapper.callGenerator(cml, mdslGen, "./contracts"); // The generator creates one MDSL file per exposed service: // {filename}_{ServiceName}.mdsl // // MDSL contracts include: // - API endpoint definitions // - Data type definitions // - Operation signatures with parameters and return types // - Protected regions for manual customization System.out.println("MDSL service contracts generated"); ``` -------------------------------- ### Generate PlantUML Diagrams from CML Models Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Generates various PlantUML diagrams (component, class, state, use case, sequence) from CML models. It requires the CML resource and a PlantUMLGenerator instance. The output includes multiple .puml files for different diagram types. ```java import org.contextmapper.dsl.generator.PlantUMLGenerator; // Load the model CMLResource cml = contextMapper.loadCML("./model/insurance-context-map.cml"); // Create PlantUML generator PlantUMLGenerator plantUMLGen = new PlantUMLGenerator(); // Generate all diagram types to default directory (./src-gen) contextMapper.callGenerator(cml, plantUMLGen); // Or specify custom output directory contextMapper.callGenerator(cml, plantUMLGen, "./diagrams/plantuml"); // The generator produces: // - {filename}_ContextMap.puml (component diagram of context map) // - {filename}_BC_{BoundedContextName}.puml (class diagram per bounded context) // - {filename}_BC_{BoundedContextName}_{AggregateName}.puml (class diagram per aggregate) // - {filename}_BC_{BoundedContextName}_{AggregateName}_StateDiagram.puml (state diagrams) // - {filename}_UseCases.puml (use case diagram) // - {filename}_UseCase_{UseCaseName}_Interactions.puml (sequence diagrams) // - {filename}_SD_{SubdomainName}.puml (subdomain class diagrams) System.out.println("PlantUML diagrams generated successfully"); ``` -------------------------------- ### Add Context Mapper DSL Dependency (Gradle) Source: https://github.com/contextmapper/context-mapper-dsl/blob/master/README.md This snippet shows how to include the Context Mapper DSL as a dependency in a Gradle project. It specifies the group ID, artifact ID, and version of the library. ```gradle implementation 'org.contextmapper:context-mapper-dsl:6.12.0' ``` -------------------------------- ### Define CML Context Maps with Bounded Contexts and Relationships Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt This snippet demonstrates how to define a Context Map in CML, specifying bounded contexts and their relationships like Customer/Supplier, Anti-Corruption Layer, Partnership, and Shared Kernel. It also includes definitions for individual Bounded Contexts. ```cml ContextMap InsuranceContextMap { contains CustomerManagementContext contains CustomerSelfServiceContext contains PrintingContext contains PolicyManagementContext contains RiskManagementContext contains DebtCollection /* Customer/Supplier: [D]ownstream [U]upstream [C]onformist [S]upplier */ CustomerSelfServiceContext [D,C]<-[U,S] CustomerManagementContext /* Anticorruption Layer: [ACL], Open Host Service: [OHS], Published Language: [PL] */ CustomerManagementContext [D,ACL]<-[U,OHS,PL] PrintingContext /* Partnership: [P]artnership - both sides equal */ RiskManagementContext [P]<->[P] PolicyManagementContext : RiskAssessmentPartnership { implementationTechnology "REST API" } /* Customer/Supplier with patterns */ PolicyManagementContext [D,CF]<-[U,OHS] CustomerManagementContext /* Shared Kernel: [SK] - shared code and data model */ PolicyManagementContext [SK]<->[SK] DebtCollection } BoundedContext CustomerManagementContext { type FEATURE domainVisionStatement "Manages customer data and relationships" } BoundedContext CustomerSelfServiceContext { type APPLICATION } BoundedContext PrintingContext { type SYSTEM } BoundedContext PolicyManagementContext BoundedContext RiskManagementContext BoundedContext DebtCollection ``` -------------------------------- ### Define CML Tactical DDD Models with Aggregates, Entities, and Value Objects Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt This CML snippet illustrates the definition of tactical Domain-Driven Design models within a Bounded Context. It includes aggregates, services, entities, value objects, and enums, as well as defining a domain with subdomains and use cases. ```cml BoundedContext OnlineShopContext implements ECommerceDomain { domainVisionStatement "Online shopping platform for consumer purchases" type FEATURE Aggregate OrderAggregate { Service OrderService { @OrderId createOrder(@Order order); @Order getOrder(@OrderId orderId); void updateOrderStatus(@OrderId orderId, OrderStatus status); List<@Order> findOrdersByCustomer(@CustomerId customerId); } Entity Order { aggregateRoot String orderNumber Date orderDate OrderStatus status Money totalAmount - OrderId orderId - CustomerId customerId - List items def Money calculateTotal { /* business logic here */ } } Entity OrderItem { String productName int quantity Money unitPrice - OrderItemId orderitemId - ProductId productId } ValueObject OrderId { Long id key } ValueObject OrderItemId { Long id key } enum OrderStatus { PENDING, CONFIRMED, SHIPPED, DELIVERED, CANCELLED } } Aggregate CustomerAggregate { Entity Customer { aggregateRoot String name String email String address - CustomerId customerId - List orderHistory } ValueObject CustomerId { Long id key } } } Domain ECommerce { Subdomain BusinessToConsumer supports UC_BrowseAndBuy, UC_TrackOrder { domainVisionStatement "Enable consumers to shop online conveniently" type CORE_DOMAIN Entity Customer { String name String email } Entity Order { String orderNumber Date orderDate } Service OrderService { createOrder; trackOrder; } } } UseCase UC_BrowseAndBuy { actor = "OnlineShopper" interactions = read a "Product" with its "productName", "price", "image", create an "Order" with its "orderNumber", create an "OrderItem" with its "quantity", "price" in an "Order" benefit "Purchase products from home conveniently" } UseCase UC_TrackOrder { actor = "OnlineShopper" interactions = read an "Order" with its "orderNumber", "status", "deliveryDate" benefit "Know when the order will arrive" } ``` -------------------------------- ### Derive Bounded Context from Subdomains using Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Derives new bounded contexts from existing subdomain definitions following Domain-Driven Design principles. The refactoring loads a CML model containing subdomains, applies the DeriveBoundedContextFromSubdomains refactoring using a specified subdomain name, and saves the resulting model. Dependencies include the Context Mapper DSL library. ```java import org.contextmapper.dsl.refactoring.DeriveBoundedContextFromSubdomains; // Load model with defined subdomains CMLResource cml = contextMapper.loadCML("./model/domain-model.cml"); // Derive bounded contexts from subdomains DeriveBoundedContextFromSubdomains deriveBC = new DeriveBoundedContextFromSubdomains( "CustomerManagement" // Subdomain name ); contextMapper.applyRefactoring(cml, deriveBC); // New bounded context created with structure derived from subdomain System.out.println("Bounded context derived from subdomain"); cml.save(SaveOptions.defaultOptions().toOptionsMap()); ``` -------------------------------- ### Add Context Mapper DSL Dependency (Maven) Source: https://github.com/contextmapper/context-mapper-dsl/blob/master/README.md This snippet demonstrates how to add the Context Mapper DSL as a dependency in a Maven project. It includes the group ID, artifact ID, and version within the dependencies section. ```xml org.contextmapper context-mapper-dsl 6.12.0 ``` -------------------------------- ### Merge Bounded Contexts using Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Merges multiple specified bounded contexts into a single new context. This refactoring requires the names of the contexts to be merged and the desired name for the resulting context. It loads a CML model, performs the merge, and saves the updated model. Dependencies include the Context Mapper DSL library. ```java import org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring; // Load model CMLResource cml = contextMapper.loadCML("./model/fragmented-system.cml"); // Merge multiple contexts into one MergeBoundedContextsRefactoring mergeRefactoring = new MergeBoundedContextsRefactoring( "OrderContext", // First context to merge "ShippingContext", // Second context to merge "OrderAndShippingContext" // Name of merged context ); contextMapper.applyRefactoring(cml, mergeRefactoring); // The merged context contains all aggregates from both original contexts System.out.println("Contexts merged successfully"); cml.save(SaveOptions.defaultOptions().toOptionsMap()); ``` -------------------------------- ### Extract Partnership Relationship using Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Extracts a partnership relationship between two bounded contexts that collaborate as equals, without an upstream/downstream dependency. It loads a CML model, applies the ExtractPartnershipRefactoring with the names of the two contexts, and saves the result. Dependencies include the Context Mapper DSL library. ```java import org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring; // Load model CMLResource cml = contextMapper.loadCML("./model/system.cml"); // Extract partnership between two contexts ExtractPartnershipRefactoring partnership = new ExtractPartnershipRefactoring( "ContextA", // First context "ContextB" // Second context ); contextMapper.applyRefactoring(cml, partnership); // Partnership pattern is added to context map // Both contexts cooperate without upstream/downstream relationship System.out.println("Partnership relationship established"); cml.save(SaveOptions.defaultOptions().toOptionsMap()); ``` -------------------------------- ### Split Aggregate by Entities using Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Splits a large aggregate within a bounded context into smaller, more manageable aggregates based on entity grouping. It requires the bounded context name and the aggregate name to be split. The refactoring is applied to the loaded CML model, and changes are saved. Dependencies include the Context Mapper DSL library. ```java import org.contextmapper.dsl.refactoring.SplitAggregateByEntitiesRefactoring; // Load model CMLResource cml = contextMapper.loadCML("./model/large-aggregate.cml"); // Split aggregate within a bounded context SplitAggregateByEntitiesRefactoring splitAgg = new SplitAggregateByEntitiesRefactoring( "OrderManagementContext", // Bounded context name "OrderAggregate" // Aggregate to split ); contextMapper.applyRefactoring(cml, splitAgg); // Multiple aggregates are created, each containing related entities System.out.println("Aggregate split into smaller aggregates"); cml.save(SaveOptions.defaultOptions().toOptionsMap()); ``` -------------------------------- ### Extract Shared Kernel Relationship using Java Source: https://context7.com/contextmapper/context-mapper-dsl/llms.txt Extracts a shared kernel relationship between two bounded contexts that share a common subset of their models. This refactoring involves loading a CML model, applying the ExtractSharedKernelRefactoring with the names of the collaborating contexts, and saving the changes. Dependencies include the Context Mapper DSL library. ```java import org.contextmapper.dsl.refactoring.ExtractSharedKernelRefactoring; // Load model CMLResource cml = contextMapper.loadCML("./model/system.cml"); // Extract shared kernel between contexts ExtractSharedKernelRefactoring sharedKernel = new ExtractSharedKernelRefactoring( "PaymentContext", // First context sharing model "BillingContext" // Second context sharing model ); contextMapper.applyRefactoring(cml, sharedKernel); // Shared Kernel pattern is added - both teams maintain shared code System.out.println("Shared Kernel relationship established"); cml.save(SaveOptions.defaultOptions().toOptionsMap()); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.