Search in sources :

Example 71 with FunctionalException

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;
}
Also used : SetDeviceAliasResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceAliasResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SetDeviceLifecycleStatusAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceLifecycleStatusAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse) SetDeviceVerificationKeyAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceVerificationKeyAsyncResponse) SetEventNotificationsAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetEventNotificationsAsyncResponse) UpdateDeviceCdmaSettingsAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsAsyncResponse) UpdateDeviceSslCertificationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceSslCertificationAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) 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 72 with FunctionalException

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;
}
Also used : FindScheduledTasksResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindScheduledTasksResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ScheduledTaskWithoutData(org.opensmartgridplatform.domain.core.entities.ScheduledTaskWithoutData) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) 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 73 with FunctionalException

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;
}
Also used : RemoveManufacturerResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.RemoveManufacturerResponse) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) 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 74 with FunctionalException

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;
}
Also used : RemoveDeviceModelResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.RemoveDeviceModelResponse) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) 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 75 with FunctionalException

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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ExistingEntityException(org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)155 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)63 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)54 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)54 ConstraintViolationException (javax.validation.ConstraintViolationException)51 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)47 Device (org.opensmartgridplatform.domain.core.entities.Device)32 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)31 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)22 Transactional (org.springframework.transaction.annotation.Transactional)19 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)15 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)12 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)11 ArrayList (java.util.ArrayList)10 Test (org.junit.jupiter.api.Test)10 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)10 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)9 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)9