Search in sources :

Example 1 with SetLightAsyncResponse

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

the class SetLightSteps method theSetLightResponseContains.

/**
 * The check for the response from the Platform.
 *
 * @param expectedResponseData The table with the expected fields in the response.
 * @apiNote The response will contain the correlation uid, so store that in the current scenario
 *     context for later use.
 */
@Then("^the set light async response contains$")
public void theSetLightResponseContains(final Map<String, String> expectedResponseData) {
    final SetLightAsyncResponse asyncResponse = (SetLightAsyncResponse) ScenarioContext.current().get(PlatformKeys.RESPONSE);
    assertThat(asyncResponse.getAsyncResponse().getCorrelationUid()).isNotNull();
    assertThat(asyncResponse.getAsyncResponse().getDeviceId()).isEqualTo(getString(expectedResponseData, PlatformKeys.KEY_DEVICE_IDENTIFICATION));
    // Save the returned CorrelationUid in the Scenario related context for
    // further use.
    saveCorrelationUidInScenarioContext(asyncResponse.getAsyncResponse().getCorrelationUid(), getString(expectedResponseData, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION));
    LOGGER.info("Got CorrelationUid: [" + ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID) + "]");
}
Also used : SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) Then(io.cucumber.java.en.Then)

Example 2 with SetLightAsyncResponse

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

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

the class PublicLightingAdHocManagementEndpoint method setLight.

// === SET LIGHT ===
@PayloadRoot(localPart = "SetLightRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightAsyncResponse setLight(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Light Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetLightAsyncResponse response = new SetLightAsyncResponse();
    try {
        final List<LightValue> lightValues = new ArrayList<>(this.adHocManagementMapper.mapAsList(request.getLightValue(), LightValue.class));
        final String correlationUid = this.adHocManagementService.enqueueSetLightRequest(organisationIdentification, request.getDeviceIdentification(), lightValues, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        LOGGER.error(EXCEPTION_OCCURRED, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ResumeScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse) GetStatusAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse) SetTransitionAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) 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 4 with SetLightAsyncResponse

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

the class OsgpPublicLightingClientSoapService method switchLightRequest.

/**
 * Creates a SetLight request using the parameters deviceId and lightOn. Sends the request to the
 * platform using the WebServiceTemplate.
 *
 * <p>Returns the CorrelationId response from the Platform.
 */
public String switchLightRequest(final String deviceId, final boolean lightOn) {
    final SetLightRequest request = new SetLightRequest();
    final LightValue lightValue = new LightValue();
    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)

Aggregations

SetLightAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse)4 LightValue (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightValue)2 SetLightRequest (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightRequest)2 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)2 Then (io.cucumber.java.en.Then)1 ArrayList (java.util.ArrayList)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 GetStatusAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse)1 ResumeScheduleAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse)1 SetTransitionAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 LightValue (org.opensmartgridplatform.domain.core.valueobjects.LightValue)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1