Search in sources :

Example 1 with FunctionblockProperty

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

the class ModelDtoFactory method createResource.

public static Infomodel createResource(InformationModel model, Optional<MappingModel> mappingModel) {
    Infomodel infoResource = new Infomodel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.InformationModel);
    for (FunctionblockProperty property : model.getProperties()) {
        infoResource.getFunctionblocks().add(createProperty(property, mappingModel));
    }
    infoResource.setDescription(model.getDescription());
    infoResource.setDisplayName(model.getDisplayname());
    infoResource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    if (mappingModel.isPresent()) {
        MappingModel _mappingModel = mappingModel.get();
        infoResource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
        for (MappingRule rule : getInfoModelRule(_mappingModel.getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                infoResource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                infoResource.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return infoResource;
}
Also used : Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) 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) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 2 with FunctionblockProperty

use of org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty 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 3 with FunctionblockProperty

use of org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty 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 FunctionblockProperty

use of org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty 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 FunctionblockProperty

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

the class CoAPGenerator method generate.

public IGenerationResult generate(InformationModel infomodel, InvocationContext mappingContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    /*
		/ Generate the client part...
		*/
    String CLIENT_PROJ = infomodel.getName() + COAP_CLIENT_PROJECT_SUFFIX;
    initPaths(CLIENT_PROJ);
    generator.addTask(new CoAPClientInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPMethodTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ClientDemoApp", CLIENT_PROJ)));
    generator.generate(infomodel, mappingContext, zipOutputter);
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(entity, zipOutputter);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(en, zipOutputter);
        }
        for (Operation op : fb.getOperations()) {
            generateForOperation(op, zipOutputter);
        }
        if (fb.getStatus() != null) {
            for (Property property : fb.getStatus().getProperties()) {
                generateForProperty(property, zipOutputter);
            }
        }
        this.generateForClientFunctionBlock(fbp.getType(), zipOutputter);
    }
    /*
		/ Generate the server part...
		*/
    String SERVER_PROJ = infomodel.getName() + COAP_SERVER_PROJECT_SUFFIX;
    initPaths(SERVER_PROJ);
    generator.addTask(new CoAPServerGeneratorTask(COAP_SERVER_NAME, COAP_SERVER_PACKAGE, JAVA_FILE_EXTENSION, coapServerPath, JAVA_INTERFACE_PREFIX + COAP_REQUEST_HANDLER_NAME, COAP_REQUEST_HANDLER_PACKAGE));
    generator.addTask(new CoAPServerIMRequestHandlerGeneratorTask(COAP_REQUEST_HANDLER_NAME, JAVA_FILE_EXTENSION, coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE, JAVA_INTERFACE_PREFIX, COAP_PRIM_TYPE_WRAPPER_SUFFIX, IM_PACKAGE, DT_PACKAGE, getOpParamSetPackage(), getPrimitiveParamWrapperPackage()));
    generator.addTask(new JavaInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ICoAPRequestHandlerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new JsonTransformerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new URIAnalyzerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ResourceTemplate(coapServerPath, COAP_SERVER_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LinkTemplate(coapServerPath, COAP_SERVER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPServerDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE, COAP_SERVER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ServerDemoApp", SERVER_PROJ)));
    generator.generate(infomodel, mappingContext, zipOutputter);
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        this.generateForFunctionBlock(fbp.getType(), zipOutputter);
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(entity, zipOutputter);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(en, zipOutputter);
        }
        for (Operation op : fb.getOperations()) {
            generateForOperation(op, zipOutputter);
        }
    }
    return zipOutputter;
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ICoAPRequestHandlerTemplate(org.eclipse.vorto.codegen.coap.server.templates.ICoAPRequestHandlerTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ClientTemplate(org.eclipse.vorto.codegen.coap.client.templates.ClientTemplate) ClientDemoAppTemplate(org.eclipse.vorto.codegen.coap.client.templates.ClientDemoAppTemplate) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) JavaInformationModelInterfaceGeneratorTask(org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelInterfaceGeneratorTask) JavaInformationModelGeneratorTask(org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelGeneratorTask) PomFileTemplate(org.eclipse.vorto.codegen.coap.common.templates.PomFileTemplate) CoAPServerDemoAppTemplate(org.eclipse.vorto.codegen.coap.server.templates.CoAPServerDemoAppTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) CoAPClientInformationModelGeneratorTask(org.eclipse.vorto.codegen.coap.client.tasks.CoAPClientInformationModelGeneratorTask) CoAPServerIMRequestHandlerGeneratorTask(org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerIMRequestHandlerGeneratorTask) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) CoAPMethodTemplate(org.eclipse.vorto.codegen.coap.client.templates.CoAPMethodTemplate) URIAnalyzerTemplate(org.eclipse.vorto.codegen.coap.server.templates.URIAnalyzerTemplate) ResourceTemplate(org.eclipse.vorto.codegen.coap.server.templates.ResourceTemplate) CoAPServerGeneratorTask(org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerGeneratorTask) JsonTransformerTemplate(org.eclipse.vorto.codegen.coap.server.templates.JsonTransformerTemplate) LinkTemplate(org.eclipse.vorto.codegen.coap.server.templates.LinkTemplate)

Aggregations

FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)15 GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)9 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)8 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)8 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)5 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)4 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)4 IGenerationResult (org.eclipse.vorto.codegen.api.IGenerationResult)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 HashSet (java.util.HashSet)1 EObject (org.eclipse.emf.ecore.EObject)1 GeneratorTaskFromFileTemplate (org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate)1 Characteristic (org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic)1 Service (org.eclipse.vorto.codegen.ble.model.blegatt.Service)1 ThingsClientGeneratorTask (org.eclipse.vorto.codegen.bosch.things.javaclient.tasks.ThingsClientGeneratorTask)1 ThingsIntegrationUtilGeneratorTask (org.eclipse.vorto.codegen.bosch.things.javaclient.tasks.ThingsIntegrationUtilGeneratorTask)1 FunctionblockTemplate (org.eclipse.vorto.codegen.bosch.things.javaclient.templates.FunctionblockTemplate)1 LogbackTemplate (org.eclipse.vorto.codegen.bosch.things.javaclient.templates.LogbackTemplate)1 PomTemplate (org.eclipse.vorto.codegen.bosch.things.javaclient.templates.PomTemplate)1 CoAPClientInformationModelGeneratorTask (org.eclipse.vorto.codegen.coap.client.tasks.CoAPClientInformationModelGeneratorTask)1