diff --git a/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/application/services/DeviceManagementService.java b/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/application/services/DeviceManagementService.java index bfff9e32d50..b3ca5facc0d 100644 --- a/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/application/services/DeviceManagementService.java +++ b/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/application/services/DeviceManagementService.java @@ -340,7 +340,6 @@ private Page findDevices( return devices; } - @Transactional(value = "transactionManager") public Page applyFilter( final DeviceFilter deviceFilter, final Organisation organisation, final PageRequest request) throws ArgumentNullOrEmptyException { diff --git a/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/endpoints/DeviceManagementEndpoint.java b/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/endpoints/DeviceManagementEndpoint.java index 37f073ce5b8..c65fe5059f8 100644 --- a/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/endpoints/DeviceManagementEndpoint.java +++ b/osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/endpoints/DeviceManagementEndpoint.java @@ -294,10 +294,8 @@ public FindEventsResponse findEventsRequest( response .getEvents() .addAll(this.deviceManagementMapper.mapAsList(result.getContent(), Event.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()); + response.setPage(pageToPage(result)); + } catch (final ConstraintViolationException e) { throw new FunctionalException( FunctionalExceptionType.VALIDATION_ERROR, @@ -335,10 +333,7 @@ public FindDevicesResponse findDevices( 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()); + response.setPage(pageToPage(result)); } if (result != null && request.isUsePages() != null && !request.isUsePages()) { @@ -370,6 +365,17 @@ private DeviceFilter deviceFilterFrom(final FindDevicesRequest request) { return this.deviceManagementMapper.map(request.getDeviceFilter(), DeviceFilter.class); } + private org.opensmartgridplatform.adapter.ws.schema.core.common.Page pageToPage(Page page) { + var xsdPage = new org.opensmartgridplatform.adapter.ws.schema.core.common.Page(); + xsdPage.setPageSize(page.getSize()); + xsdPage.setTotalPages(page.getTotalPages()); + xsdPage.setCurrentPage(page.getNumber()); + // It is very unlikely that the system will have more than 2147483647 devices or events, + // so it should be safe to cast to an int + xsdPage.setTotalElements(Long.valueOf(page.getTotalElements()).intValue()); + return xsdPage; + } + // suppress warning about unused method. This method is used in findDevices. @SuppressWarnings("squid:S1144") private PageSpecifier pageFrom(final FindDevicesRequest request) { diff --git a/osgp/shared/osgp-ws-core/src/main/resources/schemas/common-ws-core.xsd b/osgp/shared/osgp-ws-core/src/main/resources/schemas/common-ws-core.xsd index ef0b2a55ef5..bf59c1a3544 100644 --- a/osgp/shared/osgp-ws-core/src/main/resources/schemas/common-ws-core.xsd +++ b/osgp/shared/osgp-ws-core/src/main/resources/schemas/common-ws-core.xsd @@ -56,10 +56,12 @@ - + +