Search in sources :

Example 1 with EnumValue

use of org.contextmapper.tactic.dsl.tacticdsl.EnumValue 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 EnumValue

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

the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreateEnum.

@Test
public void canCreateEnum() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    Enum enumm = TacticdslFactory.eINSTANCE.createEnum();
    enumm.setName("TestType");
    EnumValue value1 = TacticdslFactory.eINSTANCE.createEnumValue();
    value1.setName("VAL1");
    EnumValue value2 = TacticdslFactory.eINSTANCE.createEnumValue();
    value2.setName("VAL2");
    enumm.getValues().add(value1);
    enumm.getValues().add(value2);
    aggregate.getDomainObjects().add(enumm);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("	enum TestType {" + System.lineSeparator() + "		VAL1" + System.lineSeparator() + "		VAL2" + System.lineSeparator() + "	}" + System.lineSeparator()));
}
Also used : Enum(org.contextmapper.tactic.dsl.tacticdsl.Enum) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 3 with EnumValue

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

the class AbstractPlantUMLClassDiagramCreator method printEnum.

private void printEnum(Enum theEnum, int indentation) {
    printIndentation(indentation);
    sb.append("enum").append(" ").append(theEnum.getName()).append(" {");
    linebreak();
    for (EnumValue value : theEnum.getValues()) {
        printIndentation(indentation + 1);
        sb.append(value.getName());
        linebreak();
    }
    printIndentation(indentation);
    sb.append("}");
    linebreak();
}
Also used : EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue)

Example 4 with EnumValue

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

the class MDSLDataTypeCreator method createAttributesForEnum.

private List<DataTypeAttribute> createAttributesForEnum(Enum enumm) {
    List<DataTypeAttribute> attributes = new ArrayList<>();
    for (EnumValue value : enumm.getValues()) {
        DataTypeAttribute attribute = new DataTypeAttribute();
        attribute.setName(mdslNameEncoder.encodeName(value.getName()));
        attribute.setType(mdslNameEncoder.encodeName(enumm.getName()));
        attributes.add(attribute);
    }
    return attributes;
}
Also used : EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) DataTypeAttribute(org.contextmapper.dsl.generator.mdsl.model.DataTypeAttribute) ArrayList(java.util.ArrayList)

Example 5 with EnumValue

use of org.contextmapper.tactic.dsl.tacticdsl.EnumValue 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

EnumValue (org.contextmapper.tactic.dsl.tacticdsl.EnumValue)5 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)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 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 ArrayList (java.util.ArrayList)1 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)1 CommandInvokation (org.contextmapper.dsl.contextMappingDSL.CommandInvokation)1 ContextMappingDSLPackage (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage)1 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)1