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;
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations