use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method setDeviceAlias.
@PayloadRoot(localPart = "SetDeviceAliasRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public SetDeviceAliasResponse setDeviceAlias(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetDeviceAliasRequest request) throws OsgpException {
LOGGER.info("Setting device alias for device: {} to: {}.", request.getDeviceIdentification(), request.getDeviceAlias());
try {
this.deviceManagementService.setDeviceAlias(organisationIdentification, request.getDeviceIdentification(), request.getDeviceAlias(), request.getDeviceOutputSettings());
} 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.getDeviceIdentification(), organisationIdentification, e);
this.handleException(e);
}
final SetDeviceAliasResponse setDeviceAliasResponse = new SetDeviceAliasResponse();
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, request.getDeviceIdentification());
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
setDeviceAliasResponse.setAsyncResponse(asyncResponse);
try {
this.notificationService.sendNotification(organisationIdentification, request.getDeviceIdentification(), null, null, null, NotificationType.DEVICE_UPDATED);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return setDeviceAliasResponse;
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method findScheduledTasks.
@PayloadRoot(localPart = "FindScheduledTasksRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindScheduledTasksResponse findScheduledTasks(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindScheduledTasksRequest request) throws OsgpException {
LOGGER.info("Finding scheduled tasks for organisation: {}.", organisationIdentification);
final FindScheduledTasksResponse response = new FindScheduledTasksResponse();
try {
final List<ScheduledTaskWithoutData> scheduledTasks;
if (request.getDeviceIdentification() == null) {
scheduledTasks = this.deviceManagementService.findScheduledTasks(organisationIdentification);
} else {
scheduledTasks = this.deviceManagementService.findScheduledTasks(organisationIdentification, request.getDeviceIdentification());
}
response.getScheduledTask().addAll(this.deviceManagementMapper.mapAsList(scheduledTasks, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.ScheduledTask.class));
} 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 FirmwareManagementEndpoint method removedManufacturer.
@PayloadRoot(localPart = "RemoveManufacturerRequest", namespace = NAMESPACE)
@ResponsePayload
public RemoveManufacturerResponse removedManufacturer(@OrganisationIdentification final String organisationIdentification, @RequestPayload final RemoveManufacturerRequest request) throws OsgpException {
LOGGER.info("Removing manufacturer:{}.", request.getManufacturerId());
final RemoveManufacturerResponse removeManufacturerResponse = new RemoveManufacturerResponse();
try {
this.firmwareManagementService.removeManufacturer(organisationIdentification, request.getManufacturerId());
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception removing manufacturer", e);
this.handleException(e);
} catch (final FunctionalException e) {
LOGGER.error("Exception removing manufacturer: {} ", e.getMessage(), e);
if (e.getExceptionType().equals(FunctionalExceptionType.EXISTING_DEVICEMODEL_MANUFACTURER)) {
removeManufacturerResponse.setResult(OsgpResultType.NOT_OK);
removeManufacturerResponse.setDescription(REMOVE_MANUFACTURER_EXISTING_DEVICEMODEL);
return removeManufacturerResponse;
}
this.handleException(e);
} catch (final Exception e) {
LOGGER.error("Exception: {} while removing manufacturer: {} for organisation {}", e.getMessage(), request.getManufacturerId(), organisationIdentification, e);
this.handleException(e);
}
removeManufacturerResponse.setResult(OsgpResultType.OK);
return removeManufacturerResponse;
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class FirmwareManagementEndpoint method removedDeviceModel.
@PayloadRoot(localPart = "RemoveDeviceModelRequest", namespace = NAMESPACE)
@ResponsePayload
public RemoveDeviceModelResponse removedDeviceModel(@OrganisationIdentification final String organisationIdentification, @RequestPayload final RemoveDeviceModelRequest request) throws OsgpException {
LOGGER.info("Removing devicemodel:{}.", request.getDeviceModelId());
final RemoveDeviceModelResponse removeDeviceModelResponse = new RemoveDeviceModelResponse();
try {
this.firmwareManagementService.removeDeviceModel(organisationIdentification, request.getDeviceManufacturerId(), request.getDeviceModelId());
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception removing deviceModel", e);
this.handleException(e);
} catch (final FunctionalException e) {
LOGGER.error("Exception removing deviceModel: {} ", e.getMessage(), e);
if (FunctionalExceptionType.EXISTING_DEVICE_DEVICEMODEL == e.getExceptionType()) {
removeDeviceModelResponse.setResult(OsgpResultType.NOT_OK);
removeDeviceModelResponse.setDescription(REMOVE_DEVICEMODEL_EXISTING_DEVICE);
return removeDeviceModelResponse;
}
if (FunctionalExceptionType.EXISTING_DEVICEMODEL_FIRMWARE == e.getExceptionType()) {
removeDeviceModelResponse.setResult(OsgpResultType.NOT_OK);
removeDeviceModelResponse.setDescription(REMOVE_DEVICEMODEL_EXISTING_FIRMWARE);
return removeDeviceModelResponse;
}
this.handleException(e);
} catch (final Exception e) {
LOGGER.error("Exception: {} while removing deviceModel: {} for organisation {}", e.getMessage(), request.getDeviceModelId(), organisationIdentification, e);
this.handleException(e);
}
removeDeviceModelResponse.setResult(OsgpResultType.OK);
return removeDeviceModelResponse;
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceInstallationService method addLightMeasurementDevice.
@Transactional(value = "writableTransactionManager")
public void addLightMeasurementDevice(@Identification final String organisationIdentification, @Valid final LightMeasurementDevice newLightMeasurementDevice, @Identification final String ownerOrganisationIdentification) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.GET_ORGANISATIONS);
this.domainHelperService.isOrganisationEnabled(organisation);
// If the device already exists, throw an exception.
final Device existingDevice = this.writableDeviceRepository.findByDeviceIdentification(newLightMeasurementDevice.getDeviceIdentification());
// field
if (existingDevice != null && StringUtils.isNotBlank(existingDevice.getDeviceType())) {
throw new FunctionalException(FunctionalExceptionType.EXISTING_DEVICE, ComponentType.WS_CORE, new ExistingEntityException(Device.class, newLightMeasurementDevice.getDeviceIdentification()));
}
LightMeasurementDevice lmd;
if (existingDevice != null) {
// Update existing light measurement device
lmd = this.writableLightMeasurementDeviceRepository.findByDeviceIdentification(newLightMeasurementDevice.getDeviceIdentification());
lmd.updateMetaData(newLightMeasurementDevice.getAlias(), newLightMeasurementDevice.getContainerAddress(), newLightMeasurementDevice.getGpsCoordinates());
lmd.getAuthorizations().clear();
} else {
// Create a new LMD instance.
lmd = new LightMeasurementDevice(newLightMeasurementDevice.getDeviceIdentification(), newLightMeasurementDevice.getAlias(), newLightMeasurementDevice.getContainerAddress(), newLightMeasurementDevice.getGpsCoordinates(), null);
}
lmd.setDeviceModel(newLightMeasurementDevice.getDeviceModel());
lmd.setDescription(newLightMeasurementDevice.getDescription());
lmd.setCode(newLightMeasurementDevice.getCode());
lmd.setColor(newLightMeasurementDevice.getColor());
lmd.setDigitalInput(newLightMeasurementDevice.getDigitalInput());
final Organisation ownerOrganisation = this.domainHelperService.findOrganisation(ownerOrganisationIdentification);
lmd = this.writableLightMeasurementDeviceRepository.save(lmd);
final DeviceAuthorization authorization = lmd.addAuthorization(ownerOrganisation, DeviceFunctionGroup.OWNER);
this.writableAuthorizationRepository.save(authorization);
LOGGER.info("Created new light measurement device {} with owner {}", newLightMeasurementDevice.getDeviceIdentification(), ownerOrganisationIdentification);
}
Aggregations