use of org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse in project open-smart-grid-platform by OSGP.
the class FindDeviceSteps method theFindDevicesResponseContainsDevices.
@Then("the find devices response contains \"{int}\" device(s)")
public void theFindDevicesResponseContainsDevices(final Integer numberOfDevices) throws Throwable {
final FindDevicesResponse response = (FindDevicesResponse) ScenarioContext.current().get(PlatformCommonKeys.RESPONSE);
assertThat(response.getDevices().size()).isEqualTo((int) numberOfDevices);
}
use of org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse in project open-smart-grid-platform by OSGP.
the class FindDeviceSteps method theFindDevicesResponseContainsAtIndex.
@Then("the find devices response contains at index \"{int}\"")
public void theFindDevicesResponseContainsAtIndex(final Integer index, final Map<String, String> expectedDevice) throws Throwable {
final FindDevicesResponse response = (FindDevicesResponse) ScenarioContext.current().get(PlatformCommonKeys.RESPONSE);
DeviceSteps.checkDevice(expectedDevice, response.getDevices().get(index - 1));
}
use of org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindDevicesResponse 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