Search in sources :

Example 6 with WidgetBuilder

use of com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder in project service-api by reportportal.

the class CreateWidgetHandlerImpl method createWidget.

@Override
public EntryCreatedRS createWidget(WidgetRQ createWidgetRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    List<UserFilter> userFilter = getUserFilters(createWidgetRQ.getFilterIds(), projectDetails.getProjectId(), user.getUsername());
    BusinessRule.expect(widgetRepository.existsByNameAndOwnerAndProjectId(createWidgetRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, createWidgetRQ.getName());
    Widget widget = new WidgetBuilder().addWidgetRq(createWidgetRQ).addProject(projectDetails.getProjectId()).addFilters(userFilter).addOwner(user.getUsername()).get();
    widgetContentFieldsValidator.validate(widget);
    widgetPostProcessors.stream().filter(widgetPostProcessor -> widgetPostProcessor.supports(widget)).forEach(widgetPostProcessor -> widgetPostProcessor.postProcess(widget));
    widgetRepository.save(widget);
    aclHandler.initAcl(widget, user.getUsername(), projectDetails.getProjectId(), BooleanUtils.isTrue(createWidgetRQ.getShare()));
    if (widget.isShared()) {
        ofNullable(widget.getFilters()).ifPresent(filters -> updateUserFilterHandler.updateSharing(filters, projectDetails.getProjectId(), widget.isShared()));
    }
    messageBus.publishActivity(new WidgetCreatedEvent(TO_ACTIVITY_RESOURCE.apply(widget), user.getUserId(), user.getUsername()));
    return new EntryCreatedRS(widget.getId());
}
Also used : CreateWidgetHandler(com.epam.ta.reportportal.core.widget.CreateWidgetHandler) Autowired(org.springframework.beans.factory.annotation.Autowired) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) BooleanUtils(org.apache.commons.lang3.BooleanUtils) WidgetCreatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetCreatedEvent) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) ProjectFilter(com.epam.ta.reportportal.commons.querygen.ProjectFilter) CRITERIA_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID) WidgetPostProcessor(com.epam.ta.reportportal.core.widget.content.updater.WidgetPostProcessor) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Condition(com.epam.ta.reportportal.commons.querygen.Condition) Pageable(org.springframework.data.domain.Pageable) Predicates.not(com.epam.ta.reportportal.commons.Predicates.not) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.WidgetConverter.TO_ACTIVITY_RESOURCE) ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) WidgetValidator(com.epam.ta.reportportal.core.widget.content.updater.validator.WidgetValidator) Collectors(java.util.stream.Collectors) WidgetRepository(com.epam.ta.reportportal.dao.WidgetRepository) List(java.util.List) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) UpdateUserFilterHandler(com.epam.ta.reportportal.core.filter.UpdateUserFilterHandler) UserFilterRepository(com.epam.ta.reportportal.dao.UserFilterRepository) Widget(com.epam.ta.reportportal.entity.widget.Widget) Collections(java.util.Collections) WidgetCreatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetCreatedEvent) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Widget(com.epam.ta.reportportal.entity.widget.Widget) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)

Example 7 with WidgetBuilder

use of com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder in project service-api by reportportal.

the class HealthCheckTableReadyContentResolverTest method getContentTest.

@Test
void getContentTest() {
    WidgetRQ widgetRQ = new WidgetRQ();
    widgetRQ.setName("name");
    widgetRQ.setWidgetType("componentHealthCheckTable");
    ContentParameters contentParameters = new ContentParameters();
    contentParameters.setContentFields(new ArrayList<>());
    contentParameters.setItemsCount(600);
    Map<String, Object> options = new HashMap<>();
    contentParameters.setWidgetOptions(options);
    widgetRQ.setContentParameters(contentParameters);
    widgetRQ.setFilterIds(Collections.singletonList(1L));
    widgetRQ.setDescription("descr");
    SortEntry sortEntry = new SortEntry();
    sortEntry.setSortingColumn("passingRate");
    Widget widget = new WidgetBuilder().addWidgetRq(widgetRQ).addOption("viewName", "name").addOption("sort", sortEntry).addOption(ATTRIBUTE_KEYS, Lists.newArrayList("k1", "k2")).get();
    HealthCheckTableContent content = new HealthCheckTableContent();
    content.setAttributeValue("v2");
    content.setPassingRate(50.00);
    HashMap<String, Integer> statistics = new HashMap<>();
    statistics.put(EXECUTIONS_PASSED, 5);
    statistics.put(EXECUTIONS_TOTAL, 10);
    content.setStatistics(statistics);
    when(widgetContentRepository.componentHealthCheckTable(any())).thenReturn(Lists.newArrayList(content));
    MultiValueMap<String, String> values = new LinkedMultiValueMap<>();
    values.put(ATTRIBUTES, Lists.newArrayList("v1"));
    Map<String, Object> result = contentResolver.loadContent(widget, values);
    List<HealthCheckTableContent> resultList = (List<HealthCheckTableContent>) result.get("result");
    HealthCheckTableContent tableContent = resultList.get(0);
    assertEquals(content.getPassingRate(), tableContent.getPassingRate());
    assertEquals(content.getAttributeValue(), tableContent.getAttributeValue());
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Widget(com.epam.ta.reportportal.entity.widget.Widget) ContentParameters(com.epam.ta.reportportal.ws.model.widget.ContentParameters) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) HealthCheckTableContent(com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableContent) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) SortEntry(com.epam.ta.reportportal.ws.model.widget.SortEntry) Test(org.junit.jupiter.api.Test)

Example 8 with WidgetBuilder

use of com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder 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);
    }
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) ProjectFilter(com.epam.ta.reportportal.commons.querygen.ProjectFilter) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) Value(org.springframework.beans.factory.annotation.Value) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) Service(org.springframework.stereotype.Service) PROJECT_NOT_FOUND(com.epam.ta.reportportal.ws.model.ErrorType.PROJECT_NOT_FOUND) Condition(com.epam.ta.reportportal.commons.querygen.Condition) CRITERIA_NAME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_NAME) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Resource(org.springframework.core.io.Resource) ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) ObjectType(com.epam.ta.reportportal.entity.filter.ObjectType) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) DashboardWidgetId(com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId) Filter(com.epam.ta.reportportal.commons.querygen.Filter) CRITERIA_ITEM_ATTRIBUTE_VALUE(com.epam.ta.reportportal.commons.querygen.constant.ItemAttributeConstant.CRITERIA_ITEM_ATTRIBUTE_VALUE) com.epam.ta.reportportal.dao(com.epam.ta.reportportal.dao) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IOException(java.io.IOException) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) FilterSort(com.epam.ta.reportportal.entity.filter.FilterSort) Sets(com.google.common.collect.Sets) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Optional(java.util.Optional) Widget(com.epam.ta.reportportal.entity.widget.Widget) Transactional(org.springframework.transaction.annotation.Transactional) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType)

Aggregations

WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)8 Widget (com.epam.ta.reportportal.entity.widget.Widget)6 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)4 WidgetRQ (com.epam.ta.reportportal.ws.model.widget.WidgetRQ)3 ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 Condition (com.epam.ta.reportportal.commons.querygen.Condition)2 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)2 WidgetType (com.epam.ta.reportportal.entity.widget.WidgetType)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Pageable (org.springframework.data.domain.Pageable)2 Service (org.springframework.stereotype.Service)2 Predicates.not (com.epam.ta.reportportal.commons.Predicates.not)1 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)1 CRITERIA_ID (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID)1 CRITERIA_NAME (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_NAME)1