use of org.openremote.model.value.MetaItemDescriptor in project openremote by openremote.
the class AssetModelInfoExtension method emitElements.
@SuppressWarnings("rawtypes")
@Override
public void emitElements(Writer writer, Settings settings, boolean exportKeyword, TsModel model) {
Map<String, String> assetMap = new HashMap<>();
Map<String, String> otherMap = new HashMap<>();
Arrays.stream(ValueUtil.getAssetInfos(null)).forEach(assetModelInfo -> {
String assetDescriptorName = assetModelInfo.getAssetDescriptor().getName();
assetMap.put(assetDescriptorName.toUpperCase(Locale.ROOT), assetDescriptorName);
// Store attributes
Arrays.stream(assetModelInfo.getAttributeDescriptors()).forEach(attributeDescriptor -> {
String attributeName = attributeDescriptor.getName();
otherMap.put(attributeName.toUpperCase(Locale.ROOT), attributeName);
});
});
emitEnum(writer, "WellknownAssets", assetMap);
writer.writeIndentedLine("");
emitEnum(writer, "WellknownAttributes", otherMap);
otherMap.clear();
Arrays.stream(ValueUtil.getMetaItemDescriptors()).forEach(metaItemDescriptor -> {
String metaName = metaItemDescriptor.getName();
otherMap.put(metaName.toUpperCase(Locale.ROOT), metaName);
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownMetaItems", otherMap);
otherMap.clear();
Arrays.stream(ValueUtil.getValueDescriptors()).forEach(valueDescriptor -> {
String valueTypeName = valueDescriptor.getName();
otherMap.put(valueTypeName.toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", ""), valueTypeName);
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownValueTypes", otherMap);
otherMap.clear();
Arrays.stream(Constants.class.getFields()).filter(f -> f.getName().startsWith("UNITS_")).forEach(unitField -> {
String unitName = unitField.getName().substring(6);
try {
otherMap.put(unitName.toUpperCase(Locale.ROOT), (String) unitField.get(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownUnitTypes", otherMap);
otherMap.clear();
Arrays.stream(Ruleset.class.getFields()).filter(f -> f.getType() == MetaItemDescriptor.class).forEach(rulesetMeta -> {
try {
MetaItemDescriptor metaItemDescriptor = (MetaItemDescriptor) rulesetMeta.get(null);
otherMap.put(metaItemDescriptor.getName().toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", ""), metaItemDescriptor.getName());
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownRulesetMetaItems", otherMap);
}
Aggregations