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