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());
}
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());
}
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);
}
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());
}
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);
}
}
Aggregations