use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method updateDeviceAuthorisations.
@PayloadRoot(localPart = "UpdateDeviceAuthorisationsRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public UpdateDeviceAuthorisationsResponse updateDeviceAuthorisations(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceAuthorisationsRequest request) throws OsgpException {
LOGGER.info("Update device autorisations for organisation: {}.", organisationIdentification);
final List<String> deviceIdentifications = new ArrayList<>();
try {
for (final DeviceAuthorisation authorization : request.getDeviceAuthorisations()) {
LOGGER.info("device: {}, organisation: {}, isRevoked: {}, functionGroup: {}", authorization.getDeviceIdentification(), authorization.getOrganisationIdentification(), authorization.isRevoked(), authorization.getFunctionGroup());
}
for (final DeviceAuthorisation authorization : request.getDeviceAuthorisations()) {
if (authorization.isRevoked() != null && authorization.isRevoked()) {
this.deviceManagementService.removeDeviceAuthorization(organisationIdentification, authorization.getOrganisationIdentification(), authorization.getDeviceIdentification(), this.deviceManagementMapper.map(authorization.getFunctionGroup(), DeviceFunctionGroup.class));
} else {
this.deviceManagementService.addDeviceAuthorization(organisationIdentification, authorization.getOrganisationIdentification(), authorization.getDeviceIdentification(), this.deviceManagementMapper.map(authorization.getFunctionGroup(), DeviceFunctionGroup.class));
}
// Save the device identification for notification later.
if (!deviceIdentifications.contains(authorization.getDeviceIdentification())) {
deviceIdentifications.add(authorization.getDeviceIdentification());
}
}
} 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);
}
for (final String deviceIdentification : deviceIdentifications) {
try {
this.notificationService.sendNotification(organisationIdentification, deviceIdentification, null, null, null, NotificationType.DEVICE_UPDATED);
} catch (final Exception e) {
LOGGER.error("Caught exception when sending notification", e);
}
}
return new UpdateDeviceAuthorisationsResponse();
}
use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method updateDeviceProtocol.
@PayloadRoot(localPart = "UpdateDeviceProtocolRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public UpdateDeviceProtocolResponse updateDeviceProtocol(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceProtocolRequest request) throws OsgpException {
LOGGER.info("Update device protocol for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
try {
final ProtocolInfo protocolInfo = request.getProtocolInfo();
this.deviceManagementService.updateDeviceProtocol(organisationIdentification, request.getDeviceIdentification(), protocolInfo.getProtocol(), protocolInfo.getProtocolVersion());
} 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 new UpdateDeviceProtocolResponse();
}
use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method findDeviceAuthorisations.
@PayloadRoot(localPart = "FindDeviceAuthorisationsRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindDeviceAuthorisationsResponse findDeviceAuthorisations(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindDeviceAuthorisationsRequest request) throws OsgpException {
LOGGER.info("Find device autorisations for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
final FindDeviceAuthorisationsResponse response = new FindDeviceAuthorisationsResponse();
try {
final List<org.opensmartgridplatform.domain.core.entities.DeviceAuthorization> authorizations = this.deviceManagementService.findDeviceAuthorisations(organisationIdentification, request.getDeviceIdentification());
response.getDeviceAuthorisations().addAll(this.deviceManagementMapper.mapAsList(authorizations, DeviceAuthorisation.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 DeviceManagementEndpoint method findMessageLogs.
@PayloadRoot(localPart = "FindMessageLogsRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindMessageLogsResponse findMessageLogs(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindMessageLogsRequest request) throws OsgpException {
final WsMessageLogFilter filter = this.deviceManagementMapper.map(request.getMessageLogFilter(), WsMessageLogFilter.class);
LOGGER.info("Find message logs of filter {} for organisation: {}.", filter, organisationIdentification);
final FindMessageLogsResponse response = new FindMessageLogsResponse();
try {
final Slice<DeviceLogItem> page = this.deviceManagementService.findDeviceMessages(organisationIdentification, filter);
// Map to output
final MessageLogPage logPage = new MessageLogPage();
logPage.getMessageLogs().addAll(this.deviceManagementMapper.mapAsList(page.getContent(), MessageLog.class));
logPage.setNextPageAvailable(page.hasNext());
response.setMessageLogPage(logPage);
} 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 createOrganisation.
@PayloadRoot(localPart = "CreateOrganisationRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public CreateOrganisationResponse createOrganisation(@OrganisationIdentification final String organisationIdentification, @RequestPayload final CreateOrganisationRequest request) throws OsgpException {
LOGGER.info("Create organisation: {}, with name: {}.", request.getOrganisation().getOrganisationIdentification(), request.getOrganisation().getName());
final Organisation organisation = this.deviceManagementMapper.map(request.getOrganisation(), Organisation.class);
// mapping fails for the 'enabled' field of the DeviceManagement Schema
// Organisation / Organisation
organisation.setIsEnabled(request.getOrganisation().isEnabled());
try {
this.deviceManagementService.addOrganisation(organisationIdentification, organisation);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_ADMIN, new ValidationException(e.getConstraintViolations()));
} catch (final TransactionSystemException e) {
throw new TechnicalException(COMPONENT_TYPE_WS_ADMIN, e);
} catch (final Exception e) {
this.handleException(e);
}
return new CreateOrganisationResponse();
}
Aggregations