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, ConnectionLimitDefaultRepository connectionLimitDefaultRepository, Clock clock, StreamerManager streamerManager, HandshakeService handshakeService, PermissionScheduler permissionScheduler, AuthService authService, DataSourceService dataSourceService, AiidaLocalDataNeedService aiidaLocalDataNeedService, AiidaEventPublisher aiidaEventPublisher, SecretsService secretsService) -
Method Summary
Modifier and TypeMethodDescriptionacceptInboundPermission(UUID permissionId, AcceptInboundPermissionDto acceptDto) Accepts the inbound permission request with the passed ID.acceptOutboundPermission(UUID permissionId, AcceptOutboundPermissionDto acceptDto) Accepts the outbound permission request with the passed ID.fetchPermissionDetails(AiidaPermissionRequestsDto permissionRequests) Fetches the details of the permission requests contained in an AIIDA code from the respective EDDIE framework and validates whether this AIIDA instance can fulfill them.Returns the permission with the specified ID.Returns all permission objects that are persisted, sorted by their grantTime descending.voidonApplicationEvent(@NonNull org.springframework.context.event.ContextRefreshedEvent event) Gets all accepted permissions with MQTT credentials from the database and checks if they have expired.voidrejectPermission(UUID permissionId, RejectPermissionDto rejectDto) Rejects the permission request with the passed ID at the respective EDDIE framework.revokePermission(UUID permissionId) Revokes the specified permission by updating its status and records the timestamp and persisting the changes.updateDisplayName(UUID permissionId, String displayName) Updates the display name of the permission with the passed id.updateInboundMessageFormat(UUID permissionId, InboundMessageFormat inboundMessageFormat) 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, ConnectionLimitDefaultRepository connectionLimitDefaultRepository, Clock clock, StreamerManager streamerManager, HandshakeService handshakeService, PermissionScheduler permissionScheduler, AuthService authService, DataSourceService dataSourceService, AiidaLocalDataNeedService aiidaLocalDataNeedService, AiidaEventPublisher aiidaEventPublisher, SecretsService secretsService)
-
-
Method Details
-
revokePermission
public Permission revokePermission(UUID permissionId) throws PermissionNotFoundException, PermissionStateTransitionException, UnauthorizedException, InvalidUserException, InboundDataSourceInUseException 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.InvalidUserExceptionInboundDataSourceInUseException
-
fetchPermissionDetails
public List<PendingPermissionDto> fetchPermissionDetails(AiidaPermissionRequestsDto permissionRequests) throws PermissionAlreadyExistsException, DetailFetchingFailedException, InvalidUserException, ActiveFcaPermissionAlreadyExistsException, PermissionStartInThePastException, PermissionDataNeedTypeNotSupportedException, LimitDefaultsNotAllowedException Fetches the details of the permission requests contained in an AIIDA code from the respective EDDIE framework and validates whether this AIIDA instance can fulfill them. Nothing is persisted, so the AIIDA code can be used again as long as the permission requests were neither accepted nor rejected. If a permission request cannot be fulfilled, e.g. because the start date lies in the past, the EDDIE framework is informed with the reason before an exception is thrown.- Parameters:
permissionRequests- Contents of the AIIDA code.- Returns:
- The details of each permission request.
- Throws:
PermissionAlreadyExistsException- There is already an accepted permission with the ID.DetailFetchingFailedException- AIIDA failed the handshake with EDDIE for permission details.InvalidUserException- The id of the current user can not be determined by the token.ActiveFcaPermissionAlreadyExistsException- There is already an active permission for the meter ID provided in the permission request.PermissionStartInThePastException- The start date lies in the past.PermissionDataNeedTypeNotSupportedException- The data need type of the permission is not supported by this AIIDA instance.LimitDefaultsNotAllowedException- Default connection limits were set but the permission is not eligible for them or minLimitKw is not less than maxLimitKw.
-
acceptOutboundPermission
public Permission acceptOutboundPermission(UUID permissionId, AcceptOutboundPermissionDto acceptDto) throws PermissionAlreadyExistsException, DetailFetchingFailedException, InvalidUserException, ActiveFcaPermissionAlreadyExistsException, PermissionStartInThePastException, PermissionDataNeedTypeNotSupportedException, LimitDefaultsNotAllowedException, InvalidOutboundPermissionException, DataSourceNotFoundException, IncompatibleDataSourceException, SecretStoringException Accepts the outbound permission request with the passed ID. The details are fetched and validated again, as the client cannot be trusted. Afterward, the permission request is accepted at the EDDIE framework, and the permission is persisted asPermissionStatus.ACCEPTEDtogether with its MQTT credentials and the selected data source, before data sharing is started or scheduled.- Parameters:
permissionId- The ID of the permission request that should be accepted.acceptDto- Handshake information from the AIIDA code and the selections of the user.- Returns:
- The accepted and persisted permission.
- Throws:
InvalidOutboundPermissionException- The permission request is not an outbound permission request.DataSourceNotFoundException- The data source does not exist or belongs to another user.IncompatibleDataSourceException- The data source does not match the asset or schemas of the data need.DetailFetchingFailedException- Fetching the details or accepting at the EDDIE framework failed.PermissionAlreadyExistsExceptionInvalidUserExceptionActiveFcaPermissionAlreadyExistsExceptionPermissionStartInThePastExceptionPermissionDataNeedTypeNotSupportedExceptionLimitDefaultsNotAllowedExceptionSecretStoringException
-
acceptInboundPermission
public Permission acceptInboundPermission(UUID permissionId, AcceptInboundPermissionDto acceptDto) throws PermissionAlreadyExistsException, DetailFetchingFailedException, InvalidUserException, ActiveFcaPermissionAlreadyExistsException, PermissionStartInThePastException, PermissionDataNeedTypeNotSupportedException, LimitDefaultsNotAllowedException, InvalidInboundPermissionException, AssetNotAllowedException, SecretStoringException Accepts the inbound permission request with the passed ID. The details are fetched and validated again, as the client cannot be trusted. Afterward, the permission request is accepted at the EDDIE framework, and the permission is persisted asPermissionStatus.ACCEPTEDtogether with its MQTT credentials, before its data source is created and data sharing is started or scheduled.- Parameters:
permissionId- The ID of the permission request that should be accepted.acceptDto- Handshake information from the AIIDA code and the selections of the user.- Returns:
- The accepted and persisted permission.
- Throws:
InvalidInboundPermissionException- The permission request is not an inbound permission request.AssetNotAllowedException- The selected asset is not allowed by the data need.DetailFetchingFailedException- Fetching the details or accepting at the EDDIE framework failed.PermissionAlreadyExistsExceptionInvalidUserExceptionActiveFcaPermissionAlreadyExistsExceptionPermissionStartInThePastExceptionPermissionDataNeedTypeNotSupportedExceptionLimitDefaultsNotAllowedExceptionSecretStoringException
-
rejectPermission
public void rejectPermission(UUID permissionId, RejectPermissionDto rejectDto) throws PermissionAlreadyExistsException Rejects the permission request with the passed ID at the respective EDDIE framework. Nothing is persisted.- Parameters:
permissionId- The ID of the permission request that should be rejected.rejectDto- Handshake information from the AIIDA code and an optional reason.- Throws:
PermissionAlreadyExistsException- The permission was already accepted.
-
updateInboundMessageFormat
public Permission updateInboundMessageFormat(UUID permissionId, @Nullable InboundMessageFormat inboundMessageFormat) throws PermissionNotFoundException, UnauthorizedException, InvalidUserException, MissingInboundMessageFormatException, InvalidInboundPermissionException -
updateDisplayName
public Permission updateDisplayName(UUID permissionId, @Nullable String displayName) throws PermissionNotFoundException, UnauthorizedException, InvalidUserException, MissingDisplayNameException Updates the display name of the permission with the passed id.- Parameters:
permissionId- The ID of the permission that should be renamed.displayName- The new display name for the permission.- Returns:
- The updated permission object.
- Throws:
UnauthorizedException- If the current user is not the owner of the Permission.MissingDisplayNameException- If displayName is null or blank.PermissionNotFoundExceptionInvalidUserException
-
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
-
getAcceptedInboundPermissions
- 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 accepted permissions with MQTT credentials 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>
-