use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceSmr5 method getConfigurationObject.
@Override
ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException {
final DataObject resultData = result.getResultData();
if (resultData == null || !resultData.isBitString()) {
LOGGER.warn("Configuration object result data is not a BitString: {}", resultData);
throw new ProtocolAdapterException("Expected bit-string data as Configuration object result data, but got: " + (resultData == null ? "null" : resultData.getType()));
}
LOGGER.info("SMR5 Configuration object current BitString: {}", this.dlmsHelper.getDebugInfo(resultData));
final BitString bitString = resultData.getValue();
final byte[] flagByteArray = bitString.getBitString();
final List<ConfigurationFlagDto> configurationFlagDtos = this.toConfigurationFlags(flagByteArray);
final ConfigurationFlagsDto configurationFlagsDto = new ConfigurationFlagsDto(configurationFlagDtos);
return new ConfigurationObjectDto(configurationFlagsDto);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4 method getConfigurationFlags.
private ConfigurationFlagsDto getConfigurationFlags(final DataObject flags) throws ProtocolAdapterException {
if (flags == null || !flags.isBitString()) {
final String message = String.format("Expected ConfigurationObject flags as BitString, but got: %s", flags);
LOGGER.warn(message);
throw new ProtocolAdapterException(message);
}
final BitString bitString = flags.getValue();
final byte[] flagBytes = bitString.getBitString();
final List<ConfigurationFlagDto> configurationFlags = this.toConfigurationFlags(flagBytes);
return new ConfigurationFlagsDto(configurationFlags);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectRequestMappingTest method checkSetConfigurationObjectRequestData.
// method to check values of all objects that are mapped when a
// SetConfigurationObjectRequest is mapped.
private void checkSetConfigurationObjectRequestData(final GprsOperationModeType gprsOperationModeType, final ConfigurationFlagType configurationFlagType, final ConfigurationFlags configurationFlags, final SetConfigurationObjectRequestDto setConfigurationObjectRequestDto) {
// check if SetConfigurationObjectRequesDataDto object is present
final SetConfigurationObjectRequestDataDto setConfigurationObjectRequestDataDto = setConfigurationObjectRequestDto.getSetConfigurationObjectRequestData();
assertThat(setConfigurationObjectRequestDto).isNotNull();
// check if ConfigurationObjectDto object is present
final ConfigurationObjectDto configurationObjectDto = setConfigurationObjectRequestDataDto.getConfigurationObject();
assertThat(configurationObjectDto).isNotNull();
// check the GprsOperationModeTypeDto value
final GprsOperationModeTypeDto gprsOperationModeTypeDto = configurationObjectDto.getGprsOperationMode();
assertThat(gprsOperationModeTypeDto.name()).isEqualTo(gprsOperationModeType.name());
// check if ConfigurationFlagsDto object is present, and if its List is
// of an equal size.
final ConfigurationFlagsDto configurationFlagsDto = configurationObjectDto.getConfigurationFlags();
assertThat(configurationFlagsDto).isNotNull();
assertThat(configurationFlagsDto.getFlags().size()).isEqualTo(configurationFlags.getFlags().size());
// check ConfigurationObjectFlagTypeDto value.
final ConfigurationFlagDto configurationFlagDto = configurationFlagsDto.getFlags().get(0);
final ConfigurationFlagTypeDto configurationFlagTypeDto = configurationFlagDto.getConfigurationFlagType();
assertThat(configurationFlagTypeDto.name()).isEqualTo(configurationFlagType.name());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectResponseMappingTest method makeConfigurationObjectDto.
private ConfigurationObjectDto makeConfigurationObjectDto() {
final List<ConfigurationFlagDto> configurationFlags = new ArrayList<>();
configurationFlags.add(this.makeConfigurationFlagDto());
final ConfigurationFlagsDto flags = new ConfigurationFlagsDto(configurationFlags);
final ConfigurationObjectDto configObjectDto = new ConfigurationObjectDto(GprsOperationModeTypeDto.ALWAYS_ON, flags);
return configObjectDto;
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectServiceTest method getFlagsCannotFindBitPosition.
@Test
void getFlagsCannotFindBitPosition() {
// SETUP
final ArrayList<ConfigurationFlagDto> flags = new ArrayList<>();
flags.add(new ConfigurationFlagDto(ConfigurationFlagTypeDto.PO_ENABLE, true));
final ConfigurationFlagsDto flagsToSet = new ConfigurationFlagsDto(flags);
when(this.configurationToSet.getConfigurationFlags()).thenReturn(flagsToSet);
when(this.configurationOnDevice.getConfigurationFlags()).thenReturn(this.emptyFlags());
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
// CALL
this.instance.getFlags(this.configurationToSet, this.configurationOnDevice);
});
}
Aggregations