Search in sources :

Example 6 with ModelProperty

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

the class AbstractDataMapper method mapFunctionBlock.

private FunctionblockData mapFunctionBlock(ModelProperty fbProperty, JXPathContext context) {
    FunctionblockData fbData = new FunctionblockData(fbProperty.getName());
    FunctionblockModel fbModel = specification.getFunctionBlock(fbProperty.getName());
    for (ModelProperty statusProperty : fbModel.getStatusProperties()) {
        try {
            Object mapped = this.mapProperty(statusProperty, context);
            if (mapped != null) {
                fbData.withStatusProperty(statusProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException | JXPathInvalidAccessException ex) {
            if (statusProperty.isMandatory()) {
                return null;
            }
        }
    }
    for (ModelProperty configProperty : fbModel.getConfigurationProperties()) {
        try {
            Object mapped = this.mapProperty(configProperty, context);
            if (mapped != null) {
                fbData.withConfigurationProperty(configProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException | JXPathInvalidAccessException ex) {
            if (configProperty.isMandatory()) {
                return null;
            }
        }
    }
    return onlyReturnIfPopulated(fbData);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException)

Example 7 with ModelProperty

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

the class AbstractDataMapper method map.

public MappedData map(DataInput input, MappingContext mappingContext) {
    JXPathContext context = newContext(input.getValue());
    context.setFunctions(converterLibrary);
    InfomodelData normalized = new InfomodelData();
    final Infomodel deviceInfoModel = specification.getInfoModel();
    for (ModelProperty fbProperty : deviceInfoModel.getFunctionblocks()) {
        if (mappingContext.isIncluded(fbProperty.getName())) {
            FunctionblockData mappedFb = mapFunctionBlock(fbProperty, context);
            if (mappedFb != null) {
                normalized.withFunctionblock(mappedFb);
            }
        }
    }
    return this.doMap(normalized, mappingContext);
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) InfomodelData(org.eclipse.vorto.service.mapping.normalized.InfomodelData)

Example 8 with ModelProperty

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

the class AbstractTestSpec method addFunctionblockProperty.

protected void addFunctionblockProperty(final String name, final FunctionblockModel fbm) {
    FBS.put(name, fbm);
    ModelProperty prop = new ModelProperty();
    prop.setName(name);
    prop.setType(fbm.getId());
    infomodel.getFunctionblocks().add(prop);
}
Also used : ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Example 9 with ModelProperty

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

the class SpecWithArrayPayload method createFBSpec.

@Override
protected void createFBSpec() {
    FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty = new ModelProperty();
    digitalInputStateProperty.setMandatory(true);
    digitalInputStateProperty.setName("sensor_value");
    digitalInputStateProperty.setType(PrimitiveType.STRING);
    digitalInputStateProperty.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty.addStereotype(Stereotype.createWithXpath("/@clickType[1]"));
    buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty }));
    addFunctionblockProperty("button", buttonModel);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Example 10 with ModelProperty

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

the class SpecWithBase64Converter method createButtonFb.

private FunctionblockModel createButtonFb() {
    FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty = new ModelProperty();
    digitalInputStateProperty.setMandatory(true);
    digitalInputStateProperty.setName("digital_input_state");
    digitalInputStateProperty.setType(PrimitiveType.INT);
    digitalInputStateProperty.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty.addStereotype(Stereotype.createWithXpath("base64:decodeString(/data)"));
    buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty }));
    return buttonModel;
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Aggregations

ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)23 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)18 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)4 Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)3 ArrayList (java.util.ArrayList)2 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)2 ReferenceTarget (org.eclipse.vorto.core.api.model.mapping.ReferenceTarget)2 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)2 ModelId (org.eclipse.vorto.repository.api.ModelId)2 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)2 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)2 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1