diff --git a/build.gradle b/build.gradle index 2a76af1..354968f 100644 --- a/build.gradle +++ b/build.gradle @@ -36,8 +36,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:a47f5cf' + annotationProcessor 'com.github.reportportal:service-api:a47f5cf' } implementation 'jakarta.el:jakarta.el-api:6.0.1' implementation 'org.glassfish:jakarta.el:4.0.2' diff --git a/src/main/java/com/epam/reportportal/extension/jira/CloudJiraExtension.java b/src/main/java/com/epam/reportportal/extension/jira/CloudJiraExtension.java index 6608acc..7b97eac 100644 --- a/src/main/java/com/epam/reportportal/extension/jira/CloudJiraExtension.java +++ b/src/main/java/com/epam/reportportal/extension/jira/CloudJiraExtension.java @@ -22,8 +22,7 @@ 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.PluginEvent; -import com.epam.reportportal.extension.event.StartLaunchEvent; +import com.epam.reportportal.core.events.domain.PluginUploadedEvent; import com.epam.reportportal.extension.jira.command.GetIssueCommand; import com.epam.reportportal.extension.jira.command.GetIssueFieldsCommand; import com.epam.reportportal.extension.jira.command.GetIssueTypesCommand; @@ -34,16 +33,13 @@ import com.epam.reportportal.extension.jira.command.UserSearchCommand; import com.epam.reportportal.extension.jira.command.utils.CloudJiraClientProvider; import com.epam.reportportal.extension.jira.command.utils.JIRATicketDescriptionService; -import com.epam.reportportal.extension.jira.event.launch.StartLaunchEventListener; -import com.epam.reportportal.extension.jira.event.plugin.PluginEventHandlerFactory; -import com.epam.reportportal.extension.jira.event.plugin.PluginEventListener; +import com.epam.reportportal.extension.jira.event.plugin.PluginLoadedEventListener; import com.epam.reportportal.extension.jira.info.impl.PluginInfoProviderImpl; import com.epam.reportportal.extension.jira.utils.MemoizingSupplier; import com.epam.reportportal.extension.util.RequestEntityConverter; import com.epam.reportportal.infrastructure.persistence.binary.DataStoreService; 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.LogRepository; import com.epam.reportportal.infrastructure.persistence.dao.ProjectRepository; import com.epam.reportportal.infrastructure.persistence.dao.TestItemRepository; @@ -98,8 +94,7 @@ public class CloudJiraExtension implements ReportPortalExtensionPoint, Disposabl private final ObjectMapper objectMapper; private final RequestEntityConverter requestEntityConverter; - private final Supplier> pluginLoadedListenerSupplier; - private final Supplier> startLaunchEventListenerSupplier; + private final Supplier> pluginLoadedListenerSupplier; private final Supplier cloudJiraClientProviderSupplier; @@ -122,9 +117,6 @@ public class CloudJiraExtension implements ReportPortalExtensionPoint, Disposabl @Autowired private OrganizationRepositoryCustom organizationRepository; - @Autowired - private LaunchRepository launchRepository; - @Autowired private LogRepository logRepository; @@ -143,12 +135,10 @@ public CloudJiraExtension(Map initParams) { .orElse(""); objectMapper = configureObjectMapper(); - pluginLoadedListenerSupplier = new MemoizingSupplier<>(() -> new PluginEventListener( - PLUGIN_ID, new PluginEventHandlerFactory(integrationTypeRepository, integrationRepository, + pluginLoadedListenerSupplier = new MemoizingSupplier<>(() -> new PluginLoadedEventListener( + PLUGIN_ID, integrationTypeRepository, integrationRepository, new PluginInfoProviderImpl(resourcesDir, BINARY_DATA_PROPERTIES_FILE_ID) - ))); - startLaunchEventListenerSupplier = - new MemoizingSupplier<>(() -> new StartLaunchEventListener(launchRepository)); + )); requestEntityConverter = new RequestEntityConverter(objectMapper); @@ -204,7 +194,6 @@ private void initListeners() { ApplicationEventMulticaster.class ); applicationEventMulticaster.addApplicationListener(pluginLoadedListenerSupplier.get()); - applicationEventMulticaster.addApplicationListener(startLaunchEventListenerSupplier.get()); } @Override @@ -218,7 +207,6 @@ private void removeListeners() { ApplicationEventMulticaster.class ); applicationEventMulticaster.removeApplicationListener(pluginLoadedListenerSupplier.get()); - applicationEventMulticaster.removeApplicationListener(startLaunchEventListenerSupplier.get()); } private Map> getCommonCommands() { diff --git a/src/main/java/com/epam/reportportal/extension/jira/event/EventHandlerFactory.java b/src/main/java/com/epam/reportportal/extension/jira/event/EventHandlerFactory.java deleted file mode 100644 index 0e1fdac..0000000 --- a/src/main/java/com/epam/reportportal/extension/jira/event/EventHandlerFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2021 EPAM Systems - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.epam.reportportal.extension.jira.event; - -import com.epam.reportportal.extension.jira.event.handler.EventHandler; - -/** - * @author Ivan Budayeu - */ -public interface EventHandlerFactory { - - EventHandler getEventHandler(String key); -} diff --git a/src/main/java/com/epam/reportportal/extension/jira/event/handler/EventHandler.java b/src/main/java/com/epam/reportportal/extension/jira/event/handler/EventHandler.java deleted file mode 100644 index 654d812..0000000 --- a/src/main/java/com/epam/reportportal/extension/jira/event/handler/EventHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2021 EPAM Systems - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.epam.reportportal.extension.jira.event.handler; - -/** - * @author Ivan Budayeu - */ -public interface EventHandler { - - void handle(T event); -} diff --git a/src/main/java/com/epam/reportportal/extension/jira/event/launch/StartLaunchEventListener.java b/src/main/java/com/epam/reportportal/extension/jira/event/launch/StartLaunchEventListener.java deleted file mode 100644 index 2d3d306..0000000 --- a/src/main/java/com/epam/reportportal/extension/jira/event/launch/StartLaunchEventListener.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2021 EPAM Systems - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.epam.reportportal.extension.jira.event.launch; - -import com.epam.reportportal.extension.event.StartLaunchEvent; -import com.epam.reportportal.infrastructure.persistence.dao.LaunchRepository; -import org.springframework.context.ApplicationListener; - -/** - * @author Ivan Budayeu - */ -public class StartLaunchEventListener implements ApplicationListener { - - private final LaunchRepository launchRepository; - - public StartLaunchEventListener(LaunchRepository launchRepository) { - this.launchRepository = launchRepository; - } - - @Override - public void onApplicationEvent(StartLaunchEvent event) { - - } -} diff --git a/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginEventHandlerFactory.java b/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginEventHandlerFactory.java deleted file mode 100644 index fa176a5..0000000 --- a/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginEventHandlerFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2021 EPAM Systems - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.epam.reportportal.extension.jira.event.plugin; - -import com.epam.reportportal.extension.event.PluginEvent; -import com.epam.reportportal.extension.jira.event.EventHandlerFactory; -import com.epam.reportportal.extension.jira.event.handler.EventHandler; -import com.epam.reportportal.extension.jira.event.handler.plugin.PluginLoadedEventHandler; -import com.epam.reportportal.extension.jira.info.PluginInfoProvider; -import com.epam.reportportal.infrastructure.persistence.dao.IntegrationRepository; -import com.epam.reportportal.infrastructure.persistence.dao.IntegrationTypeRepository; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Ivan Budayeu - */ -public class PluginEventHandlerFactory implements EventHandlerFactory { - - public static final String LOAD_KEY = "load"; - - private final Map> eventHandlerMapping; - - public PluginEventHandlerFactory(IntegrationTypeRepository integrationTypeRepository, - IntegrationRepository integrationRepository, - PluginInfoProvider pluginInfoProvider) { - this.eventHandlerMapping = new HashMap<>(); - this.eventHandlerMapping.put(LOAD_KEY, - new PluginLoadedEventHandler(integrationTypeRepository, integrationRepository, pluginInfoProvider) - ); - } - - @Override - public EventHandler getEventHandler(String key) { - return eventHandlerMapping.get(key); - } -} diff --git a/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginEventListener.java b/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginEventListener.java deleted file mode 100644 index 10c0f49..0000000 --- a/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginEventListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2021 EPAM Systems - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.epam.reportportal.extension.jira.event.plugin; - -import static java.util.Optional.ofNullable; - -import com.epam.reportportal.extension.event.PluginEvent; -import com.epam.reportportal.extension.jira.event.EventHandlerFactory; -import org.springframework.context.ApplicationListener; - -/** - * @author Ivan Budayeu - */ -public class PluginEventListener implements ApplicationListener { - - private final String pluginId; - private final EventHandlerFactory pluginEventEventHandlerFactory; - - public PluginEventListener(String pluginId, EventHandlerFactory pluginEventEventHandlerFactory) { - this.pluginId = pluginId; - this.pluginEventEventHandlerFactory = pluginEventEventHandlerFactory; - } - - @Override - public void onApplicationEvent(PluginEvent event) { - if (supports(event)) { - ofNullable(pluginEventEventHandlerFactory.getEventHandler(event.getType())).ifPresent( - pluginEventEventHandler -> pluginEventEventHandler - .handle(event)); - } - } - - private boolean supports(PluginEvent event) { - return pluginId.equals(event.getPluginId()); - } -} diff --git a/src/main/java/com/epam/reportportal/extension/jira/event/handler/plugin/PluginLoadedEventHandler.java b/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginLoadedEventListener.java similarity index 69% rename from src/main/java/com/epam/reportportal/extension/jira/event/handler/plugin/PluginLoadedEventHandler.java rename to src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginLoadedEventListener.java index 93fee92..9308067 100644 --- a/src/main/java/com/epam/reportportal/extension/jira/event/handler/plugin/PluginLoadedEventHandler.java +++ b/src/main/java/com/epam/reportportal/extension/jira/event/plugin/PluginLoadedEventListener.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.epam.reportportal.extension.jira.event.handler.plugin; +package com.epam.reportportal.extension.jira.event.plugin; -import com.epam.reportportal.extension.event.PluginEvent; -import com.epam.reportportal.extension.jira.event.handler.EventHandler; +import com.epam.reportportal.core.events.domain.PluginUploadedEvent; import com.epam.reportportal.extension.jira.info.PluginInfoProvider; import com.epam.reportportal.infrastructure.persistence.dao.IntegrationRepository; import com.epam.reportportal.infrastructure.persistence.dao.IntegrationTypeRepository; @@ -26,32 +25,48 @@ import java.time.Instant; import java.util.HashMap; import java.util.List; +import org.springframework.context.ApplicationListener; /** + * Event listener for plugin loaded events. + * Updates integration type information when the Jira Cloud plugin is uploaded. + * * @author Ivan Budayeu */ -public class PluginLoadedEventHandler implements EventHandler { +public class PluginLoadedEventListener implements ApplicationListener { + private final String pluginId; private final IntegrationTypeRepository integrationTypeRepository; private final IntegrationRepository integrationRepository; private final PluginInfoProvider pluginInfoProvider; - public PluginLoadedEventHandler(IntegrationTypeRepository integrationTypeRepository, + public PluginLoadedEventListener(String pluginId, + IntegrationTypeRepository integrationTypeRepository, IntegrationRepository integrationRepository, PluginInfoProvider pluginInfoProvider) { + this.pluginId = pluginId; this.integrationTypeRepository = integrationTypeRepository; this.integrationRepository = integrationRepository; this.pluginInfoProvider = pluginInfoProvider; } @Override - public void handle(PluginEvent event) { - integrationTypeRepository.findByName(event.getPluginId()).ifPresent(integrationType -> { - createIntegration(event.getPluginId(), integrationType); + public void onApplicationEvent(PluginUploadedEvent event) { + if (!supports(event)) { + return; + } + + String eventPluginId = event.getPluginActivityResource().getName(); + integrationTypeRepository.findByName(eventPluginId).ifPresent(integrationType -> { + createIntegration(eventPluginId, integrationType); integrationTypeRepository.save(pluginInfoProvider.provide(integrationType)); }); } + private boolean supports(PluginUploadedEvent event) { + return pluginId.equals(event.getPluginActivityResource().getName()); + } + private void createIntegration(String name, IntegrationType integrationType) { List integrations = integrationRepository.findAllGlobalByType(integrationType); if (integrations.isEmpty()) { @@ -65,5 +80,4 @@ private void createIntegration(String name, IntegrationType integrationType) { integrationRepository.save(integration); } } - }