Search in sources :

Example 1 with WidgetCreatedEvent

use of com.epam.ta.reportportal.core.events.activity.WidgetCreatedEvent 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)

Aggregations

ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)1 Predicates.not (com.epam.ta.reportportal.commons.Predicates.not)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 Condition (com.epam.ta.reportportal.commons.querygen.Condition)1 Filter (com.epam.ta.reportportal.commons.querygen.Filter)1 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)1 CRITERIA_ID (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID)1 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 WidgetCreatedEvent (com.epam.ta.reportportal.core.events.activity.WidgetCreatedEvent)1 UpdateUserFilterHandler (com.epam.ta.reportportal.core.filter.UpdateUserFilterHandler)1 CreateWidgetHandler (com.epam.ta.reportportal.core.widget.CreateWidgetHandler)1 WidgetPostProcessor (com.epam.ta.reportportal.core.widget.content.updater.WidgetPostProcessor)1 WidgetValidator (com.epam.ta.reportportal.core.widget.content.updater.validator.WidgetValidator)1 UserFilterRepository (com.epam.ta.reportportal.dao.UserFilterRepository)1 WidgetRepository (com.epam.ta.reportportal.dao.WidgetRepository)1 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)1 Widget (com.epam.ta.reportportal.entity.widget.Widget)1 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)1 TO_ACTIVITY_RESOURCE (com.epam.ta.reportportal.ws.converter.converters.WidgetConverter.TO_ACTIVITY_RESOURCE)1