use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class SsldConverter method convertFrom.
@Override
public Ssld convertFrom(final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device source, final Type<Ssld> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final Ssld destination = this.helper.initEntity(source);
final List<org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
for (final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting deviceOutputSetting : source.getOutputSettings()) {
final org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting(deviceOutputSetting.getInternalId(), deviceOutputSetting.getExternalId(), deviceOutputSetting.getRelayType() == null ? null : org.opensmartgridplatform.domain.core.valueobjects.RelayType.valueOf(deviceOutputSetting.getRelayType().name()), deviceOutputSetting.getAlias());
deviceOutputSettings.add(newDeviceOutputSetting);
}
destination.updateOutputSettings(deviceOutputSettings);
if (source.isPublicKeyPresent() != null) {
destination.setPublicKeyPresent(source.isPublicKeyPresent());
}
if (source.isHasSchedule() != null) {
destination.setHasSchedule(source.isHasSchedule());
}
if (source.isActivated() != null) {
destination.setActivated(source.isActivated());
}
if (source.getDeviceLifecycleStatus() != null) {
destination.setDeviceLifecycleStatus(DeviceLifecycleStatus.valueOf(source.getDeviceLifecycleStatus().name()));
}
// clearing the existing Eans to prevent duplication
destination.setEans(new ArrayList<Ean>());
for (final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean ean : source.getEans()) {
final Ean newEan = new Ean(destination, ean.getCode(), ean.getDescription());
destination.getEans().add(newEan);
}
return destination;
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class EventNotificationMessageService method handleSwitchDeviceEvents.
private void handleSwitchDeviceEvents(final Device device, final List<Event> switchDeviceEvents) throws UnknownEntityException {
LOGGER.info("handleSwitchDeviceEvents() called for device: {} with lightSwitchingEvents.size(): {}", device.getDeviceIdentification(), switchDeviceEvents.size());
if (switchDeviceEvents.isEmpty()) {
return;
}
// Determine light and tariff relays for SSLD.
final Ssld ssld = this.eventNotificationHelperService.findSsld(device.getId());
final Set<Integer> indexesLightRelays = new TreeSet<>();
final Set<Integer> indexesTariffRelays = new TreeSet<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
if (deviceOutputSetting.getOutputType().equals(RelayType.LIGHT)) {
indexesLightRelays.add(deviceOutputSetting.getExternalId());
}
if (deviceOutputSetting.getOutputType().equals(RelayType.TARIFF) || deviceOutputSetting.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
indexesTariffRelays.add(deviceOutputSetting.getExternalId());
}
}
this.printRelayIndexes(indexesLightRelays, indexesTariffRelays, device.getDeviceIdentification());
final Map<Integer, RelayStatus> lastRelayStatusPerIndex = new TreeMap<>();
for (final Event lightSwitchingEvent : switchDeviceEvents) {
final Integer index = lightSwitchingEvent.getIndex();
if (index == 0) {
this.handleLightSwitchingEventForIndex0(indexesLightRelays, device, lightSwitchingEvent, lastRelayStatusPerIndex);
} else {
this.createRelayStatus(device, lightSwitchingEvent, index, lastRelayStatusPerIndex);
}
}
this.printRelayStatuses(lastRelayStatusPerIndex, device.getDeviceIdentification());
if (!lastRelayStatusPerIndex.isEmpty()) {
LOGGER.info("calling ssld.updateSwitchingEventRelayStatuses() for device: {} with lastRelayStatusPerIndex.size(): {}", ssld.getDeviceIdentification(), lastRelayStatusPerIndex.size());
ssld.updateSwitchingEventRelayStatuses(lastRelayStatusPerIndex);
this.eventNotificationHelperService.saveSsld(ssld);
this.sendRequestMessageToDomainCore(MessageType.RELAY_STATUS_UPDATED_EVENTS.name(), ssld.getDeviceIdentification(), null);
}
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class EventNotificationMessageService method handleSwitchingEvent.
private void handleSwitchingEvent(final String deviceIdentification, final Date dateTime, final EventType eventType, final int index) throws UnknownEntityException {
final Ssld ssld = this.eventNotificationHelperService.findSsld(deviceIdentification);
// index.
if (index == 0) {
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
if (deviceOutputSetting.getOutputType().equals(RelayType.LIGHT)) {
this.updateRelayStatusForEvent(deviceOutputSetting.getExternalId(), ssld, dateTime, eventType);
}
}
} else {
this.updateRelayStatusForEvent(index, ssld, dateTime, eventType);
}
this.eventNotificationHelperService.saveSsld(ssld);
this.sendRequestMessageToDomainCore(MessageType.RELAY_STATUS_UPDATED_EVENTS.name(), deviceIdentification, null);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceDomainService method searchActiveDevice.
public Device searchActiveDevice(@Identification final String deviceIdentification, final ComponentType osgpComponent) throws FunctionalException {
final Device device = this.searchDevice(deviceIdentification);
// For smartmeters, we want to able to communicate no matter what the
// device life cycle status is.
final Optional<SmartMeter> smartMeter = this.smartMeterRepository.findById(device.getId());
if (smartMeter.isPresent()) {
return device;
}
if (!device.isActivated() || !device.getDeviceLifecycleStatus().equals(DeviceLifecycleStatus.IN_USE)) {
throw new FunctionalException(FunctionalExceptionType.INACTIVE_DEVICE, osgpComponent, new InactiveDeviceException(deviceIdentification));
}
// Note: since this code is still specific for SSLD / PSLD, this null
// check is needed.
final Optional<Ssld> ssld = this.ssldRepository.findById(device.getId());
if (ssld.isPresent() && !ssld.get().isPublicKeyPresent()) {
throw new FunctionalException(FunctionalExceptionType.UNREGISTERED_DEVICE, osgpComponent, new UnregisteredDeviceException(deviceIdentification));
}
return device;
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method setDeviceAlias.
@Transactional(value = "writableTransactionManager")
public void setDeviceAlias(@Identification final String organisationIdentification, final String deviceIdentification, final String deviceAlias, final List<DeviceOutputSetting> newDeviceOutputSettings) throws FunctionalException {
final Ssld existingSsld = this.writableSsldRepository.findByDeviceIdentification(deviceIdentification);
if (existingSsld == null) {
// device does not exist
LOGGER.info("Device does not exist, cannot set Alias.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceIdentification));
}
// Check to see if the organization is authorized for SET_DEVICE_ALIASES
final Organisation organisation = this.organisationRepository.findByOrganisationIdentification(organisationIdentification);
this.domainHelperService.isAllowed(organisation, existingSsld, DeviceFunction.SET_DEVICE_ALIASES);
if (deviceAlias != null) {
existingSsld.setAlias(deviceAlias);
this.writableDeviceRepository.save(existingSsld);
}
if (newDeviceOutputSettings != null && !newDeviceOutputSettings.isEmpty()) {
this.updateRelayAliases(newDeviceOutputSettings, existingSsld);
}
}
Aggregations