Search in sources :

Example 1 with WidgetBuilder

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

the class ComponentHealthCheckTableEventHandlerTest method getWidget.

private Widget getWidget() {
    Widget widget = new Widget();
    widget.setId(1L);
    widget.setWidgetType("componentHealthCheckTable");
    return new WidgetBuilder(widget).addProject(1L).get();
}
Also used : Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)

Example 2 with WidgetBuilder

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

the class AbstractViewGenerator method generate.

@Transactional
public void generate(boolean refresh, String viewName, Widget widget, Filter launchesFilter, Sort launchesSort, MultiValueMap<String, String> params) {
    try {
        LOGGER.debug("Widget {} - {}. Generation started", widget.getWidgetType(), widget.getId());
        generateView(refresh, viewName, widget, launchesFilter, launchesSort, params);
        LOGGER.debug("Widget {} - {}. Generation finished", widget.getWidgetType(), widget.getId());
        widgetRepository.save(new WidgetBuilder(widget).addOption(STATE, WidgetState.READY.getValue()).addOption(VIEW_NAME, viewName).addOption(LAST_REFRESH, Date.from(LocalDateTime.now().atZone(ZoneOffset.UTC).toInstant())).get());
        LOGGER.debug("Widget {} - {}. State updated to: {}", widget.getWidgetType(), widget.getId(), WidgetOptionUtil.getValueByKey(STATE, widget.getWidgetOptions()));
    } catch (Exception exc) {
        LOGGER.error("Error during view creation: " + exc.getMessage());
        widgetRepository.save(new WidgetBuilder(widget).addOption(STATE, WidgetState.FAILED.getValue()).get());
        LOGGER.error("Generation failed. Widget {} - {}. State updated to: {}", widget.getWidgetType(), widget.getId(), WidgetOptionUtil.getValueByKey(STATE, widget.getWidgetOptions()));
    }
}
Also used : WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with WidgetBuilder

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

the class CreatedMaterializedWidgetStateHandler method handleWidgetState.

@Override
public Map<String, Object> handleWidgetState(Widget widget, MultiValueMap<String, String> params) {
    widgetRepository.save(new WidgetBuilder(widget).addOption(STATE, WidgetState.RENDERING.getValue()).get());
    eventPublisher.publishEvent(new GenerateWidgetViewEvent(widget.getId(), params));
    return emptyMap();
}
Also used : GenerateWidgetViewEvent(com.epam.ta.reportportal.core.events.widget.GenerateWidgetViewEvent) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)

Example 4 with WidgetBuilder

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

the class GetWidgetHandlerImpl method getWidgetPreview.

@Override
public Map<String, ?> getWidgetPreview(WidgetPreviewRQ previewRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    WidgetType widgetType = WidgetType.findByName(previewRQ.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_REQUEST, formattedSupplier("Unsupported widget type '{}'", previewRQ.getWidgetType())));
    List<UserFilter> userFilter = null;
    if (CollectionUtils.isNotEmpty(previewRQ.getFilterIds())) {
        userFilter = getPermittedFilters(previewRQ.getFilterIds().toArray(Long[]::new), projectDetails, user);
    }
    if (!unfilteredWidgetTypes.contains(widgetType) && CollectionUtils.isEmpty(userFilter)) {
        return Collections.emptyMap();
    }
    Widget widget = new WidgetBuilder().addWidgetPreviewRq(previewRQ).addProject(projectDetails.getProjectId()).addFilters(userFilter).get();
    if (widgetType.isSupportMultilevelStructure()) {
        return multilevelLoadContentStrategy.get(widgetType).loadContent(Lists.newArrayList(widget.getContentFields()), buildFilterStrategyMapping.get(widgetType).buildFilter(widget), widget.getWidgetOptions(), null, null, widget.getItemsCount());
    } else {
        return loadContentStrategy.get(widgetType).loadContent(Lists.newArrayList(widget.getContentFields()), buildFilterStrategyMapping.get(widgetType).buildFilter(widget), widget.getWidgetOptions(), widget.getItemsCount());
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)

Example 5 with WidgetBuilder

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

the class UpdateWidgetHandlerImpl method updateWidget.

@Override
public OperationCompletionRS updateWidget(Long widgetId, WidgetRQ updateRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Widget widget = getShareableEntityHandler.getAdministrated(widgetId, projectDetails);
    widgetContentFieldsValidator.validate(widget);
    if (!widget.getName().equals(updateRQ.getName())) {
        BusinessRule.expect(widgetRepository.existsByNameAndOwnerAndProjectId(updateRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, updateRQ.getName());
    }
    WidgetActivityResource before = TO_ACTIVITY_RESOURCE.apply(widget);
    List<UserFilter> userFilter = getUserFilters(updateRQ.getFilterIds(), projectDetails.getProjectId(), user.getUsername());
    String widgetOptionsBefore = parseWidgetOptions(widget);
    updateSharing(widget, projectDetails.getProjectId(), updateRQ.getShare());
    widget = new WidgetBuilder(widget).addWidgetRq(updateRQ).addFilters(userFilter).get();
    widgetRepository.save(widget);
    messageBus.publishActivity(new WidgetUpdatedEvent(before, TO_ACTIVITY_RESOURCE.apply(widget), widgetOptionsBefore, parseWidgetOptions(widget), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("Widget with ID = '" + widget.getId() + "' successfully updated.");
}
Also used : WidgetActivityResource(com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource) WidgetUpdatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetUpdatedEvent) Widget(com.epam.ta.reportportal.entity.widget.Widget) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

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