use of org.openremote.model.asset.agent.ProtocolDescriptor in project openremote by openremote.
the class AssetEditActivity method writeAttributeTypesToView.
protected void writeAttributeTypesToView(Runnable onComplete) {
view.selectWellKnownType(asset.getWellKnownType());
view.setAvailableWellKnownTypes(AssetType.valuesSorted());
view.setType(asset.getType());
view.setTypeEditable(isNullOrEmpty(assetId));
// Populate add attributes drop down based on asset type
if (asset.getWellKnownType() == AssetType.AGENT && !isNullOrEmpty(asset.getId())) {
List<Pair<String, String>> displayNamesAndTypes = new ArrayList<>();
displayNamesAndTypes.add(new Pair<>(ValueEditors.EMPTY_LINE, null));
environment.getApp().getRequests().sendAndReturn(protocolDescriptorArrayMapper, requestParams -> agentResource.getSupportedProtocols(requestParams, assetId), 200, protocolDescriptors -> {
this.protocolDescriptors.addAll(Arrays.asList(protocolDescriptors));
updateMetaItemDescriptors();
view.setFormBusy(false);
Arrays.stream(protocolDescriptors).sorted(Comparator.comparing(ProtocolDescriptor::getDisplayName)).forEach(protocolDescriptor -> displayNamesAndTypes.add(new Pair<>(protocolDescriptor.getDisplayName(), protocolDescriptor.getName())));
displayNamesAndTypes.add(new Pair<>(ValueEditors.EMPTY_LINE, null));
displayNamesAndTypes.addAll(attributeTypesToList());
view.setAvailableAttributeTypes(displayNamesAndTypes);
onComplete.run();
});
} else {
// Get all protocol descriptors for all agents
environment.getApp().getRequests().sendAndReturn(protocolDescriptorMapMapper, agentResource::getAllSupportedProtocols, 200, protocolDescriptorMap -> {
protocolDescriptorMap.forEach((id, descriptors) -> {
for (ProtocolDescriptor newDescriptor : descriptors) {
if (this.protocolDescriptors.stream().noneMatch(pd -> pd.getName().equals(newDescriptor.getName()))) {
this.protocolDescriptors.add(newDescriptor);
}
}
});
updateMetaItemDescriptors();
view.setFormBusy(false);
view.setAvailableAttributeTypes(attributeTypesToList());
onComplete.run();
});
}
}
Aggregations