use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method setCommunicationNetworkInformation.
@PayloadRoot(localPart = "SetCommunicationNetworkInformationRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public SetCommunicationNetworkInformationResponse setCommunicationNetworkInformation(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetCommunicationNetworkInformationRequest request) throws OsgpException {
LOGGER.info("SetCommunicationNetworkInformation for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
SetCommunicationNetworkInformationResponse response = null;
try {
response = new SetCommunicationNetworkInformationResponse();
final org.opensmartgridplatform.domain.core.entities.Device updatedDevice = this.deviceManagementService.updateCommunicationNetworkInformation(organisationIdentification, request.getDeviceIdentification(), request.getIpAddress(), request.getBtsId(), request.getCellId());
response.setResult(OsgpResultType.OK);
response.setIpAddress(updatedDevice.getIpAddress());
response.setBtsId(updatedDevice.getBtsId());
response.setCellId(updatedDevice.getCellId());
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_TYPE_WS_ADMIN, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method findDevicesWhichHaveNoOwner.
@PayloadRoot(localPart = "FindDevicesWhichHaveNoOwnerRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindDevicesWhichHaveNoOwnerResponse findDevicesWhichHaveNoOwner(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindDevicesWhichHaveNoOwnerRequest request) throws OsgpException {
LOGGER.info("Finding devices which have no owner for organisation: {}.", organisationIdentification);
final FindDevicesWhichHaveNoOwnerResponse response = new FindDevicesWhichHaveNoOwnerResponse();
try {
final List<org.opensmartgridplatform.domain.core.entities.Device> devicesWithoutOwner = this.deviceManagementService.findDevicesWhichHaveNoOwner(organisationIdentification);
response.getDevices().addAll(this.deviceManagementMapper.mapAsList(devicesWithoutOwner, org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.Device.class));
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_TYPE_WS_ADMIN, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementEndpoint method switchConfiguration.
@PayloadRoot(localPart = "SwitchConfigurationRequest", namespace = NAMESPACE)
@ResponsePayload
public SwitchConfigurationAsyncResponse switchConfiguration(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SwitchConfigurationRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Switch Configuration Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final SwitchConfigurationAsyncResponse response = new SwitchConfigurationAsyncResponse();
try {
final String correlationUid = this.configurationManagementService.enqueueSwitchConfigurationRequest(organisationIdentification, request.getDeviceIdentification(), String.valueOf(request.getConfigurationBank()), MessagePriorityEnum.getMessagePriority(messagePriority));
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementEndpoint method setConfiguration.
@PayloadRoot(localPart = "SetConfigurationRequest", namespace = NAMESPACE)
@ResponsePayload
public SetConfigurationAsyncResponse setConfiguration(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetConfigurationRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Set Configuration Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final SetConfigurationAsyncResponse response = new SetConfigurationAsyncResponse();
try {
// Get the request parameters, make sure that they are in UTC.
// Maybe add an adapter to the service, so that all date-time are
// converted to UTC automatically.
final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
final Configuration configuration = this.configurationManagementMapper.map(request.getConfiguration(), Configuration.class);
final String correlationUid = this.configurationManagementService.enqueueSetConfigurationRequest(organisationIdentification, request.getDeviceIdentification(), configuration, scheduleTime, MessagePriorityEnum.getMessagePriority(messagePriority));
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class DeviceInstallationEndpoint method updateLightMeasurementDevice.
@PayloadRoot(localPart = "UpdateLightMeasurementDeviceRequest", namespace = DEVICE_INSTALLATION_NAMESPACE)
@ResponsePayload
public UpdateLightMeasurementDeviceResponse updateLightMeasurementDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateLightMeasurementDeviceRequest request) throws OsgpException {
LOGGER.info("Updating light measurement device: {}.", request.getDeviceIdentification());
try {
final LightMeasurementDevice device = this.deviceInstallationMapper.map(request.getUpdatedLightMeasurementDevice(), LightMeasurementDevice.class);
this.deviceInstallationService.updateLightMeasurementDevice(organisationIdentification, device);
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception update Device: {} ", e.getMessage(), e);
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
LOGGER.error(EXCEPTION_WHILE_UPDATING_DEVICE, e.getMessage(), request.getUpdatedLightMeasurementDevice().getDeviceIdentification(), organisationIdentification, e);
this.handleException(e);
}
try {
this.notificationService.sendNotification(organisationIdentification, request.getDeviceIdentification(), null, null, null, NotificationType.DEVICE_UPDATED);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new UpdateLightMeasurementDeviceResponse();
}
Aggregations