use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class PublicLightingAdHocManagementEndpoint method resumeSchedule.
// === RESUME SCHEDULE ===
@PayloadRoot(localPart = "ResumeScheduleRequest", namespace = NAMESPACE)
@ResponsePayload
public ResumeScheduleAsyncResponse resumeSchedule(@OrganisationIdentification final String organisationIdentification, @RequestPayload final ResumeScheduleRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Resume Schedule Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final ResumeScheduleAsyncResponse response = new ResumeScheduleAsyncResponse();
try {
final ResumeScheduleData resumeScheduleData = new ResumeScheduleData();
if (request.getIndex() != null) {
resumeScheduleData.setIndex(request.getIndex());
}
resumeScheduleData.setIsImmediate(request.isIsImmediate());
final String correlationUid = this.adHocManagementService.enqueueResumeScheduleRequest(organisationIdentification, request.getDeviceIdentification(), resumeScheduleData, MessagePriorityEnum.getMessagePriority(messagePriority));
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} 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.exceptionhandling.OsgpException 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.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class PublicLightingScheduleManagementEndpoint method setLightSchedule.
// === SET LIGHT SCHEDULE ===
@PayloadRoot(localPart = "SetScheduleRequest", namespace = NAMESPACE)
@ResponsePayload
public SetScheduleAsyncResponse setLightSchedule(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetScheduleRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Set Schedule Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final SetScheduleAsyncResponse response = new SetScheduleAsyncResponse();
try {
// Get the request parameters, make sure that they are in UTC.
// Maybe add an adapter to the service, so that all datetime are
// converted to utc automatically.
final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
final List<ScheduleEntry> scheduleEntries = this.scheduleManagementMapper.mapAsList(request.getSchedules(), org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry.class);
final Schedule schedule = new Schedule(scheduleEntries, request.getAstronomicalSunriseOffset(), request.getAstronomicalSunsetOffset());
final String correlationUid = this.scheduleManagementService.enqueueSetLightSchedule(organisationIdentification, request.getDeviceIdentification(), schedule, scheduleTime, MessagePriorityEnum.getMessagePriority(messagePriority));
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class PublicLightingScheduleManagementEndpoint method getSetLightScheduleResponse.
@PayloadRoot(localPart = "SetScheduleAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public SetScheduleResponse getSetLightScheduleResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetScheduleAsyncRequest request) throws OsgpException {
LOGGER.info("Get Set Schedule Response Request received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
final SetScheduleResponse response = new SetScheduleResponse();
try {
final ResponseData responseData = this.responseDataService.dequeue(request.getAsyncRequest().getCorrelationUid(), COMPONENT_WS_PUBLIC_LIGHTING);
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (responseData.getMessageData() instanceof String) {
response.setDescription((String) responseData.getMessageData());
}
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class PublicLightingAdHocManagementEndpoint method setLightMeasurementDevice.
// === SET LIGHT MEASUREMENT DEVICE ===
@PayloadRoot(localPart = "SetLightMeasurementDeviceRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightMeasurementDeviceResponse setLightMeasurementDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightMeasurementDeviceRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Set Light Measurement Device Request received from organisation: {} for device: {} for light measurement device: {} with message priority: {}", organisationIdentification, request.getDeviceIdentification(), request.getLightMeasurementDeviceIdentification(), messagePriority);
final SetLightMeasurementDeviceResponse response = new SetLightMeasurementDeviceResponse();
try {
this.adHocManagementService.coupleLightMeasurementDeviceForSsld(organisationIdentification, request.getDeviceIdentification(), request.getLightMeasurementDeviceIdentification(), MessagePriorityEnum.getMessagePriority(messagePriority));
response.setResult(OsgpResultType.OK);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
Aggregations