Interface TestItemRepository

    • Method Detail

      • findParentByChildId

        @Query(value="SELECT * FROM test_item WHERE item_id = (SELECT parent_id FROM test_item WHERE item_id = :childId)",
               nativeQuery=true)
        java.util.Optional<TestItem> findParentByChildId​(@Param("childId")
                                                         java.lang.Long childId)
      • findIdsByNotHasChildrenAndLaunchIdAndStatus

        @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) ORDER BY test_item.item_id LIMIT :pageSize OFFSET :pageOffset",
               nativeQuery=true)
        java.util.List<java.lang.Long> findIdsByNotHasChildrenAndLaunchIdAndStatus​(@Param("launchId")
                                                                                   java.lang.Long launchId,
                                                                                   @Param("status")
                                                                                   StatusEnum status,
                                                                                   @Param("pageSize")
                                                                                   java.lang.Integer limit,
                                                                                   @Param("pageOffset")
                                                                                   java.lang.Long offset)
        Retrieve the List of the TestItem.getItemId() by launch ID, Enum.name() and TestItem.isHasChildren() == false
        Parameters:
        launchId - Launch.getId()
        status - Enum.name()
        Returns:
        the List of the TestItem.getItemId()
      • findIdsByHasChildrenAndLaunchIdAndStatusOrderedByPathLevel

        @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, test_item.item_id LIMIT :pageSize OFFSET :pageOffset",
               nativeQuery=true)
        java.util.List<java.lang.Long> findIdsByHasChildrenAndLaunchIdAndStatusOrderedByPathLevel​(@Param("launchId")
                                                                                                  java.lang.Long launchId,
                                                                                                  @Param("status")
                                                                                                  StatusEnum status,
                                                                                                  @Param("pageSize")
                                                                                                  java.lang.Integer limit,
                                                                                                  @Param("pageOffset")
                                                                                                  java.lang.Long offset)
        Retrieve the List of the TestItem.getItemId() by launch ID, Enum.name() and TestItem.isHasChildren() == true ordered (DESCENDING) by 'nlevel' of the TestItem.getPath()
        Parameters:
        launchId - Launch.getId()
        status - Enum.name()
        Returns:
        the List of the TestItem.getItemId()
        See Also:
        https://www.postgresql.org/docs/current/ltree.html
      • findIdsByNotHasChildrenAndParentPathAndStatus

        @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) ORDER BY test_item.item_id LIMIT :pageSize OFFSET :pageOffset",
               nativeQuery=true)
        java.util.List<java.lang.Long> findIdsByNotHasChildrenAndParentPathAndStatus​(@Param("parentPath")
                                                                                     java.lang.String parentPath,
                                                                                     @Param("status")
                                                                                     StatusEnum status,
                                                                                     @Param("pageSize")
                                                                                     java.lang.Integer limit,
                                                                                     @Param("pageOffset")
                                                                                     java.lang.Long offset)
        Retrieve the Stream of the TestItem.getItemId() under parent TestItem.getPath(), Enum.name() and TestItem.isHasChildren() == false
        Parameters:
        parentPath - TestItem.getPath() of the parent item
        status - Enum.name()
        Returns:
        the List of the TestItem.getItemId()
      • findIdsByHasChildrenAndParentPathAndStatusOrderedByPathLevel

        @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, test_item.item_id LIMIT :pageSize OFFSET :pageOffset",
               nativeQuery=true)
        java.util.List<java.lang.Long> findIdsByHasChildrenAndParentPathAndStatusOrderedByPathLevel​(@Param("parentPath")
                                                                                                    java.lang.String parentPath,
                                                                                                    @Param("status")
                                                                                                    StatusEnum status,
                                                                                                    @Param("pageSize")
                                                                                                    java.lang.Integer limit,
                                                                                                    @Param("pageOffset")
                                                                                                    java.lang.Long offset)
        Retrieve the Stream of the TestItem.getItemId() under parent TestItem.getPath(), Enum.name() and TestItem.isHasChildren() == true ordered (DESCENDING) by 'nlevel' of the TestItem.getPath()
        Parameters:
        parentPath - TestItem.getPath() of the parent item
        status - Enum.name()
        Returns:
        the List of the TestItem.getItemId()
        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)
      • findIdByUuidForUpdate

        @Query(value="SELECT ti.item_id FROM test_item ti WHERE ti.uuid = :uuid FOR UPDATE",
               nativeQuery=true)
        java.util.Optional<java.lang.Long> findIdByUuidForUpdate​(@Param("uuid")
                                                                 java.lang.String uuid)
        Finds TestItem.getItemId() 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
      • handleRetry

        @Query(value="SELECT handle_retry(:itemId, :retryParent)",
               nativeQuery=true)
        void handleRetry​(@Param("itemId")
                         java.lang.Long itemId,
                         @Param("retryParent")
                         java.lang.Long retryParent)
        Execute sql-function that changes a structure of retries assigning TestItem.getRetryOf() value of the previously inserted retries and previous retries' parent to the new inserted parent id
        Parameters:
        itemId - Previous retries' parent TestItem.getItemId()
        retryParent - The new-inserted TestItem.getItemId()
      • 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
      • hasChildrenWithStats

        @Query(value="SELECT exists(SELECT 1 FROM test_item t WHERE t.parent_id = :itemId AND t.has_stats)",
               nativeQuery=true)
        boolean hasChildrenWithStats​(@Param("itemId")
                                     java.lang.Long itemId)
        Checks does test item have children with TestItem.isHasStats() == true.
        Parameters:
        itemId - Parent item id
        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
      • hasItemsWithIssueByLaunch

        @Query(value="SELECT EXISTS(SELECT 1 FROM test_item ti JOIN issue i ON ti.item_id = i.issue_id WHERE ti.launch_id = :launchId)",
               nativeQuery=true)
        boolean hasItemsWithIssueByLaunch​(@Param("launchId")
                                          java.lang.Long launchId)
        True if the launch has any items with issue.
        Parameters:
        launchId - parent item TestItem.getItemId()
        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
      • findByPath

        @Query(value="SELECT * FROM test_item t WHERE t.path = CAST(:path AS LTREE)",
               nativeQuery=true)
        java.util.Optional<TestItem> findByPath​(@Param("path")
                                                java.lang.String path)
        Finds TestItem with specified path
        Parameters:
        path - Path of TestItem
        Returns:
        Optional of TestItem if it exists, Optional.empty() if not
      • findLatestIdByUniqueIdAndLaunchIdAndParentId

        @Query(value="SELECT t.item_id FROM test_item t WHERE t.unique_id = :uniqueId AND t.launch_id = :launchId  AND t.parent_id = :parentId AND t.has_stats AND t.retry_of IS NULL ORDER BY t.start_time DESC, t.item_id DESC LIMIT 1 FOR UPDATE",
               nativeQuery=true)
        java.util.Optional<java.lang.Long> findLatestIdByUniqueIdAndLaunchIdAndParentId​(@Param("uniqueId")
                                                                                        java.lang.String uniqueId,
                                                                                        @Param("launchId")
                                                                                        java.lang.Long launchId,
                                                                                        @Param("parentId")
                                                                                        java.lang.Long parentId)
        Finds latest TestItem.getItemId() with specified uniqueId, launchId, parentId
        Parameters:
        uniqueId - TestItem.getUniqueId()
        launchId - TestItem.getLaunchId()
        parentId - TestItem.getParentId()
        Returns:
        Optional of TestItem if exists otherwise Optional.empty()
      • findLatestIdByUniqueIdAndLaunchIdAndParentIdAndItemIdNotEqual

        @Query(value="SELECT t.item_id FROM test_item t WHERE t.unique_id = :uniqueId AND t.launch_id = :launchId  AND t.parent_id = :parentId AND t.item_id != :itemId AND t.has_stats AND t.retry_of IS NULL ORDER BY t.start_time DESC, t.item_id DESC LIMIT 1 FOR UPDATE",
               nativeQuery=true)
        java.util.Optional<java.lang.Long> findLatestIdByUniqueIdAndLaunchIdAndParentIdAndItemIdNotEqual​(@Param("uniqueId")
                                                                                                         java.lang.String uniqueId,
                                                                                                         @Param("launchId")
                                                                                                         java.lang.Long launchId,
                                                                                                         @Param("parentId")
                                                                                                         java.lang.Long parentId,
                                                                                                         @Param("itemId")
                                                                                                         java.lang.Long itemId)
        Finds latest TestItem.getItemId() with specified uniqueId, launchId, parentId and not equal itemId
        Parameters:
        uniqueId - TestItem.getUniqueId()
        launchId - TestItem.getLaunchId()
        parentId - TestItem.getParentId()
        itemId - TestItem.getItemId() ()}
        Returns:
        Optional of TestItem if exists otherwise Optional.empty()
      • 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)
      • findLatestIdByTestCaseHashAndLaunchIdWithoutParents

        @Query(value="SELECT t.item_id FROM test_item t WHERE t.test_case_hash = :testCaseHash AND t.launch_id = :launchId AND t.parent_id IS NULL  ORDER BY t.start_time DESC, t.item_id DESC LIMIT 1 FOR UPDATE",
               nativeQuery=true)
        java.util.Optional<java.lang.Long> findLatestIdByTestCaseHashAndLaunchIdWithoutParents​(@Param("testCaseHash")
                                                                                               java.lang.Integer testCaseHash,
                                                                                               @Param("launchId")
                                                                                               java.lang.Long launchId)
        Finds latest root(without any parent) TestItem with specified testCaseHash and launchId
        Parameters:
        testCaseHash - TestItem.getTestCaseHash()
        launchId - TestItem.getLaunchId()
        Returns:
        Optional of TestItem.getItemId() if exists otherwise Optional.empty()
      • findLatestIdByTestCaseHashAndLaunchIdAndParentId

        @Query(value="SELECT t.item_id FROM test_item t WHERE t.test_case_hash = :testCaseHash AND t.launch_id = :launchId  AND t.parent_id = :parentId AND t.has_stats AND t.retry_of IS NULL ORDER BY t.start_time DESC, t.item_id DESC LIMIT 1 FOR UPDATE",
               nativeQuery=true)
        java.util.Optional<java.lang.Long> findLatestIdByTestCaseHashAndLaunchIdAndParentId​(@Param("testCaseHash")
                                                                                            java.lang.Integer testCaseHash,
                                                                                            @Param("launchId")
                                                                                            java.lang.Long launchId,
                                                                                            @Param("parentId")
                                                                                            java.lang.Long parentId)
        Finds latest TestItem.getItemId() with specified testCaseHash, launchId and parentId
        Parameters:
        testCaseHash - TestItem.getTestCaseHash()
        launchId - TestItem.getLaunchId()
        parentId - TestItem.getParentId()
        Returns:
        Optional of TestItem.getItemId() if exists otherwise Optional.empty()