use of org.opensmartgridplatform.oslp.Oslp.DeviceType in project open-smart-grid-platform by OSGP.
the class DeviceManagementController method fetchData.
private void fetchData(final Model model, final String deviceIdentification, final Integer pageNumber, final Integer devicesPerPage, final String sortDirection) {
final int pageNr;
if (pageNumber == null) {
pageNr = 1;
} else {
pageNr = pageNumber;
}
final Page<Device> page = this.deviceManagementService.findPageOfDevices(deviceIdentification, pageNr - 1, devicesPerPage, sortDirection);
// Set the correct model elements
final int current = pageNr;
final int begin = Math.max(1, current - PAGING_LIMITER_MIN);
final int end = Math.min(begin + PAGING_LIMITER_MAX, page.getTotalPages());
model.addAttribute(MODEL_ATTRIBUTE_DEVICE_IDENTIFICATION, deviceIdentification);
model.addAttribute(MODEL_ATTRIBUTE_PAGE_TOTAL, page.getTotalPages());
model.addAttribute(MODEL_ATTRIBUTE_PAGE_BEGIN, begin);
model.addAttribute(MODEL_ATTRIBUTE_PAGE_END, end);
model.addAttribute(MODEL_ATTRIBUTE_PAGE_CURRENT, current);
model.addAttribute(MODEL_ATTRIBUTE_DEVICES_PER_PAGE, devicesPerPage);
model.addAttribute(MODEL_ATTRIBUTE_SORT_DIRECTION, sortDirection);
model.addAttribute(MODEL_ATTRIBUTE_DEVICES, page.getContent());
final List<String> deviceTypes = new ArrayList<>();
for (final DeviceType devicetype : DeviceType.values()) {
deviceTypes.add(devicetype.name());
}
model.addAttribute(MODEL_ATTRIBUTE_DEVICETYPES, deviceTypes);
LOGGER.debug("Fetched data: {} records, {} pages", page.getContent().size(), page.getTotalPages());
}
Aggregations