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());
}
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));
}
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));
}
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));
}
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;
}
Aggregations