use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreateReferences.
@Test
public void canCreateReferences() {
// given
BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
aggregate.setName("testAggregate");
boundedContext.getAggregates().add(aggregate);
Entity customer = TacticdslFactory.eINSTANCE.createEntity();
customer.setName("Customer");
Entity address = TacticdslFactory.eINSTANCE.createEntity();
address.setName("Address");
Entity anotherObject = TacticdslFactory.eINSTANCE.createEntity();
anotherObject.setName("AnotherObject");
Reference reference = TacticdslFactory.eINSTANCE.createReference();
reference.setDomainObjectType(address);
reference.setName("entity2Ref");
Reference listReference = TacticdslFactory.eINSTANCE.createReference();
listReference.setCollectionType(CollectionType.LIST);
listReference.setName("myListReference");
listReference.setDomainObjectType(anotherObject);
customer.getReferences().add(reference);
customer.getReferences().add(listReference);
aggregate.getDomainObjects().add(customer);
aggregate.getDomainObjects().add(address);
aggregate.getDomainObjects().add(anotherObject);
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains(" class Address <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + " }" + System.lineSeparator()));
assertTrue(plantUML.contains(" class Customer <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + " Address entity2Ref" + System.lineSeparator() + " List<AnotherObject> myListReference" + System.lineSeparator() + " }" + System.lineSeparator()));
assertTrue(plantUML.contains("Customer --> Address : entity2Ref" + System.lineSeparator()));
assertTrue(plantUML.contains("Customer o-- AnotherObject : myListReference" + System.lineSeparator()));
}
use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.
the class MDSLDataTypeCreator method createAttributes4ReferencesList.
private List<DataTypeAttribute> createAttributes4ReferencesList(List<Reference> references) {
List<DataTypeAttribute> mdslAttributes = Lists.newArrayList();
for (Reference reference : references) {
DataType referencedType = createMDSLDataType(createComplexTypeForReference(reference));
mdslAttributes.add(createAttribute(reference.getName(), referencedType.getName(), isCollection(reference.getCollectionType()), reference.isNullable()));
}
return mdslAttributes;
}
use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.
the class ServiceCutterOutputToContextMappingModelConverter method reconstructReference.
private void reconstructReference(DomainObject sourceObject, Reference originalReference, String targetTypeName) {
BoundedContext parentBC = new CMLModelObjectsResolvingHelper(originalModelState).resolveBoundedContext(sourceObject);
if (parentBC == null)
// in case this source object is not part of a Bounded Context
return;
List<DomainObject> targetDomainObjects = EcoreUtil2.eAllOfType(model, DomainObject.class).stream().filter(obj -> obj.getName().equals(targetTypeName)).collect(Collectors.toList());
if (targetDomainObjects.size() == 1) {
Reference reference = TacticdslFactory.eINSTANCE.createReference();
reference.setName(originalReference.getName());
reference.setDomainObjectType(targetDomainObjects.get(0));
reference.setCollectionType(originalReference.getCollectionType());
reference.setDoc(originalReference.getDoc());
sourceObject.getReferences().add(reference);
} else {
sourceObject.setComment("/* Service Cut generator: it was not possible to reconstruct the reference '" + originalReference.getName() + "' from " + sourceObject.getName() + " to " + targetTypeName + ". Please re-create that reference manually. */");
}
}
use of org.contextmapper.tactic.dsl.tacticdsl.Reference 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);
}
}
use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.
the class DeriveSubdomainFromUserRequirements method deriveSubdomainEntityReferences.
private void deriveSubdomainEntityReferences(Subdomain subdomain, List<Feature> features) {
for (Feature feature : features) {
if (feature.getContainerEntity() == null || "".equals(feature.getContainerEntity()))
continue;
String containerEntityName = mapEntityName(feature.getContainerEntity());
String referencedEntityName = mapEntityName(feature.getEntity());
Entity containerEntity = subdomain.getEntities().stream().filter(e -> e.getName().equals(containerEntityName)).findFirst().get();
Entity referencedEntity = subdomain.getEntities().stream().filter(e -> e.getName().equals(referencedEntityName)).findFirst().get();
String refName = referencedEntity.getName().toLowerCase() + "List";
if (containerEntity.getReferences().stream().filter(r -> r.getName().equals(refName)).findAny().isPresent())
continue;
Reference reference = TacticdslFactory.eINSTANCE.createReference();
reference.setName(refName);
reference.setCollectionType(CollectionType.LIST);
reference.setDomainObjectType(referencedEntity);
addElementToEList(containerEntity.getReferences(), reference);
}
}
Aggregations