Interface JpaPermissionRequestRepository

All Superinterfaces:
AtPermissionRequestRepository, org.springframework.data.repository.PagingAndSortingRepository<EdaPermissionRequest,Long>, PermissionRequestRepository<AtPermissionRequest>, org.springframework.data.repository.Repository<EdaPermissionRequest,Long>

@Repository @Transactional(readOnly=true) public interface JpaPermissionRequestRepository extends org.springframework.data.repository.PagingAndSortingRepository<EdaPermissionRequest,Long>, AtPermissionRequestRepository
  • Method Details

    • findByPermissionId

      Optional<AtPermissionRequest> findByPermissionId(String permissionId)
      Description copied from interface: PermissionRequestRepository
      Finds a permission request by its permission id. If there is no permission request, it returns an empty optional.
      Specified by:
      findByPermissionId in interface PermissionRequestRepository<AtPermissionRequest>
      Parameters:
      permissionId - the id of the permission request.
      Returns:
      an optional that contains the permission request if it exists.
    • findByConversationIdOrCMRequestId

      @Query(value="WITH permissions AS (\n SELECT DISTINCT ON (permission_id) permission_id\n FROM at_eda.permission_event\n WHERE cm_request_id = :cmRequestId or conversation_id = :conversationId\n)\nSELECT DISTINCT ON (pe.permission_id)\n pe.permission_id,\n at_eda.firstval_agg(pe.cm_request_id) OVER w AS cm_request_id,\n at_eda.firstval_agg(pe.connection_id) OVER w AS connection_id,\n at_eda.firstval_agg(pe.conversation_id) OVER w AS conversation_id,\n at_eda.firstval_agg(pe.created) OVER w AS created,\n at_eda.firstval_agg(pe.data_need_id) OVER w AS data_need_id,\n at_eda.firstval_agg(pe.dso_id) OVER w AS dso_id,\n at_eda.firstval_agg(pe.granularity) OVER w AS granularity,\n at_eda.firstval_agg(pe.metering_point_id) OVER w AS metering_point_id,\n at_eda.firstval_agg(pe.permission_start) OVER w AS permission_start,\n at_eda.firstval_agg(pe.permission_end) OVER w AS permission_end,\n at_eda.firstval_agg(pe.cm_consent_id) OVER w AS cm_consent_id,\n at_eda.firstval_agg(pe.message) OVER w AS message,\n at_eda.firstval_agg(pe.status) OVER w AS status,\n at_eda.firstval_agg(pe.cause) OVER w AS cause\nFROM at_eda.permission_event pe\n JOIN permissions USING (permission_id)\nWINDOW w AS (\n PARTITION BY pe.permission_id\n ORDER BY pe.event_created DESC\n ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\n )\nORDER BY pe.permission_id, pe.event_created DESC;\n", nativeQuery=true) List<AtPermissionRequestProjection> findByConversationIdOrCMRequestId(@Param("conversationId") String conversationId, @Param("cmRequestId") @Nullable String cmRequestId)
      Description copied from interface: AtPermissionRequestRepository
      Finds permission requests by either conversation id or CMRequest id. Might return multiple as receiving permission for multiple metering points create new permission request that share the conversation and CMRequest id.
      Specified by:
      findByConversationIdOrCMRequestId in interface AtPermissionRequestRepository
      Parameters:
      conversationId - the conversation id of the request.
      cmRequestId - the request id of the original CM Request.
      Returns:
      a List, which is empty if there is no matching permission request.
    • findByConversationIdAndMeteringPointId

      @Query("SELECT pr FROM EdaPermissionRequest pr WHERE pr.conversationId = :conversationId AND pr.meteringPointId = :meteringPointId") Optional<AtPermissionRequest> findByConversationIdAndMeteringPointId(@Param("conversationId") String conversationId, @Param("meteringPointId") @Nullable String meteringPointId)
      Description copied from interface: AtPermissionRequestRepository
      Finds a permission request by its conversation id and metering point id.
      Specified by:
      findByConversationIdAndMeteringPointId in interface AtPermissionRequestRepository
      Parameters:
      conversationId - the conversation id of the request.
      meteringPointId - the metering point id of the request.
      Returns:
      an optional, which is empty if there is no matching permission request.
    • findAcceptedAndFulfilledByMeteringPointIdAndDate

      @Query(value=" WITH permissions_for_metering_point AS (SELECT DISTINCT ON (permission_id) permission_id\n FROM at_eda.permission_event\n WHERE metering_point_id = :meteringPointId),\n permission_result AS (SELECT DISTINCT ON (pe.permission_id) pe.permission_id,\n at_eda.firstval_agg(cm_request_id) OVER w AS cm_request_id,\n at_eda.firstval_agg(connection_id) OVER w AS connection_id,\n at_eda.firstval_agg(conversation_id) OVER w AS conversation_id,\n at_eda.firstval_agg(created) OVER w AS created,\n at_eda.firstval_agg(data_need_id) OVER w AS data_need_id,\n at_eda.firstval_agg(dso_id) OVER w AS dso_id,\n at_eda.firstval_agg(granularity) OVER w AS granularity,\n at_eda.firstval_agg(metering_point_id) OVER w AS metering_point_id,\n at_eda.firstval_agg(permission_start) OVER w AS permission_start,\n at_eda.firstval_agg(permission_end) OVER w AS permission_end,\n at_eda.firstval_agg(cm_consent_id) OVER w AS cm_consent_id,\n at_eda.firstval_agg(message) OVER w AS message,\n at_eda.firstval_agg(status) OVER w AS status,\n at_eda.firstval_agg(cause) OVER w AS cause\n FROM at_eda.permission_event pe, permissions_for_metering_point pm\n WHERE pe.permission_id = pm.permission_id\n WINDOW w AS (PARTITION BY pe.permission_id ORDER BY event_created DESC)\n ORDER BY pe.permission_id, pe.event_created)\n SELECT pr\n FROM permission_result pr\n where pr.permission_start <= :date\n AND (pr.permission_end >= :date OR pr.permission_end IS NULL)\n AND pr.status IN (\'ACCEPTED\',\'FULFILLED\');\n", nativeQuery=true) List<AtPermissionRequestProjection> findAcceptedAndFulfilledByMeteringPointIdAndDate(@Param("meteringPointId") String meteringPointId, @Param("date") LocalDate date)
      Description copied from interface: AtPermissionRequestRepository
      This method returns all PermissionProcessStatus.ACCEPTED and PermissionProcessStatus.FULFILLED permission requests that are associated with the given metering point and where the date is between start and end of the permission request
      Specified by:
      findAcceptedAndFulfilledByMeteringPointIdAndDate in interface AtPermissionRequestRepository
      Parameters:
      meteringPointId - for which to get permission requests
      date - to filter time relevant permission requests
      Returns:
      a list of matching permission requests
    • findByConsentId

      @Query(value="WITH permissions AS (\n SELECT DISTINCT ON (permission_id) permission_id\n FROM at_eda.permission_event\n WHERE cm_consent_id = :consentId\n)\nSELECT DISTINCT ON (pe.permission_id)\n pe.permission_id,\n at_eda.firstval_agg(pe.cm_request_id) OVER w AS cm_request_id,\n at_eda.firstval_agg(pe.connection_id) OVER w AS connection_id,\n at_eda.firstval_agg(pe.conversation_id) OVER w AS conversation_id,\n at_eda.firstval_agg(pe.created) OVER w AS created,\n at_eda.firstval_agg(pe.data_need_id) OVER w AS data_need_id,\n at_eda.firstval_agg(pe.dso_id) OVER w AS dso_id,\n at_eda.firstval_agg(pe.granularity) OVER w AS granularity,\n at_eda.firstval_agg(pe.metering_point_id) OVER w AS metering_point_id,\n at_eda.firstval_agg(pe.permission_start) OVER w AS permission_start,\n at_eda.firstval_agg(pe.permission_end) OVER w AS permission_end,\n at_eda.firstval_agg(pe.cm_consent_id) OVER w AS cm_consent_id,\n at_eda.firstval_agg(pe.message) OVER w AS message,\n at_eda.firstval_agg(pe.status) OVER w AS status,\n at_eda.firstval_agg(pe.cause) OVER w AS cause\nFROM at_eda.permission_event pe\n JOIN permissions USING (permission_id)\nWINDOW w AS (\n PARTITION BY pe.permission_id\n ORDER BY pe.event_created DESC\n ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\n )\nORDER BY pe.permission_id, pe.event_created DESC;\n", nativeQuery=true) Optional<AtPermissionRequestProjection> findByConsentId(@Param("consentId") String consentId)
      Specified by:
      findByConsentId in interface AtPermissionRequestRepository
    • findByStatusIn

      Specified by:
      findByStatusIn in interface AtPermissionRequestRepository
    • findByMeteringPointIdAndDateAndStateSentToPAOrAfterAccepted

      @Query(value=" WITH permissions_for_metering_point AS (SELECT DISTINCT ON (permission_id) permission_id\n FROM at_eda.permission_event\n WHERE metering_point_id = :meteringPointId),\n permission_result AS (SELECT DISTINCT ON (pe.permission_id) pe.permission_id,\n at_eda.firstval_agg(cm_request_id) OVER w AS cm_request_id,\n at_eda.firstval_agg(connection_id) OVER w AS connection_id,\n at_eda.firstval_agg(conversation_id) OVER w AS conversation_id,\n at_eda.firstval_agg(created) OVER w AS created,\n at_eda.firstval_agg(data_need_id) OVER w AS data_need_id,\n at_eda.firstval_agg(dso_id) OVER w AS dso_id,\n at_eda.firstval_agg(granularity) OVER w AS granularity,\n at_eda.firstval_agg(metering_point_id) OVER w AS metering_point_id,\n at_eda.firstval_agg(permission_start) OVER w AS permission_start,\n at_eda.firstval_agg(permission_end) OVER w AS permission_end,\n at_eda.firstval_agg(cm_consent_id) OVER w AS cm_consent_id,\n at_eda.firstval_agg(message) OVER w AS message,\n at_eda.firstval_agg(status) OVER w AS status,\n at_eda.firstval_agg(cause) OVER w AS cause\n FROM at_eda.permission_event pe, permissions_for_metering_point pm\n WHERE pe.permission_id = pm.permission_id\n WINDOW w AS (PARTITION BY pe.permission_id ORDER BY event_created DESC)\n ORDER BY pe.permission_id, pe.event_created)\n SELECT permission_id,\n cm_request_id,\n connection_id,\n conversation_id,\n created,\n data_need_id,\n dso_id,\n granularity,\n metering_point_id,\n permission_start,\n permission_end,\n cm_consent_id,\n message,\n status,\n cause\n FROM permission_result\n where permission_start <= :date\n AND (permission_end >= :date OR permission_end IS NULL)\n AND status IN (\n \'ACCEPTED\',\n \'FULFILLED\',\n \'SENT_TO_PERMISSION_ADMINISTRATOR\'\n );\n", nativeQuery=true) List<AtPermissionRequestProjection> findByMeteringPointIdAndDateAndStateSentToPAOrAfterAccepted(String meteringPointId, LocalDate date)
      This method returns all permission requests that are associated with the given metering point, where: For more info about the states consult "permission-process-model.md"
      Parameters:
      meteringPointId - for which to get permission requests
      date - to filter time relevant permission requests
      Returns:
      a list of matching permission requests