LaunchTimelineEventProvider.java
4.08 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchManager
* com.adobe.cq.launches.api.timeline.LaunchTimelineEventType
* com.adobe.granite.timeline.TimelineEvent
* com.adobe.granite.timeline.TimelineEventProvider
* com.adobe.granite.timeline.TimelineEventType
* com.day.cq.wcm.api.Page
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.launches.impl.timeline;
import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.launches.api.LaunchManager;
import com.adobe.cq.launches.api.timeline.LaunchTimelineEventType;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import com.adobe.granite.timeline.TimelineEvent;
import com.adobe.granite.timeline.TimelineEventProvider;
import com.adobe.granite.timeline.TimelineEventType;
import com.day.cq.wcm.api.Page;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class LaunchTimelineEventProvider
implements TimelineEventProvider {
private static final Logger log = LoggerFactory.getLogger(LaunchTimelineEventProvider.class);
public static final TimelineEventType EVENT_TYPE = new LaunchTimelineEventType(){
public String getName() {
return LaunchTimelineEventType.class.getCanonicalName();
}
};
public boolean accepts(Resource resource) {
return resource.adaptTo(Page.class) != null;
}
public Collection<TimelineEvent> getEvents(Resource resource) {
ArrayList<TimelineEvent> events = new ArrayList<TimelineEvent>();
ResourceResolver resolver = resource.getResourceResolver();
LaunchManager launchManager = (LaunchManager)resolver.adaptTo(LaunchManager.class);
if (launchManager != null) {
long start = System.currentTimeMillis();
Collection resourceLaunches = launchManager.getLaunches(resource);
log.debug(">>> retrieved all launches for resource [{}] in [{}ms]", (Object)resource.getPath(), (Object)(System.currentTimeMillis() - start));
long startTimelineEntries = System.currentTimeMillis();
for (Launch launch : resourceLaunches) {
events.add(new LaunchTimelineEvent(launch, resource));
}
log.debug(">>> converted launches to timeline events for resource [{}] took [{}ms]", (Object)resource.getPath(), (Object)(System.currentTimeMillis() - startTimelineEntries));
} else {
log.error("cannot get launches events: launch manager unavailable!");
}
return events;
}
public TimelineEventType getType() {
return EVENT_TYPE;
}
private static class LaunchTimelineEvent
implements TimelineEvent {
private final Launch launch;
private final Resource resource;
private static final String ACTION = "Launch Created";
public LaunchTimelineEvent(Launch launch, Resource resource) {
this.launch = launch;
this.resource = resource;
}
public String getAction() {
return "Launch Created";
}
public String getDescription() {
return this.launch.getTitle();
}
public String getOrigin() {
return LaunchUtils.getProductionResource(this.resource).getPath();
}
public long getTime() {
return this.launch.getCreated().getTimeInMillis();
}
public TimelineEventType getType() {
return LaunchTimelineEventProvider.EVENT_TYPE;
}
public String getUserID() {
return this.launch.getCreatedBy();
}
}
}