Package energy.eddie.aiida.services
Class PermissionService
java.lang.Object
energy.eddie.aiida.services.PermissionService
- All Implemented Interfaces:
EventListener,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
@Service
public class PermissionService
extends Object
implements org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
Constructor Summary
ConstructorsConstructorDescriptionPermissionService(PermissionRepository permissionRepository, Clock clock, StreamerManager streamerManager, HandshakeService handshakeService, PermissionScheduler permissionScheduler, AuthService authService, AiidaLocalDataNeedService aiidaLocalDataNeedService, AiidaEventPublisher aiidaEventPublisher) -
Method Summary
Modifier and TypeMethodDescriptionacceptPermission(UUID permissionId, UUID dataSourceId) Accept the permission with the passed id.voidaddDataSourceToPermission(DataSource dataSource, UUID permissionId) Returns the permission with the specified ID.Returns all permission objects that are persisted, sorted by their grantTime descending.voidonApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event) Gets all active permissions from the database and checks if they have expired.rejectPermission(UUID permissionId) Reject the specified permission.revokePermission(UUID permissionId) Revokes the specified permission by updating its status and records the timestamp and persisting the changes.setupNewPermission(QrCodeDto qrCodeDto) Saves a new permission in the database and fetches the details of the permission by executing the first part of the handshake with the associated EDDIE framework.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
PermissionService
@Autowired public PermissionService(PermissionRepository permissionRepository, Clock clock, StreamerManager streamerManager, HandshakeService handshakeService, PermissionScheduler permissionScheduler, AuthService authService, AiidaLocalDataNeedService aiidaLocalDataNeedService, AiidaEventPublisher aiidaEventPublisher)
-
-
Method Details
-
revokePermission
public Permission revokePermission(UUID permissionId) throws PermissionNotFoundException, PermissionStateTransitionException, UnauthorizedException, InvalidUserException Revokes the specified permission by updating its status and records the timestamp and persisting the changes. If an error during shutdown of the AiidaStreamer or sending of theAiidaConnectionStatusMessageDtooccurs, they are logged but not propagated to the caller.- Parameters:
permissionId- The ID of the permission that should be revoked.- Returns:
- Updated permission object that has been persisted.
- Throws:
PermissionNotFoundException- In case no permission with the specified ID can be found.PermissionStateTransitionException- In case the permission has a status that makes it not eligible for revocation.UnauthorizedException- If the current user is not the owner of the Permission.InvalidUserException
-
setupNewPermission
public Permission setupNewPermission(QrCodeDto qrCodeDto) throws PermissionAlreadyExistsException, PermissionUnfulfillableException, DetailFetchingFailedException, InvalidUserException Saves a new permission in the database and fetches the details of the permission by executing the first part of the handshake with the associated EDDIE framework. If the permission is not fulfillable by this AIIDA instance, e.g. because the requested data is missing or the start date lies in the past, anUNFULFILLABLEstatus message is sent to EDDIE, before aPermissionUnfulfillableExceptionis thrown.After this method, the status of the permission will be either
FETCHED_DETAILSorUNFULFILLABLE.- Parameters:
qrCodeDto- Data transfer object containing the information for the new permission.- Returns:
- Permission object with the details as fetched from EDDIE.
- Throws:
PermissionAlreadyExistsException- If there is already a permission with the ID.PermissionUnfulfillableException- If the permission cannot be fulfilled for whatever reason.InvalidUserException- If the id of the current user can not be determined by the token.DetailFetchingFailedException
-
rejectPermission
public Permission rejectPermission(UUID permissionId) throws PermissionStateTransitionException, PermissionNotFoundException, UnauthorizedException, InvalidUserException Reject the specified permission. Updates the database and informs the EDDIE framework of the permission about the rejection.- Parameters:
permissionId- The ID of the permission that should be rejected.- Returns:
- The updated permission object.
- Throws:
PermissionStateTransitionException- Thrown if the permission is not in the statePermissionStatus.FETCHED_DETAILS.UnauthorizedException- If the current user is not the owner of the Permission.PermissionNotFoundExceptionInvalidUserException
-
acceptPermission
public Permission acceptPermission(UUID permissionId, @Nullable UUID dataSourceId) throws PermissionStateTransitionException, PermissionNotFoundException, DetailFetchingFailedException, UnauthorizedException, InvalidUserException Accept the permission with the passed id. Updates the database and informs the EDDIE framework about the acceptance. Will fetch the MQTT details from the EDDIE framework and either schedules the start (if start date is in the future) or starts the data sharing right away.- Parameters:
permissionId- The ID of the permission that should be accpted.dataSourceId- The ID of the data source that should be used for the permission.- Returns:
- The updated permission object.
- Throws:
PermissionStateTransitionException- Thrown if the permission is not in the statePermissionStatus.FETCHED_DETAILS.UnauthorizedException- If the current user is not the owner of the Permission.PermissionNotFoundExceptionDetailFetchingFailedExceptionInvalidUserException
-
getAllPermissionsSortedByGrantTime
Returns all permission objects that are persisted, sorted by their grantTime descending.- Returns:
- A list of permissions, sorted by grantTime descending, i.e. the permission with the newest grantTime is the first item.
- Throws:
InvalidUserException
-
findById
Returns the permission with the specified ID.- Parameters:
permissionId- The unique ID of the permission to be returned.- Returns:
- The permission object with the specified ID.
- Throws:
PermissionNotFoundException- In case no permission with the specified ID can be found.
-
onApplicationEvent
public void onApplicationEvent(@NonNull org.springframework.context.event.ContextRefreshedEvent event) Gets all active permissions from the database and checks if they have expired. If not, streaming is resumed, otherwise their database entry will be updated accordingly. This is done when aContextRefreshedEventis received, which ensures that all beans are started and the database is set up correctly.- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
addDataSourceToPermission
-