Search in sources :

Example 1 with GenerationResultZip

use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.

the class KuraGenerator method generate.

@Override
public IGenerationResult generate(InformationModel context, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip outputter = new GenerationResultZip(context, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new EclipseClasspathTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new EclipseProjectFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ManifestTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new BuildPropertiesTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ComponentXmlTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new IDataServiceTemplate()));
    if (invocationContext.getConfigurationProperties().getOrDefault("boschcloud", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschDataServiceTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new ThingClientFactoryTemplate()));
    } else if (invocationContext.getConfigurationProperties().getOrDefault("boschhub", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschHubDataService()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschHubClientTemplate()));
    } else {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new KuraCloudDataServiceTemplate()));
    }
    if (invocationContext.getConfigurationProperties().getOrDefault("bluetooth", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new MetatypeTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceBluetoothFinderTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new ConfigurationTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceFilterTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceToInformationModelTransformerTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new InformationModelConsumerTemplate()));
    } else {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DefaultAppTemplate()));
    }
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new InformationModelTemplate()));
    for (FunctionblockProperty fbProperty : context.getProperties()) {
        new GeneratorTaskFromFileTemplate<>(new FunctionblockTemplate(context)).generate(fbProperty.getType(), invocationContext, outputter);
    }
    generator.generate(context, invocationContext, outputter);
    return outputter;
}
Also used : EclipseClasspathTemplate(org.eclipse.vorto.codegen.kura.templates.EclipseClasspathTemplate) PomTemplate(org.eclipse.vorto.codegen.kura.templates.PomTemplate) InformationModelConsumerTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.InformationModelConsumerTemplate) ComponentXmlTemplate(org.eclipse.vorto.codegen.kura.templates.osgiinf.ComponentXmlTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) BoschHubClientTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.BoschHubClientTemplate) ConfigurationTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.ConfigurationTemplate) ManifestTemplate(org.eclipse.vorto.codegen.kura.templates.ManifestTemplate) BoschHubDataService(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.BoschHubDataService) EclipseProjectFileTemplate(org.eclipse.vorto.codegen.kura.templates.EclipseProjectFileTemplate) KuraCloudDataServiceTemplate(org.eclipse.vorto.codegen.kura.templates.KuraCloudDataServiceTemplate) GeneratorTaskFromFileTemplate(org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate) DeviceBluetoothFinderTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.DeviceBluetoothFinderTemplate) MetatypeTemplate(org.eclipse.vorto.codegen.kura.templates.osgiinf.MetatypeTemplate) DeviceToInformationModelTransformerTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.DeviceToInformationModelTransformerTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) BuildPropertiesTemplate(org.eclipse.vorto.codegen.kura.templates.BuildPropertiesTemplate) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) IDataServiceTemplate(org.eclipse.vorto.codegen.kura.templates.IDataServiceTemplate) ThingClientFactoryTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.ThingClientFactoryTemplate) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) FunctionblockTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.FunctionblockTemplate) BoschDataServiceTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.BoschDataServiceTemplate) InformationModelTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.InformationModelTemplate) DefaultAppTemplate(org.eclipse.vorto.codegen.kura.templates.DefaultAppTemplate) DeviceFilterTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.DeviceFilterTemplate)

Example 2 with GenerationResultZip

use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.

the class LatexGenerator method generate.

public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    generator.addTask(new LatexInformationModelGeneratorTask(LATEX_FILE_EXTENSION, LATEX_TARGET_PATH));
    generator.generate(infomodel, invocationContext, zipOutputter);
    return zipOutputter;
}
Also used : GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) LatexInformationModelGeneratorTask(org.eclipse.vorto.codegen.latex.tasks.LatexInformationModelGeneratorTask)

Example 3 with GenerationResultZip

use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.

the class MQTTPlatformGenerator method generate.

@Override
public IGenerationResult generate(InformationModel context, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip outputter = new GenerationResultZip(context, getServiceKey());
    for (FunctionblockProperty property : context.getProperties()) {
        ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
        if (property.getType().getFunctionblock().getStatus() != null) {
            generator.addTask(new GeneratorTaskFromFileTemplate<>(new IClientHandlerTemplate()));
            generator.addTask(new GeneratorTaskFromFileTemplate<>(new MqttConfigurationTemplate()));
        }
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
        generator.generate(property.getType(), invocationContext, outputter);
    }
    IGenerationResult javaResult = invocationContext.lookupGenerator(JavabeanGenerator.KEY).generate(context, invocationContext, monitor);
    return GenerationResultBuilder.from(outputter).append(javaResult).build();
}
Also used : PomTemplate(org.eclipse.vorto.codegen.mqtt.templates.PomTemplate) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) IClientHandlerTemplate(org.eclipse.vorto.codegen.mqtt.templates.IClientHandlerTemplate) IGenerationResult(org.eclipse.vorto.codegen.api.IGenerationResult) MqttConfigurationTemplate(org.eclipse.vorto.codegen.mqtt.templates.MqttConfigurationTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

Example 4 with GenerationResultZip

use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.

the class ProSystGenerator method generate.

@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext ctx, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    Set<EObject> visited = new HashSet<>();
    Set<String> exports = new HashSet<>();
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        Set<String> imports = new HashSet<>();
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            if (!visited.contains(entity)) {
                generateForEntity(infomodel, ctx, entity, zipOutputter);
                visited.add(entity);
            }
            imports.add(entity.getNamespace());
            exports.add(entity.getNamespace());
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            if (!visited.contains(en)) {
                generateForEnum(infomodel, ctx, en, zipOutputter);
                visited.add(en);
            }
            imports.add(en.getNamespace());
            exports.add(en.getNamespace());
        }
        exports.add(infomodel.getNamespace());
        generateForFunctionBlock(infomodel, ctx, fbp.getType(), zipOutputter, imports.toArray(new String[imports.size()]));
    }
    generateEclipseProject(infomodel, ctx, zipOutputter, exports);
    return zipOutputter;
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) EObject(org.eclipse.emf.ecore.EObject) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) HashSet(java.util.HashSet)

Example 5 with GenerationResultZip

use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.

the class CodeGenerationController method generate.

@RequestMapping(value = "/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> generate(@PathVariable String namespace, @PathVariable String name, @PathVariable String version, final HttpServletRequest request) {
    byte[] modelResources = downloadModelWithReferences(namespace, name, version);
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelResources))).read();
    Model model = workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get();
    InformationModel infomodel = null;
    if (model instanceof InformationModel) {
        infomodel = (InformationModel) model;
    } else if (model instanceof FunctionblockModel) {
        infomodel = Utils.wrapFunctionBlock((FunctionblockModel) model);
    }
    IGenerationResult result = null;
    try {
        Map<String, String> requestParams = new HashMap<>();
        request.getParameterMap().entrySet().stream().forEach(x -> requestParams.put(x.getKey(), x.getValue()[0]));
        result = vortoGenerator.generate(infomodel, createInvocationContext(infomodel, vortoGenerator.getServiceKey(), requestParams), null);
    } catch (Exception e) {
        GenerationResultZip output = new GenerationResultZip(infomodel, vortoGenerator.getServiceKey());
        Generated generated = new Generated("generation_error.log", "/generated", e.getMessage());
        output.write(generated);
        result = output;
    }
    return ResponseEntity.ok().contentLength(result.getContent().length).header("content-disposition", "attachment; filename = " + result.getFileName()).contentType(MediaType.parseMediaType(result.getMediatype())).body(new InputStreamResource(new ByteArrayInputStream(result.getContent())));
}
Also used : Generated(org.eclipse.vorto.codegen.api.Generated) HashMap(java.util.HashMap) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IGenerationResult(org.eclipse.vorto.codegen.api.IGenerationResult) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InputStreamResource(org.springframework.core.io.InputStreamResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)15 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)12 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)11 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)9 IGenerationResult (org.eclipse.vorto.codegen.api.IGenerationResult)4 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)4 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)4 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)4 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)4 HashMap (java.util.HashMap)2 GeneratorTaskFromFileTemplate (org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate)2 GenerationResultBuilder (org.eclipse.vorto.codegen.utils.GenerationResultBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ZipInputStream (java.util.zip.ZipInputStream)1 EObject (org.eclipse.emf.ecore.EObject)1 DatatypeGeneratorTask (org.eclipse.vorto.codegen.api.DatatypeGeneratorTask)1 Generated (org.eclipse.vorto.codegen.api.Generated)1 JavaClientTask (org.eclipse.vorto.codegen.bosch.things.javaclient.JavaClientTask)1