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);
}
}
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;
}
};
}
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());
}
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());
}
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());
}
Aggregations