use of org.contextmapper.dsl.generator.exception.GeneratorInputException in project context-mapper-dsl by ContextMapper.
the class ContextMapGenerationHandler method runGeneration.
@Override
protected void runGeneration(Resource resource, ExecutionEvent event, IFileSystemAccess2 fsa) {
try {
if (!generator.isGraphvizInstalled()) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Graphviz installation not found", "Graphviz has not been found on your system. Ensure it is installed and the binaries are part of your PATH environment variable.");
return;
}
} 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);
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Graphviz installation check", "Your PATH variable could not be parsed to check if Graphviz is installed. The generator may not work if Graphviz is not available.");
}
GenerateContextMapContext context = createContext(event);
new WizardDialog(HandlerUtil.getActiveShell(event), new GenerateContextMapWizard(context, executionContext -> {
persistContext(event, executionContext);
generator.setContextMapFormats(context.getFormats().toArray(new ContextMapFormat[context.getFormats().size()]));
generator.setLabelSpacingFactor(context.getLabelSpacingFactor());
generator.clusterTeams(context.clusterTeams());
if (context.isFixWidth())
generator.setWidth(context.getWidth());
else if (context.isFixHeight())
generator.setHeight(context.getHeight());
generator.printAdditionalLabels(context.generateAdditionalLabels());
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
getGenerator().doGenerate(resource, fsa, new GeneratorContext());
} catch (GeneratorInputException e) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Model Input", e.getMessage());
}
}
});
return true;
})).open();
}
use of org.contextmapper.dsl.generator.exception.GeneratorInputException in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method checkPreconditions.
private void checkPreconditions() {
Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
List<Aggregate> exposedAggregates = Lists.newArrayList();
List<Application> applications = Lists.newArrayList();
for (UpstreamAPIContext context : upstreamContexts.values()) {
exposedAggregates.addAll(context.getExposedAggregates());
if (context.getApplicationLayer() != null)
applications.add(context.getApplicationLayer());
}
if (exposedAggregates.isEmpty() && applications.isEmpty())
throw new GeneratorInputException("None of your upstream-downstream relationships exposes any Aggregates or application layers. Therefore there is nothing to generate. Use the 'exposedAggregates' attribute on your upstream-downstream relationships to specify which Aggregates are exposed by the upstream or model an 'Application' in your upstream.");
boolean atLeastOneAggregateWithAnOperation = false;
for (Aggregate exposedAggregate : exposedAggregates) {
Optional<DomainObject> aggregateRoot = exposedAggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).findFirst();
if (aggregateRoot.isPresent() && !aggregateRoot.get().getOperations().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = exposedAggregate.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
for (Application application : applications) {
if (!application.getCommands().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
if (!atLeastOneAggregateWithAnOperation)
throw new GeneratorInputException("None of your exposed Aggregates contains either Service or 'Aggregate Root' operations/methods. Therefore there is nothing to generate. Add at least one operation/method to the 'Aggregate Root' or to a Service in one of your exposed Aggregates to get a result.");
}
use of org.contextmapper.dsl.generator.exception.GeneratorInputException in project context-mapper-dsl by ContextMapper.
the class GenericContentGenerator method generateFromContextMappingModel.
@Override
protected void generateFromContextMappingModel(ContextMappingModel model, IFileSystemAccess2 fsa, URI inputFileURI) {
if (freemarkerTemplateFile == null)
throw new GeneratorInputException("The freemarker template has not been set!");
if (!freemarkerTemplateFile.exists())
throw new GeneratorInputException("The file '" + freemarkerTemplateFile.getAbsolutePath().toString() + "' does not exist!");
if (targetFileName == null || "".equals(targetFileName))
throw new GeneratorInputException("Please provide a name for the file that shall be generated.");
FreemarkerTextGenerator generator = new FreemarkerTextGenerator(freemarkerTemplateFile);
for (Map.Entry<String, Object> customDataEntry : customDataMap.entrySet()) {
generator.registerCustomModelProperty(customDataEntry.getKey(), customDataEntry.getValue());
}
fsa.generateFile(targetFileName, generator.generate(model));
}
use of org.contextmapper.dsl.generator.exception.GeneratorInputException in project context-mapper-dsl by ContextMapper.
the class GenericTextFileGenerationCommand method executeCommand.
@Override
public void executeCommand(CMLResource cmlResource, Document document, ILanguageServerAccess access, ExecuteCommandParams params) {
if (params.getArguments().size() != 2 || params.getArguments().get(1).getClass() != JsonArray.class)
throw new ContextMapperApplicationException("This command expects a JSON array with the following values as second parameter: URI to Freemarker template, filename string for output file");
JsonArray paramArray = (JsonArray) params.getArguments().get(1);
JsonObject paramObject = paramArray.get(0).getAsJsonObject();
try {
URI templateURI = new URI(paramObject.get("templateUri").getAsString());
if (!templateURI.toString().startsWith("file:"))
throw new GeneratorInputException("Please provide a URI to a local file (Freemarker template)!");
generator.setFreemarkerTemplateFile(Paths.get(templateURI).toFile());
generator.setTargetFileName(paramObject.get("outputFileName").getAsString());
} catch (URISyntaxException e) {
throw new ContextMapperApplicationException("The passed template URI is not a valid URI.", e);
}
super.executeCommand(cmlResource, document, access, params);
}
use of org.contextmapper.dsl.generator.exception.GeneratorInputException in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method mapFlowStep.
private void mapFlowStep(OrchestrationFlow mdslFlow, FlowStep step) {
if (step.getClass() == org.contextmapper.dsl.contextMappingDSL.impl.CommandInvokationStepImpl.class) {
CommandInvokationStep cis = (CommandInvokationStep) step;
EitherCommandOrOperationInvokation ecooi = cis.getAction();
EList<DomainEvent> events = cis.getEvents();
if (ecooi instanceof SingleCommandInvokation) {
SingleCommandInvokation ci = (SingleCommandInvokation) ecooi;
boolean first;
String andEvents = combineEvents(events, " + ");
String commands = "";
first = true;
for (CommandEvent ce : ci.getCommands()) {
// we can only have one entry, but still checking (could also validate size and go to index 0 directly)
if (!first) {
commands += "-";
first = false;
}
commands += ce.getName();
}
mdslFlow.addCommandInvocationStep(andEvents, commands);
} else if (ecooi instanceof ConcurrentCommandInvokation) {
ConcurrentCommandInvokation cci = (ConcurrentCommandInvokation) ecooi;
EList<CommandEvent> commands = cci.getCommands();
String andEvents = combineEvents(events, " + ");
String andCommands = commands.get(0).getName();
for (int i = 1; i < commands.size(); i++) {
andCommands += " + " + commands.get(i).getName();
}
mdslFlow.addCommandInvocationStep(andEvents, andCommands);
} else if (ecooi instanceof ExclusiveAlternativeCommandInvokation) {
ExclusiveAlternativeCommandInvokation eaci = (ExclusiveAlternativeCommandInvokation) ecooi;
EList<CommandEvent> commands = eaci.getCommands();
String xorEvents = combineEvents(events, " + ");
String xorCommands = commands.get(0).getName();
for (int i = 1; i < commands.size(); i++) {
xorCommands += " x " + commands.get(i).getName();
}
mdslFlow.addCommandInvocationStep(xorEvents, xorCommands);
} else if (ecooi instanceof InclusiveAlternativeCommandInvokation) {
InclusiveAlternativeCommandInvokation eaci = (InclusiveAlternativeCommandInvokation) ecooi;
EList<CommandEvent> commands = eaci.getCommands();
String orEvents = combineEvents(events, " + ");
String orCommands = commands.get(0).getName();
for (int i = 1; i < commands.size(); i++) {
orCommands += " o " + commands.get(i).getName();
}
mdslFlow.addCommandInvocationStep(orEvents, orCommands);
} else {
throw new GeneratorInputException("Not yet implemented: support for " + ecooi.getClass());
}
} else if (step.getClass() == org.contextmapper.dsl.contextMappingDSL.impl.DomainEventProductionStepImpl.class) {
DomainEventProductionStep depStep = (DomainEventProductionStep) step;
EitherCommandOrOperation action = depStep.getAction();
EventProduction ep = depStep.getEventProduction();
if (ep instanceof SingleEventProduction) {
EList<DomainEvent> events = ep.getEvents();
// we can only have one entry, so just in case:
if (events.size() != 1)
throw new InvalidParameterException("Single event production must not list more than one event.");
mdslFlow.addEventProductionStep(action.getCommand().getName(), events.get(0).getName());
} else if (ep instanceof MultipleEventProduction) {
String andEvents = mapEvents(action, ep, " + ");
mdslFlow.addEventProductionStep(action.getCommand().getName(), andEvents);
} else if (ep instanceof InclusiveAlternativeEventProduction) {
String orEvents = mapEvents(action, ep, " o ");
mdslFlow.addEventProductionStep(action.getCommand().getName(), orEvents);
} else if (ep instanceof ExclusiveAlternativeEventProduction) {
String xorEvents = mapEvents(action, ep, " x ");
mdslFlow.addEventProductionStep(action.getCommand().getName(), xorEvents);
} else {
throw new GeneratorInputException("Not yet implemented: support for " + ep.getClass());
}
}
}
Aggregations