@@ -187,7 +187,7 @@ public class Validator {
187
187
"Message validate" );
188
188
private Set <String > targetDevices ;
189
189
private final LoggingHandler outputLogger ;
190
- private ImmutableSet <String > expectedDevices ;
190
+ private Set <String > expectedDevices ;
191
191
private File outBaseDir ;
192
192
private File schemaRoot ;
193
193
private String schemaSpec ;
@@ -244,6 +244,11 @@ public Map<String, ReportingDevice> getReportingDevices() {
244
244
return reportingDevices ;
245
245
}
246
246
247
+ @ VisibleForTesting
248
+ public Set <String > getExpectedDevices () {
249
+ return expectedDevices ;
250
+ }
251
+
247
252
Validator processArgs (List <String > argListRaw ) {
248
253
List <String > argList = new ArrayList <>(argListRaw );
249
254
try {
@@ -453,7 +458,7 @@ private void setMessageTraceDir(String writeDirArg) {
453
458
private void initializeExpectedDevices () {
454
459
Set <String > siteDevices = siteModel .getDeviceIds ();
455
460
try {
456
- expectedDevices = ImmutableSet . copyOf (siteDevices );
461
+ expectedDevices = new HashSet <> (siteDevices );
457
462
for (String device : siteDevices ) {
458
463
ReportingDevice reportingDevice = newReportingDevice (device );
459
464
try {
@@ -612,25 +617,28 @@ private void handleUdmiConfig(UdmiConfig udmiConfig) {
612
617
}
613
618
614
619
private boolean handleMetadataUpdate (Map <String , String > attributes , Object messageObject ) {
615
- String deviceId = attributes .get ("deviceId" );
616
620
String subFolderRaw = attributes .get (SUBFOLDER_PROPERTY_KEY );
617
621
String subTypeRaw = attributes .get (SUBTYPE_PROPERTY_KEY );
618
622
619
- if (SubType .MODEL .value ().equals (subTypeRaw ) && SubFolder .UPDATE .value ().equals (subFolderRaw )) {
620
- if (reportingDevices .containsKey (deviceId )) {
621
- ReportingDevice device = reportingDevices .get (deviceId );
622
- Metadata metadata = convertTo (Metadata .class ,
623
- requireNonNull (messageObject , "messageObject is null" ));
623
+ if (!SubType .MODEL .value ().equals (subTypeRaw )
624
+ || !SubFolder .UPDATE .value ().equals (subFolderRaw )) {
625
+ return false ;
626
+ }
624
627
625
- if (catchToNull (() -> metadata .cloud .operation ) == Operation .DELETE ) {
626
- reportingDevices .remove (deviceId );
627
- } else if (metadata .system != null ) {
628
- device .setMetadata (metadata );
629
- }
630
- }
631
- return true ;
628
+ String deviceId = attributes .get ("deviceId" );
629
+ Metadata metadata = convertTo (Metadata .class ,
630
+ requireNonNull (messageObject , "messageObject is null" ));
631
+ ReportingDevice device = reportingDevices .computeIfAbsent (deviceId , this ::newReportingDevice );
632
+
633
+ if (catchToNull (() -> metadata .cloud .operation ) == Operation .DELETE ) {
634
+ reportingDevices .remove (deviceId );
635
+ } else {
636
+ ifNotNullThen (metadata .system , () -> {
637
+ device .setMetadata (metadata );
638
+ expectedDevices .add (deviceId );
639
+ });
632
640
}
633
- return false ;
641
+ return true ;
634
642
}
635
643
636
644
protected synchronized void validateMessage (MessageBundle message ) {
0 commit comments