Search in sources :

Example 21 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld 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 22 with Ssld

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

the class DeviceInstallationEndpoint method updateDevice.

@PayloadRoot(localPart = "UpdateDeviceRequest", namespace = DEVICE_INSTALLATION_NAMESPACE)
@ResponsePayload
public UpdateDeviceResponse updateDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceRequest request) throws OsgpException {
    LOGGER.info("Updating device: {}.", request.getDeviceIdentification());
    try {
        final Ssld device = this.deviceInstallationMapper.map(request.getUpdatedDevice(), Ssld.class);
        this.deviceInstallationService.updateDevice(organisationIdentification, device);
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        LOGGER.error(EXCEPTION_WHILE_UPDATING_DEVICE, e.getMessage(), request.getUpdatedDevice().getDeviceIdentification(), organisationIdentification, e);
        this.handleException(e);
    }
    try {
        this.notificationService.sendNotification(organisationIdentification, request.getDeviceIdentification(), null, null, null, NotificationType.DEVICE_UPDATED);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return new UpdateDeviceResponse();
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) UpdateDeviceResponse(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.UpdateDeviceResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 23 with Ssld

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

the class DeviceManagementMapperTest method mapsUpdatedDeviceToDevice.

@Test
public void mapsUpdatedDeviceToDevice() {
    final UpdatedDevice updatedDevice = new UpdatedDevice();
    final DeviceOutputSetting outputSetting = new DeviceOutputSetting();
    outputSetting.setAlias(DOS_ALIAS);
    outputSetting.setInternalId(RELAY_INTERNAL_ID);
    outputSetting.setExternalId(RELAY_EXTERNAL_ID);
    outputSetting.setRelayType(RelayType.LIGHT);
    updatedDevice.getOutputSettings().add(outputSetting);
    final Address address = new Address();
    address.setStreet(STREET);
    address.setNumber(HOUSE_NUMBER);
    address.setNumberAddition(HOUSE_NUMBER_ADDITION);
    address.setPostalCode(POSTAL_CODE);
    address.setCity(CITY);
    address.setMunicipality(MUNICIPALITY);
    updatedDevice.setContainerAddress(address);
    updatedDevice.setDeviceLifecycleStatus(DeviceLifecycleStatus.IN_USE);
    final Ssld expected = new Ssld();
    final List<org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting> expectedOutputSettings = new ArrayList<>();
    final org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting expectedOutputSetting = new org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting(RELAY_INTERNAL_ID, RELAY_EXTERNAL_ID, org.opensmartgridplatform.domain.core.valueobjects.RelayType.LIGHT, DOS_ALIAS);
    expectedOutputSettings.add(expectedOutputSetting);
    expected.updateOutputSettings(expectedOutputSettings);
    final org.opensmartgridplatform.domain.core.valueobjects.Address expectedAddress = new org.opensmartgridplatform.domain.core.valueobjects.Address(CITY, POSTAL_CODE, STREET, HOUSE_NUMBER, HOUSE_NUMBER_ADDITION, MUNICIPALITY);
    expected.setContainerAddress(expectedAddress);
    expected.setDeviceLifecycleStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceLifecycleStatus.IN_USE);
    final Ssld actual = this.mapper.map(updatedDevice, Ssld.class);
    assertThat(expected).usingRecursiveComparison().ignoringFields("creationTime", "modificationTime").isEqualTo(actual);
}
Also used : Address(org.opensmartgridplatform.adapter.ws.schema.core.common.Address) ArrayList(java.util.ArrayList) UpdatedDevice(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdatedDevice) DeviceOutputSetting(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Example 24 with Ssld

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

the class AdHocManagementService method resumeSchedule.

// === RESUME SCHEDULE ===
public void resumeSchedule(final CorrelationIds ids, final Integer index, final boolean isImmediate, final String messageType, final int messagePriority) throws FunctionalException {
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    final Ssld ssld = this.findSsldForDevice(device);
    if (!ssld.getHasSchedule()) {
        throw new FunctionalException(FunctionalExceptionType.UNSCHEDULED_DEVICE, ComponentType.DOMAIN_PUBLIC_LIGHTING, new ValidationException(String.format("Device %1$s does not have a schedule.", ids.getDeviceIdentification())));
    }
    final ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainerDto = new ResumeScheduleMessageDataContainerDto(index, isImmediate);
    this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, resumeScheduleMessageDataContainerDto), messageType, messagePriority, device.getIpAddress());
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResumeScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ResumeScheduleMessageDataContainerDto) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 25 with Ssld

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

the class ScheduleManagementService method setHasSchedule.

// === SET HAS SCHEDULE ===
/**
 * Method for setting the 'hasSchedule' boolean for a device.
 *
 * @throws FunctionalException
 */
public void setHasSchedule(final String deviceIdentification, final Boolean hasSchedule) throws FunctionalException {
    LOGGER.info("setHasSchedule called for device {} with hasSchedule: {}.", deviceIdentification, hasSchedule);
    final Device device = this.findActiveDevice(deviceIdentification);
    final Ssld ssld = this.findSsldForDevice(device);
    ssld.setHasSchedule(hasSchedule);
    this.ssldRepository.save(ssld);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)50 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)16 Device (org.opensmartgridplatform.domain.core.entities.Device)13 ArrayList (java.util.ArrayList)12 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)11 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 Test (org.junit.jupiter.api.Test)9 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9 Given (io.cucumber.java.en.Given)8 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)8 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)5 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)5 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)5 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)4 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)4 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)4