use of com.epam.ta.reportportal.entity.item.PathName in project service-api by reportportal.
the class SearchLogServiceImpl method composeResponse.
private SearchLogRs composeResponse(Map<Long, TestItem> testItemMapping, Long projectId, Long itemId, Log log) {
TestItem testItem = ofNullable(testItemMapping.get(itemId)).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, itemId));
Long launchId = ofNullable(testItem.getLaunchId()).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, testItem.getLaunchId()));
Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, launchId));
Map<Long, PathName> pathNameMapping = testItemRepository.selectPathNames(singletonList(testItem));
SearchLogRs response = new SearchLogRs();
response.setLaunchId(launch.getId());
ofNullable(pathNameMapping.get(testItem.getItemId())).ifPresent(pathName -> {
response.setPathNames(TestItemConverter.PATH_NAME_TO_RESOURCE.apply(pathName));
});
response.setItemId(testItem.getItemId());
response.setItemName(testItem.getName());
response.setPath(testItem.getPath());
response.setPatternTemplates(testItem.getPatternTemplateTestItems().stream().map(patternTemplateTestItem -> patternTemplateTestItem.getPatternTemplate().getName()).collect(toSet()));
response.setDuration(ofNullable(testItem.getItemResults().getDuration()).orElseGet(() -> getDuration(testItem)));
response.setStatus(testItem.getItemResults().getStatus().name());
TestItem itemWithStats = testItem;
while (!itemWithStats.isHasStats()) {
final Long parentId = itemWithStats.getParentId();
itemWithStats = testItemRepository.findById(parentId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, parentId));
}
response.setIssue(IssueConverter.TO_MODEL.apply(itemWithStats.getItemResults().getIssue()));
response.setLogs(Lists.newArrayList(TO_LOG_ENTRY.apply(log)));
return response;
}
Aggregations