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