Skip to content

Commit

Permalink
CML: Add rule for coordination between services of different contexts (
Browse files Browse the repository at this point in the history
  • Loading branch information
mLeveIST authored Nov 14, 2023
1 parent 314b9ca commit cc42f8d
Show file tree
Hide file tree
Showing 30 changed files with 1,296 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ plugin.xml_gen
.gradle/
build/

# MacOS
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,34 @@ class SketchMinerGeneratorCommandTest extends AbstractCMLCommandTest {
srcGenFolder.exists.assertTrue
new File(srcGenFolder, "test_BC_TestContext_TestFlow.sketch_miner").exists.assertTrue
}

@Test
def void testSketchMinerGeneratorCommandExecutionOnCoordination() {
// given
initializeCommandsDynamically()
val model = '''
BoundedContext ContextA {
Application {
Coordination TestCoordination {
ContextA::TestService::testOperation;
}
Service TestService {
testOperation;
}
}
}
'''
val fileURI = 'test.cml'.writeFile(model)

// when
val result = languageServer.executeCommand(
new ExecuteCommandParams("cml.generate.sketchminer", #[new JsonPrimitive(fileURI)]))
val resultVal = result.get as String

// then
CMLCommandService.COMMAND_EXECUTED_RETURN_VALUE.assertEquals(resultVal)
srcGenFolder.exists.assertTrue
new File(srcGenFolder, "coordinations/test_BC_ContextA_TestCoordination.sketch_miner").exists.assertTrue
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 The Context Mapper Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.contextmapper.dsl.ide.tests.quickfixes

import org.contextmapper.dsl.ide.tests.commands.AbstractCMLCommandTest
import org.junit.jupiter.api.Test

class OpenCoordinationInBPMNSketchMinerActionTest extends AbstractCMLCommandTest {

@Test
def void canOfferCodeAction() {
testCodeAction [
model = '''
BoundedContext ContextA {
Application {
Coordination TestCoordination {
ContextA::TestService::testOperation;
}
Service TestService {
testOperation;
}
}
}
'''
expectedCodeActions = '''
title : Open coordination in BPMN Sketch Miner
kind : quickfix
command : Command [
title = "Open coordination in BPMN Sketch Miner"
command = "cml.coordination.open.sketch.miner"
arguments = LinkedList (
"https://www.bpmn-sketch-miner.ai/index.html#EYBwNgdgXAbgjAKALRIQYQPYQC4FMAe2AglAggM64BOMAlgMa4AEAKrudgMrV2MB0eDgHkQ1AIbZaWMkA"
)
]
codes : open-coordination-in-sketch-miner
edit :
'''
]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
import org.contextmapper.dsl.ide.actions.impl.SwitchFromSharedKernelToPartnershipAction;
import org.contextmapper.dsl.ide.edit.WorkspaceEditRecorder;
import org.contextmapper.dsl.ide.quickfix.QuickfixCommandMapper;
import org.contextmapper.dsl.ide.quickfix.impl.OpenCoordinationInSketchMinerCommandMapper;
import org.contextmapper.dsl.ide.quickfix.impl.OpenFlowInSketchMinerCommandMapper;
import org.contextmapper.dsl.ide.quickfix.impl.SplitStoryByVerbCommandMapper;
import org.contextmapper.dsl.quickfixes.CMLQuickFix;
import org.contextmapper.dsl.quickfixes.CreateMissingBoundedContextQuickFix;
import org.contextmapper.dsl.quickfixes.SplitStoryByVerb;
import org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix;
import org.contextmapper.dsl.validation.ApplicationCoordinationSemanticsValidator;
import org.contextmapper.dsl.validation.ApplicationFlowSemanticsValidator;
import org.contextmapper.dsl.validation.DomainObjectValidator;
import org.contextmapper.dsl.validation.UserRequirementsValidator;
Expand Down Expand Up @@ -119,6 +121,7 @@ private void registerAllQuickFixes() {
registerActionQuickFix(DomainObjectValidator.ID_IS_PRIMITIVE_CODE, new ExtractIDValueObjectQuickFix());
registerCommandQuickFix(UserRequirementsValidator.ID_SPLIT_FEATURE_BY_VERB_SUGGESTION, new SplitStoryByVerbCommandMapper(new SplitStoryByVerb()));
registerCommandQuickFix(ApplicationFlowSemanticsValidator.SKETCH_MINER_INFO_ID, new OpenFlowInSketchMinerCommandMapper());
registerCommandQuickFix(ApplicationCoordinationSemanticsValidator.SKETCH_MINER_INFO_ID, new OpenCoordinationInSketchMinerCommandMapper());
}

public List<? extends Command> getApplicableActionCommands(CMLResource resource, List<EObject> selectedObjects) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 The Context Mapper Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.contextmapper.dsl.ide.quickfix.impl;

import java.util.Arrays;

import org.contextmapper.dsl.cml.CMLResource;
import org.contextmapper.dsl.contextMappingDSL.Coordination;
import org.contextmapper.dsl.generator.sketchminer.SketchMinerLinkCreator;
import org.contextmapper.dsl.ide.quickfix.QuickfixCommandMapper;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.Command;

import com.google.common.collect.Lists;

public class OpenCoordinationInSketchMinerCommandMapper implements QuickfixCommandMapper {

@Override
public CodeAction getCodeAction(CMLResource cmlResource, EObject selectedObject) {
Coordination coordination = (Coordination) selectedObject;
CodeAction action = new CodeAction("Open coordination in BPMN Sketch Miner");
action.setKind(CodeActionKind.QuickFix);
Command command = new Command("Open coordination in BPMN Sketch Miner", "cml.coordination.open.sketch.miner");
command.setArguments(Lists.newLinkedList(Arrays.asList(new String[] { new SketchMinerLinkCreator().createSketchMinerLink(coordination) })));
action.setCommand(command);
return action;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
ContextMap InsuranceMap {
contains UserContext
contains InsuranceQuotes

InsuranceQuotes <- UserContext
}

BoundedContext UserContext {

Application {
Service UserService {
void submitRequest(@Request request);
}
}
}

BoundedContext InsuranceQuotes {

Application {
Coordination QuoteRequestAcceptedCoordination {
UserContext::UserService::submitRequest;
InsuranceQuotes::QuoteRequestService::checkRequest;
InsuranceQuotes::QuoteRequestService::receiveAndCheckQuote;
InsuranceQuotes::QuoteRequestService::accept;
}

Service QuoteRequestService {
void checkRequest(@Request request);
void receiveAndCheckQuote(@Request request);
void reject(@Request request);
void accept(@Request request);
}
}

Aggregate QuoteRequest {
Entity Request {
aggregateRoot
}

enum RequestState {
aggregateLifecycle
SUBMITTED, RECEIVED, REJECTED, ACCEPTED, EXPIRED, POLICY_CREATED
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

BoundedContext EmptyContext // ignored
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

ContextMap TestMap {
contains ContextA
contains ContextB

ContextA <- ContextB
}

BoundedContext ContextA {
Application {
Coordination TestCoordination {
ContextA::ServiceA::operationA;
ContextB::ServiceB::operationB;
}
Service ServiceA {
operationA;
}
}
}

BoundedContext ContextB {
Application {
Service ServiceB {
operationB;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

ContextMap TestMap {
contains ContextA
contains ContextB
contains ContextC

ContextA <- ContextB
ContextA <- ContextC
}

BoundedContext ContextA {
Application {
Coordination TestCoordination {
ContextA::ServiceA::operationA1;
ContextB::ServiceB::operationB;
ContextA::ServiceA::operationA2;
ContextC::ServiceC::operationC;
}
Service ServiceA {
operationA1;
operationA2;
}
}
}

BoundedContext ContextB {
Application {
Service ServiceB {
operationB;
}
}
}

BoundedContext ContextC {
Application {
Service ServiceC {
operationC;
}
}
}

Loading

0 comments on commit cc42f8d

Please sign in to comment.