Search in sources :

Example 1 with FunctionblockModel

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

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

the class DefaultMappingClient method newPropertyQuery.

@Override
public IMappingQuery<ModelProperty> newPropertyQuery(IMappedElement element) {
    final List<ModelProperty> properties = new ArrayList<ModelProperty>();
    if (element instanceof FunctionblockModel) {
        FunctionblockModel fbm = (FunctionblockModel) element;
        properties.addAll(fbm.getConfigurationProperties());
        properties.addAll(fbm.getStatusProperties());
        properties.addAll(fbm.getFaultProperties());
    } else if (element instanceof Infomodel) {
        Infomodel im = (Infomodel) element;
        properties.addAll(im.getFunctionblocks());
    } else if (element instanceof EntityModel) {
        EntityModel entity = (EntityModel) element;
        properties.addAll(entity.getProperties());
    } else {
        throw new UnsupportedOperationException();
    }
    return new MappingQueryJxPath<ModelProperty>() {

        @Override
        protected Collection<ModelProperty> getAll() {
            return properties;
        }
    };
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) ArrayList(java.util.ArrayList) EntityModel(org.eclipse.vorto.repository.api.content.EntityModel)

Example 3 with FunctionblockModel

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

the class ModelRepositoryClientTest method testQueryModelPropertyByMappedAttribute.

@Test
public void testQueryModelPropertyByMappedAttribute() throws Exception {
    FunctionblockModel accelerometer = modelRepo.getContent(ModelId.fromPrettyFormat("com.ipso.smartobjects.Accelerometer:0.0.1"), FunctionblockModel.class, "lwm2m").get();
    List<ModelProperty> properties = mapping.newPropertyQuery(accelerometer).stereotype("Resource").attribute("ID", "5702").list();
    assertEquals(1, properties.size());
    assertEquals("x_value", properties.get(0).getName());
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Test(org.junit.Test)

Example 4 with FunctionblockModel

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

the class ModelRepositoryClientTest method testGetModelForTargetPlatform.

@Test
public void testGetModelForTargetPlatform() throws Exception {
    FunctionblockModel accelerometer = modelRepo.getContent(ModelId.fromPrettyFormat("com.ipso.smartobjects.Accelerometer:0.0.1"), FunctionblockModel.class, "lwm2m").get();
    assertNotNull(accelerometer);
    assertEquals("lwm2m", accelerometer.getTargetPlatformKey());
    assertTrue(accelerometer.getStereotype("Object").isPresent());
    assertEquals(7, accelerometer.getStereotype("Object").get().getAttributes().size());
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) Test(org.junit.Test)

Example 5 with FunctionblockModel

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

the class ModelRepositoryClientTest method testMandatoryFields.

@Test
public void testMandatoryFields() throws Exception {
    FunctionblockModel model = modelRepo.getContent(ModelId.fromPrettyFormat("devices.fb.DistanceSensor:1.0.0"), FunctionblockModel.class).get();
    assertNotNull(model);
    assertEquals("distance", model.getStatusProperties().get(0).getName());
    assertEquals(PrimitiveType.DOUBLE, model.getStatusProperties().get(0).getType());
    assertEquals(true, model.getStatusProperties().get(0).isMandatory());
    assertEquals(false, model.getStatusProperties().get(0).isMultiple());
    assertEquals("sensor_units", model.getStatusProperties().get(1).getName());
    assertEquals(false, model.getStatusProperties().get(1).isMandatory());
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) Test(org.junit.Test)

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