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;
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations