Search in sources :

Example 1 with CMLModelObjectsResolvingHelper

use of org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper in project context-mapper-dsl by ContextMapper.

the class ApplicationFlowSemanticsValidator method commandInvokationMustReferCommandInSameContext.

@Check
public void commandInvokationMustReferCommandInSameContext(final CommandInvokation commandInvokation) {
    CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper((ContextMappingModel) EcoreUtil2.getRootContainer(commandInvokation));
    BoundedContext currentContext = helper.resolveBoundedContext(commandInvokation);
    for (CommandEvent commandEvent : commandInvokation.getCommands()) {
        BoundedContext commandContext = helper.resolveBoundedContext((EObject) commandEvent);
        if (commandContext == null || !currentContext.getName().equals(commandContext.getName()))
            error(String.format(COMMAND_OR_OPERATION_IS_NOT_PART_OF_BOUNDED_CONTEXT, commandEvent.getName(), currentContext.getName()), commandInvokation, ContextMappingDSLPackage.Literals.COMMAND_INVOKATION__COMMANDS, commandInvokation.getCommands().indexOf(commandEvent));
    }
}
Also used : CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Check(org.eclipse.xtext.validation.Check)

Example 2 with CMLModelObjectsResolvingHelper

use of org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper 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 3 with CMLModelObjectsResolvingHelper

use of org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper in project context-mapper-dsl by ContextMapper.

the class MergeAggregatesAction method isApplicable.

@Override
public boolean isApplicable() {
    Set<Aggregate> aggregates = getSelectedAggregates();
    if (aggregates.isEmpty() || aggregates.size() > 1)
        return false;
    BoundedContext parentContext = new CMLModelObjectsResolvingHelper(cmlResource.getContextMappingModel()).resolveBoundedContext(aggregates.iterator().next());
    return EcoreUtil2.eAllOfType(parentContext, Aggregate.class).size() > 1;
}
Also used : CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate)

Example 4 with CMLModelObjectsResolvingHelper

use of org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper in project context-mapper-dsl by ContextMapper.

the class MergeAggregatesAction method getCommand.

@Override
public Command getCommand() {
    Aggregate aggregate = getSelectedAggregate();
    BoundedContext parentContext = new CMLModelObjectsResolvingHelper(cmlResource.getContextMappingModel()).resolveBoundedContext(aggregate);
    List<Object> commandArguments = Lists.newLinkedList();
    commandArguments.add(cmlResource.getURI().toString());
    commandArguments.add(aggregate.getName());
    commandArguments.addAll(EcoreUtil2.eAllOfType(parentContext, Aggregate.class).stream().map(agg -> agg.getName()).filter(name -> !name.equals(aggregate.getName())).collect(Collectors.toSet()));
    return new Command("Merge Aggregates", "cml.ar.mergeAggregates.proxy", commandArguments);
}
Also used : CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) List(java.util.List) Lists(com.google.common.collect.Lists) Command(org.eclipse.lsp4j.Command) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) CMLCodeAction(org.contextmapper.dsl.ide.actions.CMLCodeAction) Collectors(java.util.stream.Collectors) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) Command(org.eclipse.lsp4j.Command) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) EObject(org.eclipse.emf.ecore.EObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate)

Example 5 with CMLModelObjectsResolvingHelper

use of org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper in project context-mapper-dsl by ContextMapper.

the class ServiceCutterOutputToContextMappingModelConverter method reconstructReference.

private void reconstructReference(DomainObject sourceObject, Reference originalReference, String targetTypeName) {
    BoundedContext parentBC = new CMLModelObjectsResolvingHelper(originalModelState).resolveBoundedContext(sourceObject);
    if (parentBC == null)
        // in case this source object is not part of a Bounded Context
        return;
    List<DomainObject> targetDomainObjects = EcoreUtil2.eAllOfType(model, DomainObject.class).stream().filter(obj -> obj.getName().equals(targetTypeName)).collect(Collectors.toList());
    if (targetDomainObjects.size() == 1) {
        Reference reference = TacticdslFactory.eINSTANCE.createReference();
        reference.setName(originalReference.getName());
        reference.setDomainObjectType(targetDomainObjects.get(0));
        reference.setCollectionType(originalReference.getCollectionType());
        reference.setDoc(originalReference.getDoc());
        sourceObject.getReferences().add(reference);
    } else {
        sourceObject.setComment("/* Service Cut generator: it was not possible to reconstruct the reference '" + originalReference.getName() + "' from " + sourceObject.getName() + " to " + targetTypeName + ". Please re-create that reference manually. */");
    }
}
Also used : SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) URI(org.eclipse.emf.common.util.URI) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) HashSet(java.util.HashSet) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) ServiceRelation(ch.hsr.servicecutter.api.model.ServiceRelation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Map(java.util.Map) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) SolverPriority(ch.hsr.servicecutter.solver.SolverPriority) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) Service(ch.hsr.servicecutter.api.model.Service) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) SharedKernel(org.contextmapper.dsl.contextMappingDSL.SharedKernel) SolverAlgorithm(ch.hsr.servicecutter.solver.SolverAlgorithm) 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) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext)

Aggregations

CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)10 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)8 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)6 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)6 Check (org.eclipse.xtext.validation.Check)6 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)5 List (java.util.List)4 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)3 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)3 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)3 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)3 EObject (org.eclipse.emf.ecore.EObject)3 ServiceCutterContext (ch.hsr.servicecutter.api.ServiceCutterContext)2 Service (ch.hsr.servicecutter.api.model.Service)2 ServiceRelation (ch.hsr.servicecutter.api.model.ServiceRelation)2 SolverResult (ch.hsr.servicecutter.api.model.SolverResult)2