Search in sources :

Example 1 with ServiceCutterContextBuilder

use of ch.hsr.servicecutter.api.ServiceCutterContextBuilder 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)

Aggregations

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 SolverResult (ch.hsr.servicecutter.api.model.SolverResult)1 SolverConfiguration (ch.hsr.servicecutter.solver.SolverConfiguration)1 IOException (java.io.IOException)1 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)1 ContextMappingModelToServiceCutterERDConverter (org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter)1 ServiceCutterOutputToContextMappingModelConverter (org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1