Search in sources :

Example 1 with LightValue

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue in project open-smart-grid-platform by OSGP.

the class AuthorizeDeviceFunctionsSteps method setLightSchedule.

private void setLightSchedule(final Map<String, String> requestParameters) throws WebServiceSecurityException, GeneralSecurityException, IOException {
    final org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleRequest request = new org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleRequest();
    request.setDeviceIdentification(getString(requestParameters, PlatformPubliclightingKeys.KEY_DEVICE_IDENTIFICATION, PlatformPubliclightingDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    final Schedule schedule = new Schedule();
    schedule.setActionTime(ActionTimeType.SUNRISE);
    schedule.setIndex(0);
    schedule.setWeekDay(WeekDayType.ALL);
    schedule.setTime(DateTime.now().toString());
    schedule.setIsEnabled(true);
    schedule.setMinimumLightsOn(10);
    final org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.LightValue lightValue = new org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.LightValue();
    lightValue.setDimValue(100);
    lightValue.setIndex(1);
    lightValue.setOn(true);
    schedule.getLightValue().add(lightValue);
    schedule.setTriggerType(TriggerType.LIGHT_TRIGGER);
    final WindowType windowType = new WindowType();
    windowType.setMinutesAfter(0);
    windowType.setMinutesBefore(0);
    schedule.setTriggerWindow(windowType);
    request.getSchedules().add(schedule);
    ScenarioContext.current().put(PlatformPubliclightingKeys.RESPONSE, this.publicLightingScheduleManagementClient.setSchedule(request));
}
Also used : LightValue(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue) TariffSchedule(org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffSchedule) Schedule(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.Schedule) WindowType(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.WindowType)

Example 2 with LightValue

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue in project open-smart-grid-platform by OSGP.

the class GetStatusSteps method thePlatformBuffersAGetStatusResponseMessageForDevice.

@Then("^the platform buffers a get status response message for device \"([^\"]*)\"$")
public void thePlatformBuffersAGetStatusResponseMessageForDevice(final String deviceIdentification, final Map<String, String> expectedResult) {
    final GetStatusAsyncRequest request = this.getGetStatusAsyncRequest(deviceIdentification);
    final GetStatusResponse response = Wait.untilAndReturn(() -> {
        final GetStatusResponse retval = this.publicLightingClient.getGetStatusResponse(request);
        assertThat(retval).isNotNull();
        assertThat(retval.getResult()).isEqualTo(Enum.valueOf(OsgpResultType.class, expectedResult.get(PlatformPubliclightingKeys.KEY_RESULT)));
        return retval;
    });
    final DeviceStatus deviceStatus = (DeviceStatus) response.getStatus();
    assertThat(deviceStatus.getPreferredLinkType()).isEqualTo(getEnum(expectedResult, PlatformPubliclightingKeys.KEY_PREFERRED_LINKTYPE, LinkType.class));
    assertThat(deviceStatus.getActualLinkType()).isEqualTo(getEnum(expectedResult, PlatformPubliclightingKeys.KEY_ACTUAL_LINKTYPE, LinkType.class));
    assertThat(deviceStatus.getLightType()).isEqualTo(getEnum(expectedResult, PlatformPubliclightingKeys.KEY_LIGHTTYPE, LightType.class));
    if (expectedResult.containsKey(PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONTYPES) && !expectedResult.get(PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONTYPES).isEmpty()) {
        assertThat(deviceStatus.getEventNotifications().size()).isEqualTo(getString(expectedResult, PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONS, PlatformPubliclightingDefaults.DEFAULT_EVENTNOTIFICATIONS).split(PlatformPubliclightingKeys.SEPARATOR_COMMA).length);
        for (final String eventNotification : getString(expectedResult, PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONS, PlatformPubliclightingDefaults.DEFAULT_EVENTNOTIFICATIONS).split(PlatformPubliclightingKeys.SEPARATOR_COMMA)) {
            assertThat(deviceStatus.getEventNotifications().contains(Enum.valueOf(EventNotificationType.class, eventNotification))).isTrue();
        }
    }
    if (expectedResult.containsKey(PlatformPubliclightingKeys.KEY_LIGHTVALUES) && !expectedResult.get(PlatformPubliclightingKeys.KEY_LIGHTVALUES).isEmpty()) {
        assertThat(deviceStatus.getLightValues().size()).isEqualTo(getString(expectedResult, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).split(PlatformPubliclightingKeys.SEPARATOR_COMMA).length);
        for (final String lightValues : getString(expectedResult, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).split(PlatformPubliclightingKeys.SEPARATOR_COMMA)) {
            final String[] parts = lightValues.split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON);
            final Integer index = Integer.parseInt(parts[0]);
            final Boolean on = Boolean.parseBoolean(parts[1]);
            final Integer dimValue = Integer.parseInt(parts[2]);
            boolean found = false;
            for (final LightValue lightValue : deviceStatus.getLightValues()) {
                if (Objects.equals(lightValue.getIndex(), index) && lightValue.isOn() == on && Objects.equals(lightValue.getDimValue(), dimValue)) {
                    found = true;
                    break;
                }
            }
            assertThat(found).isTrue();
        }
    }
}
Also used : LightType(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightType) GetStatusAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncRequest) GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse) LightValue(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) OsgpResultType(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.OsgpResultType) DeviceStatus(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus) EventNotificationType(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.EventNotificationType) LinkType(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LinkType) Then(io.cucumber.java.en.Then)

Example 3 with LightValue

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue in project open-smart-grid-platform by OSGP.

the class SetLightSteps method receivingAsetLightRequestWithValidLightValuesAndInvalidLightValues.

@When("^receiving a set light request with \"([^\"]*)\" valid lightvalues and \"([^\"]*)\" invalid lightvalues$")
public void receivingAsetLightRequestWithValidLightValuesAndInvalidLightValues(final Integer nofValidLightValues, final Integer nofInvalidLightValues, final Map<String, String> requestParameters) throws Throwable {
    final SetLightRequest request = new SetLightRequest();
    request.setDeviceIdentification(getString(requestParameters, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    for (int i = 0; i < nofValidLightValues; i++) {
        final LightValue lightValue = new LightValue();
        lightValue.setIndex(i + 2);
        lightValue.setDimValue(getInteger(requestParameters, PlatformKeys.KEY_DIMVALUE, PlatformDefaults.DEFAULT_DIMVALUE));
        lightValue.setOn(getBoolean(requestParameters, PlatformKeys.KEY_ON, PlatformDefaults.DEFAULT_ON));
        request.getLightValue().add(lightValue);
    }
    for (int i = 0; i < nofInvalidLightValues; i++) {
        final LightValue lightValue = new LightValue();
        lightValue.setIndex(i + 2 + nofValidLightValues);
        lightValue.setDimValue(50);
        lightValue.setOn(false);
        request.getLightValue().add(lightValue);
    }
    try {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, this.client.setLight(request));
    } catch (final SoapFaultClientException ex) {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, ex);
    }
}
Also used : LightValue(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue) SoapFaultClientException(org.springframework.ws.soap.client.SoapFaultClientException) SetLightRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightRequest) When(io.cucumber.java.en.When)

Example 4 with LightValue

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue in project open-smart-grid-platform by OSGP.

the class OsgpPublicLightingClientSoapService method setLightRequest.

/**
 * Creates a WebServiceTemplate and a SetLightRequest with the parameters deviceId, dimValue and
 * LightOn. Sends the SetLightRequest to the platform using the WebServiceTemplate. Returns the
 * response (CorrelationId) from the Platform.
 *
 * @return correlation id
 */
public String setLightRequest(final String deviceId, final int dimValue, final boolean lightOn) {
    final SetLightRequest request = new SetLightRequest();
    final LightValue lightValue = new LightValue();
    lightValue.setDimValue(dimValue);
    lightValue.setOn(lightOn);
    final WebServiceTemplate template = this.soapRequestHelper.createPublicLightingRequest();
    request.setDeviceIdentification(deviceId);
    request.getLightValue().add(lightValue);
    final SetLightAsyncResponse response = (SetLightAsyncResponse) template.marshalSendAndReceive(request);
    return response.getAsyncResponse().getCorrelationUid();
}
Also used : LightValue(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) SetLightRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightRequest) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse)

Example 5 with LightValue

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue in project open-smart-grid-platform by OSGP.

the class SetLightSteps method receivingASetLightRequest.

/**
 * Sends a Set Light request to the platform for a given device identification.
 *
 * @param requestParameters The table with the request parameters.
 * @throws Throwable when an error occurs
 */
@When("^receiving a set light request$")
public void receivingASetLightRequest(final Map<String, String> requestParameters) throws Throwable {
    final SetLightRequest request = new SetLightRequest();
    request.setDeviceIdentification(getString(requestParameters, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    final LightValue lightValue = new LightValue();
    lightValue.setIndex(getInteger(requestParameters, PlatformKeys.KEY_INDEX, PlatformDefaults.DEFAULT_INDEX));
    if (requestParameters.containsKey(PlatformKeys.KEY_DIMVALUE) && !StringUtils.isEmpty(requestParameters.get(PlatformKeys.KEY_DIMVALUE))) {
        lightValue.setDimValue(getInteger(requestParameters, PlatformKeys.KEY_DIMVALUE, PlatformDefaults.DEFAULT_DIMVALUE));
    }
    lightValue.setOn(getBoolean(requestParameters, PlatformKeys.KEY_ON, PlatformDefaults.DEFAULT_ON));
    request.getLightValue().add(lightValue);
    try {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, this.client.setLight(request));
    } catch (final SoapFaultClientException ex) {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, ex);
    }
}
Also used : LightValue(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue) SoapFaultClientException(org.springframework.ws.soap.client.SoapFaultClientException) SetLightRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightRequest) When(io.cucumber.java.en.When)

Aggregations

LightValue (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue)9 SetLightRequest (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightRequest)6 When (io.cucumber.java.en.When)3 SoapFaultClientException (org.springframework.ws.soap.client.SoapFaultClientException)3 SetLightAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse)2 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)2 Then (io.cucumber.java.en.Then)1 DeviceStatus (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus)1 EventNotificationType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.EventNotificationType)1 GetStatusAsyncRequest (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncRequest)1 GetStatusResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse)1 LightType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightType)1 LinkType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LinkType)1 OsgpResultType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.OsgpResultType)1 Schedule (org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.Schedule)1 WindowType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.WindowType)1 TariffSchedule (org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffSchedule)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 DeviceLightStatus (org.opensmartgridplatform.webdemoapp.domain.DeviceLightStatus)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1