Search in sources :

Example 1 with PageSpecifier

use of org.opensmartgridplatform.shared.application.config.PageSpecifier 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 2 with PageSpecifier

use of org.opensmartgridplatform.shared.application.config.PageSpecifier 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

ConstraintViolationException (javax.validation.ConstraintViolationException)2 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)2 PageSpecifier (org.opensmartgridplatform.shared.application.config.PageSpecifier)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)2 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)2 Device (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device)1 FindDevicesResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse)1 DevicePage (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DevicePage)1 FindAllDevicesResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse)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 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 Endpoint (org.springframework.ws.server.endpoint.annotation.Endpoint)1