From e8d187c543ff2b66fd0d2e36fadb2d55f28337fe Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Fri, 29 Sep 2023 15:40:22 +0200 Subject: [PATCH 01/13] fix(validation): Remove corresponding issues on branch delete --- .../snowowl/core/branch/BranchDeleteRequest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java index 9914728fb21..3bdb4d019ac 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java @@ -15,11 +15,16 @@ */ package com.b2international.snowowl.core.branch; +import org.elasticsearch.core.List; + import com.b2international.commons.exceptions.NotFoundException; import com.b2international.index.revision.BaseRevisionBranching; +import com.b2international.snowowl.core.TerminologyResource; import com.b2international.snowowl.core.authorization.AccessControl; import com.b2international.snowowl.core.domain.RepositoryContext; import com.b2international.snowowl.core.identity.Permission; +import com.b2international.snowowl.core.repository.PathTerminologyResourceResolver; +import com.b2international.snowowl.core.validation.ValidationRequests; /** * @since 4.1 @@ -33,6 +38,13 @@ public BranchDeleteRequest(final String branchPath) { @Override public Boolean execute(RepositoryContext context) { try { + + //Remove issues corresponding to this branch + TerminologyResource resource = context.service(PathTerminologyResourceResolver.class).resolve(context, context.info().id(), getBranchPath()); + String resourceURI = resource.getResourceURI(getBranchPath()).toString(); + ValidationRequests.issues().prepareDelete().setCodeSystemURIs(List.of(resourceURI)).build().execute(context); + + //Remove branch context.service(BaseRevisionBranching.class).delete(getBranchPath()); } catch (NotFoundException e) { // ignore From 0100342d92a23a7d4aa3aa08588a0a5ac9a059e9 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Tue, 3 Oct 2023 10:34:15 +0200 Subject: [PATCH 02/13] fix(validation): Refactor validation issue clean up --- .../core/branch/BranchDeleteRequest.java | 23 ++++-- .../core/branch/ValidationCleanupService.java | 75 +++++++++++++++++++ .../internal/validation/ValidationPlugin.java | 2 + 3 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java index 3bdb4d019ac..9631936fcde 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java @@ -15,7 +15,8 @@ */ package com.b2international.snowowl.core.branch; -import org.elasticsearch.core.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.b2international.commons.exceptions.NotFoundException; import com.b2international.index.revision.BaseRevisionBranching; @@ -24,13 +25,15 @@ import com.b2international.snowowl.core.domain.RepositoryContext; import com.b2international.snowowl.core.identity.Permission; import com.b2international.snowowl.core.repository.PathTerminologyResourceResolver; -import com.b2international.snowowl.core.validation.ValidationRequests; /** * @since 4.1 */ public final class BranchDeleteRequest extends BranchBaseRequest implements AccessControl { + private static final long serialVersionUID = 1L; + private static final Logger LOGGER = LoggerFactory.getLogger(BranchDeleteRequest.class); + public BranchDeleteRequest(final String branchPath) { super(branchPath); } @@ -38,14 +41,18 @@ public BranchDeleteRequest(final String branchPath) { @Override public Boolean execute(RepositoryContext context) { try { - - //Remove issues corresponding to this branch - TerminologyResource resource = context.service(PathTerminologyResourceResolver.class).resolve(context, context.info().id(), getBranchPath()); - String resourceURI = resource.getResourceURI(getBranchPath()).toString(); - ValidationRequests.issues().prepareDelete().setCodeSystemURIs(List.of(resourceURI)).build().execute(context); - //Remove branch context.service(BaseRevisionBranching.class).delete(getBranchPath()); + + try { + //Schedule a job to remove issues corresponding to this branch + TerminologyResource resource = context.service(PathTerminologyResourceResolver.class).resolve(context, context.info().id(), getBranchPath()); + String resourceURI = resource.getResourceURI(getBranchPath()).toString(); + context.service(ValidationCleanupService.class).removeStaleIssues(context, resourceURI); + } catch (Exception e) { + LOGGER.trace("Failed to remove validation issues associated with deleted branch {}", getBranchPath(), e); + } + } catch (NotFoundException e) { // ignore } diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java new file mode 100644 index 00000000000..a8573055821 --- /dev/null +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -0,0 +1,75 @@ +package com.b2international.snowowl.core.branch; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.jobs.ISchedulingRule; + +import com.b2international.snowowl.core.ServiceProvider; +import com.b2international.snowowl.core.events.AsyncRequest; +import com.b2international.snowowl.core.identity.User; +import com.b2international.snowowl.core.jobs.JobRequests; +import com.b2international.snowowl.core.jobs.SerializableSchedulingRule; +import com.b2international.snowowl.core.validation.ValidationRequests; +import com.google.common.base.Joiner; + +public class ValidationCleanupService { + + public static final SerializableSchedulingRule VALIDATION_ISSUE_CLEANUP_RULE = new SerializableSchedulingRule() { + + private static final long serialVersionUID = 1L; + + @Override + public boolean isConflicting(ISchedulingRule rule) { + return rule == this; + } + + @Override + public boolean contains(ISchedulingRule rule) { + return rule == this; + } + }; + + public ValidationCleanupService() { + } + + public void removeStaleIssues(ServiceProvider context, String resourceURI) { + removeStaleIssues(context, List.of(resourceURI), Collections.emptyList()); + } + + public void removeStaleIssues(ServiceProvider context, List resourceURIs) { + removeStaleIssues(context, resourceURIs, Collections.emptyList()); + } + + public void removeStaleIssues(ServiceProvider context, String resourceURI, List previousAnalysisRunIds) { + removeStaleIssues(context, List.of(resourceURI), previousAnalysisRunIds); + } + + public void removeStaleIssues(ServiceProvider context, List resourceURIs, List previousAnalysisRunIds) { + AsyncRequest request; + + if (!previousAnalysisRunIds.isEmpty()) { + request = ValidationRequests.issues() + .prepareDelete() + .setResultIds(previousAnalysisRunIds) + .buildAsync(); + } else { + request = ValidationRequests.issues() + .prepareDelete() + .setCodeSystemURIs(resourceURIs) + .buildAsync(); + } + + final String description = String.format("Remove validation issues on stale/removed branch(es) %s", Joiner.on(", ").join(resourceURIs)); + + JobRequests.prepareSchedule() + .setRequest(request) + .setDescription(description) + .setUser(context.service(User.class).getUserId()) + .setAutoClean(true) + .setSchedulingRule(VALIDATION_ISSUE_CLEANUP_RULE) + .build() + .execute(context); + } + +} diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/internal/validation/ValidationPlugin.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/internal/validation/ValidationPlugin.java index cab3cbcdd01..a830569ac01 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/internal/validation/ValidationPlugin.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/internal/validation/ValidationPlugin.java @@ -31,6 +31,7 @@ import com.b2international.index.mapping.Mappings; import com.b2international.index.query.Expressions; import com.b2international.index.query.Query; +import com.b2international.snowowl.core.branch.ValidationCleanupService; import com.b2international.snowowl.core.config.IndexSettings; import com.b2international.snowowl.core.config.RepositoryConfiguration; import com.b2international.snowowl.core.config.SnowOwlConfiguration; @@ -106,6 +107,7 @@ public void preRun(SnowOwlConfiguration configuration, Environment env) throws E env.services().registerService(ValidationConfiguration.class, validationConfig); env.services().registerService(ValidationThreadPool.class, new ValidationThreadPool(numberOfValidationThreads, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs)); env.services().registerService(ValidationIssueDetailExtensionProvider.class, new ValidationIssueDetailExtensionProvider(env.service(ClassPathScanner.class))); + env.services().registerService(ValidationCleanupService.class, new ValidationCleanupService()); final List listOfFiles = validationDirectories.stream().flatMap(path -> Arrays.asList(path.toFile().listFiles()).stream()).toList(); final Set validationRuleFiles = Sets.newHashSet(); From 54788d6ee06664535ad45ffd614eab439821e46e Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Tue, 3 Oct 2023 11:15:11 +0200 Subject: [PATCH 03/13] fix(validation): Fix log tracing --- .../snowowl/core/branch/BranchDeleteRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java index 9631936fcde..7e11a0b23c7 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java @@ -50,7 +50,7 @@ public Boolean execute(RepositoryContext context) { String resourceURI = resource.getResourceURI(getBranchPath()).toString(); context.service(ValidationCleanupService.class).removeStaleIssues(context, resourceURI); } catch (Exception e) { - LOGGER.trace("Failed to remove validation issues associated with deleted branch {}", getBranchPath(), e); + LOGGER.trace(String.format("Failed to remove validation issues associated with deleted branch %s", getBranchPath()), e); } } catch (NotFoundException e) { From ddb1859c96c0040630a80a695592042d7812eb0a Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 16:07:16 +0100 Subject: [PATCH 04/13] fix(cleanup): Rename parameter --- .../snowowl/core/branch/ValidationCleanupService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index a8573055821..7944883a98a 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -45,13 +45,13 @@ public void removeStaleIssues(ServiceProvider context, String resourceURI, List< removeStaleIssues(context, List.of(resourceURI), previousAnalysisRunIds); } - public void removeStaleIssues(ServiceProvider context, List resourceURIs, List previousAnalysisRunIds) { + public void removeStaleIssues(ServiceProvider context, List resourceURIs, List resultIds) { AsyncRequest request; - if (!previousAnalysisRunIds.isEmpty()) { + if (!resultIds.isEmpty()) { request = ValidationRequests.issues() .prepareDelete() - .setResultIds(previousAnalysisRunIds) + .setResultIds(resultIds) .buildAsync(); } else { request = ValidationRequests.issues() From 487b222a2c563b6e86fd1c623b451879c6f44eb1 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 17:37:57 +0100 Subject: [PATCH 05/13] fix(cleanup): Update parameter name --- .../snowowl/core/branch/ValidationCleanupService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index 7944883a98a..eb74e1a3118 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -41,8 +41,8 @@ public void removeStaleIssues(ServiceProvider context, List resourceURIs removeStaleIssues(context, resourceURIs, Collections.emptyList()); } - public void removeStaleIssues(ServiceProvider context, String resourceURI, List previousAnalysisRunIds) { - removeStaleIssues(context, List.of(resourceURI), previousAnalysisRunIds); + public void removeStaleIssues(ServiceProvider context, String resourceURI, List resultIds) { + removeStaleIssues(context, List.of(resourceURI), resultIds); } public void removeStaleIssues(ServiceProvider context, List resourceURIs, List resultIds) { From e3ed5500e342ca0623b3e5691dd5719d72086109 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 17:41:33 +0100 Subject: [PATCH 06/13] fix(cleanup): Do not delete issues without resource/branch restrictions --- .../snowowl/core/branch/ValidationCleanupService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index eb74e1a3118..7cf244147d6 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -54,6 +54,10 @@ public void removeStaleIssues(ServiceProvider context, List resourceURIs .setResultIds(resultIds) .buildAsync(); } else { + if (resourceURIs.isEmpty()) { + return; + } + request = ValidationRequests.issues() .prepareDelete() .setCodeSystemURIs(resourceURIs) From eff0ef2ebc59e9095b52a193361a3b282cb64455 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 17:47:11 +0100 Subject: [PATCH 07/13] fix(cleanup): Use CompareUtils for empty checks --- .../snowowl/core/branch/ValidationCleanupService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index 7cf244147d6..c452afb1103 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -5,6 +5,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; +import com.b2international.commons.CompareUtils; import com.b2international.snowowl.core.ServiceProvider; import com.b2international.snowowl.core.events.AsyncRequest; import com.b2international.snowowl.core.identity.User; @@ -48,13 +49,13 @@ public void removeStaleIssues(ServiceProvider context, String resourceURI, List< public void removeStaleIssues(ServiceProvider context, List resourceURIs, List resultIds) { AsyncRequest request; - if (!resultIds.isEmpty()) { + if (!CompareUtils.isEmpty(resultIds)) { request = ValidationRequests.issues() .prepareDelete() .setResultIds(resultIds) .buildAsync(); } else { - if (resourceURIs.isEmpty()) { + if (CompareUtils.isEmpty(resourceURIs)) { return; } From 204b04f0b3a75c17f1b21709e2ab1fc6ba009084 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 17:49:56 +0100 Subject: [PATCH 08/13] fix(cleanup): Fix job description --- .../snowowl/core/branch/ValidationCleanupService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index c452afb1103..64508e94403 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -65,7 +65,7 @@ public void removeStaleIssues(ServiceProvider context, List resourceURIs .buildAsync(); } - final String description = String.format("Remove validation issues on stale/removed branch(es) %s", Joiner.on(", ").join(resourceURIs)); + final String description = String.format("Remove validation issues on stale/removed branch(es) of %s", Joiner.on(", ").join(resourceURIs)); JobRequests.prepareSchedule() .setRequest(request) From 7f56487742c3ba4bc05501f16d3a64ab06f71748 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 18:03:41 +0100 Subject: [PATCH 09/13] fix(cleanup): Rename service methods --- .../snowowl/core/branch/BranchDeleteRequest.java | 2 +- .../core/branch/ValidationCleanupService.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java index 7e11a0b23c7..33833f39103 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java @@ -48,7 +48,7 @@ public Boolean execute(RepositoryContext context) { //Schedule a job to remove issues corresponding to this branch TerminologyResource resource = context.service(PathTerminologyResourceResolver.class).resolve(context, context.info().id(), getBranchPath()); String resourceURI = resource.getResourceURI(getBranchPath()).toString(); - context.service(ValidationCleanupService.class).removeStaleIssues(context, resourceURI); + context.service(ValidationCleanupService.class).scheduleStaleIssueRemoval(context, resourceURI); } catch (Exception e) { LOGGER.trace(String.format("Failed to remove validation issues associated with deleted branch %s", getBranchPath()), e); } diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index 64508e94403..2f2f5b48fde 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -34,19 +34,19 @@ public boolean contains(ISchedulingRule rule) { public ValidationCleanupService() { } - public void removeStaleIssues(ServiceProvider context, String resourceURI) { - removeStaleIssues(context, List.of(resourceURI), Collections.emptyList()); + public void scheduleStaleIssueRemoval(ServiceProvider context, String resourceURI) { + scheduleStaleIssueRemoval(context, List.of(resourceURI), Collections.emptyList()); } - public void removeStaleIssues(ServiceProvider context, List resourceURIs) { - removeStaleIssues(context, resourceURIs, Collections.emptyList()); + public void scheduleStaleIssueRemoval(ServiceProvider context, List resourceURIs) { + scheduleStaleIssueRemoval(context, resourceURIs, Collections.emptyList()); } - public void removeStaleIssues(ServiceProvider context, String resourceURI, List resultIds) { - removeStaleIssues(context, List.of(resourceURI), resultIds); + public void scheduleStaleIssueRemoval(ServiceProvider context, String resourceURI, List resultIds) { + scheduleStaleIssueRemoval(context, List.of(resourceURI), resultIds); } - public void removeStaleIssues(ServiceProvider context, List resourceURIs, List resultIds) { + public void scheduleStaleIssueRemoval(ServiceProvider context, List resourceURIs, List resultIds) { AsyncRequest request; if (!CompareUtils.isEmpty(resultIds)) { From 8500f18300080c7b1fa70e786fbd81fd0d3c6a51 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Wed, 6 Dec 2023 18:07:51 +0100 Subject: [PATCH 10/13] fix(cleanup): Let default user be set for job request --- .../snowowl/core/branch/ValidationCleanupService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index 2f2f5b48fde..08b3e514a9a 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -70,7 +70,6 @@ public void scheduleStaleIssueRemoval(ServiceProvider context, List reso JobRequests.prepareSchedule() .setRequest(request) .setDescription(description) - .setUser(context.service(User.class).getUserId()) .setAutoClean(true) .setSchedulingRule(VALIDATION_ISSUE_CLEANUP_RULE) .build() From f16b635749c61222d53ac6fe19ca403e52da0d63 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Tue, 12 Dec 2023 10:18:19 +0100 Subject: [PATCH 11/13] fix(cleanup): Organize import statements --- .../snowowl/core/branch/ValidationCleanupService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index 08b3e514a9a..28e627b208c 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -8,7 +8,6 @@ import com.b2international.commons.CompareUtils; import com.b2international.snowowl.core.ServiceProvider; import com.b2international.snowowl.core.events.AsyncRequest; -import com.b2international.snowowl.core.identity.User; import com.b2international.snowowl.core.jobs.JobRequests; import com.b2international.snowowl.core.jobs.SerializableSchedulingRule; import com.b2international.snowowl.core.validation.ValidationRequests; From 0e9f56b67d6f10a6edb22a4dbc91d586fa815de6 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Tue, 12 Dec 2023 10:19:33 +0100 Subject: [PATCH 12/13] fix(cleanup): Add missing license header and since tag --- .../core/branch/ValidationCleanupService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index 28e627b208c..e8eea90131a 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 B2i Healthcare Pte Ltd, http://b2i.sg + * + * 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.b2international.snowowl.core.branch; import java.util.Collections; @@ -13,6 +29,9 @@ import com.b2international.snowowl.core.validation.ValidationRequests; import com.google.common.base.Joiner; +/** + * @since 9.0 + */ public class ValidationCleanupService { public static final SerializableSchedulingRule VALIDATION_ISSUE_CLEANUP_RULE = new SerializableSchedulingRule() { From c96bc9665c572c475a7d39f3bfab9de85a120368 Mon Sep 17 00:00:00 2001 From: AAAlinaaa Date: Tue, 12 Dec 2023 11:43:27 +0100 Subject: [PATCH 13/13] fix(cleanup): Call dedicated methods in the different delete scenarios --- .../core/branch/ValidationCleanupService.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java index e8eea90131a..a2b665243a4 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java @@ -16,7 +16,6 @@ package com.b2international.snowowl.core.branch; -import java.util.Collections; import java.util.List; import org.eclipse.core.runtime.jobs.ISchedulingRule; @@ -53,36 +52,44 @@ public ValidationCleanupService() { } public void scheduleStaleIssueRemoval(ServiceProvider context, String resourceURI) { - scheduleStaleIssueRemoval(context, List.of(resourceURI), Collections.emptyList()); + scheduleStaleIssueRemoval(context, List.of(resourceURI)); } public void scheduleStaleIssueRemoval(ServiceProvider context, List resourceURIs) { - scheduleStaleIssueRemoval(context, resourceURIs, Collections.emptyList()); + deleteRequestByResourceURIs(context, resourceURIs); } public void scheduleStaleIssueRemoval(ServiceProvider context, String resourceURI, List resultIds) { - scheduleStaleIssueRemoval(context, List.of(resourceURI), resultIds); + deleteRequestByResultIds(context, List.of(resourceURI), resultIds); } - public void scheduleStaleIssueRemoval(ServiceProvider context, List resourceURIs, List resultIds) { - AsyncRequest request; + private void deleteRequestByResultIds(ServiceProvider context, List resourceURIs, List resultIds) { + if (CompareUtils.isEmpty(resultIds)) { + return; + } - if (!CompareUtils.isEmpty(resultIds)) { - request = ValidationRequests.issues() - .prepareDelete() - .setResultIds(resultIds) - .buildAsync(); - } else { - if (CompareUtils.isEmpty(resourceURIs)) { - return; - } - - request = ValidationRequests.issues() + AsyncRequest request = ValidationRequests.issues() .prepareDelete() - .setCodeSystemURIs(resourceURIs) + .setResultIds(resultIds) .buildAsync(); + + scheduleDeleteRequest(context, resourceURIs, request); + } + + private void deleteRequestByResourceURIs(ServiceProvider context, List resourceURIs) { + if (CompareUtils.isEmpty(resourceURIs)) { + return; } + AsyncRequest request = ValidationRequests.issues() + .prepareDelete() + .setCodeSystemURIs(resourceURIs) + .buildAsync(); + + scheduleDeleteRequest(context, resourceURIs, request); + } + + private void scheduleDeleteRequest(ServiceProvider context, List resourceURIs, AsyncRequest request) { final String description = String.format("Remove validation issues on stale/removed branch(es) of %s", Joiner.on(", ").join(resourceURIs)); JobRequests.prepareSchedule()