Search in sources :

Example 1 with Stereotype

use of org.eclipse.vorto.repository.api.content.Stereotype in project vorto by eclipse.

the class MappingSpecificationBuilder method build.

public IMappingSpecification build() {
    try {
        Infomodel infomodel = this.repositoryClient.getContent(ModelId.fromPrettyFormat(this.modelId), Infomodel.class, this.targetPlatformKey).get();
        DefaultMappingSpecification specification = new DefaultMappingSpecification();
        specification.setInfomodel(infomodel);
        for (ModelProperty fbProperty : infomodel.getFunctionblocks()) {
            ModelId fbModelId = (ModelId) fbProperty.getType();
            ModelId mappingId = fbProperty.getMappingReference();
            FunctionblockModel fbm;
            if (mappingId != null) {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, mappingId).get();
            } else {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, this.targetPlatformKey).get();
            }
            if (fbm.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
                Stereotype functionsStereotype = fbm.getStereotype(STEREOTYPE_FUNCTIONS).get();
                JavascriptFunctions functions = new JavascriptFunctions(fbProperty.getName().toLowerCase());
                for (String functionName : functionsStereotype.getAttributes().keySet()) {
                    if (!"_namespace".equalsIgnoreCase(functionName)) {
                        functions.addFunction(functionName, functionsStereotype.getAttributes().get(functionName));
                    }
                }
                this.library.addFunctions(functions);
            }
            specification.getFbs().put(fbProperty.getName(), fbm);
        }
        specification.setLibrary(this.library);
        return specification;
    } catch (Exception e) {
        throw new MappingSpecificationProblem("Problem reading mapping specification", e);
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) DefaultMappingSpecification(org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification) JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 2 with Stereotype

use of org.eclipse.vorto.repository.api.content.Stereotype in project vorto by eclipse.

the class BleGattDeviceBuilder method buildCharacteristic.

private BleGattCharacteristic buildCharacteristic(ModelProperty property) {
    BleGattCharacteristic ch = new BleGattCharacteristic();
    // Determine if a characteristic uses notification (derived from "eventable" attribute)
    for (IPropertyAttribute attr : property.getAttributes()) {
        if (attr instanceof BooleanAttributeProperty) {
            BooleanAttributeProperty attrprop = (BooleanAttributeProperty) attr;
            if ((attrprop.getType() == BooleanAttributePropertyType.EVENTABLE) && (attrprop.isValue())) {
                ch.setNotified(true);
            }
        }
    }
    // Get the relevant information for BLE GATT Characteristics
    Optional<Stereotype> sourceSt = property.getStereotype("source");
    if (sourceSt.isPresent()) {
        Stereotype source = sourceSt.get();
        if (source.getAttributes().containsKey("uuid")) {
            ch.setUuid(UUID.fromString(source.getAttributes().get("uuid").toString()));
        }
        if (source.getAttributes().containsKey("onConnect")) {
            BleGattInitSequenceElement elt = new BleGattInitSequenceElement(ch, source.getAttributes().get("onConnect"));
            device.addInitSequenceElement(elt);
        }
        if (source.getAttributes().containsKey("handle")) {
            ch.setHandle(source.getAttributes().get("handle"));
        }
    }
    return ch;
}
Also used : IPropertyAttribute(org.eclipse.vorto.repository.api.content.IPropertyAttribute) BooleanAttributeProperty(org.eclipse.vorto.repository.api.content.BooleanAttributeProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype)

Example 3 with Stereotype

use of org.eclipse.vorto.repository.api.content.Stereotype in project vorto by eclipse.

the class BleGattDeviceBuilder method build.

public BleGattDevice build() {
    this.device = new BleGattDevice();
    for (ModelProperty fbprop : infomodel.getFunctionblocks()) {
        FunctionblockModel fb = mappingSpec.getFunctionBlock(fbprop.getName());
        if ("blegatt".equals(fb.getTargetPlatformKey())) {
            BleGattService service = new BleGattService();
            Optional<Stereotype> stereotype = fb.getStereotype("source");
            if (stereotype.isPresent()) {
                String uuid = stereotype.get().getAttributes().get("uuid");
                if (uuid != null) {
                    service.setUuid(UUID.fromString(uuid));
                }
            }
            for (ModelProperty prop : fb.getConfigurationProperties()) {
                BleGattCharacteristic ch = buildCharacteristic(prop);
                if (ch.getUuid() != null) {
                    service.addCharacteristics(ch);
                }
            }
            for (ModelProperty prop : fb.getStatusProperties()) {
                BleGattCharacteristic ch = buildCharacteristic(prop);
                if (ch.getUuid() != null) {
                    service.addCharacteristics(ch);
                }
            }
            device.addService(service);
        }
    }
    return device;
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype)

Aggregations

Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)3 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)2 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)2 ModelId (org.eclipse.vorto.repository.api.ModelId)1 BooleanAttributeProperty (org.eclipse.vorto.repository.api.content.BooleanAttributeProperty)1 IPropertyAttribute (org.eclipse.vorto.repository.api.content.IPropertyAttribute)1 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)1 JavascriptFunctions (org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)1 DefaultMappingSpecification (org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification)1