Search in sources :

Example 1 with RtuDevice

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

the class LightMeasurementRtuDeviceCreator method apply.

@Override
public RtuDevice apply(final Protocol protocol, final Map<String, String> settings) {
    RtuDevice device = new RtuDevice(this.deviceIdentification(settings));
    device.setDeviceType(DeviceType.LIGHT_MEASUREMENT_RTU.getPlatformDeviceType());
    device.setNetworkAddress(this.networkAddress(settings));
    device.setDeviceLifecycleStatus(this.deviceLifecycleStatus(settings));
    device.setActivated(this.activated(settings));
    device.updateProtocol(this.protocolInfo(protocol));
    device.setDomainInfo(this.domainInfo());
    device = this.rtuDeviceRepository.save(device);
    this.addDeviceAuthorization(device, settings);
    return device;
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice)

Example 2 with RtuDevice

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

the class RtuDeviceSteps method anRtuDevice.

@Given("^an rtu device$")
@Transactional("txMgrCore")
public RtuDevice anRtuDevice(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    final RtuDevice rtuDevice = new RtuDevice(deviceIdentification);
    rtuDevice.setDomainInfo(this.domainInfoRepository.findByDomainAndDomainVersion(getString(settings, PlatformKeys.KEY_DOMAIN, PlatformDefaults.DOMAIN), getString(settings, PlatformKeys.KEY_DOMAIN_VERSION, PlatformDefaults.DOMAIN_VERSION)));
    rtuDevice.messageReceived(this.getLastCommunicationTime(settings).toDate().toInstant());
    return this.rtuDeviceRepository.save(rtuDevice);
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RtuDevice

use of org.opensmartgridplatform.domain.core.entities.RtuDevice 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)

Example 4 with RtuDevice

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

the class DistributionAutomationService method processRequest.

private String processRequest(final String organisationIdentification, final String deviceIdentification, final Serializable request, final DeviceFunction deviceFunction, final MessageType messageType) throws OsgpException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final RtuDevice device = this.domainHelperService.findDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, deviceFunction);
    final DistributionAutomationRequestMessage message = new DistributionAutomationRequestMessage(messageType, correlationUid, organisationIdentification, deviceIdentification, request);
    try {
        this.requestMessageSender.send(message);
    } catch (final ArgumentNullOrEmptyException e) {
        throw new TechnicalException(ComponentType.WS_DISTRIBUTION_AUTOMATION, e);
    }
    return correlationUid;
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) ArgumentNullOrEmptyException(org.opensmartgridplatform.domain.core.exceptions.ArgumentNullOrEmptyException) DistributionAutomationRequestMessage(org.opensmartgridplatform.adapter.ws.da.infra.jms.DistributionAutomationRequestMessage)

Example 5 with RtuDevice

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

the class MicrogridsService method enqueueSetDataRequest.

public String enqueueSetDataRequest(final String organisationIdentification, final String deviceIdentification, final SetDataRequest setDataRequest) throws OsgpException {
    LOGGER.debug("enqueueSetDataRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final RtuDevice device = this.domainHelperService.findDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_DATA);
    final MicrogridsRequestMessage message = new MicrogridsRequestMessage(MessageType.SET_DATA, correlationUid, organisationIdentification, deviceIdentification, setDataRequest);
    try {
        this.requestMessageSender.send(message);
    } catch (final ArgumentNullOrEmptyException e) {
        throw new TechnicalException(ComponentType.WS_MICROGRIDS, e);
    }
    return correlationUid;
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) ArgumentNullOrEmptyException(org.opensmartgridplatform.domain.core.exceptions.ArgumentNullOrEmptyException) MicrogridsRequestMessage(org.opensmartgridplatform.adapter.ws.microgrids.infra.jms.MicrogridsRequestMessage)

Aggregations

RtuDevice (org.opensmartgridplatform.domain.core.entities.RtuDevice)10 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)3 ArgumentNullOrEmptyException (org.opensmartgridplatform.domain.core.exceptions.ArgumentNullOrEmptyException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 Instant (java.time.Instant)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 MicrogridsRequestMessage (org.opensmartgridplatform.adapter.ws.microgrids.infra.jms.MicrogridsRequestMessage)2 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Given (io.cucumber.java.en.Given)1 JMSException (javax.jms.JMSException)1 DistributionAutomationRequestMessage (org.opensmartgridplatform.adapter.ws.da.infra.jms.DistributionAutomationRequestMessage)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1 JpaOptimisticLockingFailureException (org.springframework.orm.jpa.JpaOptimisticLockingFailureException)1