use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method revokeKey.
// === REVOKE KEY ===
public void revokeKey(final String organisationIdentification, @Identification final String deviceIdentification, final String correlationUid, final String messageType) throws FunctionalException {
LOGGER.info("MessageType: {}. Revoking key for device [{}] on behalf of organisation [{}]", messageType, deviceIdentification, organisationIdentification);
try {
this.organisationDomainService.searchOrganisation(organisationIdentification);
} catch (final UnknownEntityException e) {
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.DOMAIN_ADMIN, e);
}
this.osgpCoreRequestMessageSender.send(new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, null), messageType, null);
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class AddDeviceRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
final MessageMetadata deviceMessageMetadata = MessageMetadata.fromMessage(message);
final AddRtuDeviceRequest addRtuDeviceRequest = (AddRtuDeviceRequest) message.getObject();
try {
this.deviceManagementService.addDevice(deviceMessageMetadata, addRtuDeviceRequest);
} catch (final FunctionalException e) {
this.handleError(e, deviceMessageMetadata.getCorrelationUid(), deviceMessageMetadata.getOrganisationIdentification(), deviceMessageMetadata.getDeviceIdentification(), deviceMessageMetadata.getMessageType());
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException 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.FunctionalException 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.FunctionalException 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;
}
Aggregations