Search in sources :

Example 1 with DownstreamContext

use of org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createClient.

private EndpointClient createClient(DownstreamContext downstreamContext) {
    EndpointClient client = new EndpointClient();
    client.setName(mdslEncoder.encodeName(downstreamContext.getDownstreamName() + CLIENT_NAME_EXTENSION));
    List<String> endpoints = downstreamContext.getConsumedAggregates().stream().map(agg -> agg.getName()).collect(Collectors.toList());
    for (String offer : endpoints) {
        client.addConsumedOffer(offer);
    }
    if (!downstreamContext.getDownstreamRoles().isEmpty()) {
        String roles = String.join(" and ", downstreamContext.getDownstreamRoles().stream().map(ur -> ur.getName() + " (" + ur.getLiteral() + ")").collect(Collectors.toList()));
        client.addComment("Generated from DDD downstream Bounded Context '" + downstreamContext.getDownstreamName() + "' implementing " + roles + ".");
    }
    if (downstreamContext.getDomainVisionStatement() != null && !"".equals(downstreamContext.getDomainVisionStatement()))
        client.setDomainVisionStatement(downstreamContext.getDomainVisionStatement());
    return client;
}
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) EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient)

Example 2 with DownstreamContext

use of org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createServiceSpecification.

private ServiceSpecification createServiceSpecification(String apiName, UpstreamAPIContext context) {
    ServiceSpecification specification = new ServiceSpecification();
    specification.setName(mdslEncoder.encodeName(apiName));
    if (context.getUpstreamRoles().contains(UpstreamRole.OPEN_HOST_SERVICE) && context.getUpstreamRoles().contains(UpstreamRole.PUBLISHED_LANGUAGE)) {
        specification.setUsageContext(APIUsageContext.PUBLIC_API);
    } else if (context.getUpstreamRoles().contains(UpstreamRole.OPEN_HOST_SERVICE)) {
        specification.setUsageContext(APIUsageContext.COMMUNITY_API);
    }
    if (context.getApplicationLayer() != null) {
        specification.addEndpoint(createEndpoint(context.getApplicationLayer(), specification));
        for (DomainEvent de : context.getApplicationLayer().getEvents()) {
            specification.addEventType(de.getName());
        // TODO map data structure, not just name (if present)
        }
        // add event types for all domain events in all exposed aggregates
        for (Aggregate exposedAggregate : context.getExposedAggregates()) {
            for (SimpleDomainObject objectInAggregate : exposedAggregate.getDomainObjects()) {
                // check type of domain object (entity? event?...?):
                if (objectInAggregate instanceof DomainEvent) {
                    DomainEvent de = (DomainEvent) objectInAggregate;
                    // TODO make sure names are unique/do not add duplicates
                    specification.addEventType(de.getName());
                }
            }
        }
        for (CommandEvent ce : context.getApplicationLayer().getCommands()) {
            specification.addCommandType(ce.getName());
        }
        EList<Flow> flows = context.getApplicationLayer().getFlows();
        for (Flow cmlFlow : flows) {
            OrchestrationFlow mdslFlow = new OrchestrationFlow();
            mdslFlow.setName(cmlFlow.getName());
            for (FlowStep step : cmlFlow.getSteps()) {
                mapFlowStep(mdslFlow, step);
            }
            specification.addFlow(mdslFlow);
        }
    }
    for (Aggregate aggregate : context.getExposedAggregates()) {
        specification.addEndpoint(createEndpoint(aggregate, specification));
    }
    for (DataType dataType : dataTypeCreator.getAllDataTypes()) {
        specification.addDataType(dataType);
    }
    specification.addProvider(createProvider(context, specification.getEndpoints()));
    for (DownstreamContext downstreamContext : context.getDownstreamContexts()) {
        specification.addClient(createClient(downstreamContext));
    }
    return specification;
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) Flow(org.contextmapper.dsl.contextMappingDSL.Flow)

Aggregations

Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)2 FlowStep (org.contextmapper.dsl.contextMappingDSL.FlowStep)2 DownstreamContext (org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext)2 DataType (org.contextmapper.dsl.generator.mdsl.model.DataType)2 OrchestrationFlow (org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow)2 ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)2 CommandEvent (org.contextmapper.tactic.dsl.tacticdsl.CommandEvent)2 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)2 SimpleDomainObject (org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 InvalidParameterException (java.security.InvalidParameterException)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Application (org.contextmapper.dsl.contextMappingDSL.Application)1 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)1