Skip to content

Commit

Permalink
Add launch ids to the path names queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pbortnik committed Jul 19, 2021
1 parent c34e644 commit 1e60c08
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,22 @@ Page<TestItemHistory> loadItemsHistoryPage(boolean isLatest, Queryable launchFil
* Select ids and names of all items in a tree till current for provided item id
*
* @param itemId {@link TestItem#getItemId()}
* @param launchId {@link TestItem#getLaunchId()}()}
* @param projectId Project
* @return id from collection -> {@link PathName}
*/
Map<Long, String> selectPathNames(Long itemId, Long projectId);
Map<Long, String> selectPathNames(Long itemId, Long launchId, Long projectId);

/**
* Select {@link PathName} containing ids and names of all items in a tree till current and launch name and number
* for each item id from the provided collection
*
* @param ids {@link Collection} of {@link TestItem#getItemId()}
* @param launchIds {@link Collection} of {@link TestItem#getLaunchId()}()}
* @param projectId Project
* @return id from collection -> {@link PathName}
*/
Map<Long, PathName> selectPathNames(Collection<Long> ids, Long projectId);
Map<Long, PathName> selectPathNames(Collection<Long> ids, Collection<Long> launchIds, Long projectId);

/**
* Select item IDs by analyzed status and {@link TestItem#getLaunchId()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ public Optional<Pair<Long, String>> selectPath(String uuid) {
}

@Override
public Map<Long, String> selectPathNames(Long itemId, Long projectId) {
return getPathNamesResult(Collections.singletonList(itemId), projectId).stream()
public Map<Long, String> selectPathNames(Long itemId, Long launchId, Long projectId) {
return getPathNamesResult(Collections.singletonList(itemId), Collections.singletonList(launchId), projectId).stream()
.filter(result -> !itemId.equals(result.get(fieldName("id"))))
.collect(LinkedHashMap::new,
(m, result) -> ofNullable(result.get(fieldName("id"))).ifPresent(id -> m.put((Long) id,
Expand All @@ -664,8 +664,8 @@ public Map<Long, String> selectPathNames(Long itemId, Long projectId) {
}

@Override
public Map<Long, PathName> selectPathNames(Collection<Long> ids, Long projectId) {
return PATH_NAMES_FETCHER.apply(getPathNamesResult(ids, projectId));
public Map<Long, PathName> selectPathNames(Collection<Long> ids, Collection<Long> launchIds, Long projectId) {
return PATH_NAMES_FETCHER.apply(getPathNamesResult(ids, launchIds, projectId));
}

/**
Expand Down Expand Up @@ -927,7 +927,8 @@ private Condition hasContentQuery(JTestItem nested, SelectQuery<? extends Record
}
}

private Result<Record5<Long, Long, String, Integer, String>> getPathNamesResult(Collection<Long> ids, Long projectId) {
private Result<Record5<Long, Long, String, Integer, String>> getPathNamesResult(Collection<Long> ids, Collection<Long> launchIds,
Long projectId) {
final String tree = "supplytree";
Table<Record> supplytree = table(name(tree));
Field<Long> TREE_ITEM_ID = field(name(tree, "item_id"), Long.class);
Expand All @@ -948,6 +949,7 @@ private Result<Record5<Long, Long, String, Integer, String>> getPathNamesResult(
.on(TEST_ITEM.LAUNCH_ID.eq(LAUNCH.ID))
.where(TEST_ITEM.PARENT_ID.isNull())
.and(LAUNCH.PROJECT_ID.eq(projectId))
.and(TEST_ITEM.LAUNCH_ID.in(launchIds))
.unionAll(select(TEST_ITEM.ITEM_ID,
TEST_ITEM.PARENT_ID,
TEST_ITEM.NAME.as("leaf_name"),
Expand All @@ -960,7 +962,8 @@ private Result<Record5<Long, Long, String, Integer, String>> getPathNamesResult(
.on(TEST_ITEM.LAUNCH_ID.eq(LAUNCH.ID))
.join(supplytree)
.on(TEST_ITEM.PARENT_ID.eq(TREE_ITEM_ID))
.where(LAUNCH.PROJECT_ID.eq(projectId))))
.where(LAUNCH.PROJECT_ID.eq(projectId))
.and(TEST_ITEM.LAUNCH_ID.in(launchIds))))
.select(TREE_ITEM_ID, ID, LAUNCH_NAME, NUMBER, NAME)
.from(supplytree)
.where(TREE_ITEM_ID.in(ids))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ void hasLogsTest() {

@Test
void selectPathNames() {
Map<Long, String> results = testItemRepository.selectPathNames(3L, 1L);
Map<Long, String> results = testItemRepository.selectPathNames(3L, 1L, 1L);
assertThat("Incorrect class type", results.getClass(), Matchers.theInstance(LinkedHashMap.class));
assertThat("Incorrect items size", results.size(), Matchers.equalTo(2));
}

@Test
void selectMultiplePathNames() {
Map<Long, PathName> results = testItemRepository.selectPathNames(Lists.newArrayList(3L, 4L, 2L), 1L);
Map<Long, PathName> results = testItemRepository.selectPathNames(Lists.newArrayList(3L, 4L, 2L), Lists.newArrayList(1L), 1L);
assertThat("Incorrect class type", results.getClass(), Matchers.theInstance(HashMap.class));
results.values()
.forEach(pathName -> assertThat("Incorrect class type",
Expand Down Expand Up @@ -233,7 +233,12 @@ void findLatestByUniqueIdAndLaunchIdAndParentId() {

@Test
void findLatestIdByUniqueIdAndLaunchIdAndParentIdAndItemIdNotEqual() {
final Optional<Long> latestItem = testItemRepository.findLatestIdByUniqueIdAndLaunchIdAndParentIdAndItemIdNotEqual("unqIdSTEP_R12", 12L, 101L, 100L);
final Optional<Long> latestItem = testItemRepository.findLatestIdByUniqueIdAndLaunchIdAndParentIdAndItemIdNotEqual(
"unqIdSTEP_R12",
12L,
101L,
100L
);
assertTrue(latestItem.isPresent());
}

Expand All @@ -245,15 +250,15 @@ void selectIdsByFilter() {
.withCondition(new FilterCondition(Condition.EQUALS, false, "1", CRITERIA_ISSUE_GROUP_ID))
.build();

List<Long> itemIds = testItemRepository.selectIdsByFilter(1L, filter, 1,0);
List<Long> itemIds = testItemRepository.selectIdsByFilter(1L, filter, 1, 0);

Assertions.assertEquals(1, itemIds.size());
}

@Sql("/db/fill/item/items-with-nested-steps.sql")
@Test
void selectIdsByHasDescendants() {
final List<Long> itemIds = testItemRepository.selectIdsByHasDescendants(List.of(130L,131L,132L,133L));
final List<Long> itemIds = testItemRepository.selectIdsByHasDescendants(List.of(130L, 131L, 132L, 133L));
Assertions.assertEquals(3, itemIds.size());
}

Expand All @@ -276,15 +281,25 @@ void selectIdsByPatternLogMessage() {
@Sql("/db/fill/item/items-with-nested-steps.sql")
@Test
void selectIdsUnderByStringLogMessage() {
final List<Long> result = testItemRepository.selectIdsUnderByStringLogMessage(10L, List.of(132L, 133L), LogLevel.ERROR_INT, "NullPointer");
final List<Long> result = testItemRepository.selectIdsUnderByStringLogMessage(
10L,
List.of(132L, 133L),
LogLevel.ERROR_INT,
"NullPointer"
);
Assertions.assertEquals(1, result.size());
Assertions.assertEquals(132L, result.get(0));
}

@Sql("/db/fill/item/items-with-nested-steps.sql")
@Test
void selectIdsUnderByRegexLogMessage() {
final List<Long> result = testItemRepository.selectIdsUnderByRegexLogMessage(10L, List.of(132L, 133L), LogLevel.ERROR_INT, "[A-Za-z]*");
final List<Long> result = testItemRepository.selectIdsUnderByRegexLogMessage(
10L,
List.of(132L, 133L),
LogLevel.ERROR_INT,
"[A-Za-z]*"
);
Assertions.assertEquals(1, result.size());
Assertions.assertEquals(132L, result.get(0));
}
Expand Down Expand Up @@ -714,9 +729,7 @@ void findAllNestedStepsByIds() {

@Test
void findIndexTestItemByLaunchId() {
final List<IndexTestItem> items = testItemRepository.findIndexTestItemByLaunchId(1L,
List.of(JTestItemTypeEnum.STEP)
);
final List<IndexTestItem> items = testItemRepository.findIndexTestItemByLaunchId(1L, List.of(JTestItemTypeEnum.STEP));
assertEquals(3, items.size());
}

Expand Down

0 comments on commit 1e60c08

Please sign in to comment.