Search in sources :

Example 6 with Ssld

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

the class FirmwareManagementService method updateFirmware.

// === UPDATE FIRMWARE ===
public void updateFirmware(final CorrelationIds ids, final FirmwareUpdateMessageDataContainer firmwareUpdateMessageDataContainer, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
    LOGGER.debug("Update firmware called with organisation [{}], device [{}], firmwareIdentification [{}].", ids.getOrganisationIdentification(), ids.getDeviceIdentification(), firmwareUpdateMessageDataContainer.getFirmwareUrl());
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    if (device instanceof Ssld) {
        this.createSsldPendingFirmwareUpdateRecord(ids, firmwareUpdateMessageDataContainer.getFirmwareUrl());
    }
    this.osgpCoreRequestMessageSender.sendWithScheduledTime(new RequestMessage(ids, this.domainCoreMapper.map(firmwareUpdateMessageDataContainer, org.opensmartgridplatform.dto.valueobjects.FirmwareUpdateMessageDataContainer.class)), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 7 with Ssld

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

the class DeviceManagementService method handleUpdateKeyResponse.

public void handleUpdateKeyResponse(final String deviceIdentification, final String organisationIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("MessageType: {}. Handle update key response for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
        if (device == null) {
            // Device not found, create new device
            LOGGER.debug("Device [{}] does not exist, creating new device", deviceIdentification);
            device = new Ssld(deviceIdentification);
        }
        device.setPublicKeyPresent(true);
        this.ssldRepository.save(device);
        LOGGER.info("publicKey has been set for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while updating key", e);
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PlatformException(org.opensmartgridplatform.domain.core.exceptions.PlatformException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 8 with Ssld

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

the class DeviceManagementService method handleRevokeKeyResponse.

public void handleRevokeKeyResponse(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("MessageType: {}. Handle revoke key for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
        if (device == null) {
            throw new PlatformException(String.format("Device not found: %s", deviceIdentification));
        }
        final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
        ssld.setPublicKeyPresent(false);
        this.ssldRepository.save(ssld);
        LOGGER.info("publicKey has been revoked for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while revoking key", e);
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Device(org.opensmartgridplatform.domain.core.entities.Device) PlatformException(org.opensmartgridplatform.domain.core.exceptions.PlatformException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PlatformException(org.opensmartgridplatform.domain.core.exceptions.PlatformException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 9 with Ssld

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

the class PublicLightingAdHocManagementEndpoint method findAllDevices.

@PayloadRoot(localPart = "FindAllDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public FindAllDevicesResponse findAllDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllDevicesRequest request) throws OsgpException {
    LOGGER.info("Finding All Devices Request received from organisation: {}.", organisationIdentification);
    final FindAllDevicesResponse response = new FindAllDevicesResponse();
    try {
        final PageSpecifier pageSpecifier = new PageSpecifier(request.getPageSize(), request.getPage());
        final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, pageSpecifier);
        if (page != null && !page.isEmpty()) {
            final List<Ssld> sslds = listOfType(page, Ssld.class);
            final List<LightMeasurementDevice> lmds = listOfType(page, LightMeasurementDevice.class);
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setPageSize(page.getSize());
            devicePage.getPage().setTotalPages(page.getTotalPages());
            devicePage.getPage().setCurrentPage(page.getNumber());
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(sslds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld.class));
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(lmds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice.class));
            response.setDevicePage(devicePage);
        } else {
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setCurrentPage(0);
            devicePage.getPage().setPageSize(request.getPageSize() == null ? 0 : request.getPageSize());
            devicePage.getPage().setTotalPages(0);
            response.setDevicePage(devicePage);
        }
    } catch (final ConstraintViolationException e) {
        LOGGER.error(EXCEPTION_OCCURRED, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : PageSpecifier(org.opensmartgridplatform.shared.application.config.PageSpecifier) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) 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) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ConstraintViolationException(javax.validation.ConstraintViolationException) DevicePage(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DevicePage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 10 with Ssld

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

the class ConfigurationManagementService method handleGetConfigurationResponse.

public void handleGetConfigurationResponse(final ConfigurationDto configurationDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    Configuration configuration = null;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
        final List<DeviceOutputSetting> outputSettings = ssld.getOutputSettings();
        this.replaceEmptyOutputSettings(configurationDto, outputSettings);
        configuration = this.domainCoreMapper.map(configurationDto, Configuration.class);
        // TARIFF_REVERSED will be changed to the correct RelayType.
        for (final DeviceOutputSetting dos : outputSettings) {
            if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
                for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
                    if (rm.getIndex() == dos.getExternalId() && rm.getRelayType().equals(RelayType.TARIFF)) {
                        rm.changeRelayType(RelayType.TARIFF_REVERSED);
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception for messageType: {}", messageType, e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, e.getMessage(), e);
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(configuration).withMessagePriority(messagePriority).withMessageType(MessageType.GET_CONFIGURATION.name()).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) 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