|
10 | 10 | import java.util.concurrent.atomic.AtomicInteger; |
11 | 11 | import java.util.concurrent.atomic.AtomicLong; |
12 | 12 | import java.util.function.BooleanSupplier; |
| 13 | +import java.util.function.Consumer; |
13 | 14 |
|
14 | 15 | import org.hibernate.infra.replicate.jira.JiraConfig; |
15 | 16 | import org.hibernate.infra.replicate.jira.service.jira.client.JiraRestClient; |
16 | 17 | import org.hibernate.infra.replicate.jira.service.jira.client.JiraRestClientBuilder; |
| 18 | +import org.hibernate.infra.replicate.jira.service.jira.handler.JiraIssueTransitionOnlyEventHandler; |
17 | 19 | import org.hibernate.infra.replicate.jira.service.jira.model.hook.JiraWebHookEvent; |
18 | 20 | import org.hibernate.infra.replicate.jira.service.jira.model.hook.JiraWebHookIssue; |
19 | 21 | import org.hibernate.infra.replicate.jira.service.jira.model.hook.JiraWebHookIssueLink; |
@@ -154,6 +156,25 @@ public void registerManagementRoutes(@Observes ManagementInterface mi) { |
154 | 156 | triggerSyncEvent(context.sourceJiraClient().getIssue(issue), context); |
155 | 157 | rc.end(); |
156 | 158 | }); |
| 159 | + mi.router().get("/sync/issues/transition/re-sync/:project").blockingHandler(rc -> { |
| 160 | + // TODO: we can remove this one once we figure out why POST management does not |
| 161 | + // work correctly... |
| 162 | + String project = rc.pathParam("project"); |
| 163 | + String query = rc.queryParam("query").getFirst(); |
| 164 | + |
| 165 | + HandlerProjectContext context = contextPerProject.get(project); |
| 166 | + |
| 167 | + if (context == null) { |
| 168 | + throw new IllegalArgumentException("Unknown project '%s'".formatted(project)); |
| 169 | + } |
| 170 | + |
| 171 | + context.submitTask(() -> { |
| 172 | + syncByQuery(query, context, jiraIssue -> { |
| 173 | + context.submitTask(new JiraIssueTransitionOnlyEventHandler(reportingConfig, context, jiraIssue)); |
| 174 | + }); |
| 175 | + }); |
| 176 | + rc.end(); |
| 177 | + }); |
157 | 178 | mi.router().post("/sync/issues/list").consumes(MediaType.APPLICATION_JSON).blockingHandler(rc -> { |
158 | 179 | // sync issues based on a list of issue-keys supplied in the JSON body: |
159 | 180 | JsonObject request = rc.body().asJsonObject(); |
@@ -272,12 +293,16 @@ public void finishProcessingAndShutdown() { |
272 | 293 | } |
273 | 294 |
|
274 | 295 | private void syncByQuery(String query, HandlerProjectContext context) { |
| 296 | + syncByQuery(query, context, jiraIssue -> triggerSyncEvent(jiraIssue, context)); |
| 297 | + } |
| 298 | + |
| 299 | + private void syncByQuery(String query, HandlerProjectContext context, Consumer<JiraIssue> action) { |
275 | 300 | JiraIssues issues = null; |
276 | 301 | int start = 0; |
277 | 302 | int max = 100; |
278 | 303 | do { |
279 | 304 | issues = context.sourceJiraClient().find(query, start, max); |
280 | | - issues.issues.forEach(jiraIssue -> triggerSyncEvent(jiraIssue, context)); |
| 305 | + issues.issues.forEach(action); |
281 | 306 |
|
282 | 307 | start += max; |
283 | 308 | } while (!issues.issues.isEmpty()); |
|
0 commit comments