Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FDP-2136: Correctly send total items count for devices search #1284

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading