Search in sources :

Example 1 with RetrievePushNotificationAlarmResponse

use of org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse in project open-smart-grid-platform by OSGP.

the class SmartMeteringMonitoringEndpoint method getRetrievePushNotificationAlarmResponse.

@PayloadRoot(localPart = "RetrievePushNotificationAlarmRequest", namespace = SMARTMETER_MONITORING_NAMESPACE)
@ResponsePayload
public RetrievePushNotificationAlarmResponse getRetrievePushNotificationAlarmResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final RetrievePushNotificationAlarmRequest request) throws OsgpException {
    log.info("Incoming RetrievePushNotificationAlarmRequest for correlation UID: {}", request.getCorrelationUid());
    RetrievePushNotificationAlarmResponse response = null;
    try {
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), PushNotificationAlarm.class, ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "retrieving the push notification alarm");
        response = this.monitoringMapper.map(responseData.getMessageData(), RetrievePushNotificationAlarmResponse.class);
    } catch (final FunctionalException e) {
        throw e;
    } catch (final Exception e) {
        log.error("Exception: {} while sending RetrievePushNotificationAlarmRequest for correlation UID: {} for organisation {}.", e.getMessage(), request.getCorrelationUid(), organisationIdentification);
        this.handleException(e);
    }
    return response;
}
Also used : ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) RetrievePushNotificationAlarmResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) 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 RetrievePushNotificationAlarmResponse

use of org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse 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 3 with RetrievePushNotificationAlarmResponse

use of org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse in project open-smart-grid-platform by OSGP.

the class PushNotificationsAlarmConverter method convert.

@Override
public RetrievePushNotificationAlarmResponse convert(final PushNotificationAlarm source, final Type<? extends RetrievePushNotificationAlarmResponse> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final RetrievePushNotificationAlarmResponse response = new RetrievePushNotificationAlarmResponse();
    response.setDeviceIdentification(source.getDeviceIdentification());
    final AlarmRegister alarmRegister = new AlarmRegister();
    final List<AlarmType> alarmTypes = alarmRegister.getAlarmTypes();
    final Set<org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmType> alarms = source.getAlarms();
    for (final org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmType alarm : alarms) {
        alarmTypes.add(AlarmType.valueOf(alarm.name()));
    }
    response.setAlarmRegister(alarmRegister);
    return response;
}
Also used : AlarmType(org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AlarmType) AlarmRegister(org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.AlarmRegister) RetrievePushNotificationAlarmResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse)

Example 4 with RetrievePushNotificationAlarmResponse

use of org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse in project open-smart-grid-platform by OSGP.

the class PushNotificationAlarmMappingTest method testPushNotificationAlarmMappingWithEmptySet.

/**
 * Tests if a PushNotificationAlarm is mapped correctly with an empty Set.
 */
@Test
void testPushNotificationAlarmMappingWithEmptySet() {
    // build test data
    final Set<AlarmType> alarms = new TreeSet<>();
    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.getAlarmRegister()).isNotNull();
    assertThat(mapped.getAlarmRegister().getAlarmTypes()).isNotNull();
    assertThat(mapped.getDeviceIdentification()).isEqualTo(DEVICE_ID);
    assertThat(mapped.getAlarmRegister().getAlarmTypes().isEmpty()).isTrue();
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) TreeSet(java.util.TreeSet) 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 RetrievePushNotificationAlarmResponse

use of org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse in project open-smart-grid-platform by OSGP.

the class PushNotificationAlarmMappingTest method testPushNotificationAlarmMappingWithFilledSet.

/**
 * Tests if a PushNotificationAlarm object is mapped correctly with a filled Set.
 */
@Test
void testPushNotificationAlarmMappingWithFilledSet() {
    // build test data
    final Set<AlarmType> alarms = new TreeSet<>();
    alarms.add(ALARMTYPE);
    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.getAlarmRegister()).isNotNull();
    assertThat(mapped.getAlarmRegister().getAlarmTypes()).isNotEmpty();
    assertThat(mapped.getAlarmRegister().getAlarmTypes().get(0)).isNotNull();
    assertThat(mapped.getDeviceIdentification()).isEqualTo(DEVICE_ID);
    assertThat(mapped.getAlarmRegister().getAlarmTypes().get(0).name()).isEqualTo(ALARMTYPE.name());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) TreeSet(java.util.TreeSet) AlarmType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmType) RetrievePushNotificationAlarmResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse) Test(org.junit.jupiter.api.Test)

Aggregations

RetrievePushNotificationAlarmResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse)5 Test (org.junit.jupiter.api.Test)3 AlarmType (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmType)3 PushNotificationAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm)3 TreeSet (java.util.TreeSet)2 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)1 AlarmType (org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AlarmType)1 AlarmRegister (org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.AlarmRegister)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1