Commit eaaa6444 authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Merge branch...

Merge branch '103-propagate-value-type-when-copying-characteristics-to-rfs-from-supporting-resources' into 'develop'

Resolve "Propagate value type, when copying characteristics to RFS from supporting resources"

See merge request !103
parents 6c5a7d52 1ab00dd8
Loading
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -1243,6 +1243,10 @@ public class ServiceRepoService {
    }
    
    
    private String normalizeValueType(String valueType) {
  	  return (valueType == null || valueType.isBlank()) ? "" : valueType.trim();
	}

    private CharCopyResult copyCharacteristicsFromResource( @Valid Service aService, @Valid ServiceUpdate supd, @Valid Resource res) {

      Boolean characteristicFoundDifferent = false;
@@ -1285,20 +1289,27 @@ public class ServiceRepoService {

            String characteristicname = kind + resourcename + rChar.getName();
            Characteristic servChar = supd.getServiceCharacteristicByName( characteristicname );
           
		    if ( servChar != null && servChar.getValue() != null) {  
              if (! servChar.getValue().getValue().equals( rChar.getValue().getValue() ) ) {
			  boolean valueChanged = ! servChar.getValue().getValue().equals( rChar.getValue().getValue() );
			  boolean typeChanged = ! normalizeValueType( servChar.getValueType() ).equals( normalizeValueType( rChar.getValueType() ) );
			
              if ( valueChanged || typeChanged ) {
                characteristicFoundDifferent = true;
                supd.getServiceCharacteristicByName( characteristicname ) .value(new Any( rChar.getValue() ));  
                logger.debug("====================>  update characteristic: " + characteristicname +", value: "+ rChar.getValue().getValue());                      
				servChar.value( new Any( rChar.getValue() ) );
				servChar.setValueType( rChar.getValueType() );

                logger.debug("====================>  update characteristic: " + characteristicname + ", value: " + rChar.getValue().getValue() + ", valueType: " + rChar.getValueType());                      
              }
              
            } else {
              Characteristic cNew = new Characteristic();
              cNew.setName( characteristicname );     
              cNew.value( new Any( rChar.getValue() ));
			  cNew.setValueType( rChar.getValueType());
              supd.addServiceCharacteristicItem( cNew );
              characteristicFoundDifferent = true;
              logger.debug("====================>  add New characteristic: " + characteristicname +", value: "+ rChar.getValue().getValue());
              logger.debug("====================>  add New characteristic: " + characteristicname +", value: " + rChar.getValue().getValue() + ", valueType: " + rChar.getValueType()); 
            }