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