Search in sources :

Example 1 with ExtractSuggestedService

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

the class ExtractSuggestedServiceRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    BoundedContext bc = (BoundedContext) getSelectedElement();
    ChooseName4NewBoundedContextContext refactoringContext = new ChooseName4NewBoundedContextContext("NewBoundedContext");
    originalCMLResource = getAllResources().getResource(new ExtractSuggestedService(bc, "TempBC").constructOriginalModelUri(), false);
    if (originalCMLResource == null)
        throw new ContextMapperApplicationException("We were not able to find the original CML model. Please do not rename the models after generating service cut suggestions.");
    new WizardDialog(HandlerUtil.getActiveShell(event), new ChooseName4NewBoundedContextWizard(refactoringContext, executionContext -> {
        return finishRefactoring(new ExtractSuggestedService(bc, executionContext.getNewBoundedContextName()), new CMLResource(originalCMLResource), event);
    })).open();
}
Also used : ExtractSuggestedService(org.contextmapper.dsl.refactoring.ExtractSuggestedService) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) ChooseName4NewBoundedContextContext(org.contextmapper.dsl.ui.handler.wizard.ChooseName4NewBoundedContextContext) ChooseName4NewBoundedContextWizard(org.contextmapper.dsl.ui.handler.wizard.ChooseName4NewBoundedContextWizard) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 2 with ExtractSuggestedService

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

the class ExtractSuggestedServiceCommand method getRefactoring.

@Override
protected SemanticCMLRefactoring getRefactoring(ExecuteCommandParams params) {
    JsonArray refactoringParams = (JsonArray) params.getArguments().get(1);
    JsonPrimitive serviceCutResourceURI = (JsonPrimitive) refactoringParams.get(0);
    JsonPrimitive serviceToExtractName = (JsonPrimitive) refactoringParams.get(1);
    JsonPrimitive newBoundedContextName = (JsonPrimitive) refactoringParams.get(2);
    URI serviceCutURI = URI.createURI(serviceCutResourceURI.getAsString());
    CMLResource serviceCutResource = new CMLResource(cmlResource.getResourceSet().getResource(serviceCutURI, true));
    Optional<BoundedContext> serviceToExtract = serviceCutResource.getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals(serviceToExtractName.getAsString())).findFirst();
    if (!serviceToExtract.isPresent())
        throw new ContextMapperApplicationException("A service with the name '" + serviceToExtractName.getAsString() + "' does not exist in the CML model '" + serviceCutResourceURI.getAsString() + "'.");
    return new ExtractSuggestedService(serviceToExtract.get(), newBoundedContextName.getAsString());
}
Also used : JsonArray(com.google.gson.JsonArray) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess) URI(org.eclipse.emf.common.util.URI) WorkspaceEditRecorder(org.contextmapper.dsl.ide.edit.WorkspaceEditRecorder) ExtractSuggestedService(org.contextmapper.dsl.refactoring.ExtractSuggestedService) SemanticCMLRefactoring(org.contextmapper.dsl.refactoring.SemanticCMLRefactoring) Document(org.eclipse.xtext.ide.server.Document) JsonArray(com.google.gson.JsonArray) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) Optional(java.util.Optional) JsonPrimitive(com.google.gson.JsonPrimitive) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ExtractSuggestedService(org.contextmapper.dsl.refactoring.ExtractSuggestedService) JsonPrimitive(com.google.gson.JsonPrimitive) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) URI(org.eclipse.emf.common.util.URI)

Example 3 with ExtractSuggestedService

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

the class ExtractSuggestedServiceAction method getCommand.

@Override
public Command getCommand() {
    BoundedContext bc = getSelectedSystemBoundedContext();
    List<Object> commandArguments = Lists.newLinkedList();
    URI originalURI = new ExtractSuggestedService(bc, "NoNameBC").constructOriginalModelUri();
    commandArguments.add(originalURI.toString());
    commandArguments.add(cmlResource.getURI().toString());
    commandArguments.add(bc.getName());
    return new Command("Extract Suggested Service in Original Model", "cml.ar.extractSuggestedService.proxy", commandArguments);
}
Also used : ExtractSuggestedService(org.contextmapper.dsl.refactoring.ExtractSuggestedService) Command(org.eclipse.lsp4j.Command) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) EObject(org.eclipse.emf.ecore.EObject) URI(org.eclipse.emf.common.util.URI)

Aggregations

BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)3 ExtractSuggestedService (org.contextmapper.dsl.refactoring.ExtractSuggestedService)3 CMLResource (org.contextmapper.dsl.cml.CMLResource)2 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)2 URI (org.eclipse.emf.common.util.URI)2 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Optional (java.util.Optional)1 WorkspaceEditRecorder (org.contextmapper.dsl.ide.edit.WorkspaceEditRecorder)1 SemanticCMLRefactoring (org.contextmapper.dsl.refactoring.SemanticCMLRefactoring)1 ChooseName4NewBoundedContextContext (org.contextmapper.dsl.ui.handler.wizard.ChooseName4NewBoundedContextContext)1 ChooseName4NewBoundedContextWizard (org.contextmapper.dsl.ui.handler.wizard.ChooseName4NewBoundedContextWizard)1 EObject (org.eclipse.emf.ecore.EObject)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Command (org.eclipse.lsp4j.Command)1 ExecuteCommandParams (org.eclipse.lsp4j.ExecuteCommandParams)1 Document (org.eclipse.xtext.ide.server.Document)1 ILanguageServerAccess (org.eclipse.xtext.ide.server.ILanguageServerAccess)1