Search in sources :

Example 1 with AlarmNotificationsDto

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

the class SetAlarmNotificationsCommandExecutor method alarmNotifications.

private AlarmNotificationsDto alarmNotifications(final long alarmFilterLongValue, final DlmsObjectType alarmRegisterDlmsObjectType) {
    final BitSet bitSet = BitSet.valueOf(new long[] { alarmFilterLongValue });
    final Set<AlarmNotificationDto> notifications = new TreeSet<>();
    for (final AlarmTypeDto alarmType : this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType)) {
        final boolean enabled = bitSet.get(this.alarmHelperService.getAlarmRegisterBitIndex(alarmType));
        notifications.add(new AlarmNotificationDto(alarmType, enabled));
    }
    return new AlarmNotificationsDto(notifications);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) TreeSet(java.util.TreeSet) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) BitSet(java.util.BitSet) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)

Example 2 with AlarmNotificationsDto

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

the class AlarmNotificationsMappingTest method testWithSet.

// Tests if mapping with a Set with an entry succeeds.
@Test
public void testWithSet() {
    // create test data
    final AlarmNotification alarmNotification = new AlarmNotification(AlarmType.CLOCK_INVALID, true);
    final Set<AlarmNotification> alarmNotificationSet = new TreeSet<>();
    alarmNotificationSet.add(alarmNotification);
    final AlarmNotifications alarmNotifications = new AlarmNotifications(alarmNotificationSet);
    // actual mapping
    final AlarmNotificationsDto alarmNotificationsDto = this.configurationMapper.map(alarmNotifications, AlarmNotificationsDto.class);
    // check if mapping was successful
    assertThat(alarmNotificationsDto).isNotNull();
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet()).isNotNull();
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet().size()).isEqualTo(alarmNotificationSet.size());
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet().isEmpty()).isFalse();
    // To see if there is an AlarmNotifictionDto with the same variables as
    // the AlarmNotification in the Set.
    final AlarmNotificationDto alarmNotificationDto = new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true);
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet().contains(alarmNotificationDto)).isTrue();
}
Also used : AlarmNotifications(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotifications) AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) TreeSet(java.util.TreeSet) AlarmNotification(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) Test(org.junit.jupiter.api.Test)

Example 3 with AlarmNotificationsDto

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

the class AlarmNotificationsMappingTest method testWithEmptySet.

// The Set may be empty. Tests if mapping with an empty Set succeeds.
@Test
public void testWithEmptySet() {
    // create test data
    final Set<AlarmNotification> alarmNotificationSet = new TreeSet<>();
    final AlarmNotifications alarmNotifications = new AlarmNotifications(alarmNotificationSet);
    // actual mapping
    final AlarmNotificationsDto alarmNotificationsDto = this.configurationMapper.map(alarmNotifications, AlarmNotificationsDto.class);
    // check if mapping was successful
    assertThat(alarmNotificationsDto).isNotNull();
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet()).isNotNull();
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet()).isEmpty();
}
Also used : AlarmNotifications(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotifications) TreeSet(java.util.TreeSet) AlarmNotification(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) Test(org.junit.jupiter.api.Test)

Example 4 with AlarmNotificationsDto

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

the class SetAlarmNotificationsCommandExecutorTest method execute.

private AccessResultCode execute(final AlarmNotificationDto... alarmNotificationDtos) throws OsgpException {
    final Set<AlarmNotificationDto> alarmNotificationDtoSet = new HashSet<>(Arrays.asList(alarmNotificationDtos));
    final AlarmNotificationsDto alarmNotificationsDto = new AlarmNotificationsDto(alarmNotificationDtoSet);
    return this.executor.execute(this.connMgr, this.device, alarmNotificationsDto, this.messageMetadata);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) HashSet(java.util.HashSet)

Example 5 with AlarmNotificationsDto

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

the class SetAlarmNotificationsRequestMessageProcessor method handleMessage.

@Override
protected Serializable handleMessage(final DlmsConnectionManager conn, final DlmsDevice device, final Serializable requestObject, final MessageMetadata messageMetadata) throws OsgpException {
    this.assertRequestObjectType(AlarmNotificationsDto.class, requestObject);
    final AlarmNotificationsDto alarmNotifications = (AlarmNotificationsDto) requestObject;
    this.configurationService.setAlarmNotifications(conn, device, alarmNotifications, messageMetadata);
    return null;
}
Also used : AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)

Aggregations

AlarmNotificationsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)7 TreeSet (java.util.TreeSet)4 AlarmNotificationDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto)4 BitSet (java.util.BitSet)2 Test (org.junit.jupiter.api.Test)2 AlarmNotification (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification)2 AlarmNotifications (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotifications)2 AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 AccessResultCode (org.openmuc.jdlms.AccessResultCode)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 GetResult (org.openmuc.jdlms.GetResult)1 SetParameter (org.openmuc.jdlms.SetParameter)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 AbstractCommandExecutor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor)1 DlmsObjectConfigService (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService)1