Search in sources :

Example 1 with STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE

use of org.contextmapper.dsl.validation.ValidationMessages.STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE 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 STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE

use of org.contextmapper.dsl.validation.ValidationMessages.STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE in project context-mapper-dsl by ContextMapper.

the class ApplicationFlowSemanticsValidator method checkThatStateTransitionStatesBelongToAggregate.

@Check
public void checkThatStateTransitionStatesBelongToAggregate(final DomainEventProductionStep step) {
    if (step.getAggregate() == null)
        return;
    if (step.getStateTransition() == null)
        return;
    CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper((ContextMappingModel) EcoreUtil2.getRootContainer(step));
    Set<String> aggregateStates = helper.resolveAggregateStates(step.getAggregate());
    for (EnumValue value : step.getStateTransition().getFrom()) {
        if (!aggregateStates.contains(value.getName()))
            error(String.format(STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE, value.getName(), step.getAggregate().getName()), step.getStateTransition(), TacticdslPackage.Literals.STATE_TRANSITION__FROM, step.getStateTransition().getFrom().indexOf(value));
    }
    for (EnumValue value : step.getStateTransition().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(), step.getAggregate().getName()), step.getStateTransition().getTarget(), TacticdslPackage.Literals.STATE_TRANSITION_TARGET__TO, step.getStateTransition().getTarget().getTo().indexOf(value));
    }
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) VISUALIZE_FLOW_WITH_SKETCH_MINER(org.contextmapper.dsl.validation.ValidationMessages.VISUALIZE_FLOW_WITH_SKETCH_MINER) TacticdslPackage(org.contextmapper.tactic.dsl.tacticdsl.TacticdslPackage) Set(java.util.Set) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) EObject(org.eclipse.emf.ecore.EObject) COMMAND_OR_OPERATION_IS_NOT_PART_OF_BOUNDED_CONTEXT(org.contextmapper.dsl.validation.ValidationMessages.COMMAND_OR_OPERATION_IS_NOT_PART_OF_BOUNDED_CONTEXT) Collectors(java.util.stream.Collectors) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE(org.contextmapper.dsl.validation.ValidationMessages.STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) CommandInvokation(org.contextmapper.dsl.contextMappingDSL.CommandInvokation) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) OperationInvokation(org.contextmapper.dsl.contextMappingDSL.OperationInvokation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) ContextMappingDSLPackage(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Check(org.eclipse.xtext.validation.Check) EValidatorRegistrar(org.eclipse.xtext.validation.EValidatorRegistrar) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) AbstractDeclarativeValidator(org.eclipse.xtext.validation.AbstractDeclarativeValidator) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) Check(org.eclipse.xtext.validation.Check)

Aggregations

Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE (org.contextmapper.dsl.validation.ValidationMessages.STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE)2 EnumValue (org.contextmapper.tactic.dsl.tacticdsl.EnumValue)2 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)2 TacticdslPackage (org.contextmapper.tactic.dsl.tacticdsl.TacticdslPackage)2 EObject (org.eclipse.emf.ecore.EObject)2 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)2 AbstractDeclarativeValidator (org.eclipse.xtext.validation.AbstractDeclarativeValidator)2 Check (org.eclipse.xtext.validation.Check)2 EValidatorRegistrar (org.eclipse.xtext.validation.EValidatorRegistrar)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)1 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)1 CommandInvokation (org.contextmapper.dsl.contextMappingDSL.CommandInvokation)1 ContextMappingDSLPackage (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage)1 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)1 EitherCommandOrOperation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation)1 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)1