Search in sources :

Example 66 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class FirmwareManagementService method addManufacturer.

/**
 * Adds new Manufacturer to the platform. Throws exception if {@link Manufacturer} already exists
 */
@Transactional(value = "writableTransactionManager")
public void addManufacturer(@Identification final String organisationIdentification, @Valid final Manufacturer manufacturer) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    this.domainHelperService.isAllowed(organisation, PlatformFunction.CREATE_MANUFACTURER);
    final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer.getCode());
    if (databaseManufacturer != null) {
        LOGGER.info("Manufacturer already exists.");
        throw new FunctionalException(FunctionalExceptionType.EXISTING_MANUFACTURER, ComponentType.WS_CORE, new ExistingEntityException(Manufacturer.class, manufacturer.getCode()));
    } else {
        this.manufacturerRepository.save(manufacturer);
    }
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ExistingEntityException(org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 67 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class FirmwareManagementService method changeDeviceModel.

/**
 * Updates a DeviceModel to the platform. Throws exception if {@link DeviceModel} doesn't exist.
 */
@Transactional(value = "writableTransactionManager")
public void changeDeviceModel(@Identification final String organisationIdentification, final String manufacturer, final String modelCode, final String description) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    this.domainHelperService.isAllowed(organisation, PlatformFunction.CHANGE_DEVICE_MODEL);
    final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer);
    final DeviceModel changedDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, modelCode);
    if (changedDeviceModel == null) {
        LOGGER.info("DeviceModel not found.");
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE, new ExistingEntityException(Manufacturer.class, modelCode));
    } else {
        changedDeviceModel.setDescription(description);
        this.deviceModelRepository.save(changedDeviceModel);
    }
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ExistingEntityException(org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 68 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceManagementEndpoint method findOrganisation.

@PayloadRoot(localPart = "FindOrganisationRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindOrganisationResponse findOrganisation(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindOrganisationRequest request) throws OsgpException {
    LOGGER.info("Find organisation for organisation: {}.", organisationIdentification);
    final FindOrganisationResponse response = new FindOrganisationResponse();
    try {
        final Organisation organisation = this.deviceManagementService.findOrganisation(organisationIdentification, request.getOrganisationIdentification());
        response.setOrganisation(this.deviceManagementMapper.map(organisation, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Organisation.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 : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) 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) FindOrganisationResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindOrganisationResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 69 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceManagementEndpoint method updateDevice.

@PayloadRoot(localPart = "UpdateDeviceRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public UpdateDeviceResponse updateDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceRequest request) throws OsgpException {
    final String deviceToUpdateIdentification = request.getDeviceIdentification();
    LOGGER.info("UpdateDeviceRequest received for device: {} for organisation: {}.", deviceToUpdateIdentification, organisationIdentification);
    try {
        final org.opensmartgridplatform.domain.core.entities.Ssld ssld = this.deviceManagementMapper.map(request.getUpdatedDevice(), org.opensmartgridplatform.domain.core.entities.Ssld.class);
        this.deviceManagementService.updateDevice(organisationIdentification, deviceToUpdateIdentification, ssld);
    } 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(), deviceToUpdateIdentification, organisationIdentification, e);
        this.handleException(e);
    }
    final UpdateDeviceResponse updateDeviceResponse = new UpdateDeviceResponse();
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceToUpdateIdentification);
    final AsyncResponse asyncResponse = new AsyncResponse();
    asyncResponse.setCorrelationUid(correlationUid);
    asyncResponse.setDeviceId(deviceToUpdateIdentification);
    updateDeviceResponse.setAsyncResponse(asyncResponse);
    try {
        this.notificationService.sendNotification(organisationIdentification, deviceToUpdateIdentification, null, null, null, NotificationType.DEVICE_UPDATED);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return updateDeviceResponse;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) UpdateDeviceResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceResponse) 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 70 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceManagementEndpoint method findAllOrganisations.

@PayloadRoot(localPart = "FindAllOrganisationsRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindAllOrganisationsResponse findAllOrganisations(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllOrganisationsRequest request) throws OsgpException {
    LOGGER.info("Find all organisations for organisation: {}.", organisationIdentification);
    final FindAllOrganisationsResponse response = new FindAllOrganisationsResponse();
    try {
        final List<Organisation> organisations = this.deviceManagementService.findAllOrganisations(organisationIdentification);
        response.getOrganisations().addAll(this.deviceManagementMapper.mapAsList(organisations, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Organisation.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 : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FindAllOrganisationsResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindAllOrganisationsResponse) 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)

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