Search in sources :

Example 1 with Reference

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()));
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with Reference

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;
}
Also used : Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) DataTypeAttribute(org.contextmapper.dsl.generator.mdsl.model.DataTypeAttribute) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType)

Example 3 with Reference

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. */");
    }
}
Also used : SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) URI(org.eclipse.emf.common.util.URI) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) HashSet(java.util.HashSet) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) ServiceRelation(ch.hsr.servicecutter.api.model.ServiceRelation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Map(java.util.Map) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) SolverPriority(ch.hsr.servicecutter.solver.SolverPriority) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) Service(ch.hsr.servicecutter.api.model.Service) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) SharedKernel(org.contextmapper.dsl.contextMappingDSL.SharedKernel) SolverAlgorithm(ch.hsr.servicecutter.solver.SolverAlgorithm) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext)

Example 4 with Reference

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);
    }
}
Also used : Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) BoundedContextType(org.contextmapper.dsl.contextMappingDSL.BoundedContextType) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Set(java.util.Set) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IteratorExtensions(org.eclipse.xtext.xbase.lib.IteratorExtensions) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) List(java.util.List) DomainPart(org.contextmapper.dsl.contextMappingDSL.DomainPart) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference)

Example 5 with Reference

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);
    }
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) Feature(org.contextmapper.dsl.contextMappingDSL.Feature)

Aggregations

Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)16 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)8 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)8 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)7 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)7 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Set (java.util.Set)4 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)4 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)4 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)4 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)4 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)4 Sets (com.google.common.collect.Sets)3 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)3 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)3 SolverAlgorithm (ch.hsr.servicecutter.solver.SolverAlgorithm)2 Maps (com.google.common.collect.Maps)2 Map (java.util.Map)2 Optional (java.util.Optional)2