Search in sources :

Example 26 with FunctionalException

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

the class DomainRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received domain request message of type: {} for domain: {} and domainVersion: {}", message.getJMSType(), this.domainInfo.getDomain(), this.domainInfo.getDomainVersion());
        if (message.propertyExists(Constants.SCHEDULE_TIME)) {
            final ScheduledTask scheduledTask = this.createScheduledTask(message);
            this.scheduledTaskRepository.save(scheduledTask);
            LOGGER.info("Scheduled task for device [{}] at [{}] created.", scheduledTask.getDeviceIdentification(), scheduledTask.getScheduledTime());
        } else {
            final ProtocolRequestMessage protocolRequestMessage = this.createProtocolRequestMessage(message);
            this.deviceRequestMessageService.processMessage(protocolRequestMessage);
            LOGGER.info("Domain request for device [{}] processed.", protocolRequestMessage.getDeviceIdentification());
        }
    } catch (final JMSException | FunctionalException e) {
        LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
    }
}
Also used : ProtocolRequestMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolRequestMessage) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 27 with FunctionalException

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

the class DeviceResponseMessageService method handleMessageRetry.

private void handleMessageRetry(final ProtocolResponseMessage message, final ScheduledTask scheduledTask) throws FunctionalException {
    final Date scheduledRetryTime = message.getRetryHeader().getScheduledRetryTime();
    final Long maxScheduleTime = message.getMaxScheduleTime();
    if (this.timeForRetryExceedsMaxScheduleTime(scheduledRetryTime, maxScheduleTime)) {
        this.scheduledTaskService.deleteScheduledTask(scheduledTask);
        throw new FunctionalException(FunctionalExceptionType.MAX_SCHEDULE_TIME_EXCEEDED, ComponentType.OSGP_CORE, message.getOsgpException());
    }
    scheduledTask.setFailed(this.determineErrorMessage(message));
    scheduledTask.retryOn(scheduledRetryTime);
    this.scheduledTaskService.saveScheduledTask(scheduledTask);
}
Also used : FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Date(java.util.Date)

Example 28 with FunctionalException

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

the class Iec61850SetScheduleCommand method setScheduleOnDevice.

public void setScheduleOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final SetScheduleDeviceRequest deviceRequest, final Ssld ssld) throws ProtocolAdapterException {
    final ScheduleDto scheduleDto = deviceRequest.getSchedule();
    final RelayTypeDto relayType = deviceRequest.getRelayType();
    final List<ScheduleEntryDto> scheduleList = scheduleDto.getScheduleList();
    try {
        // Creating a list of all Schedule entries, grouped by relay index.
        final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = this.createScheduleEntries(scheduleList, ssld, relayType);
        final Function<Void> function = new Iec61850SetScheduleFunction(iec61850Client, deviceConnection, deviceRequest, ssld, relaySchedulesEntries, this.loggingService, this.ssldDataService);
        iec61850Client.sendCommandWithRetry(function, "SetSchedule", deviceConnection.getDeviceIdentification());
    } catch (final FunctionalException e) {
        throw new ProtocolAdapterException(e.getMessage(), e);
    }
}
Also used : ScheduleEntryDto(org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto) Iec61850SetScheduleFunction(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Iec61850SetScheduleFunction) ArrayList(java.util.ArrayList) List(java.util.List) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) RelayTypeDto(org.opensmartgridplatform.dto.valueobjects.RelayTypeDto) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 29 with FunctionalException

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

the class Iec61850SetScheduleCommand method setScheduleEntry.

private ScheduleEntry setScheduleEntry(final Ssld ssld, final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries, final RelayType relayType, final List<DeviceOutputSetting> settings, final ScheduleEntryDto schedule, final LightValueDto lightValue) throws FunctionalException {
    final List<Integer> indexes = new ArrayList<>();
    if (lightValue.getIndex() == 0 && (RelayType.TARIFF.equals(relayType) || RelayType.TARIFF_REVERSED.equals(relayType))) {
        // Index 0 is not allowed for tariff switching.
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850);
    } else if (lightValue.getIndex() == 0 && RelayType.LIGHT.equals(relayType)) {
        // internal indexes to the indexes list.
        for (final DeviceOutputSetting deviceOutputSetting : settings) {
            indexes.add(deviceOutputSetting.getInternalId());
        }
    } else {
        // Index != 0, adding just the one index to the list.
        indexes.add(this.ssldDataService.convertToInternalIndex(ssld, lightValue.getIndex()));
    }
    final ScheduleEntry scheduleEntry;
    try {
        scheduleEntry = this.convertToScheduleEntry(schedule, lightValue);
    } catch (final ProtocolAdapterException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850, e);
    }
    for (final Integer internalIndex : indexes) {
        if (relaySchedulesEntries.containsKey(internalIndex)) {
            // Internal index already in the Map, adding to the List
            relaySchedulesEntries.get(internalIndex).add(scheduleEntry);
        } else {
            // First time we come across this relay, checking its
            // type.
            this.checkRelayForSchedules(this.ssldDataService.getDeviceOutputSettingForInternalIndex(ssld, internalIndex).getRelayType(), relayType, internalIndex);
            // Adding it to scheduleEntries.
            final List<ScheduleEntry> scheduleEntries = new ArrayList<>();
            scheduleEntries.add(scheduleEntry);
            relaySchedulesEntries.put(internalIndex, scheduleEntries);
        }
    }
    return scheduleEntry;
}
Also used : ScheduleEntry(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 30 with FunctionalException

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

the class AdHocManagementService method handleResponseMessageReceived.

private void handleResponseMessageReceived(final String deviceIdentification) throws FunctionalException {
    try {
        final RtuDevice device = this.rtuDeviceRepository.findByDeviceIdentification(deviceIdentification).orElseThrow(() -> new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, COMPONENT_TYPE, new UnknownEntityException(RtuDevice.class, deviceIdentification)));
        if (this.shouldUpdateCommunicationTime(device)) {
            device.messageReceived();
            this.rtuDeviceRepository.save(device);
        } else {
            LOGGER.info("Last communication time within duration: {}. Skipping last communication date update.", this.minimumDurationBetweenCommunicationTimeUpdates);
        }
    } catch (final OptimisticLockException ex) {
        LOGGER.warn("Last communication time not updated due to optimistic lock exception", ex);
    }
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) OptimisticLockException(javax.persistence.OptimisticLockException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

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