Search in sources :

Example 1 with SimpleDomainObject

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

use of org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject 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)

Example 3 with SimpleDomainObject

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

the class AbstractPlantUMLClassDiagramCreator method printModule.

protected void printModule(SculptorModule module) {
    sb.append("package ");
    if (module.getBasePackage() != null && !"".equals(module.getBasePackage()))
        sb.append(module.getBasePackage()).append(".").append(module.getName());
    else
        sb.append(module.getName());
    sb.append(" {");
    linebreak();
    for (Aggregate aggregate : module.getAggregates()) {
        printAggregate(aggregate, 1);
    }
    for (SimpleDomainObject simpleDomainObject : module.getDomainObjects()) {
        printDomainObject(simpleDomainObject, 1);
    }
    for (Service service : module.getServices()) {
        printService(service, 1);
    }
    sb.append("}");
    linebreak();
}
Also used : SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate)

Example 4 with SimpleDomainObject

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

the class PlantUMLBoundedContextClassDiagramCreator method printDiagramContent.

@Override
protected void printDiagramContent(BoundedContext boundedContext) {
    this.relationships = Lists.newArrayList();
    this.extensions = Lists.newArrayList();
    this.domainObjects = EcoreUtil2.<SimpleDomainObject>getAllContentsOfType(boundedContext, SimpleDomainObject.class);
    if (this.domainObjects.size() <= 0) {
        printEmptyDiagramNote();
        return;
    }
    for (SculptorModule module : boundedContext.getModules()) {
        printModule(module);
    }
    for (Aggregate aggregate : boundedContext.getAggregates()) {
        printAggregate(aggregate, 0);
    }
    if (boundedContext.getApplication() != null)
        printApplication(boundedContext.getApplication(), 0);
    printReferences(0);
    printLegend(boundedContext);
}
Also used : SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate)

Example 5 with SimpleDomainObject

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

the class DeriveBoundedContextFromSubdomains method copyReferences.

private void copyReferences(Entity source, Entity target, List<SimpleDomainObject> referenceableObjects) {
    Set<String> existingRefs = target.getReferences().stream().map(ref -> ref.getName()).collect(Collectors.toSet());
    for (Reference sourceRef : source.getReferences()) {
        if (existingRefs.contains(sourceRef.getName()))
            continue;
        Reference newReference = TacticdslFactory.eINSTANCE.createReference();
        newReference.setName(sourceRef.getName());
        newReference.setCollectionType(sourceRef.getCollectionType());
        newReference.setDomainObjectType(referenceableObjects.stream().filter(o -> o.getName().equals(sourceRef.getDomainObjectType().getName())).findFirst().get());
        addElementToEList(target.getReferences(), newReference);
    }
}
Also used : Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) BoundedContextType(org.contextmapper.dsl.contextMappingDSL.BoundedContextType) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Set(java.util.Set) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IteratorExtensions(org.eclipse.xtext.xbase.lib.IteratorExtensions) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) List(java.util.List) DomainPart(org.contextmapper.dsl.contextMappingDSL.DomainPart) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference)

Aggregations

SimpleDomainObject (org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject)11 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)8 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)4 Set (java.util.Set)3 CMLResource (org.contextmapper.dsl.cml.CMLResource)3 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)3 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)3 Sets (com.google.common.collect.Sets)2 Optional (java.util.Optional)2 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)2 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)2 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)2 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)2 DomainObject (org.contextmapper.tactic.dsl.tacticdsl.DomainObject)2 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)2 EObject (org.eclipse.emf.ecore.EObject)2