Search in sources :

Example 1 with EventNotificationType

use of org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method theDeviceReturnsAGetStatusResponseWithResultOverOslp.

/**
 * Setup method to set the status which should be returned by the mock.
 */
@Given("^the device returns a get status response \"([^\"]*)\" over \"([^\"]*)\"$")
public void theDeviceReturnsAGetStatusResponseWithResultOverOslp(final String result, final String protocol, final Map<String, String> requestParameters) {
    int eventNotificationTypes = 0;
    if (getString(requestParameters, PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONTYPES, PlatformPubliclightingDefaults.DEFAULT_EVENTNOTIFICATIONTYPES).trim().split(PlatformPubliclightingKeys.SEPARATOR_COMMA).length > 0) {
        for (final String eventNotificationType : getString(requestParameters, PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONTYPES, PlatformPubliclightingDefaults.DEFAULT_EVENTNOTIFICATIONTYPES).trim().split(PlatformPubliclightingKeys.SEPARATOR_COMMA)) {
            if (!eventNotificationType.isEmpty()) {
                eventNotificationTypes = eventNotificationTypes + Enum.valueOf(EventNotificationType.class, eventNotificationType.trim()).getValue();
            }
        }
    }
    final List<LightValue> lightValues = new ArrayList<>();
    if (!getString(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).isEmpty() && getString(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON).length > 0) {
        for (final String lightValueString : getString(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON)) {
            final String[] parts = lightValueString.split(PlatformPubliclightingKeys.SEPARATOR_COMMA);
            final LightValue lightValue = LightValue.newBuilder().setIndex(OslpUtils.integerToByteString(Integer.parseInt(parts[0]))).setOn(parts[1].toLowerCase().equals("true")).setDimValue(OslpUtils.integerToByteString(Integer.parseInt(parts[2]))).build();
            lightValues.add(lightValue);
        }
    }
    final List<LightValue> tariffValues = new ArrayList<>();
    if (!getString(requestParameters, PlatformPubliclightingKeys.KEY_TARIFFVALUES, PlatformPubliclightingDefaults.DEFAULT_TARIFFVALUES).isEmpty() && getString(requestParameters, PlatformPubliclightingKeys.KEY_TARIFFVALUES, PlatformPubliclightingDefaults.DEFAULT_TARIFFVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON).length > 0) {
        for (final String tariffValueString : getString(requestParameters, PlatformPubliclightingKeys.KEY_TARIFFVALUES, PlatformPubliclightingDefaults.DEFAULT_TARIFFVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON)) {
            final String[] parts = tariffValueString.split(PlatformPubliclightingKeys.SEPARATOR_COMMA);
            final LightValue tariffValue = LightValue.newBuilder().setIndex(OslpUtils.integerToByteString(Integer.parseInt(parts[0]))).setOn(parts[1].toLowerCase().equals("true")).build();
            tariffValues.add(tariffValue);
        }
    }
    this.oslpMockServer.mockGetStatusResponse(this.getDeviceUid(requestParameters), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_PREFERRED_LINKTYPE, LinkType.class, PlatformPubliclightingDefaults.DEFAULT_PREFERRED_LINKTYPE), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_ACTUAL_LINKTYPE, LinkType.class, PlatformPubliclightingDefaults.DEFAULT_ACTUAL_LINKTYPE), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTTYPE, LightType.class, PlatformPubliclightingDefaults.DEFAULT_LIGHTTYPE), eventNotificationTypes, Enum.valueOf(Status.class, result), lightValues, tariffValues);
}
Also used : LightType(org.opensmartgridplatform.oslp.Oslp.LightType) Status(org.opensmartgridplatform.oslp.Oslp.Status) LightValue(org.opensmartgridplatform.oslp.Oslp.LightValue) ArrayList(java.util.ArrayList) EventNotificationType(org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString) LinkType(org.opensmartgridplatform.oslp.Oslp.LinkType) Given(io.cucumber.java.en.Given)

Example 2 with EventNotificationType

use of org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType in project open-smart-grid-platform by OSGP.

the class DeviceManagementEndpoint method setEventNotifications.

@PayloadRoot(localPart = "SetEventNotificationsRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public SetEventNotificationsAsyncResponse setEventNotifications(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetEventNotificationsRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set EventNotifications Request received from organisation: {} for event device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetEventNotificationsAsyncResponse response = new SetEventNotificationsAsyncResponse();
    try {
        final List<EventNotificationType> eventNotifications = new ArrayList<>(this.deviceManagementMapper.mapAsList(request.getEventNotifications(), EventNotificationType.class));
        final String correlationUid = this.deviceManagementService.enqueueSetEventNotificationsRequest(organisationIdentification, request.getDeviceIdentification(), eventNotifications, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : SetEventNotificationsAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetEventNotificationsAsyncResponse) ArrayList(java.util.ArrayList) EventNotificationType(org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType) SetDeviceLifecycleStatusAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceLifecycleStatusAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse) SetDeviceVerificationKeyAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceVerificationKeyAsyncResponse) SetEventNotificationsAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetEventNotificationsAsyncResponse) UpdateDeviceCdmaSettingsAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsAsyncResponse) UpdateDeviceSslCertificationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceSslCertificationAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 3 with EventNotificationType

use of org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType in project open-smart-grid-platform by OSGP.

the class DeviceManagementServiceTest method testSetEventNotifications.

@Test
public void testSetEventNotifications() throws FunctionalException {
    final List<EventNotificationType> eventNotifications = Arrays.asList(EventNotificationType.COMM_EVENTS, EventNotificationType.DIAG_EVENTS);
    final Device device = mock(Device.class);
    when(device.getIpAddress()).thenReturn(TEST_IP);
    when(this.deviceDomainService.searchActiveDevice(TEST_DEVICE, ComponentType.DOMAIN_CORE)).thenReturn(device);
    this.deviceManagementService.setEventNotifications(TEST_ORGANISATION, TEST_DEVICE, TEST_UID, eventNotifications, TEST_MESSAGE_TYPE, TEST_PRIORITY);
    verify(this.osgpCoreRequestManager).send(this.argumentRequestMessage.capture(), this.argumentMessageType.capture(), this.argumentPriority.capture(), this.argumentIpAddress.capture());
    final RequestMessage expectedRequestMessage = this.createNewRequestMessage(new EventNotificationMessageDataContainerDto(this.domainCoreMapper.mapAsList(eventNotifications, EventNotificationTypeDto.class)));
    assertThat(this.argumentRequestMessage.getValue()).usingRecursiveComparison().isEqualTo(expectedRequestMessage);
    assertThat(this.argumentMessageType.getValue()).isEqualTo(TEST_MESSAGE_TYPE);
    assertThat(this.argumentPriority.getValue()).isEqualTo(TEST_PRIORITY);
    assertThat(this.argumentIpAddress.getValue()).isEqualTo(TEST_IP);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) EventNotificationType(org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType) EventNotificationMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationMessageDataContainerDto) Test(org.junit.jupiter.api.Test)

Aggregations

EventNotificationType (org.opensmartgridplatform.domain.core.valueobjects.EventNotificationType)3 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 Given (io.cucumber.java.en.Given)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 Test (org.junit.jupiter.api.Test)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)1 SetDeviceLifecycleStatusAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceLifecycleStatusAsyncResponse)1 SetDeviceVerificationKeyAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceVerificationKeyAsyncResponse)1 SetEventNotificationsAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetEventNotificationsAsyncResponse)1 UpdateDeviceCdmaSettingsAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsAsyncResponse)1 UpdateDeviceSslCertificationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceSslCertificationAsyncResponse)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 EventNotificationMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationMessageDataContainerDto)1 LightType (org.opensmartgridplatform.oslp.Oslp.LightType)1 LightValue (org.opensmartgridplatform.oslp.Oslp.LightValue)1 LinkType (org.opensmartgridplatform.oslp.Oslp.LinkType)1 Status (org.opensmartgridplatform.oslp.Oslp.Status)1