Search in sources :

Example 1 with FindAllDevicesResponse

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

the class FindAllDevicesSteps method theFindAllDevicesResponseContainsAtIndex.

@Then("the find all device response contains at index {string}")
public void theFindAllDevicesResponseContainsAtIndex(final String index, final Map<String, String> expectedDevice) throws Throwable {
    final FindAllDevicesResponse response = (FindAllDevicesResponse) ScenarioContext.current().get(PlatformCommonKeys.RESPONSE);
    final Device actualDevice = response.getDevicePage().getDevices().get(Integer.valueOf(index) - 1);
    if (expectedDevice.containsKey(PlatformKeys.KEY_DEVICE_UID)) {
        assertThat(actualDevice.getDeviceUid()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_DEVICE_UID));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_DEVICE_IDENTIFICATION)) {
        assertThat(actualDevice.getDeviceIdentification()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_DEVICE_IDENTIFICATION));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_POSTCODE)) {
        assertThat(actualDevice.getContainerPostalCode()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_POSTCODE));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_CITY)) {
        assertThat(actualDevice.getContainerCity()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_CITY));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_STREET)) {
        assertThat(actualDevice.getContainerStreet()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_STREET));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_NUMBER)) {
        assertThat(actualDevice.getContainerNumber()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_NUMBER));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_LATITUDE)) {
        assertThat(actualDevice.getGpsLatitude()).isEqualTo(getFloat(expectedDevice, PlatformKeys.KEY_LATITUDE));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_LONGITUDE)) {
        assertThat(actualDevice.getGpsLongitude()).isEqualTo(getFloat(expectedDevice, PlatformKeys.KEY_LONGITUDE));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_DEVICE_TYPE)) {
        assertThat(actualDevice.getDeviceType()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_DEVICE_TYPE));
    }
    if (expectedDevice.containsKey(PlatformKeys.KEY_DEVICE_ACTIVATED)) {
        assertThat(actualDevice.isActivated()).isEqualTo(getBoolean(expectedDevice, PlatformKeys.KEY_DEVICE_ACTIVATED));
    }
    if (expectedDevice instanceof Ssld) {
        final Ssld ssld = (Ssld) actualDevice;
        if (expectedDevice.containsKey(PlatformKeys.KEY_HAS_SCHEDULE)) {
            assertThat(ssld.isHasSchedule()).isEqualTo(getBoolean(expectedDevice, PlatformKeys.KEY_HAS_SCHEDULE));
        }
        if (expectedDevice.containsKey(PlatformKeys.KEY_PUBLICKEYPRESENT)) {
            assertThat(ssld.isPublicKeyPresent()).isEqualTo(getBoolean(expectedDevice, PlatformKeys.KEY_PUBLICKEYPRESENT));
        }
    }
    if (expectedDevice instanceof LightMeasurementDevice) {
        final LightMeasurementDevice lmd = (LightMeasurementDevice) actualDevice;
        if (expectedDevice.containsKey(PlatformKeys.KEY_LMD_DESCRIPTION)) {
            assertThat(lmd.getDescription()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_LMD_DESCRIPTION));
        }
        if (expectedDevice.containsKey(PlatformKeys.KEY_LMD_CODE)) {
            assertThat(lmd.getCode()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_LMD_CODE));
        }
        if (expectedDevice.containsKey(PlatformKeys.KEY_LMD_COLOR)) {
            assertThat(lmd.getColor()).isEqualTo(getString(expectedDevice, PlatformKeys.KEY_LMD_COLOR));
        }
        if (expectedDevice.containsKey(PlatformKeys.KEY_LMD_DIGITAL_INPUT)) {
            assertThat(lmd.getDigitalInput()).isEqualTo(getShort(expectedDevice, PlatformKeys.KEY_LMD_DIGITAL_INPUT));
        }
    }
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice) Device(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Device) LightMeasurementDevice(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice) FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse) Ssld(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld) Then(io.cucumber.java.en.Then)

Example 2 with FindAllDevicesResponse

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

the class PublicLightingAdHocManagementEndpoint method findAllDevices.

@PayloadRoot(localPart = "FindAllDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public FindAllDevicesResponse findAllDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllDevicesRequest request) throws OsgpException {
    LOGGER.info("Finding All Devices Request received from organisation: {}.", organisationIdentification);
    final FindAllDevicesResponse response = new FindAllDevicesResponse();
    try {
        final PageSpecifier pageSpecifier = new PageSpecifier(request.getPageSize(), request.getPage());
        final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, pageSpecifier);
        if (page != null && !page.isEmpty()) {
            final List<Ssld> sslds = listOfType(page, Ssld.class);
            final List<LightMeasurementDevice> lmds = listOfType(page, LightMeasurementDevice.class);
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setPageSize(page.getSize());
            devicePage.getPage().setTotalPages(page.getTotalPages());
            devicePage.getPage().setCurrentPage(page.getNumber());
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(sslds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld.class));
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(lmds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice.class));
            response.setDevicePage(devicePage);
        } else {
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setCurrentPage(0);
            devicePage.getPage().setPageSize(request.getPageSize() == null ? 0 : request.getPageSize());
            devicePage.getPage().setTotalPages(0);
            response.setDevicePage(devicePage);
        }
    } 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 : PageSpecifier(org.opensmartgridplatform.shared.application.config.PageSpecifier) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) 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) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ConstraintViolationException(javax.validation.ConstraintViolationException) DevicePage(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DevicePage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 3 with FindAllDevicesResponse

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

the class OsgpPublicLightingClientSoapService method findAllDevicesRequest.

/**
 * Creates a WebServiceTemplate with a FindAllDevices Request using the SoapRequestHelper class.
 * Sends the request to the Platform, and returns the List with Devices from the Response (after
 * it is converted by Orika).
 *
 * @return a list of devices
 */
public List<org.opensmartgridplatform.webdemoapp.domain.Device> findAllDevicesRequest() {
    final FindAllDevicesRequest findAllDevicesRequest = new FindAllDevicesRequest();
    final WebServiceTemplate template = this.soapRequestHelper.createPublicLightingRequest();
    final FindAllDevicesResponse response = (FindAllDevicesResponse) template.marshalSendAndReceive(findAllDevicesRequest);
    return this.publicLightingAdHocMapperFacade.mapAsList(response.getDevicePage().getDevices(), org.opensmartgridplatform.webdemoapp.domain.Device.class);
}
Also used : FindAllDevicesRequest(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesRequest) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse)

Example 4 with FindAllDevicesResponse

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

the class FindAllDevicesSteps method theFindAllDevicesResponseContainsDevices.

@Then("the find all device response contains {string} device(s)")
public void theFindAllDevicesResponseContainsDevices(final String numberOfDevices) throws Throwable {
    final FindAllDevicesResponse response = (FindAllDevicesResponse) ScenarioContext.current().get(PlatformCommonKeys.RESPONSE);
    assertThat(response.getDevicePage().getDevices().size()).isEqualTo(Integer.valueOf(numberOfDevices));
}
Also used : FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse) Then(io.cucumber.java.en.Then)

Aggregations

FindAllDevicesResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse)4 Then (io.cucumber.java.en.Then)2 ConstraintViolationException (javax.validation.ConstraintViolationException)1 Device (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Device)1 DevicePage (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DevicePage)1 FindAllDevicesRequest (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesRequest)1 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice)1 Ssld (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)1 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)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 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1