Search in sources :

Example 1 with ChangePartnershipToUpstreamDownstreamRefactoring

use of org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring in project context-mapper-dsl by ContextMapper.

the class SuspendPartnershipRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    Partnership partnership = (Partnership) getSelectedElement();
    SuspendPartnershipContext refactoringContext = new SuspendPartnershipContext(partnership.getParticipant1().getName(), partnership.getParticipant2().getName());
    new WizardDialog(HandlerUtil.getActiveShell(event), new SuspendPartnershipRefactoringWizard(refactoringContext, executionContext -> {
        if (refactoringContext.getMode() == SuspendPartnershipMode.MERGE_BOUNDED_CONTEXTS) {
            // just use the 'Merge Bounded Contexts' AR in this case ...
            return finishRefactoring(new MergeBoundedContextsRefactoring(executionContext.getMergeModeSelectedBoundedContext1(), executionContext.getMergeModeSelectedBoundedContext2(), executionContext.isMergeModeTakeAttributesFromSecondBoundedContext()), resource, event);
        } else if (refactoringContext.getMode() == SuspendPartnershipMode.EXTRACT_NEW_BOUNDED_CONTEXT) {
            return finishRefactoring(new ExtractPartnershipRefactoring(refactoringContext.getBoundedContext1(), refactoringContext.getBoundedContext2()), resource, event);
        } else {
            String upstream = refactoringContext.getBoundedContext1();
            String downstream = refactoringContext.getBoundedContext2();
            if (refactoringContext.getReplaceModeUpstreamBoundedContext().equals(refactoringContext.getBoundedContext2())) {
                upstream = refactoringContext.getBoundedContext2();
                downstream = refactoringContext.getBoundedContext1();
            }
            return finishRefactoring(new ChangePartnershipToUpstreamDownstreamRefactoring(upstream, downstream), resource, event);
        }
    })).open();
}
Also used : ChangePartnershipToUpstreamDownstreamRefactoring(org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring) Partnership(org.contextmapper.dsl.contextMappingDSL.Partnership) SuspendPartnershipRefactoringWizard(org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipRefactoringWizard) SuspendPartnershipContext(org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring)

Example 2 with ChangePartnershipToUpstreamDownstreamRefactoring

use of org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring in project context-mapper-dsl by ContextMapper.

the class SuspendPartnershipCommand method getRefactoring.

@Override
protected SemanticCMLRefactoring getRefactoring(ExecuteCommandParams params) {
    JsonArray refactoringParams = (JsonArray) params.getArguments().get(1);
    JsonPrimitive participant1 = (JsonPrimitive) refactoringParams.get(0);
    JsonPrimitive participant2 = (JsonPrimitive) refactoringParams.get(1);
    JsonPrimitive modeAsString = (JsonPrimitive) refactoringParams.get(2);
    SuspendPartnershipMode mode = SuspendPartnershipMode.valueOf(modeAsString.getAsString());
    if (mode == SuspendPartnershipMode.EXTRACT_NEW_BOUNDED_CONTEXT) {
        return new ExtractPartnershipRefactoring(participant1.getAsString(), participant2.getAsString());
    // Unfortunately MERGE mode does currently not work because of this Xtext bug:
    // https://github.com/eclipse/xtext-core/issues/1494
    // } else if (mode == SuspendPartnershipMode.MERGE_BOUNDED_CONTEXTS) {
    // return new MergeBoundedContextsRefactoring(participant1.getAsString(), participant2.getAsString());
    } else {
        String upstream = participant1.getAsString();
        String downstream = participant2.getAsString();
        JsonPrimitive upstreamContext = (JsonPrimitive) refactoringParams.get(3);
        if (upstreamContext.getAsString().equals(downstream)) {
            upstream = participant2.getAsString();
            downstream = participant1.getAsString();
        }
        return new ChangePartnershipToUpstreamDownstreamRefactoring(upstream, downstream);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ChangePartnershipToUpstreamDownstreamRefactoring(org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring) JsonPrimitive(com.google.gson.JsonPrimitive) SuspendPartnershipMode(org.contextmapper.dsl.refactoring.SuspendPartnershipMode) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring)

Aggregations

ChangePartnershipToUpstreamDownstreamRefactoring (org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring)2 ExtractPartnershipRefactoring (org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring)2 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Partnership (org.contextmapper.dsl.contextMappingDSL.Partnership)1 MergeBoundedContextsRefactoring (org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring)1 SuspendPartnershipMode (org.contextmapper.dsl.refactoring.SuspendPartnershipMode)1 SuspendPartnershipContext (org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipContext)1 SuspendPartnershipRefactoringWizard (org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipRefactoringWizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1