Skip to content

Commit

Permalink
FDP-2136: Correctly send total items count for devices search
Browse files Browse the repository at this point in the history
Signed-off-by: Jasper Kamerling <[email protected]>
  • Loading branch information
jasperkamerling committed Apr 25, 2024
1 parent 3cb3661 commit ae8dce8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ private Page<Device> findDevices(
return devices;
}

@Transactional(value = "transactionManager")
public Page<Device> applyFilter(
final DeviceFilter deviceFilter, final Organisation organisation, final PageRequest request)
throws ArgumentNullOrEmptyException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@
<xsd:sequence>
<xsd:element name="TotalPages" type="xsd:int"
minOccurs="1" maxOccurs="1" />
<xsd:element name="PageSize" type="xsd:int" minOccurs="1"
maxOccurs="1" />
<xsd:element name="PageSize" type="xsd:int"
minOccurs="1" maxOccurs="1" />
<xsd:element name="CurrentPage" type="xsd:int"
minOccurs="1" maxOccurs="1" />
<xsd:element name="TotalElements" type="xsd:int"
minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>

Expand Down

0 comments on commit ae8dce8

Please sign in to comment.