Search in sources :

Example 6 with FunctionblockModel

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

the class ModelRepositoryClientTest method testGetModelForNotAvailableTargetPlatform.

// FIXME : Repository REST URL Changes might have an impact on this test case. REST Endpoints should be tested along with repository
@Test
public void testGetModelForNotAvailableTargetPlatform() throws Exception {
    FunctionblockModel accelerometer = modelRepo.getContent(ModelId.fromPrettyFormat("com.ipso.smartobjects.Accelerometer:0.0.1"), FunctionblockModel.class, "omadm").get();
    assertNotNull(accelerometer);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) Test(org.junit.Test)

Example 7 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel 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 8 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel 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 9 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel 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)

Example 10 with FunctionblockModel

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

the class SpecWithConditionFunction 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.FLOAT);
    digitalInputStateProperty.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty.addStereotype(Stereotype.createWithConditionalXpath("(base64:decodeString(data))[0] == 104", "string:toString(base64:decodeString(data),'utf8')"));
    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)

Aggregations

FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)21 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)18 Test (org.junit.Test)4 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)2 Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)2 ArrayList (java.util.ArrayList)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 ModelId (org.eclipse.vorto.repository.api.ModelId)1 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)1 JavascriptFunctions (org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)1 DefaultMappingSpecification (org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1