Search in sources :

Example 1 with EndpointContract

use of org.contextmapper.dsl.generator.mdsl.model.EndpointContract in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canCreateMDSLModelWithoutContextMap.

@Test
void canCreateMDSLModelWithoutContextMap() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("basic-mdsl-model-test-without-contextmap.cml");
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    // then
    assertEquals(1, serviceSpecifications.size());
    ServiceSpecification spec = serviceSpecifications.get(0);
    assertEquals("CustomerManagementContextAPI", spec.getName());
    assertEquals(1, spec.getEndpoints().size());
    EndpointContract endpoint = spec.getEndpoints().get(0);
    assertEquals("Customers", endpoint.getName());
    assertEquals(2, endpoint.getOperations().size());
    EndpointOperation operation1 = endpoint.getOperations().get(0);
    assertEquals("updateAddress", operation1.getName());
    EndpointOperation operation2 = endpoint.getOperations().get(1);
    assertEquals("anotherMethod", operation2.getName());
    assertEquals(5, spec.getDataTypes().size());
    DataType dataType1 = spec.getDataTypes().get(0);
    assertEquals("Address", dataType1.getName());
    DataType dataType2 = spec.getDataTypes().get(1);
    assertEquals("Parameter1Type", dataType2.getName());
    DataType dataType3 = spec.getDataTypes().get(2);
    assertEquals("Parameter2Type", dataType3.getName());
    DataType dataType4 = spec.getDataTypes().get(3);
    assertEquals("ReturnType", dataType4.getName());
    DataType dataType5 = spec.getDataTypes().get(4);
    assertEquals("anotherMethodParameter", dataType5.getName());
    assertEquals("Address", operation1.getExpectingPayload().getName());
    assertEquals("ReturnType", operation1.getDeliveringPayload().getName());
    assertEquals("anotherMethodParameter", operation2.getExpectingPayload().getName());
    assertEquals(1, spec.getProviders().size());
    EndpointProvider provider = spec.getProviders().get(0);
    assertEquals("CustomerManagementContextProvider", provider.getName());
    assertEquals(1, provider.getEndpointOffers().size());
    EndpointOffer contractOffered = provider.getEndpointOffers().get(0);
    assertEquals("Customers", contractOffered.getOfferedEndpoint().getName());
    assertEquals("http://localhost:8000", contractOffered.getLocation());
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) CMLResource(org.contextmapper.dsl.cml.CMLResource) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with EndpointContract

use of org.contextmapper.dsl.generator.mdsl.model.EndpointContract in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createProvider.

private EndpointProvider createProvider(UpstreamAPIContext context, List<EndpointContract> endpointContracts) {
    EndpointProvider provider = new EndpointProvider();
    String implementationTechnology = context.getJoinedImplementationTechnologies();
    provider.setName(mdslEncoder.encodeName(context.getUpstreamContext().getName() + PROVIDER_NAME_EXTENSION));
    for (EndpointContract contract : endpointContracts) {
        EndpointOffer offer = new EndpointOffer();
        offer.setOfferedEndpoint(contract);
        offer.setLocation(ENDPOINT_LOCATION + (initialPort++));
        offer.setProtocol(!"".equals(implementationTechnology) ? implementationTechnology : PROTOCOL_STRING_IF_NOT_DEFINED);
        offer.setProtocolComment(!"".equals(implementationTechnology) ? "" : PROTOCOL_NOT_DEFINED_COMMENT);
        provider.addEndpointOffer(offer);
    }
    if (!context.getUpstreamRoles().isEmpty()) {
        String roles = String.join(" and ", context.getUpstreamRoles().stream().map(ur -> ur.getName() + " (" + ur.getLiteral() + ")").collect(Collectors.toList()));
        provider.addComment("Generated from DDD upstream Bounded Context '" + context.getUpstreamContext().getName() + "' implementing " + roles + ".");
    }
    if (context.getUpstreamContext().getDomainVisionStatement() != null && !"".equals(context.getUpstreamContext().getDomainVisionStatement()))
        provider.setDomainVisionStatement(context.getUpstreamContext().getDomainVisionStatement());
    return provider;
}
Also used : EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer)

Example 3 with EndpointContract

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

use of org.contextmapper.dsl.generator.mdsl.model.EndpointContract in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createEndpoint.

private EndpointContract createEndpoint(Aggregate aggregate, ServiceSpecification specification) {
    EndpointContract endpoint = new EndpointContract();
    String endpointName = mdslEncoder.encodeName(aggregate.getName());
    endpoint.setName(endpointName);
    Optional<DomainObject> aggregateRoot = aggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).findFirst();
    if (aggregateRoot.isPresent()) {
        for (DomainObjectOperation operation : aggregateRoot.get().getOperations()) {
            if (operation.getVisibility().equals(Visibility.PUBLIC))
                endpoint.addOperation(createOperation(operation, specification));
        }
    }
    List<ServiceOperation> serviceOperations = aggregate.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));
    }
    setEndpointServesAsString(endpoint, aggregate.getDoc());
    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) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)

Example 5 with EndpointContract

use of org.contextmapper.dsl.generator.mdsl.model.EndpointContract in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canCreateMDSLModel.

@Test
void canCreateMDSLModel() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("basic-mdsl-model-test.cml");
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    // then
    assertEquals(1, serviceSpecifications.size());
    ServiceSpecification spec = serviceSpecifications.get(0);
    assertEquals("CustomerManagementContextAPI", spec.getName());
    assertEquals(1, spec.getEndpoints().size());
    EndpointContract endpoint = spec.getEndpoints().get(0);
    assertEquals("Customers", endpoint.getName());
    assertEquals(2, endpoint.getOperations().size());
    EndpointOperation operation1 = endpoint.getOperations().get(0);
    assertEquals("updateAddress", operation1.getName());
    EndpointOperation operation2 = endpoint.getOperations().get(1);
    assertEquals("anotherMethod", operation2.getName());
    assertEquals(5, spec.getDataTypes().size());
    DataType dataType1 = spec.getDataTypes().get(0);
    assertEquals("Address", dataType1.getName());
    DataType dataType2 = spec.getDataTypes().get(1);
    assertEquals("Parameter1Type", dataType2.getName());
    DataType dataType3 = spec.getDataTypes().get(2);
    assertEquals("Parameter2Type", dataType3.getName());
    DataType dataType4 = spec.getDataTypes().get(3);
    assertEquals("ReturnType", dataType4.getName());
    DataType dataType5 = spec.getDataTypes().get(4);
    assertEquals("anotherMethodParameter", dataType5.getName());
    assertEquals("Address", operation1.getExpectingPayload().getName());
    assertEquals("ReturnType", operation1.getDeliveringPayload().getName());
    assertEquals("anotherMethodParameter", operation2.getExpectingPayload().getName());
    assertEquals(1, spec.getProviders().size());
    EndpointProvider provider = spec.getProviders().get(0);
    assertEquals("CustomerManagementContextProvider", provider.getName());
    assertEquals(1, provider.getEndpointOffers().size());
    EndpointOffer contractOffered = provider.getEndpointOffers().get(0);
    assertEquals("Customers", contractOffered.getOfferedEndpoint().getName());
    assertEquals("http://localhost:8000", contractOffered.getLocation());
    assertEquals("RESTful HTTP", contractOffered.getProtocol());
    assertEquals(1, spec.getClients().size());
    EndpointClient client = spec.getClients().get(0);
    assertEquals("ContractManagementContextClient", client.getName());
    assertEquals(1, client.getConsumedOfferNames().size());
    assertEquals("Customers", client.getConsumedOfferNames().get(0));
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) CMLResource(org.contextmapper.dsl.cml.CMLResource) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Aggregations

EndpointContract (org.contextmapper.dsl.generator.mdsl.model.EndpointContract)6 EndpointOffer (org.contextmapper.dsl.generator.mdsl.model.EndpointOffer)5 EndpointProvider (org.contextmapper.dsl.generator.mdsl.model.EndpointProvider)5 ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)5 DataType (org.contextmapper.dsl.generator.mdsl.model.DataType)4 EndpointOperation (org.contextmapper.dsl.generator.mdsl.model.EndpointOperation)4 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)3 CMLResource (org.contextmapper.dsl.cml.CMLResource)3 EndpointClient (org.contextmapper.dsl.generator.mdsl.model.EndpointClient)3 OrchestrationFlow (org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow)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