Search in sources :

Example 1 with ServiceCutterContext

use of ch.hsr.servicecutter.api.ServiceCutterContext 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 2 with ServiceCutterContext

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

the class NewServiceCutContextMapGenerator method generateGraphvizScoringRepresentation.

private String generateGraphvizScoringRepresentation(ServiceCutterContext context) {
    StringBuilder sb = new StringBuilder();
    Scorer scorer = new Scorer(context.getCouplingInstances(), context.getNanoEntities());
    Map<EntityPair, Map<String, Score>> scores = scorer.getScores((final String key) -> {
        return context.getSolverConfiguration().getPriorityForCouplingCriterion(key).toValue();
    });
    sb.append("graph G {" + System.lineSeparator());
    for (Entry<EntityPair, Map<String, Score>> entry : scores.entrySet()) {
        if (entry.getKey().nanoentityA == null || entry.getKey().nanoentityB == null)
            continue;
        double score = entry.getValue().values().stream().mapToDouble(Score::getPrioritizedScore).sum();
        if (score > 0) {
            String nameA = entry.getKey().nanoentityA.getContextName();
            String nameB = entry.getKey().nanoentityB.getContextName();
            sb.append("  \"" + nameA + "\" -- \"" + nameB + "\" [weight=" + score + ",label=" + score + "]; // { ");
            List<String> scoreEntries = entry.getValue().entrySet().stream().map(scoreEntry -> scoreEntry.getKey() + ": " + scoreEntry.getValue().getPriority() + " * " + scoreEntry.getValue().getScore() + " = " + scoreEntry.getValue().getPrioritizedScore()).collect(Collectors.toList());
            sb.append(String.join(", ", scoreEntries));
            sb.append(" }");
            sb.append(System.lineSeparator());
        }
    }
    sb.append("}").append(System.lineSeparator());
    return sb.toString();
}
Also used : IFileSystemAccess2(org.eclipse.xtext.generator.IFileSystemAccess2) SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) URI(org.eclipse.emf.common.util.URI) ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) UserRepresentationContainer(ch.hsr.servicecutter.api.model.UserRepresentationContainer) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) SCLToUserRepresentationsConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.SCLToUserRepresentationsConverter) Lists(com.google.common.collect.Lists) ServiceCutterConfigHandler(org.contextmapper.dsl.config.ServiceCutterConfigHandler) ServiceCutter(ch.hsr.servicecutter.api.ServiceCutter) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Map(java.util.Map) EntityPair(ch.hsr.servicecutter.model.solver.EntityPair) Score(ch.hsr.servicecutter.scorer.Score) Scorer(ch.hsr.servicecutter.scorer.Scorer) SolverConfigurationFactory(ch.hsr.servicecutter.api.SolverConfigurationFactory) ServiceCutterOutputToContextMappingModelConverter(org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) ServiceCutterUserRepresentationsModel(org.contextmapper.servicecutter.dsl.serviceCutterConfigurationDSL.ServiceCutterUserRepresentationsModel) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) ServiceCutterContextBuilder(ch.hsr.servicecutter.api.ServiceCutterContextBuilder) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) EntityPair(ch.hsr.servicecutter.model.solver.EntityPair) Scorer(ch.hsr.servicecutter.scorer.Scorer) Map(java.util.Map)

Aggregations

ServiceCutter (ch.hsr.servicecutter.api.ServiceCutter)2 ServiceCutterContext (ch.hsr.servicecutter.api.ServiceCutterContext)2 ServiceCutterContextBuilder (ch.hsr.servicecutter.api.ServiceCutterContextBuilder)2 EntityRelationDiagram (ch.hsr.servicecutter.api.model.EntityRelationDiagram)2 SolverResult (ch.hsr.servicecutter.api.model.SolverResult)2 SolverConfiguration (ch.hsr.servicecutter.solver.SolverConfiguration)2 IOException (java.io.IOException)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 ContextMappingModelToServiceCutterERDConverter (org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter)2 ServiceCutterOutputToContextMappingModelConverter (org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 SolverConfigurationFactory (ch.hsr.servicecutter.api.SolverConfigurationFactory)1 UserRepresentationContainer (ch.hsr.servicecutter.api.model.UserRepresentationContainer)1 EntityPair (ch.hsr.servicecutter.model.solver.EntityPair)1 Score (ch.hsr.servicecutter.scorer.Score)1 Scorer (ch.hsr.servicecutter.scorer.Scorer)1 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 List (java.util.List)1