Interface TestItemRepository

    • Method Detail

      • streamTestItemIdsByLaunchId

        @QueryHints()
        @Query("SELECT ti.id FROM TestItem ti WHERE ti.launchId = :launchId")
        java.util.stream.Stream<java.lang.Long> streamTestItemIdsByLaunchId​(@Param("launchId")
                                                                            java.lang.Long launchId)
      • findParentByChildId

        @Query("SELECT parent FROM TestItem child JOIN child.parent parent WHERE child.itemId = :childId")
        java.util.Optional<TestItem> findParentByChildId​(@Param("childId")
                                                         java.lang.Long childId)
      • streamIdsByNotHasChildrenAndLaunchIdAndStatus

        @QueryHints()
        @Query(value="SELECT test_item.item_id FROM test_item JOIN test_item_results result ON test_item.item_id = result.result_id  WHERE test_item.launch_id = :launchId AND NOT test_item.has_children AND result.status = cast(:#{#status.name()} AS STATUS_ENUM)",
               nativeQuery=true)
        java.util.stream.Stream<java.math.BigInteger> streamIdsByNotHasChildrenAndLaunchIdAndStatus​(@Param("launchId")
                                                                                                    java.lang.Long launchId,
                                                                                                    @Param("status")
                                                                                                    StatusEnum status)
        Retrieve the List of the TestItem.itemId by launch ID, Enum.name() and TestItem.hasChildren == false
        Parameters:
        launchId - Launch.id
        status - Enum.name()
        Returns:
        the List of the TestItem.itemId
      • streamIdsByHasChildrenAndLaunchIdAndStatusOrderedByPathLevel

        @QueryHints()
        @Query(value="SELECT test_item.item_id FROM test_item JOIN test_item_results result ON test_item.item_id = result.result_id  WHERE test_item.launch_id = :launchId AND test_item.has_children AND result.status = cast(:#{#status.name()} AS STATUS_ENUM) ORDER BY nlevel(test_item.path) DESC",
               nativeQuery=true)
        java.util.stream.Stream<java.math.BigInteger> streamIdsByHasChildrenAndLaunchIdAndStatusOrderedByPathLevel​(@Param("launchId")
                                                                                                                   java.lang.Long launchId,
                                                                                                                   @Param("status")
                                                                                                                   StatusEnum status)
        Retrieve the List of the TestItem.itemId by launch ID, Enum.name() and TestItem.hasChildren == true ordered (DESCENDING) by 'nlevel' of the TestItem.path
        Parameters:
        launchId - Launch.id
        status - Enum.name()
        Returns:
        the List of the TestItem.itemId
        See Also:
        https://www.postgresql.org/docs/current/ltree.html
      • streamIdsByNotHasChildrenAndParentPathAndStatus

        @QueryHints()
        @Query(value="SELECT test_item.item_id FROM test_item JOIN test_item_results result ON test_item.item_id = result.result_id  WHERE cast(:parentPath AS LTREE) @> test_item.path AND cast(:parentPath AS LTREE) != test_item.path  AND NOT test_item.has_children AND result.status = cast(:#{#status.name()} AS STATUS_ENUM)",
               nativeQuery=true)
        java.util.stream.Stream<java.math.BigInteger> streamIdsByNotHasChildrenAndParentPathAndStatus​(@Param("parentPath")
                                                                                                      java.lang.String parentPath,
                                                                                                      @Param("status")
                                                                                                      StatusEnum status)
        Retrieve the Stream of the TestItem.itemId under parent TestItem.path, Enum.name() and TestItem.hasChildren == false
        Parameters:
        parentPath - TestItem.path of the parent item
        status - Enum.name()
        Returns:
        the List of the TestItem.itemId
      • streamIdsByHasChildrenAndParentPathAndStatusOrderedByPathLevel

        @QueryHints()
        @Query(value="SELECT test_item.item_id FROM test_item JOIN test_item_results result ON test_item.item_id = result.result_id  WHERE cast(:parentPath AS LTREE) @> test_item.path AND cast(:parentPath AS LTREE) != test_item.path  AND test_item.has_children AND result.status = cast(:#{#status.name()} AS STATUS_ENUM) ORDER BY nlevel(test_item.path) DESC",
               nativeQuery=true)
        java.util.stream.Stream<java.math.BigInteger> streamIdsByHasChildrenAndParentPathAndStatusOrderedByPathLevel​(@Param("parentPath")
                                                                                                                     java.lang.String parentPath,
                                                                                                                     @Param("status")
                                                                                                                     StatusEnum status)
        Retrieve the Stream of the TestItem.itemId under parent TestItem.path, Enum.name() and TestItem.hasChildren == true ordered (DESCENDING) by 'nlevel' of the TestItem.path
        Parameters:
        parentPath - TestItem.path of the parent item
        status - Enum.name()
        Returns:
        the List of the TestItem.itemId
        See Also:
        https://www.postgresql.org/docs/current/ltree.html
      • findTestItemsByUniqueId

        java.util.List<TestItem> findTestItemsByUniqueId​(java.lang.String uniqueId)
      • findTestItemsByLaunchId

        java.util.List<TestItem> findTestItemsByLaunchId​(java.lang.Long launchId)
      • findByUuid

        java.util.Optional<TestItem> findByUuid​(java.lang.String uuid)
      • findByUuidForUpdate

        @Query("SELECT ti FROM TestItem ti WHERE ti.uuid = :uuid")
        @Lock(PESSIMISTIC_WRITE)
        java.util.Optional<TestItem> findByUuidForUpdate​(@Param("uuid")
                                                         java.lang.String uuid)
        Finds TestItem by TestItem.getUuid() and sets a lock on the found 'item' row in the database. Required for fetching 'item' from the concurrent environment to provide synchronization between dependant entities
        Parameters:
        uuid - TestItem.getUuid()
        Returns:
        Optional with TestItem object
      • findTestItemsByLaunchIdOrderByStartTimeAsc

        java.util.List<TestItem> findTestItemsByLaunchIdOrderByStartTimeAsc​(java.lang.Long launchId)
        Finds all TestItem by specified launch id
        Parameters:
        launchId - Launch.id
        Returns:
        List of TestItem ordered by TestItem.startTime ascending
      • deleteTestItem

        @Query(value="DELETE FROM test_item WHERE test_item.item_id = :itemId",
               nativeQuery=true)
        void deleteTestItem​(@Param("itemId")
                            java.lang.Long itemId)
      • hasChildren

        @Query(value="SELECT exists(SELECT 1 FROM test_item t WHERE t.path <@ cast(:itemPath AS LTREE) AND t.item_id != :itemId LIMIT 1)",
               nativeQuery=true)
        boolean hasChildren​(@Param("itemId")
                            java.lang.Long itemId,
                            @Param("itemPath")
                            java.lang.String itemPath)
        Checks does test item have children.
        Parameters:
        itemPath - Current item path in a tree
        Returns:
        True if has
      • hasParentWithStatus

        @Query(value="SELECT exists(SELECT 1 FROM test_item ti JOIN test_item_results tir ON ti.item_id = tir.result_id WHERE ti.path @> cast(:itemPath AS LTREE) AND ti.has_stats = TRUE AND ti.item_id != :itemId AND tir.status = cast(:#{#status.name()} AS STATUS_ENUM) LIMIT 1)",
               nativeQuery=true)
        boolean hasParentWithStatus​(@Param("itemId")
                                    java.lang.Long itemId,
                                    @Param("itemPath")
                                    java.lang.String itemPath,
                                    @Param("status")
                                    StatusEnum status)
        Checks does test item have parent with provided status.
        Parameters:
        itemId - Cuttent item id
        itemPath - Current item path in a tree
        status - StatusEnum
        Returns:
        'True' if has, otherwise 'false'
      • hasDescendantsNotInStatus

        @Query(value="SELECT exists(SELECT 1 FROM test_item ti JOIN test_item_results tir ON ti.item_id = tir.result_id WHERE ti.parent_id = :parentId AND ti.retry_of IS NULL AND CAST(tir.status AS VARCHAR) NOT IN (:statuses))",
               nativeQuery=true)
        boolean hasDescendantsNotInStatus​(@Param("parentId")
                                          java.lang.Long parentId,
                                          @Param("statuses")
                                          java.lang.String... statuses)
        Check for existence of descendants with statuses NOT EQUAL to provided status
        Parameters:
        parentId - TestItem.getParent() ID
        statuses - Enum.name() Array
        Returns:
        'true' if items with statuses NOT EQUAL to provided status exist, otherwise 'false'
      • hasItemsInStatusByParent

        @Query(value="SELECT exists(SELECT 1 FROM test_item ti JOIN test_item_results tir ON ti.item_id = tir.result_id WHERE ti.path <@ cast(:parentPath AS LTREE) AND ti.item_id != :parentId AND cast(tir.status AS VARCHAR) IN (:statuses))",
               nativeQuery=true)
        boolean hasItemsInStatusByParent​(@Param("parentId")
                                         java.lang.Long parentId,
                                         @Param("parentPath")
                                         java.lang.String parentPath,
                                         @Param("statuses")
                                         java.lang.String... statuses)
        True if the parent item has any child items with provided status.
        Parameters:
        parentId - parent item TestItem.getItemId()
        parentPath - parent item TestItem.getPath()
        statuses - child item TestItemResults.getStatus()
        Returns:
        True if contains, false if not
      • interruptInProgressItems

        @Modifying
        @Query(value="UPDATE test_item_results SET status = \'INTERRUPTED\', end_time = current_timestamp, duration = EXTRACT(EPOCH FROM current_timestamp - i.start_time)FROM test_item i WHERE i.item_id = result_id AND i.launch_id = :launchId AND status = \'IN_PROGRESS\'",
               nativeQuery=true)
        void interruptInProgressItems​(@Param("launchId")
                                      java.lang.Long launchId)
        Interrupts all StatusEnum.IN_PROGRESS children items of the launch with provided launchId. Sets them StatusEnum.INTERRUPTED status
        Parameters:
        launchId - Launch id
      • hasDescendantsNotInStatusExcludingById

        @Query(value="SELECT exists(SELECT 1 FROM test_item JOIN test_item_results result ON test_item.item_id = result.result_id  WHERE test_item.parent_id = :parentId AND test_item.item_id != :stepId AND test_item.retry_of IS NULL  AND CAST(result.status AS VARCHAR) NOT IN (:statuses))",
               nativeQuery=true)
        boolean hasDescendantsNotInStatusExcludingById​(@Param("parentId")
                                                       java.lang.Long parentId,
                                                       @Param("stepId")
                                                       java.lang.Long stepId,
                                                       @Param("statuses")
                                                       java.lang.String... statuses)
        Checks if all children of test item with id = parentId, except item with id = stepId, has status not in provided statuses
        Parameters:
        parentId - Id of parent test item
        stepId - Id of test item that should be ignored during the checking
        statuses - Enum.name() Array
        Returns:
        True if has
      • findByNameAndLaunchWithoutParents

        @Query("SELECT t FROM TestItem t WHERE t.name=:name AND t.parent IS NULL AND t.launchId=:launchId")
        java.util.Optional<TestItem> findByNameAndLaunchWithoutParents​(@Param("name")
                                                                       java.lang.String name,
                                                                       @Param("launchId")
                                                                       java.lang.Long launchId)
        Finds root(without any parent) TestItem with specified name and launchId
        Parameters:
        name - Name of TestItem
        launchId - ID of Launch
        Returns:
        Optional of TestItem if it exists, Optional.empty() if not
      • findByNameAndLaunchUnderPath

        @Query(value="SELECT * FROM test_item t WHERE t.name=:name AND t.launch_id=:launchId AND t.path <@ cast(:path AS LTREE)",
               nativeQuery=true)
        java.util.Optional<TestItem> findByNameAndLaunchUnderPath​(@Param("name")
                                                                  java.lang.String name,
                                                                  @Param("launchId")
                                                                  java.lang.Long launchId,
                                                                  @Param("path")
                                                                  java.lang.String path)
        Finds TestItem with specified name and launchId under path
        Parameters:
        name - Name of TestItem
        launchId - ID of Launch
        path - Path of TestItem
        Returns:
        Optional of TestItem if it exists, Optional.empty() if not
      • selectAllDescendantsIds

        @Query(value="SELECT item_id FROM test_item WHERE path <@ cast(:path AS LTREE)",
               nativeQuery=true)
        java.util.List<java.lang.Long> selectAllDescendantsIds​(@Param("path")
                                                               java.lang.String path)
        Finds all descendants ids of TestItem with path include its own id
        Parameters:
        path - Path of TestItem
        Returns:
        List of test item ids
      • deleteAllByItemIdIn

        void deleteAllByItemIdIn​(java.util.Collection<java.lang.Long> ids)