Search in sources :

Example 1 with GeneratorInputException

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();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) GeneratorContext(org.eclipse.xtext.generator.GeneratorContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) GenerateContextMapContext(org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapContext) GenerateContextMapWizard(org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapWizard)

Example 2 with GeneratorInputException

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.");
}
Also used : EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamRole(org.contextmapper.dsl.contextMappingDSL.UpstreamRole) EitherCommandOrOperationInvokation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation) ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) StringUtils(org.apache.commons.lang3.StringUtils) SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) InvalidParameterException(java.security.InvalidParameterException) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) Map(java.util.Map) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) SingleCommandInvokation(org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation) EventProduction(org.contextmapper.dsl.contextMappingDSL.EventProduction) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) Collectors(java.util.stream.Collectors) List(java.util.List) ExclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation) APIUsageContext(org.contextmapper.dsl.generator.mdsl.model.APIUsageContext) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Visibility(org.contextmapper.tactic.dsl.tacticdsl.Visibility) Lists(com.google.common.collect.Lists) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) Application(org.contextmapper.dsl.contextMappingDSL.Application) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Maps(com.google.common.collect.Maps) EList(org.eclipse.emf.common.util.EList) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Application(org.contextmapper.dsl.contextMappingDSL.Application)

Example 3 with GeneratorInputException

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));
}
Also used : GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) Map(java.util.Map) HashMap(java.util.HashMap) FreemarkerTextGenerator(org.contextmapper.dsl.generator.freemarker.FreemarkerTextGenerator)

Example 4 with GeneratorInputException

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);
}
Also used : JsonArray(com.google.gson.JsonArray) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) JsonObject(com.google.gson.JsonObject) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with GeneratorInputException

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());
        }
    }
}
Also used : SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) SingleCommandInvokation(org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) EventProduction(org.contextmapper.dsl.contextMappingDSL.EventProduction) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) InvalidParameterException(java.security.InvalidParameterException) EitherCommandOrOperationInvokation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) ExclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) EList(org.eclipse.emf.common.util.EList)

Aggregations

GeneratorInputException (org.contextmapper.dsl.generator.exception.GeneratorInputException)5 InvalidParameterException (java.security.InvalidParameterException)2 Map (java.util.Map)2 CommandInvokationStep (org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep)2 ConcurrentCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation)2 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)2 EitherCommandOrOperation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation)2 EitherCommandOrOperationInvokation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation)2 EventProduction (org.contextmapper.dsl.contextMappingDSL.EventProduction)2 ExclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation)2 ExclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction)2 InclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation)2 InclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction)2 MultipleEventProduction (org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction)2 SingleCommandInvokation (org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation)2 SingleEventProduction (org.contextmapper.dsl.contextMappingDSL.SingleEventProduction)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1