Search in sources :

Example 1 with FunctionblockModel

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

the class TypeImportValidation method validate.

@Override
public void validate(ModelInfo modelResource, InvocationContext context) throws ValidationException {
    Collection<String> unImportedReferences = Lists.newArrayList();
    ModelEMFResource emfModel = (ModelEMFResource) modelResource;
    Model model = emfModel.getModel();
    if (model == null)
        return;
    if (model instanceof Entity) {
        unImportedReferences.addAll(getUnimportedProperties(((Entity) model).getProperties(), model.getReferences()));
    } else if (model instanceof FunctionblockModel) {
        unImportedReferences.addAll(validateFunctionBlock((FunctionblockModel) model));
    } else if (model instanceof InformationModel) {
        unImportedReferences.addAll(getUnimportedFunctionblocks(((InformationModel) model).getProperties(), model.getReferences()));
    }
    unImportedReferences.forEach(ref -> System.out.println("Missing : " + ref));
    if (!unImportedReferences.isEmpty()) {
        throw new ValidationException(errorMessage(unImportedReferences), modelResource);
    }
}
Also used : Entity(org.eclipse.vorto.core.api.model.datatype.Entity) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ModelEMFResource(org.eclipse.vorto.repository.core.impl.ModelEMFResource) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel)

Example 2 with FunctionblockModel

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

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

the class ProSystGenerator method generateForFunctionBlock.

private void generateForFunctionBlock(InformationModel infomodel, InvocationContext ctx, FunctionblockModel fbm, IGeneratedWriter outputter, String[] imports) {
    ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
    generator.addTask(new FunctionalItemGeneratorTask(JAVA_FILE_EXTENSION, SOURCE, fbm.getNamespace()));
    generator.addTask(new FunctionalItemImplGeneratorTask(JAVA_FILE_EXTENSION, SOURCE, fbm.getNamespace(), imports));
    generator.generate(fbm, ctx, outputter);
}
Also used : FunctionalItemImplGeneratorTask(org.eclipse.vorto.codegen.prosystfi.tasks.FunctionalItemImplGeneratorTask) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) FunctionalItemGeneratorTask(org.eclipse.vorto.codegen.prosystfi.tasks.FunctionalItemGeneratorTask)

Example 4 with FunctionblockModel

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

Example 5 with FunctionblockModel

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

the class ModelTransformer method transformProperty.

private void transformProperty(Service service, Property property) {
    IMapped<Property> map = this.context.getMappedElement(property, "source");
    if (map.hasAttribute("uuid")) {
        String uuid = map.getAttributeValue("uuid", "");
        Characteristic characteristic = null;
        for (Characteristic ch : service.getCharacteristics()) {
            if (ch.getUuid().equals(uuid)) {
                characteristic = ch;
                break;
            }
        }
        if (characteristic == null) {
            characteristic = this.factory.createCharacteristic();
            characteristic.setUuid(uuid);
            if (map.hasAttribute("name")) {
                characteristic.setName(map.getAttributeValue("name", ""));
            } else {
                characteristic.setName(((FunctionblockModel) (property.eContainer().eContainer().eContainer())).getName() + property.getName());
            }
            service.getCharacteristics().add(characteristic);
        }
        if (Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")) > characteristic.getLength()) {
            characteristic.setLength(Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")));
        }
        if (Utils.isReadable(property)) {
            characteristic.setIsReadable(true);
        }
        if (Utils.isWritable(property)) {
            characteristic.setIsWritable(true);
        }
        if (Utils.isEventable(property)) {
            characteristic.setIsEventable(true);
        }
        if (map.hasAttribute("length") && map.hasAttribute("offset") && map.hasAttribute("datatype")) {
            CharacteristicProperty cp = this.factory.createCharacteristicProperty();
            cp.setDatatype(map.getAttributeValue("datatype", ""));
            cp.setLength(Integer.parseInt(map.getAttributeValue("length", "0")));
            cp.setOffset(Integer.parseInt(map.getAttributeValue("offset", "0")));
            cp.setProperty(property);
            characteristic.getProperties().add(cp);
        }
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) Characteristic(org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

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