AnalyticsComponentServiceImpl.java
3.42 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.impl;
import com.day.cq.analytics.impl.AnalyticsComponent;
import com.day.cq.analytics.impl.AnalyticsComponentQueryCache;
import com.day.cq.analytics.impl.AnalyticsComponentService;
import java.util.Collections;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class AnalyticsComponentServiceImpl
implements AnalyticsComponentService {
private static final String ANALYTICS_SUBSERVICE = "analytics";
private final Logger logger;
@Reference
private ResourceResolverFactory rrf;
@Reference
private AnalyticsComponentQueryCache analyticsComponentQueryCache;
public AnalyticsComponentServiceImpl() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public AnalyticsComponent getAnalyticsComponent(String path) {
ResourceResolver resolver = null;
try {
resolver = this.rrf.getServiceResourceResolver(Collections.singletonMap("sling.service.subservice", "analytics"));
Resource component = resolver.getResource(path + "/analytics");
if (component == null) {
AnalyticsComponent analyticsComponent = null;
return analyticsComponent;
}
AnalyticsComponent analyticsComponent = new AnalyticsComponent(component, this.analyticsComponentQueryCache);
return analyticsComponent;
}
catch (LoginException e) {
this.logger.warn("Unable to read analytics component at path " + path, (Throwable)e);
AnalyticsComponent analyticsComponent = null;
return analyticsComponent;
}
finally {
if (resolver != null) {
resolver.close();
}
}
}
protected void bindRrf(ResourceResolverFactory resourceResolverFactory) {
this.rrf = resourceResolverFactory;
}
protected void unbindRrf(ResourceResolverFactory resourceResolverFactory) {
if (this.rrf == resourceResolverFactory) {
this.rrf = null;
}
}
protected void bindAnalyticsComponentQueryCache(AnalyticsComponentQueryCache analyticsComponentQueryCache) {
this.analyticsComponentQueryCache = analyticsComponentQueryCache;
}
protected void unbindAnalyticsComponentQueryCache(AnalyticsComponentQueryCache analyticsComponentQueryCache) {
if (this.analyticsComponentQueryCache == analyticsComponentQueryCache) {
this.analyticsComponentQueryCache = null;
}
}
}