Search in sources :

Example 1 with Ean

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;
}
Also used : ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 2 with Ean

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);
}
Also used : Ean(org.opensmartgridplatform.domain.core.entities.Ean) Device(org.opensmartgridplatform.domain.core.entities.Device) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) NotAuthorizedException(org.opensmartgridplatform.domain.core.exceptions.NotAuthorizedException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Ean

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);
    }
}
Also used : Ean(org.opensmartgridplatform.domain.core.entities.Ean) ReadSettingsHelper.getLong(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getLong) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)

Example 4 with 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;
}
Also used : ArrayList(java.util.ArrayList) Device(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

Ean (org.opensmartgridplatform.domain.core.entities.Ean)4 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)3 ArrayList (java.util.ArrayList)2 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)2 Device (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device)1 ReadSettingsHelper.getLong (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getLong)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)1 NotAuthorizedException (org.opensmartgridplatform.domain.core.exceptions.NotAuthorizedException)1 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 Transactional (org.springframework.transaction.annotation.Transactional)1