Search in sources :

Example 1 with Relationship

use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.

the class ContextMapSemanticsValidator method validateThatExposedAggregateIsPartOfUpstreamContext.

@Check
public void validateThatExposedAggregateIsPartOfUpstreamContext(final ContextMap map) {
    for (Relationship rel : map.getRelationships()) {
        if (rel instanceof UpstreamDownstreamRelationship) {
            UpstreamDownstreamRelationship relationship = (UpstreamDownstreamRelationship) rel;
            BoundedContext upstreamContext = ((UpstreamDownstreamRelationship) relationship).getUpstream();
            int aggregateRefIndex = 0;
            for (Aggregate aggregate : relationship.getUpstreamExposedAggregates()) {
                List<String> aggregates = upstreamContext.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
                for (SculptorModule module : upstreamContext.getModules()) {
                    aggregates.addAll(module.getAggregates().stream().map(b -> b.getName()).collect(Collectors.toList()));
                }
                if (!aggregates.contains(aggregate.getName()))
                    error(String.format(EXPOSED_AGGREGATE_NOT_PART_OF_UPSTREAM_CONTEXT, aggregate.getName(), upstreamContext.getName()), relationship, UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM_EXPOSED_AGGREGATES, aggregateRefIndex);
                aggregateRefIndex++;
            }
        }
    }
}
Also used : CONTEXT_MAP__TYPE(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.CONTEXT_MAP__TYPE) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ORGANIZATIONAL(org.contextmapper.dsl.contextMappingDSL.ContextMapType.ORGANIZATIONAL) SYMMETRIC_RELATIONSHIP__PARTICIPANT2(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.SYMMETRIC_RELATIONSHIP__PARTICIPANT2) SYMMETRIC_RELATIONSHIP__PARTICIPANT1(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.SYMMETRIC_RELATIONSHIP__PARTICIPANT1) BoundedContextType(org.contextmapper.dsl.contextMappingDSL.BoundedContextType) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) EReference(org.eclipse.emf.ecore.EReference) Check(org.eclipse.xtext.validation.Check) TEAM(org.contextmapper.dsl.contextMappingDSL.BoundedContextType.TEAM) EXPOSED_AGGREGATE_NOT_PART_OF_UPSTREAM_CONTEXT(org.contextmapper.dsl.validation.ValidationMessages.EXPOSED_AGGREGATE_NOT_PART_OF_UPSTREAM_CONTEXT) ORGANIZATIONAL_MAP_DOES_NOT_CONTAIN_TEAM(org.contextmapper.dsl.validation.ValidationMessages.ORGANIZATIONAL_MAP_DOES_NOT_CONTAIN_TEAM) RELATIONSHIP_CONTEXT_NOT_ON_MAP_ERROR_MESSAGE(org.contextmapper.dsl.validation.ValidationMessages.RELATIONSHIP_CONTEXT_NOT_ON_MAP_ERROR_MESSAGE) UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM) Collectors(java.util.stream.Collectors) SYSTEM_LANDSCAPE_MAP_CONTAINS_TEAM(org.contextmapper.dsl.validation.ValidationMessages.SYSTEM_LANDSCAPE_MAP_CONTAINS_TEAM) List(java.util.List) CONTEXT_MAP__BOUNDED_CONTEXTS(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.CONTEXT_MAP__BOUNDED_CONTEXTS) UPSTREAM_DOWNSTREAM_RELATIONSHIP__DOWNSTREAM(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.UPSTREAM_DOWNSTREAM_RELATIONSHIP__DOWNSTREAM) UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM_EXPOSED_AGGREGATES(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage.Literals.UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM_EXPOSED_AGGREGATES) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) SYSTEM_LANDSCAPE(org.contextmapper.dsl.contextMappingDSL.ContextMapType.SYSTEM_LANDSCAPE) EValidatorRegistrar(org.eclipse.xtext.validation.EValidatorRegistrar) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) AbstractDeclarativeValidator(org.eclipse.xtext.validation.AbstractDeclarativeValidator) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Check(org.eclipse.xtext.validation.Check)

Example 2 with Relationship

use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.

the class CMLModelObjectsResolvingHelper method resolveAllAccessibleAggregates.

public List<Aggregate> resolveAllAccessibleAggregates(BoundedContext bc) {
    List<Aggregate> aggregates = Lists.newLinkedList();
    aggregates.addAll(EcoreUtil2.eAllOfType(bc, Aggregate.class));
    ContextMap contextMap = getContextMap(bc);
    if (contextMap != null) {
        for (Relationship rel : contextMap.getRelationships()) {
            if (isBCDownstreamInRelationship(rel, bc))
                aggregates.addAll(getExposedAggregates(rel));
        }
    }
    return aggregates;
}
Also used : SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap)

Example 3 with Relationship

use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.

the class ExtractPartnershipRefactoringTest method canExtractPartnership.

@ParameterizedTest
@MethodSource("createExtractPartnershipParameters")
void canExtractPartnership(String inputFile, String resultingNewBC) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    new ExtractPartnershipRefactoring("CustomerManagement", "AnotherContext").refactor(input);
    // then
    ContextMap map = input.getContextMappingModel().getMap();
    BoundedContext bc1 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement")).findFirst().get();
    BoundedContext bc2 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("AnotherContext")).findFirst().get();
    BoundedContext newBC = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals(resultingNewBC)).findFirst().get();
    assertEquals(2, map.getRelationships().size());
    assertEquals(3, map.getBoundedContexts().size());
    Relationship rel1 = map.getRelationships().get(0);
    Relationship rel2 = map.getRelationships().get(1);
    assertTrue(rel1 instanceof UpstreamDownstreamRelationship);
    assertTrue(rel2 instanceof UpstreamDownstreamRelationship);
    UpstreamDownstreamRelationship upDown1 = (UpstreamDownstreamRelationship) rel1;
    UpstreamDownstreamRelationship upDown2 = (UpstreamDownstreamRelationship) rel2;
    assertTrue(upDown1.getUpstream().equals(newBC));
    assertTrue(upDown1.getDownstream().equals(bc1));
    assertTrue(upDown2.getUpstream().equals(newBC));
    assertTrue(upDown2.getDownstream().equals(bc2));
}
Also used : UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with Relationship

use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.

the class ChangePartnershipToUpstreamDownstreamRefactoringTest method canChangePartnershipToUpstreamDownstream.

@Test
void canChangePartnershipToUpstreamDownstream() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("change-partnership-to-upstream-downstream-test-1-input.cml");
    // when
    SemanticCMLRefactoring ar = new ChangePartnershipToUpstreamDownstreamRefactoring("CustomerManagement", "AnotherContext");
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    List<ContextMappingModel> contextMappingModels = IteratorExtensions.<ContextMappingModel>toList(Iterators.<ContextMappingModel>filter(reloadResource(input).getAllContents(), ContextMappingModel.class));
    ContextMap map = contextMappingModels.get(0).getMap();
    BoundedContext upstreamContext = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement")).findFirst().get();
    BoundedContext downstreamContext = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("AnotherContext")).findFirst().get();
    assertEquals(1, map.getRelationships().size());
    Relationship rel = map.getRelationships().get(0);
    assertTrue(rel instanceof UpstreamDownstreamRelationship);
    UpstreamDownstreamRelationship upDown = (UpstreamDownstreamRelationship) rel;
    assertTrue(upDown.getUpstream().equals(upstreamContext));
    assertTrue(upDown.getDownstream().equals(downstreamContext));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Example 5 with Relationship

use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.

the class ExtractSharedKernelRefactoringTest method canExtractSharedKernel.

@ParameterizedTest
@MethodSource("createExtractSharedKernelParameters")
void canExtractSharedKernel(String inputFile, String resultingNewBC) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    new ExtractSharedKernelRefactoring("CustomerManagement", "AnotherContext").refactor(input);
    // then
    ContextMap map = input.getContextMappingModel().getMap();
    BoundedContext bc1 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement")).findFirst().get();
    BoundedContext bc2 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("AnotherContext")).findFirst().get();
    BoundedContext newBC = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals(resultingNewBC)).findFirst().get();
    assertEquals(2, map.getRelationships().size());
    assertEquals(3, map.getBoundedContexts().size());
    Relationship rel1 = map.getRelationships().get(0);
    Relationship rel2 = map.getRelationships().get(1);
    assertTrue(rel1 instanceof UpstreamDownstreamRelationship);
    assertTrue(rel2 instanceof UpstreamDownstreamRelationship);
    UpstreamDownstreamRelationship upDown1 = (UpstreamDownstreamRelationship) rel1;
    UpstreamDownstreamRelationship upDown2 = (UpstreamDownstreamRelationship) rel2;
    assertTrue(upDown1.getUpstream().equals(newBC));
    assertTrue(upDown1.getDownstream().equals(bc1));
    assertTrue(upDown2.getUpstream().equals(newBC));
    assertTrue(upDown2.getDownstream().equals(bc2));
}
Also used : UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ExtractSharedKernelRefactoring(org.contextmapper.dsl.refactoring.ExtractSharedKernelRefactoring) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Relationship (org.contextmapper.dsl.contextMappingDSL.Relationship)11 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)10 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)8 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)7 SymmetricRelationship (org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship)6 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)4 CMLResource (org.contextmapper.dsl.cml.CMLResource)3 Check (org.eclipse.xtext.validation.Check)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 EReference (org.eclipse.emf.ecore.EReference)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Lists (com.google.common.collect.Lists)1 LinkedList (java.util.LinkedList)1 BoundedContextType (org.contextmapper.dsl.contextMappingDSL.BoundedContextType)1 TEAM (org.contextmapper.dsl.contextMappingDSL.BoundedContextType.TEAM)1 ORGANIZATIONAL (org.contextmapper.dsl.contextMappingDSL.ContextMapType.ORGANIZATIONAL)1 SYSTEM_LANDSCAPE (org.contextmapper.dsl.contextMappingDSL.ContextMapType.SYSTEM_LANDSCAPE)1 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)1