Search in sources :

Example 11 with Reference

use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.

the class ContextMappingModelToServiceCutterERDConverter method mapDomainObject.

private Entity mapDomainObject(DomainObject dslDomainObject) {
    Entity entityEntity = getEntity(dslDomainObject.getName());
    entityEntity.setNanoentities(new ArrayList<>());
    for (Attribute attribute : dslDomainObject.getAttributes()) {
        entityEntity.getNanoentities().add(attribute.getName());
    }
    for (Reference reference : dslDomainObject.getReferences()) {
        entityEntity.getNanoentities().add(reference.getName());
    }
    target.getEntities().add(entityEntity);
    return entityEntity;
}
Also used : Entity(ch.hsr.servicecutter.api.model.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference)

Example 12 with Reference

use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.

the class AbstractPlantUMLClassDiagramCreator method printReferenceAttributes.

private void printReferenceAttributes(List<Reference> references, int indentation) {
    for (Reference reference : references) {
        printIndentation(indentation);
        sb.append(getReferenceTypeAsString(reference));
        if (reference.isNullable())
            sb.append("[0..1]");
        sb.append(" ").append(reference.getName());
        linebreak();
    }
}
Also used : Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference)

Example 13 with Reference

use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirementsTest method canCreateContainmentReference.

@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-9-input.cml", "derive-subdomain-from-user-story-test-12-input.cml" })
public void canCreateContainmentReference(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> userStories = Sets.newHashSet(Arrays.asList(new String[] { "US1_Create" }));
    DeriveSubdomainFromUserRequirements ar = new DeriveSubdomainFromUserRequirements("InsuranceDomain", "Customers", userStories);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    Subdomain subdomain = model.getDomains().get(0).getSubdomains().get(0);
    assertNotNull(subdomain);
    Entity customerEntity = subdomain.getEntities().stream().filter(e -> e.getName().equals("Customer")).findFirst().get();
    assertNotNull(customerEntity);
    assertEquals(1, customerEntity.getReferences().size());
    Reference addressReference = customerEntity.getReferences().stream().filter(r -> r.getName().equals("addressList")).findFirst().get();
    assertNotNull(addressReference);
    assertEquals(CollectionType.LIST, addressReference.getCollectionType());
    assertEquals("Address", addressReference.getDomainObjectType().getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Reference

use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method respectNullableOnReferences.

@Test
public void respectNullableOnReferences() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    Entity entity = TacticdslFactory.eINSTANCE.createEntity();
    entity.setName("Test");
    Entity referencedEntity = TacticdslFactory.eINSTANCE.createEntity();
    referencedEntity.setName("ReferencedEntity");
    Reference reference = TacticdslFactory.eINSTANCE.createReference();
    reference.setName("otherEntity");
    reference.setDomainObjectType(referencedEntity);
    reference.setNullable(true);
    entity.getReferences().add(reference);
    aggregate.getDomainObjects().add(entity);
    aggregate.getDomainObjects().add(referencedEntity);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("	class Test <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + "		ReferencedEntity[0..1] otherEntity" + System.lineSeparator() + "	}" + 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 15 with Reference

use of org.contextmapper.tactic.dsl.tacticdsl.Reference in project context-mapper-dsl by ContextMapper.

the class ExtractSuggestedService method findReferenceInOriginalModel.

private Reference findReferenceInOriginalModel(Reference serviceCutReference) {
    if (!(serviceCutReference.eContainer() instanceof DomainObject))
        throw new ContextMapperApplicationException("We unexpectedly found references that are not contained by 'DomainObject' objects. We currently only support Entities, ValueObjects and Events here.");
    String domainObjectName = ((DomainObject) serviceCutReference.eContainer()).getName();
    String attributeName = serviceCutReference.getName();
    for (Reference reference : EcoreUtil2.eAllOfType(model, Reference.class).stream().filter(r -> r.getName().equals(attributeName)).collect(Collectors.toList())) {
        if (reference.eContainer() instanceof DomainObject && ((DomainObject) reference.eContainer()).getName().equals(domainObjectName))
            return reference;
    }
    return null;
}
Also used : Arrays(java.util.Arrays) URI(org.eclipse.emf.common.util.URI) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) Set(java.util.Set) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) Matcher(java.util.regex.Matcher) SolverAlgorithm(ch.hsr.servicecutter.solver.SolverAlgorithm) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Map(java.util.Map) Resource(org.eclipse.emf.ecore.resource.Resource) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Pattern(java.util.regex.Pattern) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject)

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