Search in sources :

Example 1 with SolverResult

use of ch.hsr.servicecutter.api.model.SolverResult in project context-mapper-dsl by ContextMapper.

the class CMLByServiceCutterOutputGenerationHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object firstElement = structuredSelection.getFirstElement();
        if (firstElement instanceof IFile) {
            IFile file = (IFile) firstElement;
            IProject project = file.getProject();
            final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
            fsa.setProject(project);
            fsa.setMonitor(new NullProgressMonitor());
            URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
            URI resolvedFile = CommonPlugin.resolve(uri);
            IFile jsonFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resolvedFile.toFileString()));
            try {
                ServiceCutterOutputModelFactory modelFactory = new ServiceCutterOutputModelFactory();
                SolverResult solverResult = modelFactory.createFromJsonFile(jsonFile.getFullPath().toFile());
                generator.doGenerate(resourceSetProvider.get(project), uri, solverResult);
            } catch (ServiceCutterOutputModelReadingException e) {
                MessageDialog.openError(HandlerUtil.getActiveShell(event), "Input Error", e.getMessage());
            } catch (Exception e) {
                String message = e.getMessage() != null && !"".equals(e.getMessage()) ? e.getMessage() : e.getClass().getName() + " occurred in " + this.getClass().getName();
                Status status = new Status(IStatus.ERROR, DslActivator.PLUGIN_ID, message, e);
                StatusManager.getManager().handle(status);
                ErrorDialog.openError(HandlerUtil.getActiveShell(event), "Error", "Exception occured during execution of command!", status);
            }
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) ServiceCutterOutputModelFactory(org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelFactory) ExecutionException(org.eclipse.core.commands.ExecutionException) ServiceCutterOutputModelReadingException(org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelReadingException) EclipseResourceFileSystemAccess2(org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2) ISelection(org.eclipse.jface.viewers.ISelection) ServiceCutterOutputModelReadingException(org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelReadingException)

Example 2 with SolverResult

use of ch.hsr.servicecutter.api.model.SolverResult in project context-mapper-dsl by ContextMapper.

the class NewServiceCutContextMapGenerator method generateFromContextMappingModel.

@Override
protected void generateFromContextMappingModel(ContextMappingModel model, IFileSystemAccess2 fsa, URI inputFileURI) {
    checkPreconditions(model);
    String fileBaseName = inputFileURI.trimFileExtension().lastSegment();
    // prepare service cutter input
    EntityRelationDiagram erdInput = new ContextMappingModelToServiceCutterERDConverter().convert(fileBaseName, model);
    ServiceCutterContextBuilder contextBuilder = new ServiceCutterContextBuilder(erdInput);
    SolverConfiguration solverConfig = getSolverConfiguration();
    contextBuilder.withCustomSolverConfiguration(solverConfig);
    contextBuilder.withUserRepresentations(getUserRepresentations(inputFileURI));
    ServiceCutterContext context = contextBuilder.build();
    // calculate new service cut
    SolverResult result = new ServiceCutter(context).generateDecomposition();
    ContextMappingModel newServiceCutModel = new ServiceCutterOutputToContextMappingModelConverter(contextMappingModel, context, getSCLModel(inputFileURI).eResource().getURI()).convert(result);
    // save new CML file
    int counter = 1;
    String baseFileName = inputFileURI.trimFileExtension().lastSegment() + "_" + solverConfig.getAlgorithm().toString().replace(" ", "_") + "_Cut_";
    URI fileName = inputFileURI.trimFileExtension().trimSegments(1).appendSegment(baseFileName + counter).appendFileExtension("cml");
    while (resourceSet.getURIConverter().exists(fileName, null)) {
        counter++;
        fileName = inputFileURI.trimFileExtension().trimSegments(1).appendSegment(baseFileName + counter).appendFileExtension("cml");
    }
    Resource resource = resourceSet.createResource(fileName);
    resource.getContents().add(newServiceCutModel);
    try {
        resource.save(null);
    } catch (IOException e) {
        throw new RuntimeException("Saving CML model was not possible.", e);
    }
    // save scoring as graphviz DOT file
    fsa.generateFile(fileName.trimFileExtension().lastSegment() + ".gv", generateGraphvizScoringRepresentation(context));
}
Also used : ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ServiceCutter(ch.hsr.servicecutter.api.ServiceCutter) SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) ServiceCutterOutputToContextMappingModelConverter(org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter) ServiceCutterContextBuilder(ch.hsr.servicecutter.api.ServiceCutterContextBuilder)

Example 3 with SolverResult

use of ch.hsr.servicecutter.api.model.SolverResult in project context-mapper-dsl by ContextMapper.

the class ServiceCutterOutputModelFactoryTest method canCreateFromFile.

@Test
void canCreateFromFile() {
    // given
    ServiceCutterOutputModelFactory factory = new ServiceCutterOutputModelFactory();
    // when
    SolverResult solverResult = factory.createFromJsonFile(integTestFile);
    // then
    assertNotNull(solverResult);
    assertEquals(3, solverResult.getServices().size());
    assertEquals(3, solverResult.getRelations().size());
    assertEquals(2, solverResult.getUseCaseResponsibility().size());
}
Also used : SolverResult(ch.hsr.servicecutter.api.model.SolverResult) ServiceCutterOutputModelFactory(org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelFactory) Test(org.junit.jupiter.api.Test)

Example 4 with SolverResult

use of ch.hsr.servicecutter.api.model.SolverResult in project context-mapper-dsl by ContextMapper.

the class ServiceCutterOutputToContextMappingModelConverterTest method testWithSampleFile.

@Test
void testWithSampleFile() {
    // given
    SolverResult solverResult = new ServiceCutterOutputModelFactory().createFromJsonFile(sampleFile);
    // when
    ContextMappingModel contextMappingModel = this.converter.convert(solverResult);
    ContextMap contextMap = contextMappingModel.getMap();
    // then
    assertEquals(3, contextMap.getBoundedContexts().size());
    assertEquals(3, contextMap.getRelationships().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) ServiceCutterOutputModelFactory(org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelFactory) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Aggregations

SolverResult (ch.hsr.servicecutter.api.model.SolverResult)4 ServiceCutterOutputModelFactory (org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelFactory)3 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 URI (org.eclipse.emf.common.util.URI)2 Test (org.junit.jupiter.api.Test)2 ServiceCutter (ch.hsr.servicecutter.api.ServiceCutter)1 ServiceCutterContext (ch.hsr.servicecutter.api.ServiceCutterContext)1 ServiceCutterContextBuilder (ch.hsr.servicecutter.api.ServiceCutterContextBuilder)1 EntityRelationDiagram (ch.hsr.servicecutter.api.model.EntityRelationDiagram)1 SolverConfiguration (ch.hsr.servicecutter.solver.SolverConfiguration)1 IOException (java.io.IOException)1 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)1 ContextMappingModelToServiceCutterERDConverter (org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter)1 ServiceCutterOutputToContextMappingModelConverter (org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter)1 ServiceCutterOutputModelReadingException (org.contextmapper.dsl.generator.servicecutter.output.factory.ServiceCutterOutputModelReadingException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1