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));
}
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();
}
Aggregations