Search in sources :

Example 1 with ValidationException

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

the class PublicLightingAdHocManagementEndpoint method resumeSchedule.

// === RESUME SCHEDULE ===
@PayloadRoot(localPart = "ResumeScheduleRequest", namespace = NAMESPACE)
@ResponsePayload
public ResumeScheduleAsyncResponse resumeSchedule(@OrganisationIdentification final String organisationIdentification, @RequestPayload final ResumeScheduleRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Resume Schedule Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final ResumeScheduleAsyncResponse response = new ResumeScheduleAsyncResponse();
    try {
        final ResumeScheduleData resumeScheduleData = new ResumeScheduleData();
        if (request.getIndex() != null) {
            resumeScheduleData.setIndex(request.getIndex());
        }
        resumeScheduleData.setIsImmediate(request.isIsImmediate());
        final String correlationUid = this.adHocManagementService.enqueueResumeScheduleRequest(organisationIdentification, request.getDeviceIdentification(), resumeScheduleData, 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 : ResumeScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ResumeScheduleData(org.opensmartgridplatform.domain.core.valueobjects.ResumeScheduleData) 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) 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 2 with ValidationException

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

the class PublicLightingAdHocManagementEndpoint method findAllDevices.

@PayloadRoot(localPart = "FindAllDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public FindAllDevicesResponse findAllDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllDevicesRequest request) throws OsgpException {
    LOGGER.info("Finding All Devices Request received from organisation: {}.", organisationIdentification);
    final FindAllDevicesResponse response = new FindAllDevicesResponse();
    try {
        final PageSpecifier pageSpecifier = new PageSpecifier(request.getPageSize(), request.getPage());
        final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, pageSpecifier);
        if (page != null && !page.isEmpty()) {
            final List<Ssld> sslds = listOfType(page, Ssld.class);
            final List<LightMeasurementDevice> lmds = listOfType(page, LightMeasurementDevice.class);
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setPageSize(page.getSize());
            devicePage.getPage().setTotalPages(page.getTotalPages());
            devicePage.getPage().setCurrentPage(page.getNumber());
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(sslds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld.class));
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(lmds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice.class));
            response.setDevicePage(devicePage);
        } else {
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setCurrentPage(0);
            devicePage.getPage().setPageSize(request.getPageSize() == null ? 0 : request.getPageSize());
            devicePage.getPage().setTotalPages(0);
            response.setDevicePage(devicePage);
        }
    } 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 : PageSpecifier(org.opensmartgridplatform.shared.application.config.PageSpecifier) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) 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) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ConstraintViolationException(javax.validation.ConstraintViolationException) DevicePage(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DevicePage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 3 with ValidationException

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

the class PublicLightingScheduleManagementEndpoint method setLightSchedule.

// === SET LIGHT SCHEDULE ===
@PayloadRoot(localPart = "SetScheduleRequest", namespace = NAMESPACE)
@ResponsePayload
public SetScheduleAsyncResponse setLightSchedule(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetScheduleRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Schedule Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetScheduleAsyncResponse response = new SetScheduleAsyncResponse();
    try {
        // Get the request parameters, make sure that they are in UTC.
        // Maybe add an adapter to the service, so that all datetime are
        // converted to utc automatically.
        final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
        final List<ScheduleEntry> scheduleEntries = this.scheduleManagementMapper.mapAsList(request.getSchedules(), org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry.class);
        final Schedule schedule = new Schedule(scheduleEntries, request.getAstronomicalSunriseOffset(), request.getAstronomicalSunsetOffset());
        final String correlationUid = this.scheduleManagementService.enqueueSetLightSchedule(organisationIdentification, request.getDeviceIdentification(), schedule, scheduleTime, 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: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.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) DateTime(org.joda.time.DateTime) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) SetScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleAsyncResponse) ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) Schedule(org.opensmartgridplatform.domain.core.valueobjects.Schedule) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse) SetScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.schedulemanagement.SetScheduleAsyncResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 4 with ValidationException

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

the class SmartMeteringManagementEndpoint method getDevices.

@PayloadRoot(localPart = "GetDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDevicesResponse getDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDevicesRequest request) throws OsgpException {
    log.info("Get Devices Request received from organisation: {}.", organisationIdentification);
    GetDevicesResponse response = null;
    try {
        response = new GetDevicesResponse();
        final Page<Device> page = this.managementService.findAllDevices(organisationIdentification, request.getPage());
        final DevicePage devicePage = new DevicePage();
        devicePage.setTotalPages(page.getTotalPages());
        devicePage.getDevices().addAll(this.managementMapper.mapAsList(page.getContent(), org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Device.class));
        response.setDevicePage(devicePage);
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_SMART_METERING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Device(org.opensmartgridplatform.domain.core.entities.Device) ConstraintViolationException(javax.validation.ConstraintViolationException) DevicePage(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.DevicePage) 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) GetDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.GetDevicesResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 5 with ValidationException

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

the class SmartMeteringManagementEndpoint method getDisableDebuggingResponse.

@PayloadRoot(localPart = "DisableDebuggingAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public DisableDebuggingResponse getDisableDebuggingResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final DisableDebuggingAsyncRequest request) throws OsgpException {
    log.info("DisableDebugging response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
    DisableDebuggingResponse response = null;
    try {
        response = new DisableDebuggingResponse();
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "Disable Debugging");
        response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
        if (responseData.getMessageData() instanceof String) {
            response.setDescription((String) responseData.getMessageData());
        }
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) SetDeviceLifecycleStatusByChannelResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.SetDeviceLifecycleStatusByChannelResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) GetGsmDiagnosticResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.GetGsmDiagnosticResponseData) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DisableDebuggingResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.DisableDebuggingResponse) 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

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