Search in sources :

Example 1 with UpstreamAPIContext

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

the class MDSLModelCreator method collectUpstreamContexts.

private Map<String, UpstreamAPIContext> collectUpstreamContexts() {
    Map<String, UpstreamAPIContext> upstreamContextMap = Maps.newHashMap();
    List<UpstreamDownstreamRelationship> upstreamDownstreamRelationships = Lists.newLinkedList();
    if (model.getMap() != null)
        upstreamDownstreamRelationships = model.getMap().getRelationships().stream().filter(rel -> rel instanceof UpstreamDownstreamRelationship).map(rel -> (UpstreamDownstreamRelationship) rel).collect(Collectors.toList());
    for (UpstreamDownstreamRelationship relationship : upstreamDownstreamRelationships) {
        if (relationship.getUpstreamExposedAggregates().isEmpty())
            continue;
        String upstreamAPIName = relationship.getUpstream().getName() + API_NAME_EXTENSION;
        UpstreamAPIContext context = null;
        if (upstreamContextMap.containsKey(upstreamAPIName)) {
            context = upstreamContextMap.get(upstreamAPIName);
        } else {
            context = new UpstreamAPIContext();
            context.setApiName(mdslEncoder.encodeName(upstreamAPIName));
            context.setUpstreamContext(relationship.getUpstream());
            upstreamContextMap.put(upstreamAPIName, context);
        }
        context.getUpstreamRoles().addAll(relationship.getUpstreamRoles());
        for (Aggregate exposedAggregate : relationship.getUpstreamExposedAggregates()) {
            if (!context.getExposedAggregates().stream().map(agg -> agg.getName()).collect(Collectors.toList()).contains(exposedAggregate.getName()))
                context.getExposedAggregates().add(exposedAggregate);
        }
        if (relationship.getUpstream().getApplication() != null)
            context.setApplicationLayer(relationship.getUpstream().getApplication());
        context.addDownstreamContext4Relationship(relationship);
        if (relationship.getImplementationTechnology() != null && !"".equals(relationship.getImplementationTechnology()))
            context.getImplementationTechnologies().add(relationship.getImplementationTechnology());
    }
    // add all contexts that are not upstream in an upstream-downstream relationship
    for (BoundedContext bc : model.getBoundedContexts()) {
        String apiName = bc.getName() + API_NAME_EXTENSION;
        if (upstreamContextMap.containsKey(apiName) || (bc.getAggregates().isEmpty() && bc.getApplication() == null))
            continue;
        UpstreamAPIContext context = new UpstreamAPIContext();
        context.setApiName(apiName);
        context.setUpstreamContext(bc);
        context.getExposedAggregates().addAll(bc.getAggregates());
        context.setApplicationLayer(bc.getApplication());
        upstreamContextMap.put(apiName, context);
    }
    return upstreamContextMap;
}
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) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)

Example 2 with UpstreamAPIContext

use of org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext 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 UpstreamAPIContext

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

the class MDSLModelCreator method createServiceSpecifications.

public List<ServiceSpecification> createServiceSpecifications() {
    checkPreconditions();
    List<ServiceSpecification> specs = Lists.newArrayList();
    Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
    for (String apiName : upstreamContexts.keySet()) {
        UpstreamAPIContext context = upstreamContexts.get(apiName);
        specs.add(createServiceSpecification(context.getApiName(), context));
    }
    return specs;
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext)

Aggregations

UpstreamAPIContext (org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext)3 ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)3 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 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 Application (org.contextmapper.dsl.contextMappingDSL.Application)2 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)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