Search in sources :

Example 26 with ValidationException

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();
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) UpdateDeviceAuthorisationsResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.UpdateDeviceAuthorisationsResponse) ArrayList(java.util.ArrayList) DeviceAuthorisation(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.DeviceAuthorisation) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 27 with ValidationException

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();
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ProtocolInfo(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.ProtocolInfo) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) UpdateDeviceProtocolResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.UpdateDeviceProtocolResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 28 with ValidationException

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;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) DeviceAuthorisation(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.DeviceAuthorisation) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) FindDeviceAuthorisationsResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.FindDeviceAuthorisationsResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 29 with ValidationException

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;
}
Also used : WsMessageLogFilter(org.opensmartgridplatform.adapter.ws.admin.application.valueobjects.WsMessageLogFilter) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) MessageLogPage(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.MessageLogPage) MessageLog(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.MessageLog) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DeviceLogItem(org.opensmartgridplatform.logging.domain.entities.DeviceLogItem) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) FindMessageLogsResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.FindMessageLogsResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 30 with ValidationException

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();
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) ConstraintViolationException(javax.validation.ConstraintViolationException) CreateOrganisationResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.CreateOrganisationResponse) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)47 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)47 ConstraintViolationException (javax.validation.ConstraintViolationException)44 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)44 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)44 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)44 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)21 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)9 TransactionSystemException (org.springframework.transaction.TransactionSystemException)8 Device (org.opensmartgridplatform.domain.core.entities.Device)7 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)6 GetGsmDiagnosticResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.GetGsmDiagnosticResponseData)6 SetDeviceLifecycleStatusByChannelResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.SetDeviceLifecycleStatusByChannelResponseData)6 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)6 DateTime (org.joda.time.DateTime)4 SetDeviceLifecycleStatusAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceLifecycleStatusAsyncResponse)4 SetDeviceVerificationKeyAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceVerificationKeyAsyncResponse)4 SetEventNotificationsAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetEventNotificationsAsyncResponse)4 UpdateDeviceCdmaSettingsAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsAsyncResponse)4 UpdateDeviceSslCertificationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceSslCertificationAsyncResponse)4