use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm in project open-smart-grid-platform by OSGP.
the class SmartMeteringConfigurationEndpoint method getPushNotificationAlarm.
@PayloadRoot(localPart = "GetPushNotificationAlarmAsyncRequest", namespace = SMARTMETER_CONFIGURATION_NAMESPACE)
@ResponsePayload
public GetPushNotificationAlarmResponse getPushNotificationAlarm(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetPushNotificationAlarmAsyncRequest request) throws OsgpException {
log.info("GetPushNotificationAlarmRequest Request received from organisation {} for device: {}.", organisationIdentification, request.getDeviceIdentification());
final GetPushNotificationAlarmResponse response = new GetPushNotificationAlarmResponse();
try {
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (responseData != null) {
final PushNotificationAlarm p = (PushNotificationAlarm) responseData.getMessageData();
response.setDecodedMessage(p.toString());
response.setEncodedMessage(p.getAlarmBytes());
response.getAlarm().addAll(this.configurationMapper.mapAsList(p.getAlarms(), org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AlarmType.class));
}
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm 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.domain.core.valueobjects.smartmetering.PushNotificationAlarm 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.domain.core.valueobjects.smartmetering.PushNotificationAlarm in project open-smart-grid-platform by OSGP.
the class PushNotificationAlarmMappingTest method testPushNotificiationAlarmMappingWithNullSet.
/**
* Tests if mapping a PushNotificationAlarm object succeeds with a null Set.
*/
@Test
void testPushNotificiationAlarmMappingWithNullSet() {
// build test data
final Set<AlarmType> alarms = null;
final PushNotificationAlarm original = new PushNotificationAlarm(DEVICE_ID, alarms, this.alarmBytes);
// actual mapping
final RetrievePushNotificationAlarmResponse mapped = this.monitoringMapper.map(original, RetrievePushNotificationAlarmResponse.class);
// check mapping
assertThat(mapped).isNotNull();
assertThat(mapped.getDeviceIdentification()).isNotNull();
assertThat(mapped.getDeviceIdentification()).isEqualTo(DEVICE_ID);
// constructor for PushNotificationAlarm creates a new Set when passed a
// null value, so we should check for an empty List
assertThat(mapped.getAlarmRegister()).isNotNull();
assertThat(mapped.getAlarmRegister().getAlarmTypes()).isNotNull();
assertThat(mapped.getAlarmRegister().getAlarmTypes().isEmpty()).isTrue();
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm in project open-smart-grid-platform by OSGP.
the class NotificationService method handlePushNotificationAlarm.
public void handlePushNotificationAlarm(final MessageMetadata messageMetadata, final PushNotificationAlarmDto pushNotificationAlarm) {
LOGGER.info("handlePushNotificationAlarm for MessageType: {}", messageMetadata.getMessageType());
final PushNotificationAlarm pushNotificationAlarmDomain = this.mapperFactory.getMapperFacade().map(pushNotificationAlarm, PushNotificationAlarm.class);
/*
* Send the push notification alarm as a response message to the web service, so
* it can be handled similar to response messages based on earlier web service
* requests.
*/
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(ResponseMessageResultType.OK).withDataObject(pushNotificationAlarmDomain).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
Aggregations