Search in sources :

Example 21 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException 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 22 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException 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 23 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method resumeSchedule.

// === RESUME SCHEDULE ===
public void resumeSchedule(final CorrelationIds ids, final Integer index, final boolean isImmediate, final String messageType, final int messagePriority) throws FunctionalException {
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    final Ssld ssld = this.findSsldForDevice(device);
    if (!ssld.getHasSchedule()) {
        throw new FunctionalException(FunctionalExceptionType.UNSCHEDULED_DEVICE, ComponentType.DOMAIN_PUBLIC_LIGHTING, new ValidationException(String.format("Device %1$s does not have a schedule.", ids.getDeviceIdentification())));
    }
    final ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainerDto = new ResumeScheduleMessageDataContainerDto(index, isImmediate);
    this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, resumeScheduleMessageDataContainerDto), messageType, messagePriority, device.getIpAddress());
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResumeScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ResumeScheduleMessageDataContainerDto) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 24 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.

the class PublicLightingAdHocManagementEndpoint method setLight.

// === SET LIGHT ===
@PayloadRoot(localPart = "SetLightRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightAsyncResponse setLight(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Light Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetLightAsyncResponse response = new SetLightAsyncResponse();
    try {
        final List<LightValue> lightValues = new ArrayList<>(this.adHocManagementMapper.mapAsList(request.getLightValue(), LightValue.class));
        final String correlationUid = this.adHocManagementService.enqueueSetLightRequest(organisationIdentification, request.getDeviceIdentification(), lightValues, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        LOGGER.error(EXCEPTION_OCCURRED, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ResumeScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse) GetStatusAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse) SetTransitionAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) 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 25 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method removeOrganisation.

public void removeOrganisation(@Identification final String organisationIdentification, @Identification final String organisationToRemoveIdentification) throws FunctionalException {
    LOGGER.debug("removeOrganisation called with organisation {} and organisation to remove {}", organisationIdentification, organisationToRemoveIdentification);
    final Organisation organisation = this.findOrganisation(organisationIdentification);
    final Organisation organisationToRemove = this.findOrganisation(organisationToRemoveIdentification);
    this.isAllowed(organisation, PlatformFunction.REMOVE_ORGANISATION);
    try {
        final List<DeviceAuthorization> deviceAuthorizations = this.authorizationRepository.findByOrganisation(organisationToRemove);
        if (!deviceAuthorizations.isEmpty()) {
            throw new FunctionalException(FunctionalExceptionType.EXISTING_DEVICE_AUTHORIZATIONS, ComponentType.WS_ADMIN, new ValidationException(String.format("Device Authorizations are still present for the current organisation %s", organisationToRemove.getOrganisationIdentification())));
        }
        organisationToRemove.setIsEnabled(false);
        this.organisationRepository.save(organisationToRemove);
    } catch (final JpaSystemException ex) {
        if (ex.getCause() instanceof PersistenceException) {
            LOGGER.error("Remove organisation failure JpaSystemException", ex);
            throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.WS_ADMIN, new UnknownEntityException(Organisation.class, organisationToRemoveIdentification, ex));
        }
    }
}
Also used : JpaSystemException(org.springframework.orm.jpa.JpaSystemException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PersistenceException(javax.persistence.PersistenceException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

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