Search in sources :

Example 11 with InformationModel

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

the class ModelTransformer method transform.

public Device transform() {
    this.factory = ModelFactoryImpl.init();
    this.device = this.factory.createDevice();
    this.device.setName(this.infomodel.getName());
    this.device.setInfomodel(this.infomodel);
    IMapped<InformationModel> map = this.context.getMappedElement(infomodel, "DeviceInfoProfile");
    if (map.hasAttribute("modelNumber")) {
        String modelNumber = map.getAttributeValue("modelNumber", "0");
        Service service = this.factory.createService();
        service.setName("DeviceInformation");
        service.setUuid("0000180a-0000-1000-8000-00805f9b34fb");
        Characteristic characteristic = this.factory.createCharacteristic();
        characteristic.setName("ModelNumber");
        characteristic.setUuid("00002a24-0000-1000-8000-00805f9b34fb");
        characteristic.setLength(modelNumber.length() / 2);
        StringBuffer mnBuf = new StringBuffer();
        mnBuf.append("{");
        for (int i = 0; i < modelNumber.length(); i += 2) {
            mnBuf.append("0x" + modelNumber.substring(i, i + 2));
            if (i < modelNumber.length() - 2) {
                mnBuf.append(", ");
            }
        }
        mnBuf.append("}");
        characteristic.setValue(mnBuf.toString());
        service.getCharacteristics().add(characteristic);
        this.device.getServices().add(service);
    }
    for (FunctionblockProperty property : infomodel.getProperties()) {
        transformFunctionblock(property.getType());
    }
    return this.device;
}
Also used : Characteristic(org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Service(org.eclipse.vorto.codegen.ble.model.blegatt.Service) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

Example 12 with InformationModel

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

the class InformationModelElement method addModelReference.

@Override
public void addModelReference(IModelElement modelElementReference) {
    ModelReference modelReference = modelElementReference.getId().asModelReference();
    if (!containsModelReference(modelReference)) {
        getModel().getReferences().add(modelReference);
        getModel().eResource().getContents().add(modelElementReference.getModel());
    }
    InformationModel infomodel = (InformationModel) getModel();
    infomodel.getProperties().add(createFunctionblockProperty((FunctionblockModel) modelElementReference.getModel(), getVariableNames(infomodel.getProperties())));
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference)

Example 13 with InformationModel

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

the class CodeGeneratorInvocationHandler method evaluate.

private boolean evaluate(String generatorServiceKey) {
    IModelElement selectedElement = ModelProjectFactory.getInstance().getModelElementFromSelection();
    if (selectedElement == null) {
        selectedElement = ModelProjectFactory.getInstance().getSelectedModel();
    }
    if (selectedElement == null) {
        MessageDisplayFactory.getMessageDisplay().displayWarning("Model was not properly selected. Please try again.");
        return false;
    }
    if (!hasNoErrors(selectedElement)) {
        MessageDisplayFactory.getMessageDisplay().displayError("Model has errors. Cannot generate.");
        return false;
    }
    InformationModel informationModel = getInformationModel(selectedElement.getModel());
    try {
        IVortoCodeGenerator generator = lookupService.lookupByKey(generatorServiceKey);
        IGenerationResult result = generator.generate(informationModel, createInvocationContext(selectedElement.getProject(), generator.getServiceKey()), VortoCodeGenProgressMonitorFactory.getCodeGenStatusReporter());
        CodeGenerationHelper.createEclipseProject(ModelIdFactory.newInstance(informationModel), generator.getServiceKey(), result);
        VortoProgressMonitor.getDefault().display();
    } catch (Exception e) {
        MessageDisplayFactory.getMessageDisplay().displayError(e);
    }
    return true;
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) IVortoCodeGenerator(org.eclipse.vorto.codegen.api.IVortoCodeGenerator) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IGenerationResult(org.eclipse.vorto.codegen.api.IGenerationResult) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 14 with InformationModel

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

the class EclipseDittoGenerator method generate.

@Override
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 SchemaValidatorTask());
    generator.generate(infomodel, invocationContext, zipOutputter);
    GenerationResultBuilder result = GenerationResultBuilder.from(zipOutputter);
    return result.build();
}
Also used : GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) SchemaValidatorTask(org.eclipse.vorto.codegen.ditto.schema.SchemaValidatorTask) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) GenerationResultBuilder(org.eclipse.vorto.codegen.utils.GenerationResultBuilder)

Example 15 with InformationModel

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

the class EclipseHonoGenerator method generate.

@Override
public IGenerationResult generate(InformationModel model, InvocationContext context, IVortoCodeGenProgressMonitor monitor) {
    GenerationResultZip output = new GenerationResultZip(model, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new Log4jTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CertificateTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new AppTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new IDataServiceTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new HonoDataService()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new HonoMqttClientTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new InformationModelTemplate()));
    generator.generate(model, context, output);
    for (FunctionblockProperty fbProperty : model.getProperties()) {
        new GeneratorTaskFromFileTemplate<>(new FunctionblockTemplate(model)).generate(fbProperty.getType(), context, output);
    }
    return output;
}
Also used : GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IDataServiceTemplate(org.eclipse.vorto.codegen.hono.service.IDataServiceTemplate) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) FunctionblockTemplate(org.eclipse.vorto.codegen.hono.model.FunctionblockTemplate) HonoDataService(org.eclipse.vorto.codegen.hono.service.hono.HonoDataService) InformationModelTemplate(org.eclipse.vorto.codegen.hono.model.InformationModelTemplate) HonoMqttClientTemplate(org.eclipse.vorto.codegen.hono.service.hono.HonoMqttClientTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

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