Search in sources :

Example 21 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class WebDeviceGenerator 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>();
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new ServiceClassTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new PageTemplate()));
        generator.generate(property.getType(), invocationContext, outputter);
    }
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new WebSocketConfigTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new IndexHtmlFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceInfoTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceInfoServiceTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ControllersScriptFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new AppScriptFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ApplicationMainTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new CssTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ApplicationYmlTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ReadmeTemplate()));
    generator.generate(context, invocationContext, outputter);
    IGenerationResult javaResult = invocationContext.lookupGenerator(JavabeanGenerator.KEY).generate(context, invocationContext, monitor);
    return GenerationResultBuilder.from(outputter).append(javaResult).build();
}
Also used : GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) PageTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.PageTemplate) ControllersScriptFileTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.ControllersScriptFileTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) DeviceInfoServiceTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.DeviceInfoServiceTemplate) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) ServiceClassTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.ServiceClassTemplate) IGenerationResult(org.eclipse.vorto.codegen.api.IGenerationResult) IndexHtmlFileTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.IndexHtmlFileTemplate) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) PomFileTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.PomFileTemplate) ReadmeTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.ReadmeTemplate) AppScriptFileTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.AppScriptFileTemplate) ApplicationMainTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.ApplicationMainTemplate) CssTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.CssTemplate) WebSocketConfigTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.WebSocketConfigTemplate) DeviceInfoTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.DeviceInfoTemplate) ApplicationYmlTemplate(org.eclipse.vorto.codegen.webdevice.tasks.templates.ApplicationYmlTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

Example 22 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class WebUIGenerator method generate.

@Override
public IGenerationResult generate(InformationModel model, InvocationContext context, IVortoCodeGenProgressMonitor monitor) {
    GenerationResultZip output = new GenerationResultZip(model, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    /**
     * config templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LocalConfigurationTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new WebSecurityConfigTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new WebSocketConfigTemplate()));
    /**
     * model templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingTemplate()));
    /**
     * web controller templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new IdentityControllerTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingControllerTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingMessageControllerTemplate()));
    /**
     * Root Application templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingApplicationTemplate()));
    /**
     * Web static javascript templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new AppTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new BrowserControllerTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new DetailsControllerTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LoginControllerTemplate()));
    /**
     * Web static css templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new StyleTemplace()));
    /**
     * Web static html partial templates
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new IndexHtmlTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new BrowserTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LocatorTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LoginTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new DetailsTemplate()));
    /**
     * Swagger stuff
     */
    if (context.getConfigurationProperties().getOrDefault("swagger", "true").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new SwaggerConfigurationTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ApiControllerTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ApiTemplate()));
    }
    /**
     * History stuff
     */
    if (context.getConfigurationProperties().getOrDefault("persistence", "true").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CrudRepositoryTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new HistoryDataControllerTemplate()));
    }
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ApplicationConfigTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new AngularGageTemplate()));
    /**
     * IoT Cloud Platform Integration stuff
     */
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new QueryTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new DataServiceTemplate()));
    if (context.getConfigurationProperties().getOrDefault("boschcloud", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingsQueryTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingClientTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingClientBuilderTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingBuilderTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new org.eclipse.vorto.codegen.webui.templates.service.bosch.model.ThingTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new org.eclipse.vorto.codegen.webui.templates.service.bosch.model.FeatureTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingSearchResultTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingTypeAwareTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new FeatureImplTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingImplTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingSearchResultImplTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new AsyncInvocationTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new DefaultThingClient()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ThingsInvocationTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new BoschThingsDataServiceTemplate()));
    } else {
        generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new SampleDataServiceTemplate()));
    }
    generator.generate(model, context, output);
    ChainedCodeGeneratorTask<FunctionblockProperty> fbPropertyGenerators = new ChainedCodeGeneratorTask<FunctionblockProperty>();
    for (FunctionblockProperty property : model.getProperties()) {
        fbPropertyGenerators.addTask(new GeneratorTaskFromFileTemplate<>(new FeatureTemplate()));
        fbPropertyGenerators.addTask(new GeneratorTaskFromFileTemplate<>(new LocationControllerTemplate()));
        fbPropertyGenerators.generate(property, context, output);
        FunctionBlock fb = property.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(model, entity, output);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(model, en, output);
        }
    }
    return output;
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) FeatureTemplate(org.eclipse.vorto.codegen.webui.templates.model.FeatureTemplate) ThingsInvocationTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.internal.ThingsInvocationTemplate) ThingsQueryTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.ThingsQueryTemplate) ThingClientTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.ThingClientTemplate) DefaultThingClient(org.eclipse.vorto.codegen.webui.templates.service.bosch.internal.DefaultThingClient) ThingMessageControllerTemplate(org.eclipse.vorto.codegen.webui.templates.web.ThingMessageControllerTemplate) LoginControllerTemplate(org.eclipse.vorto.codegen.webui.templates.resources.js.LoginControllerTemplate) HistoryDataControllerTemplate(org.eclipse.vorto.codegen.webui.templates.web.HistoryDataControllerTemplate) IndexHtmlTemplate(org.eclipse.vorto.codegen.webui.templates.resources.IndexHtmlTemplate) CrudRepositoryTemplate(org.eclipse.vorto.codegen.webui.templates.dao.CrudRepositoryTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) AppTemplate(org.eclipse.vorto.codegen.webui.templates.resources.js.AppTemplate) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) ApiControllerTemplate(org.eclipse.vorto.codegen.webui.templates.resources.js.ApiControllerTemplate) DetailsTemplate(org.eclipse.vorto.codegen.webui.templates.resources.partials.DetailsTemplate) SampleDataServiceTemplate(org.eclipse.vorto.codegen.webui.templates.service.sample.SampleDataServiceTemplate) ThingImplTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.internal.model.ThingImplTemplate) WebSecurityConfigTemplate(org.eclipse.vorto.codegen.webui.templates.config.WebSecurityConfigTemplate) ThingClientBuilderTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.ThingClientBuilderTemplate) StyleTemplace(org.eclipse.vorto.codegen.webui.templates.resources.css.StyleTemplace) PomTemplate(org.eclipse.vorto.codegen.webui.templates.PomTemplate) LocatorTemplate(org.eclipse.vorto.codegen.webui.templates.resources.partials.LocatorTemplate) ThingsQueryTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.ThingsQueryTemplate) QueryTemplate(org.eclipse.vorto.codegen.webui.templates.service.QueryTemplate) AsyncInvocationTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.internal.AsyncInvocationTemplate) AngularGageTemplate(org.eclipse.vorto.codegen.webui.templates.resources.AngularGageTemplate) ThingControllerTemplate(org.eclipse.vorto.codegen.webui.templates.web.ThingControllerTemplate) FeatureImplTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.internal.model.FeatureImplTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ThingTemplate(org.eclipse.vorto.codegen.webui.templates.model.ThingTemplate) SampleDataServiceTemplate(org.eclipse.vorto.codegen.webui.templates.service.sample.SampleDataServiceTemplate) BoschThingsDataServiceTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.BoschThingsDataServiceTemplate) DataServiceTemplate(org.eclipse.vorto.codegen.webui.templates.service.DataServiceTemplate) ApiTemplate(org.eclipse.vorto.codegen.webui.templates.resources.partials.ApiTemplate) BoschThingsDataServiceTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.BoschThingsDataServiceTemplate) ThingBuilderTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.ThingBuilderTemplate) IdentityControllerTemplate(org.eclipse.vorto.codegen.webui.templates.web.IdentityControllerTemplate) ThingSearchResultImplTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.internal.model.ThingSearchResultImplTemplate) BrowserTemplate(org.eclipse.vorto.codegen.webui.templates.resources.partials.BrowserTemplate) LocationControllerTemplate(org.eclipse.vorto.codegen.webui.templates.resources.js.LocationControllerTemplate) DetailsControllerTemplate(org.eclipse.vorto.codegen.webui.templates.resources.js.DetailsControllerTemplate) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) BrowserControllerTemplate(org.eclipse.vorto.codegen.webui.templates.resources.js.BrowserControllerTemplate) ApplicationConfigTemplate(org.eclipse.vorto.codegen.webui.templates.resources.ApplicationConfigTemplate) ThingApplicationTemplate(org.eclipse.vorto.codegen.webui.templates.ThingApplicationTemplate) LoginTemplate(org.eclipse.vorto.codegen.webui.templates.resources.partials.LoginTemplate) ThingSearchResultTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.model.ThingSearchResultTemplate) SwaggerConfigurationTemplate(org.eclipse.vorto.codegen.webui.templates.config.SwaggerConfigurationTemplate) ThingTypeAwareTemplate(org.eclipse.vorto.codegen.webui.templates.service.bosch.model.ThingTypeAwareTemplate) WebSocketConfigTemplate(org.eclipse.vorto.codegen.webui.templates.config.WebSocketConfigTemplate) LocalConfigurationTemplate(org.eclipse.vorto.codegen.webui.templates.config.LocalConfigurationTemplate)

Example 23 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class ModelReaderTest method testReadInfomodelFromZipFile.

@Test
public void testReadInfomodelFromZipFile() throws Exception {
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(getClass().getClassLoader().getResourceAsStream("models.zip"))).read();
    Model model = workspace.get().stream().filter(p -> p.getName().equals("TI_SensorTag_CC2650")).findAny().get();
    assertNotNull(model);
    assertTrue(model instanceof InformationModel);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Model(org.eclipse.vorto.core.api.model.model.Model) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Test(org.junit.Test)

Example 24 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class ModelReaderTest method testReadFromFile.

@Test
public void testReadFromFile() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example_AWSIoTButton_1_0_0.infomodel"), ModelType.InformationModel).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_AWSButtonMapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_Button1Mapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_Button2Mapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.ipso.smartobjects_Push_button_0_0_1.fbmodel"), ModelType.Functionblock).read();
    InformationModel model = (InformationModel) workspace.get().stream().filter(p -> p instanceof InformationModel).findAny().get();
    assertNotNull(model);
    assertEquals("AWSIoTButton", model.getName());
    assertEquals("AWSButtonMapping", workspace.get().stream().filter(p -> p.getName().equals("AWSButtonMapping")).findAny().get().getName());
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ZipInputStream(java.util.zip.ZipInputStream) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Assert.assertNotNull(org.junit.Assert.assertNotNull) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ModelType(org.eclipse.vorto.repository.api.ModelType) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Model(org.eclipse.vorto.core.api.model.model.Model) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Test(org.junit.Test)

Aggregations

InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)24 GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)13 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)10 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)8 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)7 IGenerationResult (org.eclipse.vorto.codegen.api.IGenerationResult)6 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)6 Model (org.eclipse.vorto.core.api.model.model.Model)6 ZipInputStream (java.util.zip.ZipInputStream)5 IModelWorkspace (org.eclipse.vorto.server.commons.reader.IModelWorkspace)5 IVortoCodeGenerator (org.eclipse.vorto.codegen.api.IVortoCodeGenerator)4 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Generated (org.eclipse.vorto.codegen.api.Generated)3 InvocationContext (org.eclipse.vorto.codegen.api.InvocationContext)3 IOException (java.io.IOException)2 List (java.util.List)2 GeneratorTaskFromFileTemplate (org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate)2