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;
}
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;
}
Aggregations