Search in sources :

Example 1 with Application

use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method respectEventsAndCommandsAndServicesFromApplicationLayer.

@Test
public void respectEventsAndCommandsAndServicesFromApplicationLayer() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Application app = ContextMappingDSLFactory.eINSTANCE.createApplication();
    boundedContext.setApplication(app);
    DomainEvent testEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
    testEvent.setName("TestEvent");
    app.getEvents().add(testEvent);
    CommandEvent testCommand = TacticdslFactory.eINSTANCE.createCommandEvent();
    testCommand.setName("TestCommand");
    app.getCommands().add(testCommand);
    Service testService = TacticdslFactory.eINSTANCE.createService();
    testService.setName("TestService");
    app.getServices().add(testService);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("package \"'Application'\" <<Rectangle>> {" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestEvent <<(E,#ff9f4b) Domain Event>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestCommand <<(C,#3bc5e9) Command>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestService <<(S,DarkSeaGreen) Service>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
}
Also used : DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Application(org.contextmapper.dsl.contextMappingDSL.Application) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with Application

use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method checkPreconditions.

private void checkPreconditions() {
    Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
    List<Aggregate> exposedAggregates = Lists.newArrayList();
    List<Application> applications = Lists.newArrayList();
    for (UpstreamAPIContext context : upstreamContexts.values()) {
        exposedAggregates.addAll(context.getExposedAggregates());
        if (context.getApplicationLayer() != null)
            applications.add(context.getApplicationLayer());
    }
    if (exposedAggregates.isEmpty() && applications.isEmpty())
        throw new GeneratorInputException("None of your upstream-downstream relationships exposes any Aggregates or application layers. Therefore there is nothing to generate. Use the 'exposedAggregates' attribute on your upstream-downstream relationships to specify which Aggregates are exposed by the upstream or model an 'Application' in your upstream.");
    boolean atLeastOneAggregateWithAnOperation = false;
    for (Aggregate exposedAggregate : exposedAggregates) {
        Optional<DomainObject> aggregateRoot = exposedAggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).findFirst();
        if (aggregateRoot.isPresent() && !aggregateRoot.get().getOperations().isEmpty()) {
            atLeastOneAggregateWithAnOperation = true;
            break;
        }
        List<ServiceOperation> serviceOperations = exposedAggregate.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
        if (!serviceOperations.isEmpty()) {
            atLeastOneAggregateWithAnOperation = true;
            break;
        }
    }
    for (Application application : applications) {
        if (!application.getCommands().isEmpty()) {
            atLeastOneAggregateWithAnOperation = true;
            break;
        }
        List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
        if (!serviceOperations.isEmpty()) {
            atLeastOneAggregateWithAnOperation = true;
            break;
        }
    }
    if (!atLeastOneAggregateWithAnOperation)
        throw new GeneratorInputException("None of your exposed Aggregates contains either Service or 'Aggregate Root' operations/methods. Therefore there is nothing to generate. Add at least one operation/method to the 'Aggregate Root' or to a Service in one of your exposed Aggregates to get a result.");
}
Also used : EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamRole(org.contextmapper.dsl.contextMappingDSL.UpstreamRole) EitherCommandOrOperationInvokation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation) ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) StringUtils(org.apache.commons.lang3.StringUtils) SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) InvalidParameterException(java.security.InvalidParameterException) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) Map(java.util.Map) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) SingleCommandInvokation(org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation) EventProduction(org.contextmapper.dsl.contextMappingDSL.EventProduction) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) Collectors(java.util.stream.Collectors) List(java.util.List) ExclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation) APIUsageContext(org.contextmapper.dsl.generator.mdsl.model.APIUsageContext) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Visibility(org.contextmapper.tactic.dsl.tacticdsl.Visibility) Lists(com.google.common.collect.Lists) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) Application(org.contextmapper.dsl.contextMappingDSL.Application) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Maps(com.google.common.collect.Maps) EList(org.eclipse.emf.common.util.EList) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Application(org.contextmapper.dsl.contextMappingDSL.Application)

Example 3 with Application

use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createEndpoint.

private EndpointContract createEndpoint(Application application, ServiceSpecification specification) {
    EndpointContract endpoint = new EndpointContract();
    String endpointName = StringUtils.isNoneEmpty(application.getName()) ? mdslEncoder.encodeName(application.getName()) : mdslEncoder.encodeName("Application");
    endpoint.setName(endpointName);
    List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
    for (ServiceOperation serviceOperation : serviceOperations) {
        if (serviceOperation.getVisibility().equals(Visibility.PUBLIC))
            endpoint.addOperation(createOperation(serviceOperation, specification));
    }
    for (CommandEvent command : application.getCommands()) {
        endpoint.addOperation(createOperation(command, specification));
    }
    return endpoint;
}
Also used : EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamRole(org.contextmapper.dsl.contextMappingDSL.UpstreamRole) EitherCommandOrOperationInvokation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation) ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) StringUtils(org.apache.commons.lang3.StringUtils) SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) InvalidParameterException(java.security.InvalidParameterException) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) Map(java.util.Map) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) SingleCommandInvokation(org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation) EventProduction(org.contextmapper.dsl.contextMappingDSL.EventProduction) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) Collectors(java.util.stream.Collectors) List(java.util.List) ExclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation) APIUsageContext(org.contextmapper.dsl.generator.mdsl.model.APIUsageContext) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Visibility(org.contextmapper.tactic.dsl.tacticdsl.Visibility) Lists(com.google.common.collect.Lists) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) Application(org.contextmapper.dsl.contextMappingDSL.Application) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Maps(com.google.common.collect.Maps) EList(org.eclipse.emf.common.util.EList) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)

Example 4 with Application

use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method respectApplicationLayerName.

@Test
public void respectApplicationLayerName() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Application app = ContextMappingDSLFactory.eINSTANCE.createApplication();
    app.setName("MyAppLayer");
    boundedContext.setApplication(app);
    DomainEvent testEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
    testEvent.setName("TestEvent");
    app.getEvents().add(testEvent);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("package \"'MyAppLayer'\" <<Rectangle>> {" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestEvent <<(E,#ff9f4b) Domain Event>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
}
Also used : DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Application(org.contextmapper.dsl.contextMappingDSL.Application) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Aggregations

Application (org.contextmapper.dsl.contextMappingDSL.Application)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)4 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)4 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 InvalidParameterException (java.security.InvalidParameterException)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 CommandInvokationStep (org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep)2 ConcurrentCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)2 EitherCommandOrOperation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation)2 EitherCommandOrOperationInvokation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation)2 EventProduction (org.contextmapper.dsl.contextMappingDSL.EventProduction)2