use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException 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.shared.exceptionhandling.FunctionalException 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();
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceInstallationEndpoint method updateDevice.
@PayloadRoot(localPart = "UpdateDeviceRequest", namespace = DEVICE_INSTALLATION_NAMESPACE)
@ResponsePayload
public UpdateDeviceResponse updateDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceRequest request) throws OsgpException {
LOGGER.info("Updating device: {}.", request.getDeviceIdentification());
try {
final Ssld device = this.deviceInstallationMapper.map(request.getUpdatedDevice(), Ssld.class);
this.deviceInstallationService.updateDevice(organisationIdentification, device);
} catch (final ConstraintViolationException 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.getUpdatedDevice().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 UpdateDeviceResponse();
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceInstallationEndpoint method startDeviceTest.
// === START DEVICE TEST ===
@PayloadRoot(localPart = "StartDeviceTestRequest", namespace = DEVICE_INSTALLATION_NAMESPACE)
@ResponsePayload
public StartDeviceTestAsyncResponse startDeviceTest(@OrganisationIdentification final String organisationIdentification, @RequestPayload final StartDeviceTestRequest request, @MessagePriority final String messagePriority) throws OsgpException {
LOGGER.info("Start Device Test Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
final StartDeviceTestAsyncResponse response = new StartDeviceTestAsyncResponse();
try {
final AsyncResponse asyncResponse = new AsyncResponse();
final String correlationUid = this.deviceInstallationService.enqueueStartDeviceTestRequest(organisationIdentification, request.getDeviceIdentification(), MessagePriorityEnum.getMessagePriority(messagePriority));
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.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method changeManufacturer.
/**
* Updates a Manufacturer to the platform. Throws exception if {@link Manufacturer} doesn't exist.
*/
@Transactional(value = "writableTransactionManager")
public void changeManufacturer(@Identification final String organisationIdentification, @Valid final Manufacturer manufacturer) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.CHANGE_MANUFACTURER);
final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer.getCode());
if (databaseManufacturer == null) {
LOGGER.info("Manufacturer not found.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_MANUFACTURER, ComponentType.WS_CORE, new ExistingEntityException(Manufacturer.class, manufacturer.getCode()));
} else {
databaseManufacturer.setCode(manufacturer.getCode());
databaseManufacturer.setName(manufacturer.getName());
databaseManufacturer.setUsePrefix(manufacturer.isUsePrefix());
this.manufacturerRepository.save(databaseManufacturer);
}
}
Aggregations