Search in sources :

Example 1 with RefactoringInputException

use of org.contextmapper.dsl.refactoring.exception.RefactoringInputException 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 2 with RefactoringInputException

use of org.contextmapper.dsl.refactoring.exception.RefactoringInputException 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 3 with RefactoringInputException

use of org.contextmapper.dsl.refactoring.exception.RefactoringInputException 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)

Example 4 with RefactoringInputException

use of org.contextmapper.dsl.refactoring.exception.RefactoringInputException in project context-mapper-dsl by ContextMapper.

the class MergeAggregatesRefactoring method checkForPossibleDomainObjectNameClashes.

private void checkForPossibleDomainObjectNameClashes(Aggregate aggregate1, Aggregate aggregate2) {
    List<String> aggregate1DomainObjectNames = aggregate1.getDomainObjects().stream().map(obj -> obj.getName()).collect(Collectors.toList());
    List<String> aggregate2DomainObjectNames = aggregate2.getDomainObjects().stream().map(obj -> obj.getName()).collect(Collectors.toList());
    Set<String> commonDomainObjectNames = aggregate1DomainObjectNames.stream().distinct().filter(aggregate2DomainObjectNames::contains).collect(Collectors.toSet());
    if (!commonDomainObjectNames.isEmpty())
        throw new RefactoringInputException("Sorry, we cannot execute this refactoring. The selected Aggregates contain the following duplicate domain objects: " + String.join(", ", commonDomainObjectNames));
}
Also used : Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Set(java.util.Set) Collectors(java.util.stream.Collectors) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Lists(com.google.common.collect.Lists) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException)

Example 5 with RefactoringInputException

use of org.contextmapper.dsl.refactoring.exception.RefactoringInputException in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomains method doRefactor.

@Override
protected void doRefactor() {
    Set<Subdomain> selectedSubdomains = collectSubdomains();
    if (selectedSubdomains.isEmpty())
        throw new RefactoringInputException("Please provide at least one subdomain name that can be found in the given CML model.");
    BoundedContext bc = createOrGetBoundedContext(boundedContextName);
    bc.setDomainVisionStatement("This Bounded Context realizes the following subdomains: " + String.join(", ", selectedSubdomains.stream().map(sd -> sd.getName()).collect(Collectors.toList())));
    bc.setType(BoundedContextType.FEATURE);
    for (Subdomain subdomain : selectedSubdomains) {
        addElementToEList(bc.getImplementedDomainParts(), (DomainPart) subdomain);
        createAggregate4Subdomain(subdomain, bc);
    }
}
Also used : Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException)

Aggregations

RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)7 Optional (java.util.Optional)5 Lists (com.google.common.collect.Lists)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)4 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)4 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)4 Set (java.util.Set)3 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)3 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)3 Relationship (org.contextmapper.dsl.contextMappingDSL.Relationship)3 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)3 UserRequirement (org.contextmapper.dsl.contextMappingDSL.UserRequirement)3 Sets (com.google.common.collect.Sets)2 Arrays (java.util.Arrays)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 BoundedContextType (org.contextmapper.dsl.contextMappingDSL.BoundedContextType)2 DownstreamRole (org.contextmapper.dsl.contextMappingDSL.DownstreamRole)2 Feature (org.contextmapper.dsl.contextMappingDSL.Feature)2