Search in sources :

Example 1 with PatternTemplate

use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.

the class DeleteProjectSettingsHandlerImpl method deletePatternTemplate.

@Override
public OperationCompletionRS deletePatternTemplate(String projectName, ReportPortalUser user, Long id) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    PatternTemplate patternTemplate = patternTemplateRepository.findByIdAndProjectId(id, project.getId()).orElseThrow(() -> new ReportPortalException(ErrorType.PATTERN_TEMPLATE_NOT_FOUND_IN_PROJECT, id, project.getName()));
    PatternTemplateActivityResource before = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
    patternTemplateRepository.deleteById(patternTemplate.getId());
    messageBus.publishActivity(new PatternDeletedEvent(user.getUserId(), user.getUsername(), before));
    return new OperationCompletionRS(Suppliers.formattedSupplier("Pattern template with id = '{}' has been successfully removed.", id).get());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) PatternDeletedEvent(com.epam.ta.reportportal.core.events.activity.PatternDeletedEvent) PatternTemplateActivityResource(com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 2 with PatternTemplate

use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.

the class UpdateProjectSettingsHandlerImpl method updatePatternTemplate.

@Override
public OperationCompletionRS updatePatternTemplate(Long id, String projectName, UpdatePatternTemplateRQ updatePatternTemplateRQ, ReportPortalUser user) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
    PatternTemplate patternTemplate = patternTemplateRepository.findById(id).orElseThrow(() -> new ReportPortalException(ErrorType.PATTERN_TEMPLATE_NOT_FOUND_IN_PROJECT, id, project.getId()));
    final String name = StringUtils.trim(updatePatternTemplateRQ.getName());
    if (!patternTemplate.getName().equalsIgnoreCase(name)) {
        BusinessRule.expect(patternTemplateRepository.existsByProjectIdAndNameIgnoreCase(project.getId(), name), equalTo(false)).verify(ErrorType.RESOURCE_ALREADY_EXISTS, name);
    }
    PatternTemplateActivityResource before = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
    patternTemplate.setName(name);
    patternTemplate.setEnabled(updatePatternTemplateRQ.getEnabled());
    PatternTemplateActivityResource after = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
    messageBus.publishActivity(new PatternUpdatedEvent(user.getUserId(), user.getUsername(), before, after));
    return new OperationCompletionRS(Suppliers.formattedSupplier("Pattern template with ID = '{}' has been successfully updated", id).get());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) PatternTemplateActivityResource(com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PatternUpdatedEvent(com.epam.ta.reportportal.core.events.activity.PatternUpdatedEvent) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 3 with PatternTemplate

use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.

the class PatternTemplateConverterTest method toResourceTest.

@Test
public void toResourceTest() {
    PatternTemplate patternTemplate = get();
    PatternTemplateResource resource = PatternTemplateConverter.TO_RESOURCE.apply(patternTemplate);
    assertEquals(patternTemplate.getId(), resource.getId());
    assertEquals(patternTemplate.getTemplateType().name(), resource.getType());
    assertEquals(patternTemplate.getName(), resource.getName());
    assertEquals(patternTemplate.getValue(), resource.getValue());
    assertEquals(patternTemplate.isEnabled(), resource.getEnabled());
}
Also used : PatternTemplateResource(com.epam.ta.reportportal.ws.model.project.config.pattern.PatternTemplateResource) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with PatternTemplate

use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.

the class PatternTemplateConverterTest method toActivityResourceTest.

@Test
public void toActivityResourceTest() {
    PatternTemplate patternTemplate = get();
    PatternTemplateActivityResource resource = PatternTemplateConverter.TO_ACTIVITY_RESOURCE.apply(patternTemplate);
    assertEquals(patternTemplate.getId(), resource.getId());
    assertEquals(patternTemplate.getProjectId(), resource.getProjectId());
    assertEquals(patternTemplate.getName(), resource.getName());
}
Also used : PatternTemplateActivityResource(com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) Test(org.junit.jupiter.api.Test)

Example 5 with PatternTemplate

use of com.epam.ta.reportportal.entity.pattern.PatternTemplate in project service-api by reportportal.

the class PatternTemplateConverterTest method get.

private PatternTemplate get() {
    PatternTemplate patternTemplate = new PatternTemplate();
    patternTemplate.setId(1L);
    patternTemplate.setProjectId(1L);
    patternTemplate.setTemplateType(PatternTemplateType.STRING);
    patternTemplate.setEnabled(true);
    patternTemplate.setValue("qwe");
    patternTemplate.setName("name");
    return patternTemplate;
}
Also used : PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate)

Aggregations

PatternTemplate (com.epam.ta.reportportal.entity.pattern.PatternTemplate)9 Project (com.epam.ta.reportportal.entity.project.Project)3 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 PatternTemplateActivityResource (com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource)3 Test (org.junit.jupiter.api.Test)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 PatternCreatedEvent (com.epam.ta.reportportal.core.events.activity.PatternCreatedEvent)1 PatternDeletedEvent (com.epam.ta.reportportal.core.events.activity.PatternDeletedEvent)1 PatternUpdatedEvent (com.epam.ta.reportportal.core.events.activity.PatternUpdatedEvent)1 PatternTemplateBuilder (com.epam.ta.reportportal.ws.converter.builders.PatternTemplateBuilder)1 EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)1 CreatePatternTemplateRQ (com.epam.ta.reportportal.ws.model.project.config.pattern.CreatePatternTemplateRQ)1 PatternTemplateResource (com.epam.ta.reportportal.ws.model.project.config.pattern.PatternTemplateResource)1