Search in sources :

Example 1 with PushNotificationAlarm

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;
}
Also used : GetPushNotificationAlarmResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetPushNotificationAlarmResponse) PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) GetKeysResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) IOException(java.io.IOException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 2 with PushNotificationAlarm

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

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());
}
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 4 with PushNotificationAlarm

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();
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmType) RetrievePushNotificationAlarmResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse) Test(org.junit.jupiter.api.Test)

Example 5 with PushNotificationAlarm

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());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Aggregations

PushNotificationAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm)8 Test (org.junit.jupiter.api.Test)6 RetrievePushNotificationAlarmResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse)3 AlarmType (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmType)3 AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)3 PushNotificationAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto)3 TreeSet (java.util.TreeSet)2 IOException (java.io.IOException)1 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)1 GetKeysResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData)1 GetPushNotificationAlarmResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetPushNotificationAlarmResponse)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1