Search in sources :

Example 6 with EntryCreatedRS

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

the class CreateIntegrationHandlerImpl method createGlobalIntegration.

@Override
public EntryCreatedRS createGlobalIntegration(IntegrationRQ createRequest, String pluginName, ReportPortalUser user) {
    IntegrationType integrationType = integrationTypeRepository.findByName(pluginName).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, pluginName));
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integrationType.getName(), this.basicIntegrationService);
    String integrationName = ofNullable(createRequest.getName()).map(String::toLowerCase).map(name -> {
        validateGlobalIntegrationName(name, integrationType);
        return name;
    }).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_INTEGRATION_NAME, "Integration name should be not null"));
    createRequest.setName(integrationName);
    Integration integration = integrationService.createIntegration(createRequest, integrationType);
    integration.setCreator(user.getUsername());
    integrationService.checkConnection(integration);
    integrationRepository.save(integration);
    return new EntryCreatedRS(integration.getId());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) IntegrationCreatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) CreateIntegrationHandler(com.epam.ta.reportportal.core.integration.CreateIntegrationHandler) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Optional.ofNullable(java.util.Optional.ofNullable) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationTypeRepository(com.epam.ta.reportportal.dao.IntegrationTypeRepository) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationRQ(com.epam.ta.reportportal.ws.model.integration.IntegrationRQ) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) IntegrationUpdatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) IntegrationActivityResource(com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService)

Example 7 with EntryCreatedRS

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

the class CreateIntegrationHandlerImpl method createProjectIntegration.

@Override
public EntryCreatedRS createProjectIntegration(String projectName, IntegrationRQ createRequest, String pluginName, ReportPortalUser user) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    IntegrationType integrationType = integrationTypeRepository.findByName(pluginName).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, pluginName));
    IntegrationService integrationService = integrationServiceMapping.getOrDefault(integrationType.getName(), this.basicIntegrationService);
    String integrationName = ofNullable(createRequest.getName()).map(String::toLowerCase).map(name -> {
        validateProjectIntegrationName(name, integrationType, project);
        return name;
    }).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_INTEGRATION_NAME, "Integration name should be not null"));
    createRequest.setName(integrationName);
    Integration integration = integrationService.createIntegration(createRequest, integrationType);
    integration.setProject(project);
    integration.setCreator(user.getUsername());
    integrationService.checkConnection(integration);
    integrationRepository.save(integration);
    messageBus.publishActivity(new IntegrationCreatedEvent(TO_ACTIVITY_RESOURCE.apply(integration), user.getUserId(), user.getUsername()));
    return new EntryCreatedRS(integration.getId());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) IntegrationCreatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) CreateIntegrationHandler(com.epam.ta.reportportal.core.integration.CreateIntegrationHandler) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Optional.ofNullable(java.util.Optional.ofNullable) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationTypeRepository(com.epam.ta.reportportal.dao.IntegrationTypeRepository) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationRQ(com.epam.ta.reportportal.ws.model.integration.IntegrationRQ) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) IntegrationUpdatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationUpdatedEvent) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) IntegrationActivityResource(com.epam.ta.reportportal.ws.model.activity.IntegrationActivityResource) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService) IntegrationCreatedEvent(com.epam.ta.reportportal.core.events.activity.IntegrationCreatedEvent) Project(com.epam.ta.reportportal.entity.project.Project) Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) IntegrationService(com.epam.ta.reportportal.core.integration.util.IntegrationService)

Example 8 with EntryCreatedRS

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

the class CreatePluginHandlerImpl method uploadPlugin.

@Override
public EntryCreatedRS uploadPlugin(MultipartFile pluginFile) {
    String newPluginFileName = pluginFile.getOriginalFilename();
    BusinessRule.expect(newPluginFileName, StringUtils::isNotBlank).verify(ErrorType.BAD_REQUEST_ERROR, "File name should be not empty.");
    try (InputStream inputStream = pluginFile.getInputStream()) {
        IntegrationType integrationType = pluginBox.uploadPlugin(newPluginFileName, inputStream);
        return new EntryCreatedRS(integrationType.getId());
    } catch (IOException e) {
        throw new ReportPortalException(ErrorType.PLUGIN_UPLOAD_ERROR, "Error during file stream retrieving");
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) InputStream(java.io.InputStream) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) IOException(java.io.IOException) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType)

Example 9 with EntryCreatedRS

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

the class WidgetControllerTest method createWidgetPositive.

@Test
void createWidgetPositive() throws Exception {
    WidgetRQ rq = new WidgetRQ();
    rq.setName("widget");
    rq.setDescription("description");
    rq.setWidgetType("oldLineChart");
    ContentParameters contentParameters = new ContentParameters();
    contentParameters.setContentFields(Collections.singletonList("statistics$executions$passed"));
    contentParameters.setItemsCount(50);
    rq.setFilterIds(Collections.singletonList(3L));
    rq.setContentParameters(contentParameters);
    rq.setShare(true);
    final MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/widget").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON)).andExpect(status().isCreated()).andReturn();
    final EntryCreatedRS entryCreatedRS = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), EntryCreatedRS.class);
    final Optional<Widget> optionalWidget = widgetRepository.findById(entryCreatedRS.getId());
    assertTrue(optionalWidget.isPresent());
    assertEquals("widget", optionalWidget.get().getName());
    assertEquals("description", optionalWidget.get().getDescription());
}
Also used : WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) Widget(com.epam.ta.reportportal.entity.widget.Widget) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) MvcResult(org.springframework.test.web.servlet.MvcResult) ContentParameters(com.epam.ta.reportportal.ws.model.widget.ContentParameters) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 10 with EntryCreatedRS

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

the class DashboardControllerTest method createDashboardPositive.

@Test
void createDashboardPositive() throws Exception {
    CreateDashboardRQ createDashboardRQ = new CreateDashboardRQ();
    createDashboardRQ.setName("dashboard");
    createDashboardRQ.setDescription("description");
    final MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/dashboard").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(createDashboardRQ)).contentType(APPLICATION_JSON)).andExpect(status().isCreated()).andReturn();
    final EntryCreatedRS entryCreatedRS = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), EntryCreatedRS.class);
    final Optional<Dashboard> dashboardOptional = dashboardRepository.findById(entryCreatedRS.getId());
    assertTrue(dashboardOptional.isPresent());
    assertEquals("dashboard", dashboardOptional.get().getName());
    assertEquals("description", dashboardOptional.get().getDescription());
}
Also used : Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) CreateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.CreateDashboardRQ) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

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