use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse 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.adapter.ws.schema.publiclighting.common.AsyncResponse 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.adapter.ws.schema.publiclighting.common.AsyncResponse in project open-smart-grid-platform by OSGP.
the class PublicLightingAdHocManagementEndpoint method setTransition.
// === SET TRANSITION ===
@PayloadRoot(localPart = "SetTransitionRequest", namespace = NAMESPACE)
@ResponsePayload
public SetTransitionAsyncResponse setTransition(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetTransitionRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Set Transition Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final SetTransitionAsyncResponse response = new SetTransitionAsyncResponse();
try {
final TransitionMessageDataContainer transitionMessageDataContainer = new TransitionMessageDataContainer();
if (request.getTransitionType() != null) {
transitionMessageDataContainer.setTransitionType(this.adHocManagementMapper.map(request.getTransitionType(), org.opensmartgridplatform.domain.core.valueobjects.TransitionType.class));
}
DateTime dateTime = null;
if (request.getTime() != null) {
dateTime = new DateTime(request.getTime().toGregorianCalendar().getTime());
}
transitionMessageDataContainer.setDateTime(dateTime);
final String correlationUid = this.adHocManagementService.enqueueTransitionRequest(organisationIdentification, request.getDeviceIdentification(), transitionMessageDataContainer, MessagePriorityEnum.getMessagePriority(messagePriority));
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse in project open-smart-grid-platform by OSGP.
the class PublicLightingAdHocManagementEndpoint method setLight.
// === SET LIGHT ===
@PayloadRoot(localPart = "SetLightRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightAsyncResponse setLight(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Set Light Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final SetLightAsyncResponse response = new SetLightAsyncResponse();
try {
final List<LightValue> lightValues = new ArrayList<>(this.adHocManagementMapper.mapAsList(request.getLightValue(), LightValue.class));
final String correlationUid = this.adHocManagementService.enqueueSetLightRequest(organisationIdentification, request.getDeviceIdentification(), lightValues, 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.adapter.ws.schema.publiclighting.common.AsyncResponse in project open-smart-grid-platform by OSGP.
the class PublicLightingAdHocManagementEndpoint method getStatus.
// === GET STATUS ===
@PayloadRoot(localPart = "GetStatusRequest", namespace = NAMESPACE)
@ResponsePayload
public GetStatusAsyncResponse getStatus(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetStatusRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Get Status received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final GetStatusAsyncResponse response = new GetStatusAsyncResponse();
try {
final String correlationUid = this.adHocManagementService.enqueueGetStatusRequest(organisationIdentification, request.getDeviceIdentification(), MessagePriorityEnum.getMessagePriority(messagePriority));
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
Aggregations