Search in sources :

Example 1 with GetStatusResponse

use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse 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 2 with GetStatusResponse

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

the class PublicLightingAdHocManagementEndpoint method getGetStatusResponse.

@PayloadRoot(localPart = "GetStatusAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public GetStatusResponse getGetStatusResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetStatusAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Status Response received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
    final GetStatusResponse response = new GetStatusResponse();
    try {
        final ResponseMessage message = this.adHocManagementService.dequeueGetStatusResponse(request.getAsyncRequest().getCorrelationUid());
        if (message != null) {
            response.setResult(OsgpResultType.fromValue(message.getResult().getValue()));
            response.setStatus(this.adHocManagementMapper.map(message.getDataObject(), org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Status.class));
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) 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 GetStatusResponse

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

the class AsyncController method asyncGetStatusRequest.

/**
 * This controller is called on a 2 second interval by the device-status.jsp page.
 *
 * <p>The controller retrieves the correlation uid from the URL and checks (using the SoapService
 * class) if a async request is processed by the platform. If this is not the case, it re-directs
 * back to the device-status page. If the request is ready, it calls the deviceStatus controller
 * to display the response of the platform.
 */
@GetMapping(value = "/asyncStatus/{correlationId}")
public ModelAndView asyncGetStatusRequest(@PathVariable final String correlationId) {
    final ModelAndView modelView = new ModelAndView();
    final GetStatusResponse responseStatus = this.soapService.getGetStatusResponse(this.splitCorrelationId(correlationId)[1], correlationId);
    switch(responseStatus.getResult().toString()) {
        case "OK":
            return this.publicLightingController.getStatusRequest((DeviceStatus) responseStatus.getStatus(), this.splitCorrelationId(correlationId)[1]);
        default:
            LOGGER.debug("Response not ready");
            modelView.addObject("correlationId", correlationId);
            modelView.setViewName("device-status");
    }
    return modelView;
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse) ModelAndView(org.springframework.web.servlet.ModelAndView) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with GetStatusResponse

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

the class OsgpPublicLightingClientSoapService method getGetStatusResponse.

/**
 * Async request. Sends a GetStatusAsyncRequest to the platform using the deviceId and
 * correlationId parameters.
 *
 * <p>Returns the response from the Platform.
 */
public GetStatusResponse getGetStatusResponse(final String deviceId, final String correlationId) {
    final AsyncRequest asyncRequest = new AsyncRequest();
    final GetStatusAsyncRequest asyncStatusRequest = new GetStatusAsyncRequest();
    asyncRequest.setCorrelationUid(correlationId);
    asyncRequest.setDeviceId(deviceId);
    asyncStatusRequest.setAsyncRequest(asyncRequest);
    final WebServiceTemplate template = this.soapRequestHelper.createPublicLightingRequest();
    return (GetStatusResponse) template.marshalSendAndReceive(asyncStatusRequest);
}
Also used : GetStatusAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncRequest) AsyncRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncRequest) GetStatusAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncRequest) GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate)

Aggregations

GetStatusResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse)4 GetStatusAsyncRequest (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncRequest)2 Then (io.cucumber.java.en.Then)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 DeviceStatus (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus)1 EventNotificationType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.EventNotificationType)1 LightType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightType)1 LightValue (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue)1 LinkType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LinkType)1 AsyncRequest (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncRequest)1 OsgpResultType (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.OsgpResultType)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)1