AbstractBaseTask.java
2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean
* org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean$StatusCode
* org.apache.sling.event.jobs.consumer.JobExecutionContext
* org.apache.sling.event.jobs.consumer.JobExecutionContext$ResultBuilder
* org.apache.sling.event.jobs.consumer.JobExecutionResult
* org.apache.sling.event.jobs.consumer.JobExecutor
*/
package com.adobe.granite.maintenance.crx.impl;
import javax.management.openmbean.CompositeData;
import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean;
import org.apache.sling.event.jobs.consumer.JobExecutionContext;
import org.apache.sling.event.jobs.consumer.JobExecutionResult;
import org.apache.sling.event.jobs.consumer.JobExecutor;
abstract class AbstractBaseTask
implements JobExecutor {
AbstractBaseTask() {
}
protected JobExecutionResult createResult(JobExecutionContext context, String prefix, CompositeData data, Integer startId) {
String message = data == null ? null : (String)data.get("message");
Integer code = data == null ? null : (Integer)data.get("code");
Integer id = data == null ? null : (Integer)data.get("id");
boolean success = false;
StringBuilder sb = new StringBuilder(prefix);
if (data == null || code == null) {
sb.append("No result.");
} else if (startId != null && (id == null || id.intValue() != startId.intValue())) {
sb.append(RepositoryManagementMBean.StatusCode.SUCCEEDED.name);
success = true;
} else if (code.intValue() == RepositoryManagementMBean.StatusCode.UNAVAILABLE.ordinal()) {
sb.append(RepositoryManagementMBean.StatusCode.UNAVAILABLE.name);
} else if (code.intValue() == RepositoryManagementMBean.StatusCode.NONE.ordinal()) {
sb.append(RepositoryManagementMBean.StatusCode.NONE.name);
} else if (code.intValue() == RepositoryManagementMBean.StatusCode.INITIATED.ordinal()) {
sb.append(RepositoryManagementMBean.StatusCode.INITIATED.name);
success = true;
} else if (code.intValue() == RepositoryManagementMBean.StatusCode.SUCCEEDED.ordinal()) {
sb.append(RepositoryManagementMBean.StatusCode.SUCCEEDED.name);
success = true;
} else if (code.intValue() == RepositoryManagementMBean.StatusCode.FAILED.ordinal()) {
sb.append(RepositoryManagementMBean.StatusCode.FAILED.name);
} else {
return null;
}
if (message != null) {
sb.append(" ");
sb.append(message);
}
JobExecutionContext.ResultBuilder rb = context.result().message(sb.toString());
if (success) {
return rb.succeeded();
}
return rb.failed();
}
}