From a64c48e82bff992cb56afac0ded60621b1d5a17f Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Wed, 3 Jun 2026 11:58:36 +0300 Subject: [PATCH] EPMRPP-115034 || Integrate Lombok support and refactor command classes to use PluginCommandRQ --- build.gradle | 10 ++--- gradle.properties | 1 - .../extension/gitlab/GitlabExtension.java | 43 ++++++++++--------- .../extension/gitlab/client/GitlabClient.java | 6 +-- .../command/DescriptionBuilderService.java | 5 +-- .../gitlab/command/GetIssueCommand.java | 33 +++++++------- .../gitlab/command/GetIssueFieldsCommand.java | 15 ++++--- .../gitlab/command/GetIssueTypesCommand.java | 9 ++-- .../gitlab/command/GetIssuesCommand.java | 28 ++++++------ .../gitlab/command/PostTicketCommand.java | 32 +++++++------- .../RetrieveCreationParamsCommand.java | 16 ++++--- .../command/RetrieveUpdateParamsCommand.java | 17 +++++--- .../gitlab/command/SearchEpicsCommand.java | 32 +++++++------- .../gitlab/command/SearchLabelsCommand.java | 31 +++++++------ .../command/SearchMilestonesCommand.java | 30 +++++++------ .../gitlab/command/SearchUsersCommand.java | 27 ++++++------ .../gitlab/command/TestConnectionCommand.java | 26 +++++------ 17 files changed, 194 insertions(+), 167 deletions(-) diff --git a/build.gradle b/build.gradle index c97a401..b662fd3 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ plugins { id "com.github.node-gradle.node" version "7.1.0" id 'com.gradleup.shadow' version '9.3.1' id "org.jooq.jooq-codegen-gradle" version "3.19.18" + id("io.freefair.lombok") version "9.5.0" } apply from: 'project-properties.gradle' @@ -31,15 +32,10 @@ dependencies { implementation 'com.epam.reportportal:service-api' annotationProcessor 'com.epam.reportportal:service-api' } else { - implementation 'com.github.reportportal:service-api:e81b4f6' - annotationProcessor 'com.github.reportportal:service-api:e81b4f6' + implementation 'com.github.reportportal:service-api:82fa7c7' + annotationProcessor 'com.github.reportportal:service-api:82fa7c7' } - // add lombok support - compileOnly "org.projectlombok:lombok:${lombokVersion}" - annotationProcessor "org.projectlombok:lombok:${lombokVersion}" - testCompileOnly "org.projectlombok:lombok:${lombokVersion}" - testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } diff --git a/gradle.properties b/gradle.properties index ae19ace..cb8b158 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,3 @@ description=EPAM Report Portal. GitLab plugin. pluginId = GitLab springBootVersion=3.5.9 -lombokVersion=1.18.42 diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/GitlabExtension.java b/src/main/java/com/epam/reportportal/extension/gitlab/GitlabExtension.java index 5524c80..4deb0ad 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/GitlabExtension.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/GitlabExtension.java @@ -5,6 +5,7 @@ import com.epam.reportportal.extension.NamedPluginCommand; import com.epam.reportportal.extension.PluginCommand; import com.epam.reportportal.extension.ReportPortalExtensionPoint; +import com.epam.reportportal.extension.command.ExtensionCommand; import com.epam.reportportal.extension.common.IntegrationTypeProperties; import com.epam.reportportal.base.core.events.domain.PluginUploadedEvent; import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; @@ -77,16 +78,16 @@ public class GitlabExtension implements ReportPortalExtensionPoint, DisposableBe @Autowired private OrganizationRepositoryCustom organizationRepository; - private final Supplier>> pluginCommandMapping = new MemoizingSupplier<>( - this::getCommands); + private final Supplier>> pluginCommandMapping = new MemoizingSupplier<>( + this::getIntegrationExtensionCommands); + private final Supplier>> commonCommandMapping = new MemoizingSupplier<>( + this::getCommonExtensionCommands); @Autowired private LogRepository logRepository; @Autowired private TestItemRepository testItemRepository; @Autowired private BasicTextEncryptor textEncryptor; - private final Supplier>> commonPluginCommandMapping = new MemoizingSupplier<>( - this::getCommonCommands); @Autowired @Qualifier("attachmentDataStoreService") private DataStoreService dataStoreService; @@ -113,18 +114,18 @@ public GitlabExtension(Map initParams) { Map params = new HashMap<>(); params.put(ALLOWED_COMMANDS, new ArrayList<>(pluginCommandMapping.get().keySet())); params.put(DOCUMENTATION_LINK_FIELD, DOCUMENTATION_LINK); - params.put(COMMON_COMMANDS, new ArrayList<>(commonPluginCommandMapping.get().keySet())); + params.put(COMMON_COMMANDS, new ArrayList<>(commonCommandMapping.get().keySet())); return params; } @Override public PluginCommand getIntegrationCommand(String commandName) { - return pluginCommandMapping.get().get(commandName); + return null; } @Override public CommonPluginCommand getCommonCommand(String commandName) { - return commonPluginCommandMapping.get().get(commandName); + return null; } @Override @@ -158,22 +159,24 @@ private void removeListeners() { applicationEventMulticaster.removeApplicationListener(pluginLoadedListenerSupplier.get()); } - private Map> getCommonCommands() { - List> commands = new ArrayList<>(); - commands.add(new RetrieveCreationParamsCommand(textEncryptor)); - commands.add(new RetrieveUpdateParamsCommand(textEncryptor)); - commands.add(new GetIssueCommand(gitlabClientProviderSupplier.get(), integrationRepository)); + @Override + public Map> getCommonExtensionCommands() { + List> commands = new ArrayList<>(); + commands.add(new RetrieveCreationParamsCommand(textEncryptor, projectRepository, organizationRepository)); + commands.add(new RetrieveUpdateParamsCommand(textEncryptor, projectRepository, organizationRepository)); + commands.add(new GetIssueCommand(gitlabClientProviderSupplier.get(), integrationRepository, projectRepository, organizationRepository)); return commands.stream().collect(Collectors.toMap(NamedPluginCommand::getName, it -> it)); } - private Map> getCommands() { - List> commands = new ArrayList<>(); - commands.add(new TestConnectionCommand(gitlabClientProviderSupplier.get())); - commands.add(new GetIssuesCommand(gitlabClientProviderSupplier.get())); - commands.add(new SearchUsersCommand(gitlabClientProviderSupplier.get())); - commands.add(new SearchMilestonesCommand(gitlabClientProviderSupplier.get())); - commands.add(new SearchEpicsCommand(gitlabClientProviderSupplier.get())); - commands.add(new SearchLabelsCommand(gitlabClientProviderSupplier.get())); + @Override + public Map> getIntegrationExtensionCommands() { + List> commands = new ArrayList<>(); + commands.add(new TestConnectionCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository)); + commands.add(new GetIssuesCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository)); + commands.add(new SearchUsersCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository)); + commands.add(new SearchMilestonesCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository)); + commands.add(new SearchEpicsCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository)); + commands.add(new SearchLabelsCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository)); commands.add(new GetIssueTypesCommand(projectRepository, organizationRepository)); commands.add(new GetIssueFieldsCommand(projectRepository, organizationRepository)); commands.add(new PostTicketCommand(projectRepository, gitlabClientProviderSupplier.get(), diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/client/GitlabClient.java b/src/main/java/com/epam/reportportal/extension/gitlab/client/GitlabClient.java index fb1ddfb..db2be86 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/client/GitlabClient.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/client/GitlabClient.java @@ -25,8 +25,7 @@ import java.util.Map; import java.util.Objects; import org.jooq.tools.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpEntity; @@ -42,10 +41,9 @@ /** * @author Zsolt Nagyaghy */ +@Slf4j public class GitlabClient { - private static final Logger logger = LoggerFactory.getLogger(GitlabClient.class); - private static final Integer DEFAULT_PAGE_SIZE = 100; private static final Integer FIRST_PAGE = 1; private static final String QUERY_PAGE = "page"; diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/DescriptionBuilderService.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/DescriptionBuilderService.java index a61fee4..251eb53 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/DescriptionBuilderService.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/DescriptionBuilderService.java @@ -41,8 +41,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.tika.config.TikaConfig; import org.apache.tika.mime.MimeTypes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * Provide functionality for building ticket description @@ -50,13 +49,13 @@ * @author Aliaksei_Makayed * @author Dzmitry_Kavalets */ +@Slf4j public class DescriptionBuilderService { public static final String BACK_LINK_HEADER = "### **Back link to Report Portal:**"; public static final String BACK_LINK_PATTERN = "[Link to defect](%s)%n"; public static final String COMMENTS_HEADER = "### **Test Item comments:**"; public static final String CODE = "`"; - private static final Logger LOGGER = LoggerFactory.getLogger(DescriptionBuilderService.class); private static final String IMAGE_CONTENT = "image"; private static final String IMAGE_HEIGHT_TEMPLATE = "|height=366!"; diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueCommand.java index 91a27cf..2e02a51 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueCommand.java @@ -16,43 +16,44 @@ package com.epam.reportportal.extension.gitlab.command; +import static java.util.Optional.ofNullable; -import com.epam.reportportal.extension.CommonPluginCommand; -import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; -import com.epam.reportportal.extension.gitlab.utils.TicketMapper; +import com.epam.reportportal.api.model.PluginCommandRQ; import com.epam.reportportal.base.infrastructure.model.externalsystem.Ticket; import com.epam.reportportal.base.infrastructure.persistence.dao.IntegrationRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; -import java.util.Map; -import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; +import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; +import com.epam.reportportal.extension.gitlab.utils.TicketMapper; +import lombok.extern.slf4j.Slf4j; /** * @author Andrei Piankouski */ -public class GetIssueCommand implements CommonPluginCommand { - - private static final Logger LOGGER = LoggerFactory.getLogger(GetIssueCommand.class); - +@Slf4j +public class GetIssueCommand extends AbstractExtensionCommand { private static final String PROJECT_ID = "projectId"; private final GitlabClientProvider gitlabClientProvider; - private final IntegrationRepository integrationRepository; public GetIssueCommand(GitlabClientProvider gitlabClientProvider, - IntegrationRepository integrationRepository) { + IntegrationRepository integrationRepository, ProjectRepository projectRepository, + OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; this.integrationRepository = integrationRepository; } @Override - public Ticket executeCommand(Map params) { - final Long projectId = (Long) Optional.ofNullable(params.get(PROJECT_ID)).orElseThrow( + public Ticket executeCommand(PluginCommandRQ pluginCommandRq) { + var params = pluginCommandRq.getArguments(); + final Long projectId = (Long) ofNullable(params.get(PROJECT_ID)).orElseThrow( () -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, PROJECT_ID + " must be provided" )); @@ -80,7 +81,7 @@ public Ticket executeCommand(Map params) { return TicketMapper.toTicket( gitlabClientProvider.get(integration.getParams()).getIssue(issueId, btsProject)); } catch (Exception e) { - LOGGER.error("Issue not found: {}", e.getMessage(), e); + log.error("Issue not found: {}", e.getMessage(), e); throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Failed to retrieve the Gitlab ticket"); } diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueFieldsCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueFieldsCommand.java index 4ca4708..67513b6 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueFieldsCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueFieldsCommand.java @@ -20,7 +20,7 @@ import static com.epam.reportportal.extension.gitlab.command.PredefinedFieldTypes.CREATABLE_MULTI_AUTOCOMPLETE; import static com.epam.reportportal.extension.gitlab.command.PredefinedFieldTypes.MULTI_AUTOCOMPLETE; -import com.epam.reportportal.extension.ProjectMemberCommand; +import com.epam.reportportal.api.model.PluginCommandRQ; import com.epam.reportportal.base.infrastructure.model.externalsystem.AllowedValue; import com.epam.reportportal.base.infrastructure.model.externalsystem.PostFormField; import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; @@ -28,15 +28,15 @@ import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; import com.google.common.collect.Lists; import java.util.List; -import java.util.Map; import java.util.Optional; /** * @author Pavel Bortnik */ -public class GetIssueFieldsCommand extends ProjectMemberCommand> { +public class GetIssueFieldsCommand extends AbstractExtensionCommand> { public static final String ISSUE_TYPE = "issue_type"; public static final String ISSUE_TYPE_PARAM = "issueType"; @@ -53,14 +53,17 @@ public GetIssueFieldsCommand(ProjectRepository projectRepository, } @Override - protected List invokeCommand(Integration integration, Map params) { - String issueTypeParam = Optional.ofNullable(params.get(ISSUE_TYPE_PARAM)).map(it -> (String) it) + protected List invokeCommand(Integration integration, + PluginCommandRQ pluginCommandRq) { + String issueTypeParam = Optional.ofNullable(pluginCommandRq.getArguments().get(ISSUE_TYPE_PARAM)) + .map(it -> (String) it) .orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Issue type is not provided" )); List result = Lists.newArrayList( PostFormField.builder().id("title").fieldName("Title").fieldType("string").isRequired(true) - .build(), PostFormField.builder().id("description").fieldName("Description") + .build(), + PostFormField.builder().id("description").fieldName("Description") .fieldType("multilineText").build(), PostFormField.builder().id(ISSUE_TYPE).fieldName("Issue type").fieldType("issuetype") .isRequired(true).definedValues( diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueTypesCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueTypesCommand.java index 388930c..75f0c19 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueTypesCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssueTypesCommand.java @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.epam.reportportal.extension.gitlab.command; -import com.epam.reportportal.extension.ProjectMemberCommand; +import com.epam.reportportal.api.model.PluginCommandRQ; import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; import java.util.List; -import java.util.Map; /** * @author Pavel Bortnik */ -public class GetIssueTypesCommand extends ProjectMemberCommand> { +public class GetIssueTypesCommand extends AbstractExtensionCommand> { public static final String ISSUE = "Issue"; public static final String INCIDENT = "Incident"; @@ -41,7 +42,7 @@ public String getName() { } @Override - protected List invokeCommand(Integration integration, Map params) { + protected List invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { return List.of(ISSUE, INCIDENT); } } diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssuesCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssuesCommand.java index c542c47..a88e7f9 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssuesCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/GetIssuesCommand.java @@ -18,29 +18,31 @@ import static java.util.Optional.ofNullable; -import com.epam.reportportal.extension.PluginCommand; -import com.epam.reportportal.extension.gitlab.client.GitlabClient; -import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; -import com.epam.reportportal.extension.gitlab.dto.IssueDto; +import com.epam.reportportal.api.model.PluginCommandRQ; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.IntegrationParams; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; +import com.epam.reportportal.extension.gitlab.client.GitlabClient; +import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; +import com.epam.reportportal.extension.gitlab.dto.IssueDto; import java.util.List; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * @author Zsolt Nagyaghy */ -public class GetIssuesCommand implements PluginCommand> { - - private static final Logger LOGGER = LoggerFactory.getLogger(GetIssuesCommand.class); +@Slf4j +public class GetIssuesCommand extends AbstractExtensionCommand> { private final GitlabClientProvider gitlabClientProvider; - public GetIssuesCommand(GitlabClientProvider gitlabClientProvider) { + public GetIssuesCommand(GitlabClientProvider gitlabClientProvider, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; } @@ -50,7 +52,7 @@ public String getName() { } @Override - public List executeCommand(Integration integration, Map params) { + protected List invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Integration params are not specified." @@ -65,7 +67,7 @@ public List executeCommand(Integration integration, MapPavel Bortnik */ -public class PostTicketCommand extends ProjectMemberCommand { +public class PostTicketCommand extends AbstractExtensionCommand { private final GitlabClientProvider gitlabClientProvider; private final RequestEntityConverter requestEntityConverter; @@ -56,7 +57,8 @@ public class PostTicketCommand extends ProjectMemberCommand { public PostTicketCommand(ProjectRepository projectRepository, GitlabClientProvider gitlabClientProvider, RequestEntityConverter requestEntityConverter, - DescriptionBuilderService descriptionBuilderService, OrganizationRepositoryCustom organizationRepository) { + DescriptionBuilderService descriptionBuilderService, + OrganizationRepositoryCustom organizationRepository) { super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; this.requestEntityConverter = requestEntityConverter; @@ -64,9 +66,9 @@ public PostTicketCommand(ProjectRepository projectRepository, } @Override - protected Ticket invokeCommand(Integration integration, Map params) { - PostTicketRQ ticketRQ = requestEntityConverter.getEntity(CommandParamUtils.ENTITY_PARAM, params, - PostTicketRQ.class + protected Ticket invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { + PostTicketRQ ticketRQ = requestEntityConverter.getEntity(CommandParamUtils.ENTITY_PARAM, + pluginCommandRq.getArguments(), PostTicketRQ.class ); RequestEntityValidator.validate(ticketRQ); expect(ticketRQ.getFields(), not(isNull())).verify(UNABLE_INTERACT_WITH_INTEGRATION, @@ -81,7 +83,8 @@ protected Ticket invokeCommand(Integration integration, Map para try { return TicketMapper.toTicket(gitlabClient.postIssue(project, queryParams)); } catch (Exception e) { - throw new ReportPortalException(UNABLE_INTERACT_WITH_INTEGRATION, "Failed to create Gitlab ticket"); + throw new ReportPortalException(UNABLE_INTERACT_WITH_INTEGRATION, + "Failed to create Gitlab ticket"); } } @@ -97,8 +100,7 @@ private Map handleTicketFields(PostTicketRQ ticketRQ, GitlabClie String extended = Optional.ofNullable( descriptionBuilderService.getDescription(ticketRQ, gitlabClient, gitlabProjectId)) .orElse(""); - String extendedDescription = description + "\n" + extended; - params.put(field.getId(), extendedDescription); + params.put(field.getId(), description + "\n" + extended); continue; } if (NAMED_VALUE_FIELDS.contains(field.getFieldType())) { diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveCreationParamsCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveCreationParamsCommand.java index 0beba36..0f2032e 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveCreationParamsCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveCreationParamsCommand.java @@ -19,9 +19,13 @@ import static com.epam.reportportal.base.infrastructure.rules.commons.validation.BusinessRule.expect; import static com.epam.reportportal.base.infrastructure.rules.exception.ErrorType.UNABLE_INTERACT_WITH_INTEGRATION; -import com.epam.reportportal.extension.CommonPluginCommand; +import com.epam.reportportal.api.model.PluginCommandRQ; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; +import com.epam.reportportal.extension.gitlab.command.GitlabProperties; import com.google.common.collect.Maps; import java.util.Map; import org.apache.commons.collections4.MapUtils; @@ -30,11 +34,13 @@ /** * @author Pavel Bortnik */ -public class RetrieveCreationParamsCommand implements CommonPluginCommand> { +public class RetrieveCreationParamsCommand extends AbstractExtensionCommand> { private final BasicTextEncryptor textEncryptor; - public RetrieveCreationParamsCommand(BasicTextEncryptor textEncryptor) { + public RetrieveCreationParamsCommand(BasicTextEncryptor textEncryptor, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.textEncryptor = textEncryptor; } @@ -44,8 +50,8 @@ public String getName() { } @Override - //@param integration is always null because it can be not saved yet - public Map executeCommand(Map integrationParams) { + public Map executeCommand(PluginCommandRQ pluginCommandRq) { + var integrationParams = pluginCommandRq.getArguments(); expect(integrationParams, MapUtils::isNotEmpty).verify(ErrorType.BAD_REQUEST_ERROR, "No integration params provided" diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveUpdateParamsCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveUpdateParamsCommand.java index 2c5fc79..9fbe70f 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveUpdateParamsCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/RetrieveUpdateParamsCommand.java @@ -16,7 +16,10 @@ package com.epam.reportportal.extension.gitlab.command; -import com.epam.reportportal.extension.CommonPluginCommand; +import com.epam.reportportal.api.model.PluginCommandRQ; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; import com.google.common.collect.Maps; import java.util.Map; import java.util.Optional; @@ -25,11 +28,13 @@ /** * @author Pavel Bortnik */ -public class RetrieveUpdateParamsCommand implements CommonPluginCommand> { +public class RetrieveUpdateParamsCommand extends AbstractExtensionCommand> { private final BasicTextEncryptor textEncryptor; - public RetrieveUpdateParamsCommand(BasicTextEncryptor textEncryptor) { + public RetrieveUpdateParamsCommand(BasicTextEncryptor textEncryptor, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.textEncryptor = textEncryptor; } @@ -39,13 +44,13 @@ public String getName() { } @Override - //@param integration is always null because it can be not saved yet - public Map executeCommand(Map integrationParams) { + public Map executeCommand(PluginCommandRQ pluginCommandRq) { + var integrationParams = pluginCommandRq.getArguments(); Map resultParams = Maps.newHashMapWithExpectedSize(integrationParams.size()); GitlabProperties.URL.getParam(integrationParams) .ifPresent(url -> resultParams.put(GitlabProperties.URL.getName(), url)); GitlabProperties.PROJECT.getParam(integrationParams) - .ifPresent(url -> resultParams.put(GitlabProperties.PROJECT.getName(), url)); + .ifPresent(project -> resultParams.put(GitlabProperties.PROJECT.getName(), project)); GitlabProperties.API_TOKEN.getParam(integrationParams) .ifPresent(token -> resultParams.put(GitlabProperties.API_TOKEN.getName(), textEncryptor.encrypt(token))); diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchEpicsCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchEpicsCommand.java index 4ab91ed..6606843 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchEpicsCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchEpicsCommand.java @@ -18,28 +18,30 @@ import static java.util.Optional.ofNullable; -import com.epam.reportportal.extension.PluginCommand; -import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; -import com.epam.reportportal.extension.gitlab.dto.EpicDto; +import com.epam.reportportal.api.model.PluginCommandRQ; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.IntegrationParams; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; +import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; +import com.epam.reportportal.extension.gitlab.dto.EpicDto; import java.util.List; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * @author Pavel Bortnik */ -public class SearchEpicsCommand implements PluginCommand> { - - private static final Logger LOGGER = LoggerFactory.getLogger(SearchEpicsCommand.class); +@Slf4j +public class SearchEpicsCommand extends AbstractExtensionCommand> { private final GitlabClientProvider gitlabClientProvider; - public SearchEpicsCommand(GitlabClientProvider gitlabClientProvider) { + public SearchEpicsCommand(GitlabClientProvider gitlabClientProvider, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; } @@ -49,7 +51,7 @@ public String getName() { } @Override - public List executeCommand(Integration integration, Map params) { + protected List invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Integration params are not specified." @@ -59,7 +61,7 @@ public List executeCommand(Integration integration, Map () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Project ID is not specified." )); - String term = GitlabProperties.SEARCH_TERM.getParam(params).orElseThrow( + String term = GitlabProperties.SEARCH_TERM.getParam(pluginCommandRq.getArguments()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Search term is not specified" )); @@ -69,9 +71,9 @@ public List executeCommand(Integration integration, Map gitlabClientProvider.get(integrationParams).getProject(project).getNamespace().getId(); return gitlabClientProvider.get(integrationParams).searchEpics(groupId, term); } catch (Exception e) { - LOGGER.error("Issues not found: {}", e.getMessage(), e); - throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Failed to retrieve Gitlab epics"); + log.error("Issues not found: {}", e.getMessage(), e); + throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, + "Failed to retrieve Gitlab epics"); } } - } diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchLabelsCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchLabelsCommand.java index 6877806..876c971 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchLabelsCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/SearchLabelsCommand.java @@ -18,27 +18,30 @@ import static java.util.Optional.ofNullable; -import com.epam.reportportal.extension.PluginCommand; -import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; -import com.epam.reportportal.extension.gitlab.dto.LabelDto; +import com.epam.reportportal.api.model.PluginCommandRQ; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.IntegrationParams; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; +import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; +import com.epam.reportportal.extension.gitlab.dto.LabelDto; import java.util.List; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * @author Pavel Bortnik */ -public class SearchLabelsCommand implements PluginCommand> { +@Slf4j +public class SearchLabelsCommand extends AbstractExtensionCommand> { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchLabelsCommand.class); private final GitlabClientProvider gitlabClientProvider; - public SearchLabelsCommand(GitlabClientProvider gitlabClientProvider) { + public SearchLabelsCommand(GitlabClientProvider gitlabClientProvider, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; } @@ -48,7 +51,7 @@ public String getName() { } @Override - public List executeCommand(Integration integration, Map params) { + protected List invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Integration params are not specified." @@ -58,7 +61,7 @@ public List executeCommand(Integration integration, Map new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Project ID is not specified." )); - String term = GitlabProperties.SEARCH_TERM.getParam(params).orElseThrow( + String term = GitlabProperties.SEARCH_TERM.getParam(pluginCommandRq.getArguments()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Search term is not specified" )); @@ -66,9 +69,9 @@ public List executeCommand(Integration integration, MapPavel Bortnik */ -public class SearchMilestonesCommand implements PluginCommand> { - - private static final Logger LOGGER = LoggerFactory.getLogger(SearchMilestonesCommand.class); +@Slf4j +public class SearchMilestonesCommand extends AbstractExtensionCommand> { private final GitlabClientProvider gitlabClientProvider; - public SearchMilestonesCommand(GitlabClientProvider gitlabClientProvider) { + public SearchMilestonesCommand(GitlabClientProvider gitlabClientProvider, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; } @@ -49,7 +51,8 @@ public String getName() { } @Override - public List executeCommand(Integration integration, Map params) { + protected List invokeCommand(Integration integration, + PluginCommandRQ pluginCommandRq) { IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Integration params are not specified." @@ -59,7 +62,7 @@ public List executeCommand(Integration integration, Map new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Project ID is not specified." )); - String term = GitlabProperties.SEARCH_TERM.getParam(params).orElseThrow( + String term = GitlabProperties.SEARCH_TERM.getParam(pluginCommandRq.getArguments()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Search term is not specified" )); @@ -67,10 +70,9 @@ public List executeCommand(Integration integration, MapPavel Bortnik */ -public class SearchUsersCommand implements PluginCommand> { +@Slf4j +public class SearchUsersCommand extends AbstractExtensionCommand> { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchUsersCommand.class); private final GitlabClientProvider gitlabClientProvider; - public SearchUsersCommand(GitlabClientProvider gitlabClientProvider) { + public SearchUsersCommand(GitlabClientProvider gitlabClientProvider, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; } @@ -48,7 +51,7 @@ public String getName() { } @Override - public List executeCommand(Integration integration, Map params) { + protected List invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Integration params are not specified." @@ -58,7 +61,7 @@ public List executeCommand(Integration integration, Map () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Project ID is not specified." )); - String term = GitlabProperties.SEARCH_TERM.getParam(params).orElseThrow( + String term = GitlabProperties.SEARCH_TERM.getParam(pluginCommandRq.getArguments()).orElseThrow( () -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Search term is not specified" )); @@ -66,7 +69,7 @@ public List executeCommand(Integration integration, Map try { return gitlabClientProvider.get(integrationParams).searchUsers(project, term); } catch (Exception e) { - LOGGER.error("Issues not found: {}", e.getMessage(), e); + log.error("Issues not found: {}", e.getMessage(), e); throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Failed to retrieve the list of Gitlab users"); } diff --git a/src/main/java/com/epam/reportportal/extension/gitlab/command/TestConnectionCommand.java b/src/main/java/com/epam/reportportal/extension/gitlab/command/TestConnectionCommand.java index 83e70fa..31ee290 100644 --- a/src/main/java/com/epam/reportportal/extension/gitlab/command/TestConnectionCommand.java +++ b/src/main/java/com/epam/reportportal/extension/gitlab/command/TestConnectionCommand.java @@ -18,28 +18,30 @@ import static java.util.Optional.ofNullable; -import com.epam.reportportal.extension.PluginCommand; -import com.epam.reportportal.extension.gitlab.client.GitlabClient; -import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; +import com.epam.reportportal.api.model.PluginCommandRQ; +import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository; +import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration; import com.epam.reportportal.base.infrastructure.persistence.entity.integration.IntegrationParams; import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType; import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException; -import java.util.Map; +import com.epam.reportportal.extension.command.AbstractExtensionCommand; +import com.epam.reportportal.extension.gitlab.client.GitlabClient; +import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider; import java.util.Objects; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * @author Zsolt Nagyaghy */ -public class TestConnectionCommand implements PluginCommand { - - private static final Logger LOGGER = LoggerFactory.getLogger(TestConnectionCommand.class); +@Slf4j +public class TestConnectionCommand extends AbstractExtensionCommand { private final GitlabClientProvider gitlabClientProvider; - public TestConnectionCommand(GitlabClientProvider gitlabClientProvider) { + public TestConnectionCommand(GitlabClientProvider gitlabClientProvider, + ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) { + super(projectRepository, organizationRepository); this.gitlabClientProvider = gitlabClientProvider; } @@ -49,7 +51,7 @@ public String getName() { } @Override - public Boolean executeCommand(Integration integration, Map params) { + protected Boolean invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) { IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow( () -> new ReportPortalException( ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, @@ -64,7 +66,7 @@ public Boolean executeCommand(Integration integration, Map param GitlabClient restClient = gitlabClientProvider.get(integrationParams); return Objects.equals(restClient.getProject(project).getId(), Long.valueOf(project)); } catch (Exception e) { - LOGGER.error("Unable to connect to GitLab: {}", e.getMessage(), e); + log.error("Unable to connect to GitLab: {}", e.getMessage(), e); throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Unable to connect to GitLab. Please check integration parameters"); }