Search in sources :

Example 11 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class CMLModelObjectsResolvingHelper method resolveUserRequirements.

public Set<UserRequirement> resolveUserRequirements(BoundedContext boundedContext) {
    Set<UserRequirement> requirements = Sets.newHashSet();
    for (DomainPart domainPart : boundedContext.getImplementedDomainParts()) {
        if (!(domainPart instanceof Subdomain))
            continue;
        Subdomain subdomain = (Subdomain) domainPart;
        requirements.addAll(subdomain.getSupportedFeatures());
    }
    return requirements;
}
Also used : UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) DomainPart(org.contextmapper.dsl.contextMappingDSL.DomainPart)

Example 12 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirements method doRefactor.

@Override
protected void doRefactor() {
    Set<UserRequirement> selectedUserRequirements = collectUserRequirements();
    // if there are no user stories or use cases selected, we do nothing
    if (selectedUserRequirements.isEmpty())
        throw new RefactoringInputException("Please provide at least one user story or use case that exists in the CML model.");
    Domain domain = getOrCreateDomain();
    Subdomain subdomain = getOrCreateSubdomain(domain);
    addElementsToEList(subdomain.getSupportedFeatures(), Lists.newLinkedList(selectedUserRequirements));
    List<String> benefits = Lists.newLinkedList();
    if (subdomain.getDomainVisionStatement() != null && !"".equals(subdomain.getDomainVisionStatement()))
        benefits.addAll(Arrays.asList(subdomain.getDomainVisionStatement().split(BENEFIT_SEPARATOR_STRING)));
    for (UserRequirement ur : selectedUserRequirements) {
        if (!doesContainAtLeastOneEntity(ur))
            continue;
        benefits.add("Aims at promoting the following benefit for a " + ur.getRole() + ": " + ur.getBenefit());
        deriveSubdomainEntities4Features(subdomain, ur.getName(), ur.getFeatures());
    }
    for (UserRequirement ur : selectedUserRequirements) {
        deriveSubdomainEntityReferences(subdomain, ur.getFeatures());
    }
    subdomain.setDomainVisionStatement(String.join(BENEFIT_SEPARATOR_STRING, benefits));
}
Also used : UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException)

Example 13 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirements method deriveSubdomainEntities4Features.

private void deriveSubdomainEntities4Features(Subdomain subdomain, String urName, List<Feature> features) {
    for (Feature feature : features) {
        if (feature.getEntity() == null || "".equals(feature.getEntity()))
            continue;
        // create the entity
        String entityName = createEntityIfNotExisting(feature.getEntity(), subdomain, feature.getEntityAttributes());
        // create the service
        String serviceName = urName.substring(0, 1).toUpperCase() + urName.substring(1) + "Service";
        Optional<Service> alreadyExistingService = subdomain.getServices().stream().filter(s -> serviceName.equals(s.getName())).findFirst();
        Service service;
        if (!alreadyExistingService.isPresent()) {
            service = createService(serviceName, entityName, feature.getVerb());
            addElementToEList(subdomain.getServices(), service);
        } else {
            service = alreadyExistingService.get();
        }
        String operationName = feature.getVerb().replace(" ", "_") + entityName;
        Optional<ServiceOperation> alreadyExistingServiceOperation = service.getOperations().stream().filter(o -> operationName.equals(o.getName())).findFirst();
        if (!alreadyExistingServiceOperation.isPresent())
            addElementToEList(service.getOperations(), createServiceOperation(operationName));
        // create the entity that contains the one created above
        if (feature.getContainerEntity() != null && !"".equals(feature.getContainerEntity()))
            createEntityIfNotExisting(feature.getContainerEntity(), subdomain, Lists.newLinkedList());
    }
}
Also used : Arrays(java.util.Arrays) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) Set(java.util.Set) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) 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) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) 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) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Feature(org.contextmapper.dsl.contextMappingDSL.Feature)

Example 14 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirements method getOrCreateDomain.

private Domain getOrCreateDomain() {
    if (domainName == null || "".equals(domainName))
        throw new RefactoringInputException("Please provide a name for the domain where the new subdomain shall be added.");
    Optional<Domain> optDomain = getAllDomains().stream().filter(d -> domainName.equals(d.getName())).findFirst();
    if (optDomain.isPresent())
        return optDomain.get();
    Domain newDomain = ContextMappingDSLFactory.eINSTANCE.createDomain();
    newDomain.setName(domainName);
    addElementToEList(model.getDomains(), newDomain);
    return newDomain;
}
Also used : Arrays(java.util.Arrays) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) Set(java.util.Set) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) 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) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) 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) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException)

Example 15 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirements method getOrCreateSubdomain.

private Subdomain getOrCreateSubdomain(Domain domain) {
    if (subdomainName == null || "".equals(subdomainName))
        throw new RefactoringInputException("Please provide a name for the subdomain that shall be created or existing subdomain that shall contain the new entities.");
    Optional<Subdomain> optSubdomain = domain.getSubdomains().stream().filter(sd -> subdomainName.equals(sd.getName())).findFirst();
    if (optSubdomain.isPresent())
        return optSubdomain.get();
    Subdomain newSubdomain = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    newSubdomain.setName(subdomainName);
    addElementToEList(domain.getSubdomains(), newSubdomain);
    return newSubdomain;
}
Also used : Arrays(java.util.Arrays) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) Set(java.util.Set) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) 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) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) 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) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException)

Aggregations

Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)26 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)14 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)13 Test (org.junit.jupiter.api.Test)10 Collectors (java.util.stream.Collectors)9 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)9 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)9 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)9 List (java.util.List)8 Optional (java.util.Optional)8 Set (java.util.Set)8 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)8 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)8 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)8 Sets (com.google.common.collect.Sets)7 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)7 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)7 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)7 CMLResource (org.contextmapper.dsl.cml.CMLResource)6 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)6