Search in sources :

Example 1 with PushNotificationAlarmDto

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

the class PushNotificationAlarmMappingTest method testWithNullVariables.

// Test if mapping a PushNotificationAlarm object succeeds with null
// variables
@Test
public void testWithNullVariables() {
    // build test data
    final String deviceId = null;
    final EnumSet<AlarmTypeDto> alarms = null;
    final PushNotificationAlarmDto pushNotificationAlarmDto = new PushNotificationAlarmDto(deviceId, alarms, this.alarmBytes);
    // actual mapping
    final PushNotificationAlarm pushNotificationAlarm = this.mapperFactory.getMapperFacade().map(pushNotificationAlarmDto, PushNotificationAlarm.class);
    // test mapping
    assertThat(pushNotificationAlarm).isNotNull();
    assertThat(pushNotificationAlarm.getDeviceIdentification()).isNull();
    // the constructor creates an empty EnumSet when passed a null value.
    assertThat(pushNotificationAlarmDto.getAlarms()).isEmpty();
    assertThat(pushNotificationAlarm.getAlarms()).isEmpty();
    assertThat(this.alarmBytes).withFailMessage("The alarm bytes should be the same after the mapping").isEqualTo(pushNotificationAlarm.getAlarmBytes());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Test(org.junit.jupiter.api.Test)

Example 2 with PushNotificationAlarmDto

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

the class PushNotificationAlarmMappingTest method testWithEmptyEnumSet.

// Test if mapping a PushNotificationAlarm object succeeds when the EnumSet
// is empty
@Test
public void testWithEmptyEnumSet() {
    // build test data
    final String deviceId = "device1";
    final EnumSet<AlarmTypeDto> alarms = EnumSet.noneOf(AlarmTypeDto.class);
    final PushNotificationAlarmDto pushNotificationAlarmDto = new PushNotificationAlarmDto(deviceId, alarms, this.alarmBytes);
    // actual mapping
    final PushNotificationAlarm pushNotificationAlarm = this.mapperFactory.getMapperFacade().map(pushNotificationAlarmDto, PushNotificationAlarm.class);
    // test mapping
    assertThat(pushNotificationAlarm).isNotNull();
    assertThat(pushNotificationAlarm.getDeviceIdentification()).isEqualTo(deviceId);
    assertThat(pushNotificationAlarm.getAlarms()).isEmpty();
    assertThat(this.alarmBytes).isEqualTo(pushNotificationAlarm.getAlarmBytes());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Test(org.junit.jupiter.api.Test)

Example 3 with PushNotificationAlarmDto

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

the class DlmsChannelHandlerServer method processPushedAlarm.

private void processPushedAlarm(final DlmsPushNotification message, final String correlationId, final String deviceIdentification, final String ipAddress) {
    this.logMessage(message);
    final PushNotificationAlarmDto pushNotificationAlarm = new PushNotificationAlarmDto(deviceIdentification, message.getAlarms(), message.toByteArray());
    final RequestMessage requestMessage = new RequestMessage(correlationId, "no-organisation", deviceIdentification, ipAddress, null, null, pushNotificationAlarm);
    final MessageMetadata messageMetadata = new Builder().withMessagePriority(MessagePriorityEnum.HIGH.getPriority()).build();
    log.info("Sending push notification alarm to GXF with correlation ID: {}", correlationId);
    this.osgpRequestMessageSender.send(requestMessage, MessageType.PUSH_NOTIFICATION_ALARM.name(), messageMetadata);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)

Example 4 with PushNotificationAlarmDto

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

the class PushNotificationAlarmMappingTest method testWithNonEmptyEnumSet.

// Test if mapping a PushNotificationAlarm object succeeds when the EnumSet
// is not empty
@Test
public void testWithNonEmptyEnumSet() {
    // build test data
    final String deviceId = "device1";
    final EnumSet<AlarmTypeDto> alarms = EnumSet.of(AlarmTypeDto.CLOCK_INVALID);
    final PushNotificationAlarmDto pushNotificationAlarmDto = new PushNotificationAlarmDto(deviceId, alarms, this.alarmBytes);
    // actual mapping
    final PushNotificationAlarm pushNotificationAlarm = this.mapperFactory.getMapperFacade().map(pushNotificationAlarmDto, PushNotificationAlarm.class);
    // test mapping
    assertThat(pushNotificationAlarm).isNotNull();
    assertThat(pushNotificationAlarm.getDeviceIdentification()).isEqualTo(deviceId);
    assertThat(pushNotificationAlarm.getAlarms().size()).isEqualTo(alarms.size());
    assertThat(pushNotificationAlarm.getAlarms().contains(AlarmType.CLOCK_INVALID)).isTrue();
    assertThat(this.alarmBytes).isEqualTo(pushNotificationAlarm.getAlarmBytes());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Test(org.junit.jupiter.api.Test)

Example 5 with PushNotificationAlarmDto

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

the class PushNotificationAlarmMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    final MessageMetadata metadata = MessageMetadata.fromMessage(message);
    LOGGER.info("Received message of messageType: {} organisationIdentification: {} deviceIdentification: {}", this.messageType, metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
    final RequestMessage requestMessage = (RequestMessage) message.getObject();
    final Object dataObject = requestMessage.getRequest();
    try {
        final Device device = this.getDevice(metadata.getDeviceIdentification());
        final PushNotificationAlarmDto pushNotificationAlarm = (PushNotificationAlarmDto) dataObject;
        this.storeAlarmAsEvent(pushNotificationAlarm);
        final String ownerIdentification = this.getOrganisationIdentificationOfOwner(device);
        LOGGER.info("Matching owner {} with device {} handling {} from {}", ownerIdentification, metadata.getDeviceIdentification(), this.messageType, requestMessage.getIpAddress());
        final RequestMessage requestWithUpdatedOrganization = new RequestMessage(requestMessage.getCorrelationUid(), ownerIdentification, requestMessage.getDeviceIdentification(), requestMessage.getIpAddress(), requestMessage.getBaseTransceiverStationId(), requestMessage.getCellId(), pushNotificationAlarm);
        final Optional<DomainInfo> smartMeteringDomain = this.getDomainInfo();
        if (smartMeteringDomain.isPresent()) {
            this.domainRequestService.send(requestWithUpdatedOrganization, DeviceFunction.PUSH_NOTIFICATION_ALARM.name(), smartMeteringDomain.get());
            device.updateConnectionDetailsToSuccess();
            this.deviceRepository.save(device);
        } else {
            LOGGER.error("No DomainInfo found for SMART_METERING 1.0, unable to send message of message type: {} to " + "domain adapter. RequestMessage for {} dropped.", this.messageType, pushNotificationAlarm);
        }
    } catch (final OsgpException e) {
        final String errorMessage = String.format("%s occurred, reason: %s", e.getClass().getName(), e.getMessage());
        LOGGER.error(errorMessage, e);
        throw new JMSException(errorMessage);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo) JMSException(javax.jms.JMSException)

Aggregations

PushNotificationAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto)5 Test (org.junit.jupiter.api.Test)3 PushNotificationAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm)3 AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)3 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)2 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)2 JMSException (javax.jms.JMSException)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 DomainInfo (org.opensmartgridplatform.domain.core.entities.DomainInfo)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 Builder (org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)1