use of org.opensmartgridplatform.domain.core.entities.Ean 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.Ean in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method updateDevice.
@Transactional(value = "writableTransactionManager")
public void updateDevice(@Identification final String organisationIdentification, final String deviceToUpdateIdentification, @Valid final Ssld updateDevice) throws FunctionalException {
final Device existingDevice = this.writableDeviceRepository.findByDeviceIdentification(deviceToUpdateIdentification);
if (existingDevice == null) {
// device does not exist
LOGGER.info("Device does not exist, nothing to update.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceToUpdateIdentification));
}
final List<DeviceAuthorization> owners = this.writableAuthorizationRepository.findByDeviceAndFunctionGroup(existingDevice, DeviceFunctionGroup.OWNER);
// Check organisation against owner of device
boolean isOwner = false;
for (final DeviceAuthorization owner : owners) {
if (owner.getOrganisation().getOrganisationIdentification().equalsIgnoreCase(organisationIdentification)) {
isOwner = true;
}
}
if (!isOwner) {
LOGGER.info("Device has no owner yet, or organisation is not the owner.");
throw new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_CORE, new NotAuthorizedException(organisationIdentification));
}
// Update the device
existingDevice.updateMetaData(updateDevice.getAlias(), updateDevice.getContainerAddress(), updateDevice.getGpsCoordinates());
existingDevice.setActivated(updateDevice.isActivated());
if (updateDevice.getDeviceLifecycleStatus() != null) {
existingDevice.setDeviceLifecycleStatus(updateDevice.getDeviceLifecycleStatus());
}
if (updateDevice.getTechnicalInstallationDate() != null) {
existingDevice.setTechnicalInstallationDate(updateDevice.getTechnicalInstallationDate());
}
final Ssld ssld = this.writableSsldRepository.findById(existingDevice.getId()).orElseThrow(() -> new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE));
ssld.updateOutputSettings(updateDevice.receiveOutputSettings());
ssld.setEans(updateDevice.getEans());
for (final Ean ean : updateDevice.getEans()) {
ean.setDevice(ssld);
}
this.writableSsldRepository.save(ssld);
}
use of org.opensmartgridplatform.domain.core.entities.Ean in project open-smart-grid-platform by OSGP.
the class BaseDeviceSteps method addEanToDevice.
private void addEanToDevice(final Device device, final Map<String, String> settings) {
final Long eanCode = getLong(settings, PlatformKeys.EAN_CODE);
if (eanCode != null) {
final String eanDescription = getString(settings, PlatformKeys.EAN_DESCRIPTION, PlatformDefaults.DEFAULT_EAN_DESCRIPTION);
final Ean ean = new Ean(device, eanCode, eanDescription);
this.eanRepository.save(ean);
}
}
use of org.opensmartgridplatform.domain.core.entities.Ean in project open-smart-grid-platform by OSGP.
the class SsldConverter method convertTo.
@Override
public org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device convertTo(final Ssld source, final Type<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device destination = this.helper.initJaxb(source);
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(source.getDeviceIdentification());
if (ssld != null) {
final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting();
newDeviceOutputSetting.setExternalId(deviceOutputSetting.getExternalId());
newDeviceOutputSetting.setInternalId(deviceOutputSetting.getInternalId());
newDeviceOutputSetting.setRelayType(deviceOutputSetting.getOutputType() == null ? null : RelayType.valueOf(deviceOutputSetting.getOutputType().name()));
newDeviceOutputSetting.setAlias(deviceOutputSetting.getAlias());
deviceOutputSettings.add(newDeviceOutputSetting);
}
destination.getOutputSettings().addAll(deviceOutputSettings);
destination.setPublicKeyPresent(ssld.isPublicKeyPresent());
destination.setHasSchedule(ssld.getHasSchedule());
final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean> eans = new ArrayList<>();
for (final org.opensmartgridplatform.domain.core.entities.Ean ean : ssld.getEans()) {
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean newEan = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean();
newEan.setCode(ean.getCode());
newEan.setDescription(ean.getDescription());
eans.add(newEan);
}
destination.getEans().addAll(eans);
this.addRelayStatuses(destination, ssld);
}
return destination;
}
Aggregations