Search in sources :

Example 1 with EntityRelationDiagram

use of ch.hsr.servicecutter.api.model.EntityRelationDiagram in project context-mapper-dsl by ContextMapper.

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4BoundedContext.

@Test
public void canCreateEntity4BoundedContext() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext.setName("testBC");
    contextMap.getBoundedContexts().add(boundedContext);
    model.getBoundedContexts().add(boundedContext);
    model.setMap(contextMap);
    // when
    EntityRelationDiagram scDiagram = this.converter.convert("TestModel", model);
    // then
    assertEquals("TestModel", scDiagram.getName());
    assertEquals(1, scDiagram.getEntities().size());
    assertEquals("testBC_BC", scDiagram.getEntities().get(0).getName());
    assertEquals(0, scDiagram.getEntities().get(0).getNanoentities().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Example 2 with EntityRelationDiagram

use of ch.hsr.servicecutter.api.model.EntityRelationDiagram in project context-mapper-dsl by ContextMapper.

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4DomainEvent.

@Test
public void canCreateEntity4DomainEvent() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext.setName("testBC");
    contextMap.getBoundedContexts().add(boundedContext);
    model.getBoundedContexts().add(boundedContext);
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    DomainEvent domainEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
    domainEvent.setName("TestDomainEvent");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setName("attribute1");
    aggregate.getDomainObjects().add(domainEvent);
    domainEvent.getAttributes().add(attribute);
    model.setMap(contextMap);
    // when
    EntityRelationDiagram scDiagram = this.converter.convert("TestModel", model);
    // then
    List<String> entityNames = scDiagram.getEntities().stream().map(e -> e.getName()).collect(Collectors.toList());
    assertTrue(entityNames.contains("TestDomainEvent"));
    ch.hsr.servicecutter.api.model.Entity scEntity = getEntity(scDiagram.getEntities(), "TestDomainEvent");
    assertEquals(1, scEntity.getNanoentities().size());
    assertEquals("attribute1", scEntity.getNanoentities().get(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) RelationType(ch.hsr.servicecutter.api.model.EntityRelation.RelationType) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Collectors(java.util.stream.Collectors) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 3 with EntityRelationDiagram

use of ch.hsr.servicecutter.api.model.EntityRelationDiagram in project context-mapper-dsl by ContextMapper.

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4Entity.

@Test
public void canCreateEntity4Entity() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext.setName("testBC");
    contextMap.getBoundedContexts().add(boundedContext);
    model.getBoundedContexts().add(boundedContext);
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    Entity entity = TacticdslFactory.eINSTANCE.createEntity();
    entity.setName("TestEntity");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setName("attribute1");
    aggregate.getDomainObjects().add(entity);
    entity.getAttributes().add(attribute);
    model.setMap(contextMap);
    // when
    EntityRelationDiagram scDiagram = this.converter.convert("TestModel", model);
    // then
    List<String> entityNames = scDiagram.getEntities().stream().map(e -> e.getName()).collect(Collectors.toList());
    assertTrue(entityNames.contains("TestEntity"));
    ch.hsr.servicecutter.api.model.Entity scEntity = getEntity(scDiagram.getEntities(), "TestEntity");
    assertEquals(1, scEntity.getNanoentities().size());
    assertEquals("attribute1", scEntity.getNanoentities().get(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) RelationType(ch.hsr.servicecutter.api.model.EntityRelation.RelationType) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Collectors(java.util.stream.Collectors) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 4 with EntityRelationDiagram

use of ch.hsr.servicecutter.api.model.EntityRelationDiagram in project context-mapper-dsl by ContextMapper.

the class NewServiceCutContextMapGenerator method generateFromContextMappingModel.

@Override
protected void generateFromContextMappingModel(ContextMappingModel model, IFileSystemAccess2 fsa, URI inputFileURI) {
    checkPreconditions(model);
    String fileBaseName = inputFileURI.trimFileExtension().lastSegment();
    // prepare service cutter input
    EntityRelationDiagram erdInput = new ContextMappingModelToServiceCutterERDConverter().convert(fileBaseName, model);
    ServiceCutterContextBuilder contextBuilder = new ServiceCutterContextBuilder(erdInput);
    SolverConfiguration solverConfig = getSolverConfiguration();
    contextBuilder.withCustomSolverConfiguration(solverConfig);
    contextBuilder.withUserRepresentations(getUserRepresentations(inputFileURI));
    ServiceCutterContext context = contextBuilder.build();
    // calculate new service cut
    SolverResult result = new ServiceCutter(context).generateDecomposition();
    ContextMappingModel newServiceCutModel = new ServiceCutterOutputToContextMappingModelConverter(contextMappingModel, context, getSCLModel(inputFileURI).eResource().getURI()).convert(result);
    // save new CML file
    int counter = 1;
    String baseFileName = inputFileURI.trimFileExtension().lastSegment() + "_" + solverConfig.getAlgorithm().toString().replace(" ", "_") + "_Cut_";
    URI fileName = inputFileURI.trimFileExtension().trimSegments(1).appendSegment(baseFileName + counter).appendFileExtension("cml");
    while (resourceSet.getURIConverter().exists(fileName, null)) {
        counter++;
        fileName = inputFileURI.trimFileExtension().trimSegments(1).appendSegment(baseFileName + counter).appendFileExtension("cml");
    }
    Resource resource = resourceSet.createResource(fileName);
    resource.getContents().add(newServiceCutModel);
    try {
        resource.save(null);
    } catch (IOException e) {
        throw new RuntimeException("Saving CML model was not possible.", e);
    }
    // save scoring as graphviz DOT file
    fsa.generateFile(fileName.trimFileExtension().lastSegment() + ".gv", generateGraphvizScoringRepresentation(context));
}
Also used : ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ServiceCutter(ch.hsr.servicecutter.api.ServiceCutter) SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) ServiceCutterOutputToContextMappingModelConverter(org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter) ServiceCutterContextBuilder(ch.hsr.servicecutter.api.ServiceCutterContextBuilder)

Example 5 with EntityRelationDiagram

use of ch.hsr.servicecutter.api.model.EntityRelationDiagram in project context-mapper-dsl by ContextMapper.

the class ContextMappingModelToServiceCutterERDConverter method convert.

public EntityRelationDiagram convert(String modelName, ContextMappingModel cmlModel) {
    this.target = new EntityRelationDiagram();
    this.target.setName(modelName);
    this.target.setEntities(new ArrayList<>());
    this.target.setRelations(new ArrayList<>());
    initializeEntityLookupTable(cmlModel);
    for (BoundedContext bc : cmlModel.getBoundedContexts()) {
        mapBoundedContext(bc);
    }
    mapReferences4DomainObjects(EcoreUtil2.getAllContentsOfType(cmlModel, SimpleDomainObject.class));
    return target;
}
Also used : EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext)

Aggregations

EntityRelationDiagram (ch.hsr.servicecutter.api.model.EntityRelationDiagram)9 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)7 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)7 ContextMappingModelToServiceCutterERDConverter (org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter)7 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)6 Test (org.junit.jupiter.api.Test)6 RelationType (ch.hsr.servicecutter.api.model.EntityRelation.RelationType)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)5 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)5 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)5 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)5 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)5 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)5 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)5 ValueObject (org.contextmapper.tactic.dsl.tacticdsl.ValueObject)5 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5