Search in sources :

Example 1 with SetConfigurationAsyncResponse

use of org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse in project open-smart-grid-platform by OSGP.

the class SetConfigurationSteps method theSetConfigurationResponseContains.

/**
 * 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.
 * @throws Throwable
 */
@Then("^the set configuration async response contains$")
public void theSetConfigurationResponseContains(final Map<String, String> expectedResponseData) throws Throwable {
    final SetConfigurationAsyncResponse asyncResponse = (SetConfigurationAsyncResponse) ScenarioContext.current().get(PlatformKeys.RESPONSE);
    assertThat(asyncResponse.getAsyncResponse().getCorrelationUid()).isNotNull();
    assertThat(asyncResponse.getAsyncResponse().getDeviceId()).isEqualTo(getString(expectedResponseData, PlatformKeys.KEY_DEVICE_IDENTIFICATION), asyncResponse.getAsyncResponse().getDeviceId());
    // Save the returned CorrelationUid in the Scenario related context for
    // further use.
    saveCorrelationUidInScenarioContext(asyncResponse.getAsyncResponse().getCorrelationUid(), getString(expectedResponseData, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformCommonDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION));
    LOGGER.info("Got CorrelationUid: [" + ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID) + "]");
}
Also used : SetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse) Then(io.cucumber.java.en.Then)

Example 2 with SetConfigurationAsyncResponse

use of org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse in project open-smart-grid-platform by OSGP.

the class ConfigurationManagementEndpoint method setConfiguration.

@PayloadRoot(localPart = "SetConfigurationRequest", namespace = NAMESPACE)
@ResponsePayload
public SetConfigurationAsyncResponse setConfiguration(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetConfigurationRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Configuration Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetConfigurationAsyncResponse response = new SetConfigurationAsyncResponse();
    try {
        // Get the request parameters, make sure that they are in UTC.
        // Maybe add an adapter to the service, so that all date-time are
        // converted to UTC automatically.
        final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
        final Configuration configuration = this.configurationManagementMapper.map(request.getConfiguration(), Configuration.class);
        final String correlationUid = this.configurationManagementService.enqueueSetConfigurationRequest(organisationIdentification, request.getDeviceIdentification(), configuration, scheduleTime, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : SetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse) SwitchConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SwitchConfigurationAsyncResponse) SetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse) GetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.GetConfigurationAsyncResponse) DateTime(org.joda.time.DateTime) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) 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)

Aggregations

SetConfigurationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse)2 Then (io.cucumber.java.en.Then)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 DateTime (org.joda.time.DateTime)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)1 GetConfigurationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.GetConfigurationAsyncResponse)1 SwitchConfigurationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SwitchConfigurationAsyncResponse)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 Configuration (org.opensmartgridplatform.domain.core.valueobjects.Configuration)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1