Search in sources :

Example 1 with StateTransition

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

the class TacticDDDOperationsValidator method validateOperationStates.

private void validateOperationStates(EObject operation, StateTransition stateTransition) {
    if (stateTransition == null)
        return;
    CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper((ContextMappingModel) EcoreUtil2.getRootContainer(operation));
    Aggregate aggregate = helper.resolveAggregate(operation);
    if (aggregate == null)
        return;
    Set<String> aggregateStates = helper.resolveAggregateStates(aggregate);
    for (EnumValue value : stateTransition.getFrom()) {
        if (!aggregateStates.contains(value.getName()))
            error(String.format(STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE, value.getName(), aggregate.getName()), stateTransition, TacticdslPackage.Literals.STATE_TRANSITION__FROM, stateTransition.getFrom().indexOf(value));
    }
    for (EnumValue value : stateTransition.getTarget().getTo().stream().map(s -> s.getValue()).collect(Collectors.toList())) {
        if (!aggregateStates.contains(value.getName()))
            error(String.format(STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE, value.getName(), aggregate.getName()), stateTransition.getTarget(), TacticdslPackage.Literals.STATE_TRANSITION_TARGET__TO, stateTransition.getTarget().getTo().indexOf(value));
    }
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) TacticdslPackage(org.contextmapper.tactic.dsl.tacticdsl.TacticdslPackage) Set(java.util.Set) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE(org.contextmapper.dsl.validation.ValidationMessages.STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) Check(org.eclipse.xtext.validation.Check) EValidatorRegistrar(org.eclipse.xtext.validation.EValidatorRegistrar) AbstractDeclarativeValidator(org.eclipse.xtext.validation.AbstractDeclarativeValidator) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate)

Example 2 with StateTransition

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

the class PlantUMLGenerator method getAggregatesWithStatesAndTransitions.

private List<Aggregate> getAggregatesWithStatesAndTransitions(BoundedContext bc) {
    List<Aggregate> aggregates = Lists.newLinkedList();
    for (Aggregate aggregate : EcoreUtil2.eAllOfType(bc, Aggregate.class)) {
        Optional<org.contextmapper.tactic.dsl.tacticdsl.Enum> statesEnum = EcoreUtil2.eAllOfType(aggregate, org.contextmapper.tactic.dsl.tacticdsl.Enum.class).stream().filter(e -> e.isDefinesAggregateLifecycle()).findFirst();
        if (!statesEnum.isPresent())
            continue;
        List<StateTransition> stateTransitions = EcoreUtil2.eAllOfType(aggregate, StateTransition.class);
        if (!stateTransitions.isEmpty())
            aggregates.add(aggregate);
    }
    return aggregates;
}
Also used : IFileSystemAccess2(org.eclipse.xtext.generator.IFileSystemAccess2) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) URI(org.eclipse.emf.common.util.URI) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) PlantUMLSubdomainClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLSubdomainClassDiagramCreator) PlantUMLBoundedContextClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLBoundedContextClassDiagramCreator) List(java.util.List) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) PlantUMLStateDiagramCreator4Flow(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Flow) Lists(com.google.common.collect.Lists) PlantUMLAggregateClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLAggregateClassDiagramCreator) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) PlantUMLComponentDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) PlantUMLStateDiagramCreator4Aggregate(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Aggregate) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) PlantUMLModuleClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLModuleClassDiagramCreator) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) PlantUMLStateDiagramCreator4Aggregate(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Aggregate)

Example 3 with StateTransition

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

the class PlantUMLStateDiagramCreator4Aggregate method printDiagramContent.

@Override
protected void printDiagramContent(Aggregate aggregate) {
    List<ServiceOperation> serviceOperationsWithStateTransitions = EcoreUtil2.eAllOfType(aggregate, ServiceOperation.class).stream().filter(o -> o.getStateTransition() != null).collect(Collectors.toList());
    List<DomainObjectOperation> domainObjectOperationsWithStateTransitions = EcoreUtil2.eAllOfType(aggregate, DomainObjectOperation.class).stream().filter(o -> o.getStateTransition() != null).collect(Collectors.toList());
    List<StateTransition> allStateTransitions = serviceOperationsWithStateTransitions.stream().map(o -> o.getStateTransition()).collect(Collectors.toList());
    allStateTransitions.addAll(domainObjectOperationsWithStateTransitions.stream().map(o -> o.getStateTransition()).collect(Collectors.toList()));
    for (String state : collectStates(allStateTransitions)) {
        printState(state);
    }
    for (ServiceOperation operation : serviceOperationsWithStateTransitions) printTransition(operation.getStateTransition(), operation.getName());
    for (DomainObjectOperation operation : domainObjectOperationsWithStateTransitions) printTransition(operation.getStateTransition(), operation.getName());
    linebreak(2);
    sb.append("legend top center");
    linebreak();
    sb.append("  " + aggregate.getName() + " Aggregate Lifecycle");
    linebreak();
    sb.append("endlegend");
}
Also used : ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) List(java.util.List) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) Collectors(java.util.stream.Collectors) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)

Example 4 with StateTransition

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

the class PlantUMLStateDiagramCreator4Flow method printDiagramContent.

@Override
protected void printDiagramContent(Flow flow) {
    List<DomainEventProductionStep> eventProductionStepsWithStateTransitions = flow.getSteps().stream().filter(s -> s instanceof DomainEventProductionStep).map(s -> (DomainEventProductionStep) s).filter(s -> s.getStateTransition() != null).collect(Collectors.toList());
    List<StateTransition> allStateTransitions = eventProductionStepsWithStateTransitions.stream().map(s -> s.getStateTransition()).collect(Collectors.toList());
    for (String state : collectStates(allStateTransitions)) {
        printState(state);
    }
    for (DomainEventProductionStep step : eventProductionStepsWithStateTransitions) printTransition(step.getStateTransition(), step.getAction().getCommand() != null ? step.getAction().getCommand().getName() : step.getAction().getOperation().getName());
    linebreak(2);
    sb.append("legend top center");
    linebreak();
    sb.append("  " + flow.getName() + " State Transitions");
    linebreak();
    sb.append("endlegend");
}
Also used : List(java.util.List) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Collectors(java.util.stream.Collectors) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition)

Example 5 with StateTransition

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

the class AbstractPlantUMLStateDiagramCreator method collectStates.

protected Set<String> collectStates(List<StateTransition> transitions) {
    Set<String> states = Sets.newHashSet();
    for (StateTransition transition : transitions) {
        states.addAll(mapStatesToStrings(transition.getFrom()));
        states.addAll(mapStatesToStrings(transition.getTarget().getTo().stream().map(s -> s.getValue()).collect(Collectors.toList())));
    }
    return states;
}
Also used : List(java.util.List) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) Set(java.util.Set) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Sets(com.google.common.collect.Sets) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition)

Aggregations

StateTransition (org.contextmapper.tactic.dsl.tacticdsl.StateTransition)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)3 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)3 Set (java.util.Set)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)2 DomainObjectOperation (org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation)2 EnumValue (org.contextmapper.tactic.dsl.tacticdsl.EnumValue)2 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)2 EObject (org.eclipse.emf.ecore.EObject)2 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)1 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)1 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)1 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)1