Search in sources :

Example 11 with EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS 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 12 with EntryCreatedRS

use of com.epam.ta.reportportal.ws.model.EntryCreatedRS in project service-api by reportportal.

the class CreateProjectSettingsHandlerImpl method createPatternTemplate.

@Override
public EntryCreatedRS createPatternTemplate(String projectName, CreatePatternTemplateRQ createPatternTemplateRQ, ReportPortalUser user) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    PatternTemplate patternTemplate = createPatternTemplateMapping.get(PatternTemplateType.fromString(createPatternTemplateRQ.getType()).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, Suppliers.formattedSupplier("Unknown pattern template type - '{}'", createPatternTemplateRQ.getType()).get()))).createPatternTemplate(project.getId(), createPatternTemplateRQ);
    messageBus.publishActivity(new PatternCreatedEvent(user.getUserId(), user.getUsername(), PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate)));
    return new EntryCreatedRS(patternTemplate.getId());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PatternCreatedEvent(com.epam.ta.reportportal.core.events.activity.PatternCreatedEvent) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate)

Aggregations

EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)12 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)5 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 Project (com.epam.ta.reportportal.entity.project.Project)4 Test (org.junit.jupiter.api.Test)4 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)3 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)3 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)3 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)3 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 Optional.ofNullable (java.util.Optional.ofNullable)3 BooleanUtils (org.apache.commons.lang3.BooleanUtils)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)2 IntegrationCreatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent)2 IntegrationUpdatedEvent (com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent)2 CreateIntegrationHandler (com.epam.ta.reportportal.core.integration.CreateIntegrationHandler)2 IntegrationService (com.epam.ta.reportportal.core.integration.util.IntegrationService)2 IntegrationRepository (com.epam.ta.reportportal.dao.IntegrationRepository)2