Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {
implementation 'com.epam.reportportal:service-api'
annotationProcessor 'com.epam.reportportal:service-api'
} else {
implementation 'com.github.reportportal:service-api:3e34a90'
annotationProcessor 'com.github.reportportal:service-api:3e34a90'
implementation 'com.github.reportportal:service-api:4a137a7'
annotationProcessor 'com.github.reportportal:service-api:4a137a7'
}

compileOnly "org.projectlombok:lombok:${lombokVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@

package com.epam.reportportal.extension.slack;

import com.epam.reportportal.core.events.domain.PluginUploadedEvent;
import com.epam.reportportal.extension.CommonPluginCommand;
import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.extension.ReportPortalExtensionPoint;
import com.epam.reportportal.extension.common.IntegrationTypeProperties;
import com.epam.reportportal.extension.event.LaunchFinishedPluginEvent;
import com.epam.reportportal.extension.event.PluginEvent;
import com.epam.reportportal.extension.event.LaunchFinishedNotificationEvent;
import com.epam.reportportal.extension.slack.binary.JsonObjectLoader;
import com.epam.reportportal.extension.slack.binary.MessageTemplateStore;
import com.epam.reportportal.extension.slack.event.launch.SlackLaunchFinishEventListener;
import com.epam.reportportal.extension.slack.event.launch.resolver.AttachmentResolver;
import com.epam.reportportal.extension.slack.event.launch.resolver.SenderCaseMatcher;
import com.epam.reportportal.extension.slack.event.plugin.PluginEventHandlerFactory;
import com.epam.reportportal.extension.slack.event.plugin.PluginEventListener;
import com.epam.reportportal.extension.slack.event.plugin.PluginLoadedEventHandler;
import com.epam.reportportal.extension.slack.factory.PropertyCollectorFactory;
import com.epam.reportportal.extension.slack.info.impl.PluginInfoProviderImpl;
import com.epam.reportportal.extension.slack.utils.MemoizingSupplier;
import com.epam.reportportal.infrastructure.persistence.dao.IntegrationRepository;
import com.epam.reportportal.infrastructure.persistence.dao.IntegrationTypeRepository;
import com.epam.reportportal.infrastructure.persistence.dao.LaunchRepository;
import com.epam.reportportal.infrastructure.persistence.dao.ProjectRepository;
Expand Down Expand Up @@ -96,9 +94,9 @@ public class SlackPluginExtension implements ReportPortalExtensionPoint, Disposa

private final String resourcesDir;

private final Supplier<ApplicationListener<PluginEvent>> pluginLoadedListener;
private final Supplier<ApplicationListener<PluginUploadedEvent>> pluginLoadedListener;

private final Supplier<ApplicationListener<LaunchFinishedPluginEvent>> launchFinishEventListenerSupplier;
private final Supplier<ApplicationListener<LaunchFinishedNotificationEvent>> launchFinishedNotificationEventListenerSupplier;

private final Supplier<MessageTemplateStore> messageTemplateStoreSupplier;

Expand All @@ -109,9 +107,6 @@ public class SlackPluginExtension implements ReportPortalExtensionPoint, Disposa
@Autowired
private IntegrationTypeRepository integrationTypeRepository;

@Autowired
private IntegrationRepository integrationRepository;

@Autowired
private TestItemRepository testItemRepository;

Expand Down Expand Up @@ -142,20 +137,19 @@ public SlackPluginExtension(Map<String, Object> initParams) {
() -> new MessageTemplateStore(resourcesDir));

pluginLoadedListener = new MemoizingSupplier<>(
() -> new PluginEventListener(PLUGIN_ID,
new PluginEventHandlerFactory(integrationTypeRepository,
new PluginInfoProviderImpl(resourcesDir, BINARY_DATA_PROPERTIES_FILE_ID)
)
() -> new PluginLoadedEventHandler(PLUGIN_ID, integrationTypeRepository,
new PluginInfoProviderImpl(resourcesDir, BINARY_DATA_PROPERTIES_FILE_ID)
));

senderCaseMatcher = new MemoizingSupplier<>(() -> new SenderCaseMatcher(testItemRepository));

attachmentResolverSupplier = new MemoizingSupplier<>(() -> new AttachmentResolver(
jsonObjectLoader, messageTemplateStoreSupplier.get(), new PropertyCollectorFactory()));

launchFinishEventListenerSupplier = new MemoizingSupplier<>(
launchFinishedNotificationEventListenerSupplier = new MemoizingSupplier<>(
() -> new SlackLaunchFinishEventListener(projectRepository,
launchRepository, senderCaseMatcher.get(), attachmentResolverSupplier.get(), restTemplate));
launchRepository, senderCaseMatcher.get(), attachmentResolverSupplier.get(),
restTemplate));
}

@PostConstruct
Expand All @@ -170,7 +164,8 @@ private void initListeners() {
ApplicationEventMulticaster.class
);
applicationEventMulticaster.addApplicationListener(pluginLoadedListener.get());
applicationEventMulticaster.addApplicationListener(launchFinishEventListenerSupplier.get());
applicationEventMulticaster.addApplicationListener(
launchFinishedNotificationEventListenerSupplier.get());
}

private void initScripts() throws IOException {
Expand All @@ -194,7 +189,8 @@ private void removeListeners() {
ApplicationEventMulticaster.class
);
applicationEventMulticaster.removeApplicationListener(pluginLoadedListener.get());
applicationEventMulticaster.removeApplicationListener(launchFinishEventListenerSupplier.get());
applicationEventMulticaster.removeApplicationListener(
launchFinishedNotificationEventListenerSupplier.get());
}

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.epam.reportportal.extension.slack.event.launch;

import com.epam.reportportal.extension.event.LaunchFinishedPluginEvent;
import com.epam.reportportal.extension.event.LaunchFinishedNotificationEvent;
import com.epam.reportportal.extension.slack.event.launch.resolver.AttachmentResolver;
import com.epam.reportportal.extension.slack.event.launch.resolver.SenderCaseMatcher;
import com.epam.reportportal.infrastructure.persistence.dao.LaunchRepository;
Expand All @@ -39,9 +39,10 @@
* @author <a href="mailto:andrei_piankouski@epam.com">Andrei Piankouski</a>
*/
public class SlackLaunchFinishEventListener implements
ApplicationListener<LaunchFinishedPluginEvent> {
ApplicationListener<LaunchFinishedNotificationEvent> {

private static final Logger LOGGER = LoggerFactory.getLogger(SlackLaunchFinishEventListener.class);
private static final Logger LOGGER = LoggerFactory.getLogger(
SlackLaunchFinishEventListener.class);

public final static String SLACK_NOTIFICATION_ATTRIBUTE = "notifications.slack.enabled";

Expand Down Expand Up @@ -71,11 +72,11 @@ public SlackLaunchFinishEventListener(
}

@Override
public void onApplicationEvent(LaunchFinishedPluginEvent event) {
public void onApplicationEvent(LaunchFinishedNotificationEvent event) {
try {
Project project = getProject(event.getProjectId());
if (isNotificationsEnabled(project)) {
Launch launch = getLaunch(event.getSource());
Launch launch = getLaunch(event.getLaunchId());
processSenderCases(project, launch, event.getLaunchLink());
}
} catch (Exception e) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.epam.reportportal.extension.slack.event.plugin;

import com.epam.reportportal.core.events.domain.PluginUploadedEvent;
import com.epam.reportportal.extension.slack.info.PluginInfoProvider;
import com.epam.reportportal.infrastructure.persistence.dao.IntegrationTypeRepository;
import org.springframework.context.ApplicationListener;

/**
* @author Andrei Piankouski
*/
public class PluginLoadedEventHandler implements ApplicationListener<PluginUploadedEvent> {

private final String pluginId;
private final IntegrationTypeRepository integrationTypeRepository;
private final PluginInfoProvider pluginInfoProvider;

public PluginLoadedEventHandler(String pluginId,
IntegrationTypeRepository integrationTypeRepository,
PluginInfoProvider pluginInfoProvider) {
this.pluginId = pluginId;
this.integrationTypeRepository = integrationTypeRepository;
this.pluginInfoProvider = pluginInfoProvider;
}

@Override
public void onApplicationEvent(PluginUploadedEvent event) {
if (!supports(event)) {
return;
}

String eventPluginId = event.getPluginActivityResource().getName();
integrationTypeRepository.findByName(eventPluginId).ifPresent(integrationType -> {
integrationTypeRepository.save(pluginInfoProvider.provide(integrationType));
});
}

private boolean supports(PluginUploadedEvent event) {
return pluginId.equals(event.getPluginActivityResource().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.epam.reportportal.extension.event.LaunchFinishedPluginEvent;
import com.epam.reportportal.extension.event.LaunchFinishedNotificationEvent;
import com.epam.reportportal.extension.slack.event.launch.resolver.AttachmentResolver;
import com.epam.reportportal.extension.slack.event.launch.resolver.SenderCaseMatcher;
import com.epam.reportportal.extension.slack.utils.MockData;
Expand Down Expand Up @@ -77,7 +77,7 @@ void sendNotificationPositive() throws URISyntaxException {
.thenReturn(new URI("http://localhost:8080"));

slackLaunchFinishEventListener.onApplicationEvent(
new LaunchFinishedPluginEvent(1L, 10L, LAUNCH_LINK));
new LaunchFinishedNotificationEvent(1L, 10L, LAUNCH_LINK));

verify(restTemplate, times(1)).postForLocation(anyString(), anyString());

Expand Down