Search in sources :

Example 61 with Device

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

the class DeviceDomainService method searchActiveDevice.

public Device searchActiveDevice(@Identification final String deviceIdentification, final ComponentType osgpComponent) throws FunctionalException {
    final Device device = this.searchDevice(deviceIdentification);
    // For smartmeters, we want to able to communicate no matter what the
    // device life cycle status is.
    final Optional<SmartMeter> smartMeter = this.smartMeterRepository.findById(device.getId());
    if (smartMeter.isPresent()) {
        return device;
    }
    if (!device.isActivated() || !device.getDeviceLifecycleStatus().equals(DeviceLifecycleStatus.IN_USE)) {
        throw new FunctionalException(FunctionalExceptionType.INACTIVE_DEVICE, osgpComponent, new InactiveDeviceException(deviceIdentification));
    }
    // Note: since this code is still specific for SSLD / PSLD, this null
    // check is needed.
    final Optional<Ssld> ssld = this.ssldRepository.findById(device.getId());
    if (ssld.isPresent() && !ssld.get().isPublicKeyPresent()) {
        throw new FunctionalException(FunctionalExceptionType.UNREGISTERED_DEVICE, osgpComponent, new UnregisteredDeviceException(deviceIdentification));
    }
    return device;
}
Also used : UnregisteredDeviceException(org.opensmartgridplatform.domain.core.exceptions.UnregisteredDeviceException) Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) InactiveDeviceException(org.opensmartgridplatform.domain.core.exceptions.InactiveDeviceException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 62 with Device

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

the class DeviceManagementService method enqueueSetEventNotificationsRequest.

// === SET EVENT NOTIFICATIONS ===
@Transactional(value = "transactionManager")
public String enqueueSetEventNotificationsRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final List<EventNotificationType> eventNotifications, 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.SET_EVENT_NOTIFICATIONS);
    this.domainHelperService.isInMaintenance(device);
    LOGGER.debug("enqueueSetEventNotificationsRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final EventNotificationMessageDataContainer eventNotificationMessageDataContainer = new EventNotificationMessageDataContainer(eventNotifications);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_EVENT_NOTIFICATIONS.name()).withMessagePriority(messagePriority).build();
    final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).request(eventNotificationMessageDataContainer).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) Device(org.opensmartgridplatform.domain.core.entities.Device) EventNotificationMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.EventNotificationMessageDataContainer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with Device

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

the class DeviceManagementService method enqueueSetDeviceVerificationKeyRequest.

public String enqueueSetDeviceVerificationKeyRequest(final String organisationIdentification, final String deviceIdentification, final String verificationKey, 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.SET_DEVICE_VERIFICATION_KEY);
    this.domainHelperService.isInMaintenance(device);
    LOGGER.debug("enqueueSetDeviceVerificationKeyRequest 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.SET_DEVICE_VERIFICATION_KEY.name()).withMessagePriority(messagePriority).build();
    final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).request(verificationKey).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) Device(org.opensmartgridplatform.domain.core.entities.Device)

Example 64 with Device

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

the class DeviceManagementService method setDeviceAlias.

@Transactional(value = "writableTransactionManager")
public void setDeviceAlias(@Identification final String organisationIdentification, final String deviceIdentification, final String deviceAlias, final List<DeviceOutputSetting> newDeviceOutputSettings) throws FunctionalException {
    final Ssld existingSsld = this.writableSsldRepository.findByDeviceIdentification(deviceIdentification);
    if (existingSsld == null) {
        // device does not exist
        LOGGER.info("Device does not exist, cannot set Alias.");
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceIdentification));
    }
    // Check to see if the organization is authorized for SET_DEVICE_ALIASES
    final Organisation organisation = this.organisationRepository.findByOrganisationIdentification(organisationIdentification);
    this.domainHelperService.isAllowed(organisation, existingSsld, DeviceFunction.SET_DEVICE_ALIASES);
    if (deviceAlias != null) {
        existingSsld.setAlias(deviceAlias);
        this.writableDeviceRepository.save(existingSsld);
    }
    if (newDeviceOutputSettings != null && !newDeviceOutputSettings.isEmpty()) {
        this.updateRelayAliases(newDeviceOutputSettings, existingSsld);
    }
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with Device

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

the class DeviceManagementService method findEvents.

@Transactional(value = "transactionManager")
public Page<Event> findEvents(final SearchEventsCriteria criteria) throws FunctionalException {
    final String organisationIdentification = criteria.getOrganisationIdentification();
    final String deviceIdentification = criteria.getDeviceIdentification();
    LOGGER.debug("findEvents called for organisation {} and device {}", organisationIdentification, deviceIdentification);
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    this.pagingSettings.updatePagingSettings(criteria.getPageSpecifier());
    final PageRequest request = PageRequest.of(this.pagingSettings.getPageNumber(), this.pagingSettings.getPageSize(), Sort.Direction.DESC, "dateTime");
    Specification<Event> specification;
    if (deviceIdentification != null && !deviceIdentification.isEmpty()) {
        final Device device = this.domainHelperService.findDevice(deviceIdentification);
        this.domainHelperService.isAllowed(organisation, device, DeviceFunction.GET_EVENT_NOTIFICATIONS);
        specification = where(this.eventSpecifications.isFromDevice(deviceIdentification));
    } else {
        specification = where(this.eventSpecifications.isAuthorized(organisation));
    }
    final DateTime from = criteria.getFrom();
    if (from != null) {
        specification = specification.and(this.eventSpecifications.isCreatedAfter(from.toDate()));
    }
    final DateTime until = criteria.getUntil();
    if (until != null) {
        specification = specification.and(this.eventSpecifications.isCreatedBefore(until.toDate()));
    }
    specification = specification.and(this.eventSpecifications.hasEventTypes(criteria.getEventTypes()));
    specification = this.handleDescription(SearchUtil.replaceAndEscapeWildcards(criteria.getDescription()), SearchUtil.replaceAndEscapeWildcards(criteria.getDescriptionStartsWith()), specification);
    LOGGER.debug("request offset     : {}", request.getOffset());
    LOGGER.debug("        pageNumber : {}", request.getPageNumber());
    LOGGER.debug("        pageSize   : {}", request.getPageSize());
    LOGGER.debug("        sort       : {}", request.getSort());
    return this.eventRepository.findAll(specification, request);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) Event(org.opensmartgridplatform.domain.core.entities.Event) DateTime(org.joda.time.DateTime) Transactional(org.springframework.transaction.annotation.Transactional)

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