Search in sources :

Example 11 with ConfigurationObjectDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto 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);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 12 with ConfigurationObjectDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectRequestMappingTest method testMappingWithEmptyList.

// Test if mapping with ConfigurationFlags with an empty list succeeds.
@Test
public void testMappingWithEmptyList() {
    // build test data
    final String deviceIdentification = "nr1";
    final GprsOperationModeType gprsOperationModeType = GprsOperationModeType.ALWAYS_ON;
    final ConfigurationFlags configurationFlags = new ConfigurationFlags(new ArrayList<>());
    final ConfigurationObject configurationObject = new ConfigurationObject(gprsOperationModeType, configurationFlags);
    final SetConfigurationObjectRequestData setConfigurationObjectRequestData = new SetConfigurationObjectRequestData(configurationObject);
    // actual mapping
    final SetConfigurationObjectRequest setConfigurationObjectRequest = new SetConfigurationObjectRequest(deviceIdentification, setConfigurationObjectRequestData);
    final SetConfigurationObjectRequestDto setConfigurationObjectRequestDto = this.configurationMapper.map(setConfigurationObjectRequest, SetConfigurationObjectRequestDto.class);
    // check values
    assertThat(setConfigurationObjectRequestDto).isNotNull();
    assertThat(setConfigurationObjectRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
    final ConfigurationObjectDto configurationObjectDto = setConfigurationObjectRequestDto.getSetConfigurationObjectRequestData().getConfigurationObject();
    assertThat(configurationObjectDto).isNotNull();
    // Check if both configurationFlags instances have an empty list
    assertThat(configurationObjectDto.getConfigurationFlags().getFlags()).isEmpty();
}
Also used : GprsOperationModeType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GprsOperationModeType) ConfigurationObject(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ConfigurationObject) SetConfigurationObjectRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetConfigurationObjectRequest) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) SetConfigurationObjectRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetConfigurationObjectRequestDto) ConfigurationFlags(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ConfigurationFlags) SetConfigurationObjectRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetConfigurationObjectRequestData) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigurationObjectDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto 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());
}
Also used : GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) ConfigurationFlagTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagTypeDto) SetConfigurationObjectRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetConfigurationObjectRequestDataDto)

Example 14 with ConfigurationObjectDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectResponseMappingTest method testMapConfigurationObjectDto.

@Test
public void testMapConfigurationObjectDto() {
    final ConfigurationObjectDto dto = this.makeConfigurationObjectDto();
    final ConfigurationObject result = this.mapper.map(dto, ConfigurationObject.class);
    assertThat(result).withFailMessage("mapping ConfigurationObjectDto should not return null").isNotNull();
    assertThat(result).withFailMessage("mapping ConfigurationObjectDto should return correct type").isOfAnyClassIn(ConfigurationObject.class);
}
Also used : ConfigurationObject(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ConfigurationObject) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) Test(org.junit.jupiter.api.Test)

Example 15 with ConfigurationObjectDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto 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;
}
Also used : ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ArrayList(java.util.ArrayList) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)

Aggregations

ConfigurationObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)16 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)8 Test (org.junit.jupiter.api.Test)6 ConfigurationFlagDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto)6 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)5 GprsOperationModeTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto)5 AccessResultCode (org.openmuc.jdlms.AccessResultCode)4 BitString (org.openmuc.jdlms.datatypes.BitString)4 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 ArrayList (java.util.ArrayList)3 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)3 GetConfigurationObjectService (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.configuration.service.GetConfigurationObjectService)2 SetConfigurationObjectService (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.configuration.service.SetConfigurationObjectService)2 ConfigurationObject (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ConfigurationObject)2 ConfigurationFlagTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagTypeDto)2 SetConfigurationObjectRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SetConfigurationObjectRequestDataDto)2 SetConfigurationObjectRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SetConfigurationObjectRequestDto)2 List (java.util.List)1 Optional (java.util.Optional)1