Search in sources :

Example 76 with Device

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

the class DeviceInstallationService method updateLightMeasurementDevice.

@Transactional(value = "writableTransactionManager")
public void updateLightMeasurementDevice(@Identification final String organisationIdentification, @Valid final LightMeasurementDevice updateLightMeasurementDevice) throws FunctionalException {
    final LightMeasurementDevice existingLmd = this.writableLightMeasurementDeviceRepository.findByDeviceIdentification(updateLightMeasurementDevice.getDeviceIdentification());
    if (existingLmd == 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, updateLightMeasurementDevice.getDeviceIdentification()));
    }
    final List<DeviceAuthorization> owners = this.writableAuthorizationRepository.findByDeviceAndFunctionGroup(existingLmd, 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 LMD
    existingLmd.updateMetaData(updateLightMeasurementDevice.getAlias(), updateLightMeasurementDevice.getContainerAddress(), updateLightMeasurementDevice.getGpsCoordinates());
    existingLmd.setDeviceModel(updateLightMeasurementDevice.getDeviceModel());
    existingLmd.setDescription(updateLightMeasurementDevice.getDescription());
    existingLmd.setCode(updateLightMeasurementDevice.getCode());
    existingLmd.setColor(updateLightMeasurementDevice.getColor());
    existingLmd.setDigitalInput(updateLightMeasurementDevice.getDigitalInput());
    this.writableLightMeasurementDeviceRepository.save(existingLmd);
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with Device

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

the class DeviceInstallationService method enqueueStopDeviceTestRequest.

// === STOP DEVICE TEST ===
@Transactional(value = "transactionManager")
public String enqueueStopDeviceTestRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
    LOGGER.debug("Queue stop device test request");
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.STOP_SELF_TEST);
    LOGGER.debug("enqueueStopDeviceTestRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.STOP_SELF_TEST.name()).withMessagePriority(messagePriority).build();
    final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).build();
    this.commonRequestMessageSender.send(message);
    return correlationUid;
}
Also used : CommonRequestMessage(org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with Device

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

the class DeviceInstallationService method enqueueStartDeviceTestRequest.

// === START DEVICE TEST ===
@Transactional(value = "transactionManager")
public String enqueueStartDeviceTestRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
    LOGGER.debug("Queue start device test request");
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.START_SELF_TEST);
    LOGGER.debug("enqueueStartDeviceTestRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.START_SELF_TEST.name()).withMessagePriority(messagePriority).build();
    final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).build();
    this.commonRequestMessageSender.send(message);
    return correlationUid;
}
Also used : CommonRequestMessage(org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) Transactional(org.springframework.transaction.annotation.Transactional)

Example 79 with Device

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

the class DeviceInstallationService method enqueueGetStatusRequest.

// === GET STATUS ===
@Transactional(value = "transactionManager")
public String enqueueGetStatusRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.GET_STATUS);
    LOGGER.debug("enqueueGetStatusRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.GET_STATUS.name()).withMessagePriority(messagePriority).build();
    final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).build();
    this.commonRequestMessageSender.send(message);
    return correlationUid;
}
Also used : CommonRequestMessage(org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) Transactional(org.springframework.transaction.annotation.Transactional)

Example 80 with Device

use of org.opensmartgridplatform.domain.core.entities.Device 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)

Aggregations

Device (org.opensmartgridplatform.domain.core.entities.Device)179 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)49 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)36 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)35 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)32 Test (org.junit.jupiter.api.Test)27 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)27 Transactional (org.springframework.transaction.annotation.Transactional)24 Then (io.cucumber.java.en.Then)21 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)18 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)17 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)15 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)12 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)11 Date (java.util.Date)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9