Search in sources :

Example 1 with FindDevicesResponse

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

the class FindDeviceSteps method theFindDevicesResponseContainsDevices.

@Then("the find devices response contains \"{int}\" device(s)")
public void theFindDevicesResponseContainsDevices(final Integer numberOfDevices) throws Throwable {
    final FindDevicesResponse response = (FindDevicesResponse) ScenarioContext.current().get(PlatformCommonKeys.RESPONSE);
    assertThat(response.getDevices().size()).isEqualTo((int) numberOfDevices);
}
Also used : FindDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse) Then(io.cucumber.java.en.Then)

Example 2 with FindDevicesResponse

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

the class FindDeviceSteps method theFindDevicesResponseContainsAtIndex.

@Then("the find devices response contains at index \"{int}\"")
public void theFindDevicesResponseContainsAtIndex(final Integer index, final Map<String, String> expectedDevice) throws Throwable {
    final FindDevicesResponse response = (FindDevicesResponse) ScenarioContext.current().get(PlatformCommonKeys.RESPONSE);
    DeviceSteps.checkDevice(expectedDevice, response.getDevices().get(index - 1));
}
Also used : FindDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse) Then(io.cucumber.java.en.Then)

Example 3 with FindDevicesResponse

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

the class DeviceManagementEndpoint method findDevices.

@PayloadRoot(localPart = "FindDevicesRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindDevicesResponse findDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindDevicesRequest request) throws OsgpException {
    LOGGER.info("Find devices for organisation: {}.", organisationIdentification);
    final FindDevicesResponse response = new FindDevicesResponse();
    try {
        final PageSpecifier pageSpecifier = this.pageFrom(request);
        Page<org.opensmartgridplatform.domain.core.entities.Device> result = this.deviceManagementService.findDevices(organisationIdentification, pageSpecifier, this.deviceFilterFrom(request));
        if (result != null && response.getDevices() != null) {
            response.getDevices().addAll(this.deviceManagementMapper.mapAsList(result.getContent(), Device.class));
            response.setPage(new org.opensmartgridplatform.adapter.ws.schema.core.common.Page());
            response.getPage().setPageSize(result.getSize());
            response.getPage().setTotalPages(result.getTotalPages());
            response.getPage().setCurrentPage(result.getNumber());
        }
        if (result != null && request.isUsePages() != null && !request.isUsePages()) {
            int calls = 0;
            while ((calls += 1) < result.getTotalPages()) {
                request.setPage(calls);
                result = this.deviceManagementService.findDevices(organisationIdentification, pageSpecifier, this.deviceFilterFrom(request));
                response.getDevices().addAll(this.deviceManagementMapper.mapAsList(result.getContent(), Device.class));
            }
        }
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        LOGGER.error(EXCEPTION, e.getMessage(), e.getStackTrace(), e);
        this.handleException(e);
    }
    return response;
}
Also used : PageSpecifier(org.opensmartgridplatform.shared.application.config.PageSpecifier) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Device(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device) FindDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse) Endpoint(org.springframework.ws.server.endpoint.annotation.Endpoint) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

FindDevicesResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse)3 Then (io.cucumber.java.en.Then)2 ConstraintViolationException (javax.validation.ConstraintViolationException)1 Device (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 PageSpecifier (org.opensmartgridplatform.shared.application.config.PageSpecifier)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 Endpoint (org.springframework.ws.server.endpoint.annotation.Endpoint)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1