DPSEntityImporterAdapterFactory.java
6.17 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterManager
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.commons.threads.ThreadPool
* org.osgi.service.event.EventAdmin
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.service;
import com.adobe.cq.mobile.dps.impl.DPSEntityImporter;
import com.adobe.cq.mobile.dps.impl.service.AdobeDPSClient;
import com.adobe.cq.mobile.dps.impl.service.DPSConnectionAdapterFactory;
import com.adobe.cq.mobile.dps.impl.service.DPSEntityImporterImpl;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.threads.ThreadPool;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={DPSEntityImporterAdapterFactory.class})
public class DPSEntityImporterAdapterFactory {
private static Logger log = LoggerFactory.getLogger(DPSEntityImporterAdapterFactory.class);
@Property(name="adapters", propertyPrivate=1)
private static final String[] ADAPTER_CLASSES = new String[]{DPSEntityImporter.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{Session.class.getName(), ResourceResolver.class.getName()};
@Reference
private EventAdmin eventAdminService;
@Reference
AdapterManager adapterManager;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private DPSConnectionAdapterFactory dpsConnectionAdapterFactory;
@Reference
private AdobeDPSClient adobeDPSClient;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (DPSEntityImporter.class == type) {
Session userSession = null;
if (adaptable instanceof Session) {
userSession = (Session)adaptable;
} else if (adaptable instanceof ResourceResolver) {
userSession = (Session)((ResourceResolver)adaptable).adaptTo(Session.class);
} else {
log.error("Can't adapt {} to DPSEntityImporter", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()));
}
if (userSession != null) {
try {
return (AdapterType)this.getDPSEntityImporter(userSession);
}
catch (LoginException e) {
log.error("Unable to obtain the DPSEntityImporter", (Throwable)e);
}
}
}
return null;
}
private DPSEntityImporter getDPSEntityImporter(Session userSession) throws LoginException {
if (log.isDebugEnabled()) {
log.debug("Creating DPSEntityImporter for user: " + (userSession == null ? "no user" : userSession.getUserID()));
}
HashMap<String, Session> authInfo = new HashMap<String, Session>();
authInfo.put("user.jcr.session", userSession);
ResourceResolver resolver = this.resourceResolverFactory.getResourceResolver(authInfo);
PageManager pageManager = (PageManager)resolver.adaptTo(PageManager.class);
ConfigurationManager configurationManagerService = (ConfigurationManager)resolver.adaptTo(ConfigurationManager.class);
return new DPSEntityImporterImpl(userSession, this.dpsConnectionAdapterFactory, pageManager, configurationManagerService, this.eventAdminService, this.adapterManager, this.adobeDPSClient.getThreadPool());
}
protected void bindEventAdminService(EventAdmin eventAdmin) {
this.eventAdminService = eventAdmin;
}
protected void unbindEventAdminService(EventAdmin eventAdmin) {
if (this.eventAdminService == eventAdmin) {
this.eventAdminService = null;
}
}
protected void bindAdapterManager(AdapterManager adapterManager) {
this.adapterManager = adapterManager;
}
protected void unbindAdapterManager(AdapterManager adapterManager) {
if (this.adapterManager == adapterManager) {
this.adapterManager = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindDpsConnectionAdapterFactory(DPSConnectionAdapterFactory dPSConnectionAdapterFactory) {
this.dpsConnectionAdapterFactory = dPSConnectionAdapterFactory;
}
protected void unbindDpsConnectionAdapterFactory(DPSConnectionAdapterFactory dPSConnectionAdapterFactory) {
if (this.dpsConnectionAdapterFactory == dPSConnectionAdapterFactory) {
this.dpsConnectionAdapterFactory = null;
}
}
protected void bindAdobeDPSClient(AdobeDPSClient adobeDPSClient) {
this.adobeDPSClient = adobeDPSClient;
}
protected void unbindAdobeDPSClient(AdobeDPSClient adobeDPSClient) {
if (this.adobeDPSClient == adobeDPSClient) {
this.adobeDPSClient = null;
}
}
}