Search in sources :

Example 11 with FunctionblockModel

use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.

the class ModelDtoFactory method createResource.

public static org.eclipse.vorto.repository.api.content.FunctionblockModel createResource(FunctionblockModel model, Optional<MappingModel> mappingModel) {
    org.eclipse.vorto.repository.api.content.FunctionblockModel resource = new org.eclipse.vorto.repository.api.content.FunctionblockModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Functionblock);
    resource.setDescription(model.getDescription());
    resource.setDisplayName(model.getDisplayname());
    resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    if (model.getFunctionblock().getConfiguration() != null) {
        resource.setConfigurationProperties(model.getFunctionblock().getConfiguration().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
    }
    if (model.getFunctionblock().getStatus() != null) {
        resource.setStatusProperties(model.getFunctionblock().getStatus().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
    }
    if (model.getFunctionblock().getFault() != null) {
        resource.setFaultProperties(model.getFunctionblock().getFault().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
    }
    if (model.getFunctionblock().getEvents() != null) {
        resource.setEvents(model.getFunctionblock().getEvents().stream().map(e -> createEvent(e, mappingModel)).collect(Collectors.toList()));
    }
    if (model.getFunctionblock().getOperations() != null) {
        resource.setOperations(model.getFunctionblock().getOperations().stream().map(o -> createOperation(o)).collect(Collectors.toList()));
    }
    if (mappingModel.isPresent()) {
        MappingModel _mappingModel = mappingModel.get();
        resource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
        for (MappingRule rule : getFbRule(_mappingModel.getRules())) {
            StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
            resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
        }
    }
    return resource;
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.repository.api.ModelId) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 12 with FunctionblockModel

use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.

the class CGenerator method generate.

@Override
public IGenerationResult generate(InformationModel model, InvocationContext context) {
    GenerationResultZip outputter = new GenerationResultZip(model, getServiceKey());
    for (FunctionblockProperty property : model.getProperties()) {
        ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
        if (property.getType().getFunctionblock().getStatus() != null) {
            generator.addTask(new GeneratorTaskFromFileTemplate<>(new CHeaderTemplate()));
        }
        generator.generate(property.getType(), context, outputter);
    }
    return outputter;
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

Example 13 with FunctionblockModel

use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.

the class TestFunctionBlockFactory method createFunctionBlockModel.

public static FunctionblockModel createFunctionBlockModel() {
    FunctionblockModel fbmodel = FunctionblockFactory.eINSTANCE.createFunctionblockModel();
    FunctionBlock fb = FunctionblockFactory.eINSTANCE.createFunctionBlock();
    fbmodel.setName("Fridge");
    fbmodel.setCategory("demo");
    fbmodel.setDescription("A Simple Fridge Functionblock for tester");
    fbmodel.setNamespace("www.bosch.com");
    fbmodel.setVersion("1.2.3");
    fbmodel.setDisplayname("Fridge Function Block");
    fb.getOperations().add(createOnOperation());
    fb.getOperations().add(createOffOperation());
    fb.getOperations().add(createToggleOperation());
    fb.setConfiguration(createConfiguration());
    fb.setStatus(createStatus());
    fb.setFault(createFault());
    fbmodel.setFunctionblock(fb);
    return fbmodel;
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)

Example 14 with FunctionblockModel

use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel 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 15 with FunctionblockModel

use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.

the class UIComponentFactory method getByModelId.

public static IFunctionBlockUITemplate getByModelId(FunctionblockModel fbm, InvocationContext ctx) {
    IMapped<FunctionblockModel> mappedElement = ctx.getMappedElement(fbm, STEREOTYPE_COMPONENT);
    String uiType = mappedElement.getAttributeValue(ATTRIBUTE_TYPE, "default");
    if (uiType.equalsIgnoreCase("barchart")) {
        List<String> properties = new ArrayList<String>();
        for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
            IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
            String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
            if (uiProperty.equalsIgnoreCase("value")) {
                properties.add(property.getName());
            }
        }
        return new BarChartUITemplate(properties);
    } else if (uiType.equalsIgnoreCase("map")) {
        String latitude = null;
        String longitude = null;
        for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
            IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
            String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
            if (uiProperty.equalsIgnoreCase("longitude")) {
                longitude = property.getName();
            } else if (uiProperty.equalsIgnoreCase("latitude")) {
                latitude = property.getName();
            }
        }
        return new LocationMapUITemplate(longitude, latitude);
    } else if (uiType.equalsIgnoreCase("gauge")) {
        String value = null;
        String min = null;
        String max = null;
        String symbol = null;
        for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
            IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
            String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
            if (uiProperty.equalsIgnoreCase("value")) {
                value = property.getName();
            } else if (uiProperty.equalsIgnoreCase("min")) {
                min = property.getName();
            } else if (uiProperty.equalsIgnoreCase("max")) {
                max = property.getName();
            } else if (uiProperty.equalsIgnoreCase("symbol")) {
                symbol = property.getName();
            }
        }
        return new GaugeUITemplate(symbol, min, max, value);
    } else {
        return new DefaultUITemplate();
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) GaugeUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.GaugeUITemplate) ArrayList(java.util.ArrayList) LocationMapUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.LocationMapUITemplate) BarChartUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.BarChartUITemplate) IMapped(org.eclipse.vorto.codegen.api.mapping.IMapped) Property(org.eclipse.vorto.core.api.model.datatype.Property) DefaultUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.DefaultUITemplate)

Aggregations

FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)17 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)5 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)5 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)5 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)5 GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)4 Property (org.eclipse.vorto.core.api.model.datatype.Property)4 IGenerationResult (org.eclipse.vorto.codegen.api.IGenerationResult)3 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)3 ZipInputStream (java.util.zip.ZipInputStream)2 CharacteristicProperty (org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty)2 Model (org.eclipse.vorto.core.api.model.model.Model)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Collectors (java.util.stream.Collectors)1 Generated (org.eclipse.vorto.codegen.api.Generated)1 IMapped (org.eclipse.vorto.codegen.api.mapping.IMapped)1 Characteristic (org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic)1