Search in sources :

Example 1 with DomainObject

use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.

the class SplitAggregateByEntitiesTest method canSplitWithTwoAggregates.

@Test
void canSplitWithTwoAggregates() throws IOException {
    // given
    String inputModelName = "split-agg-by-entities-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    SplitAggregateByEntitiesRefactoring refactoring = new SplitAggregateByEntitiesRefactoring("Customers");
    // when
    refactoring.refactor(input);
    refactoring.persistChanges(serializer);
    // then
    BoundedContext bc = reloadResource(input).getContextMappingModel().getBoundedContexts().get(0);
    assertEquals(2, bc.getAggregates().size());
    for (Aggregate aggregate : bc.getAggregates()) {
        assertEquals(1, aggregate.getDomainObjects().size());
    }
    List<String> aggregateNames = bc.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
    assertTrue(aggregateNames.contains("Customers"));
    assertTrue(aggregateNames.contains("Account"));
    for (Aggregate aggregate : bc.getAggregates()) {
        SimpleDomainObject obj = aggregate.getDomainObjects().get(0);
        if (obj instanceof DomainObject)
            assertTrue(((DomainObject) obj).isAggregateRoot());
    }
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CMLResource(org.contextmapper.dsl.cml.CMLResource) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 2 with DomainObject

use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.

the class MergeAggregatesTest method canHandleAggregateRoots.

@Test
void canHandleAggregateRoots() throws IOException {
    // given
    String inputModelName = "merge-aggregates-test-6-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MergeAggregatesRefactoring refactoring = new MergeAggregatesRefactoring("agg1", "agg2", true);
    // when
    refactoring.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(1, model.getBoundedContexts().size());
    BoundedContext bc = model.getBoundedContexts().get(0);
    assertEquals(1, bc.getAggregates().size());
    Aggregate aggregate = bc.getAggregates().get(0);
    List<DomainObject> aggregateRoots = aggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).collect(Collectors.toList());
    assertEquals(1, aggregateRoots.size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Volatility(org.contextmapper.dsl.contextMappingDSL.Volatility) IOException(java.io.IOException) KnowledgeLevel(org.contextmapper.dsl.contextMappingDSL.KnowledgeLevel) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Test(org.junit.jupiter.api.Test) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLResource(org.contextmapper.dsl.cml.CMLResource) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 3 with DomainObject

use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.

the class MDSLDataTypeCreator method getDomainObjectAttributes.

private List<Attribute> getDomainObjectAttributes(DomainObject domainObject) {
    List<Attribute> attributes = new ArrayList<>();
    DomainObject extendsType = getExtendsType(domainObject);
    while (extendsType != null) {
        attributes.addAll(extendsType.getAttributes());
        extendsType = getExtendsType(extendsType);
    }
    attributes.addAll(domainObject.getAttributes());
    return attributes;
}
Also used : DataTypeAttribute(org.contextmapper.dsl.generator.mdsl.model.DataTypeAttribute) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ArrayList(java.util.ArrayList) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject)

Example 4 with DomainObject

use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject 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 5 with DomainObject

use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.

the class CMLModelObjectsResolvingHelperTest method canReturnNullInCaseDomainObjectIsNotPartOfBC.

@Test
public void canReturnNullInCaseDomainObjectIsNotPartOfBC() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("bc-resolving-test-1.cml");
    DomainObject domainObject = EcoreUtil2.eAllOfType(input.getContextMappingModel(), DomainObject.class).stream().filter(o -> o.getName().equals("TestEntity3")).findFirst().get();
    // when
    CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper(input.getContextMappingModel());
    BoundedContext bc = helper.resolveBoundedContext(domainObject);
    // then
    assertNull(bc);
}
Also used : DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DomainObject (org.contextmapper.tactic.dsl.tacticdsl.DomainObject)20 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)8 Maps (com.google.common.collect.Maps)6 Map (java.util.Map)6 Optional (java.util.Optional)6 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)6 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)6 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)5 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)5 SolverAlgorithm (ch.hsr.servicecutter.solver.SolverAlgorithm)4 Lists (com.google.common.collect.Lists)4 Set (java.util.Set)4 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)4 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)4 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)4 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)3 URI (org.eclipse.emf.common.util.URI)3