use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class WidgetConverterTest method getWidget.
private Widget getWidget() {
final Widget widget = new Widget();
widget.setDescription("description");
widget.setItemsCount(10);
widget.setWidgetType("widgetType");
widget.setName("name");
widget.setShared(true);
final Project project = new Project();
project.setId(3L);
widget.setProject(project);
final WidgetOptions widgetOptions = new WidgetOptions();
final HashMap<String, Object> options = new HashMap<>();
options.put("option1", "val1");
options.put("option2", "val2");
widgetOptions.setOptions(options);
widget.setWidgetOptions(widgetOptions);
final UserFilter filter = new UserFilter();
filter.setId(1L);
filter.setOwner("owner");
filter.setName("name");
filter.setTargetClass(ObjectType.Launch);
filter.setDescription("filter description");
filter.setFilterCondition(Sets.newHashSet(FilterCondition.builder().eq(CRITERIA_LAUNCH_ID, "100").build()));
widget.setFilters(Sets.newHashSet(filter));
final FilterSort filterSort = new FilterSort();
filterSort.setField("name");
filterSort.setDirection(Sort.Direction.ASC);
filterSort.setId(2L);
filter.setFilterSorts(Sets.newHashSet(filterSort));
return widget;
}
use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class DemoDashboardsService method generate.
@Transactional
public Optional<Dashboard> generate(ReportPortalUser user, Long projectId) {
Project project = projectRepository.findById(projectId).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectId));
if (dashboardRepository.existsByNameAndOwnerAndProjectId(DASHBOARD_NAME, user.getUsername(), projectId)) {
return Optional.empty();
}
UserFilter filter = createDemoFilter(user, project);
List<Widget> widgets = createWidgets(user, projectId, filter);
return Optional.of(createDemoDashboard(widgets, user, project, DASHBOARD_NAME));
}
use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.
the class DemoDashboardsService method createWidgets.
private List<Widget> createWidgets(ReportPortalUser user, Long projectId, UserFilter filter) {
try {
TypeReference<List<WidgetRQ>> type = new TypeReference<>() {
};
List<Widget> widgets = objectMapper.readValue(resource.getURL(), type).stream().map(it -> {
final WidgetBuilder widgetBuilder = new WidgetBuilder().addWidgetRq(it).addProject(projectId).addOwner(user.getUsername());
final WidgetType widgetType = WidgetType.findByName(it.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_CREATE_WIDGET, "Widget type '" + it.getWidgetType() + "' does not exists"));
if (!WidgetType.FLAKY_TEST_CASES.equals(widgetType) || !WidgetType.TOP_TEST_CASES.equals(widgetType)) {
widgetBuilder.addFilters(Sets.newHashSet(filter));
}
return widgetBuilder.get();
}).collect(toList());
widgetRepository.saveAll(widgets);
widgets.forEach(it -> aclHandler.initAcl(it, user.getUsername(), projectId, it.isShared()));
return widgets;
} catch (IOException e) {
throw new ReportPortalException("Unable to load demo_widgets.json. " + e.getMessage(), e);
}
}
Aggregations