.properties(new PropertySetBuilder() .addProperty("engUnit", new PropertyValue(PropertyDataType.String, "My Units")) .addProperty("engHigh", new PropertyValue(PropertyDataType.Int32, Integer.MAX_VALUE)) .addProperty("engLow", new PropertyValue(PropertyDataType.Int32, Integer.MIN_VALUE)) .createPropertySet()) .createMetric());
private Map<String, PropertyValue> newProps(boolean withPropTypes) throws SparkplugException { Random random = new Random(); Map<String, PropertyValue> propMap = new HashMap<String, PropertyValue>(); propMap.put("PropInt8", new PropertyValue(PropertyDataType.Int8, (byte)random.nextInt())); propMap.put("PropInt16", new PropertyValue(PropertyDataType.Int16, (short)random.nextInt())); propMap.put("PropInt32", new PropertyValue(PropertyDataType.Int32, random.nextInt())); propMap.put("PropInt64", new PropertyValue(PropertyDataType.Int64, random.nextLong())); propMap.put("PropUInt8", new PropertyValue(PropertyDataType.UInt8, (short)random.nextInt())); propMap.put("PropUInt16", new PropertyValue(PropertyDataType.UInt16, random.nextInt())); propMap.put("PropUInt32", new PropertyValue(PropertyDataType.UInt32, random.nextLong())); propMap.put("PropUInt64", new PropertyValue(PropertyDataType.UInt64, BigInteger.valueOf(random.nextLong()))); propMap.put("PropFloat", new PropertyValue(PropertyDataType.Float, random.nextFloat())); propMap.put("PropDouble", new PropertyValue(PropertyDataType.Double, random.nextDouble())); propMap.put("PropBoolean", new PropertyValue(PropertyDataType.Boolean, random.nextBoolean())); propMap.put("PropString", new PropertyValue(PropertyDataType.String, newUUID())); propMap.put("PropDateTime", new PropertyValue(PropertyDataType.DateTime, new Date())); propMap.put("PropText", new PropertyValue(PropertyDataType.Text, newUUID())); if (withPropTypes) { propMap.put("PropPropertySet", new PropertyValue(PropertyDataType.PropertySet, new PropertySetBuilder() .addProperties(newProps(false)) .createPropertySet())); List<PropertySet> propsList = new ArrayList<PropertySet>(); propsList.add(new PropertySetBuilder().addProperties(newProps(false)).createPropertySet()); propsList.add(new PropertySetBuilder().addProperties(newProps(false)).createPropertySet()); propsList.add(new PropertySetBuilder().addProperties(newProps(false)).createPropertySet()); propMap.put("PropPropertySetList", new PropertyValue(PropertyDataType.PropertySetList, propsList)); } return propMap; }
return value.getStringValue(); case PropertySet: return new PropertySetBuilder().addProperties(convertProperties(value.getPropertysetValue())) .createPropertySet(); case PropertySetList: List<PropertySet> propertySetList = new ArrayList<PropertySet>(); List<SparkplugBProto.Payload.PropertySet> list = value.getPropertysetsValue().getPropertysetList(); for (SparkplugBProto.Payload.PropertySet decodedPropSet : list) { propertySetList.add(new PropertySetBuilder().addProperties(convertProperties(decodedPropSet)) .createPropertySet());
payload.addMetric(new MetricBuilder("Properties/sw_version", String, SW_VERSION).createMetric()); PropertySet propertySet = new PropertySetBuilder() .addProperty("engUnit", new PropertyValue(PropertyDataType.String, "My Units")) .addProperty("engLow", new PropertyValue(PropertyDataType.Double, 1.0)) .addProperty("engHigh", new PropertyValue(PropertyDataType.Double, 10.0)) .createPropertySet(); payload.addMetric(new MetricBuilder("MyMetric", String, "My Value") .properties(propertySet)
.createMetric()); PropertySet propertySet = new PropertySetBuilder() .addProperty("engUnit", new PropertyValue(PropertyDataType.String, "My Units")) .addProperty("engLow", new PropertyValue(PropertyDataType.Double, 1.0)) .addProperty("engHigh", new PropertyValue(PropertyDataType.Double, 10.0)) .createPropertySet(); payload.addMetric(new MetricBuilder("MyMetric", String, "My Value") .properties(propertySet)
public MetricBuilder(Metric metric) throws SparkplugException { this.name = metric.getName(); this.alias = metric.getAlias(); this.timestamp = metric.getTimestamp(); this.dataType = metric.getDataType(); this.isHistorical = metric.isHistorical(); this.isTransient = metric.isTransient(); this.metaData = metric.getMetaData() != null ? new MetaDataBuilder(metric.getMetaData()).createMetaData() : null; this.properties = metric.getMetaData() != null ? new PropertySetBuilder(metric.getProperties()).createPropertySet() : null; switch (dataType) { case DataSet: this.value = metric.getValue() != null ? new DataSetBuilder((DataSet) metric.getValue()).createDataSet() : null; break; case Template: this.value = metric.getValue() != null ? new TemplateBuilder((Template) metric.getValue()).createTemplate() : null; break; default: this.value = metric.getValue(); } }
private Metric convertMetric(SparkplugBProto.Payload.Metric protoMetric) throws Exception { // Convert the dataType MetricDataType dataType = MetricDataType.fromInteger((protoMetric.getDatatype())); // Build and return the Metric return new MetricBuilder(protoMetric.getName(), dataType, getMetricValue(protoMetric)) .isHistorical( protoMetric.hasIsHistorical() ? protoMetric.getIsHistorical() : null) .isTransient(protoMetric .hasIsTransient() ? protoMetric.getIsTransient() : null) .timestamp(protoMetric.hasTimestamp() ? new Date(protoMetric.getTimestamp()) : null) .alias(protoMetric.hasAlias() ? protoMetric.getAlias() : null) .metaData(protoMetric.hasMetadata() ? new MetaDataBuilder().contentType(protoMetric.getMetadata().getContentType()) .size(protoMetric.getMetadata().getSize()).seq(protoMetric.getMetadata().getSeq()) .fileName(protoMetric.getMetadata().getFileName()) .fileType(protoMetric.getMetadata().getFileType()) .md5(protoMetric.getMetadata().getMd5()) .description(protoMetric.getMetadata().getDescription()).createMetaData() : null) .properties(protoMetric.hasProperties() ? new PropertySetBuilder().addProperties(convertProperties(protoMetric.getProperties())) .createPropertySet() : null) .createMetric(); }
private PropertySet newPropertySet() throws SparkplugException { return new PropertySetBuilder() .addProperties(newProps(true)) .createPropertySet(); }