TaskManagerAdapterFactory.java
6.43 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.taskmanagement.TaskManager
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Modified
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterFactory
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.event.EventAdmin
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.taskmanagement.impl.service;
import com.adobe.granite.taskmanagement.TaskManager;
import com.adobe.granite.taskmanagement.impl.jcr.TaskStorageProvider;
import com.adobe.granite.taskmanagement.impl.service.TaskManagerImpl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=1, label="Adobe Granite Task Manager Adapter Factory", description="Adapts JCR sessions or Apache Sling resource resolvers to a taskmanager instance.")
@Properties(value={@Property(name="service.description", value={"Adapts JCR sessions or Apache Sling resource resolvers to a taskmanager instance."}), @Property(name="adapter.condition", value={"If the ResourceResolver is a JcrResourceResolver or a Session."})})
@Service(value={AdapterFactory.class, TaskManagerAdapterFactory.class})
public class TaskManagerAdapterFactory
implements AdapterFactory {
private static Logger log = LoggerFactory.getLogger(TaskManagerAdapterFactory.class);
@Reference(policy=ReferencePolicy.DYNAMIC)
private volatile TaskStorageProvider taskStorageProvider;
@Reference
protected SlingRepository repository;
@Reference
private EventAdmin eventAdminService;
@Property(name="adapters", propertyPrivate=1)
private static final String[] ADAPTER_CLASSES = new String[]{TaskManager.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{Session.class.getName(), ResourceResolver.class.getName(), Resource.class.getName()};
public static final String DEFAULT_TASK_ADMIN_GROUP = "administrators";
@Property(value={"administrators", "taskmanagement-service", "projects-service"}, label="Task Administrator Group", description="The name of the group of users with task administrative rights.")
public static final String TM_ADMIN_GROUP_NAMES = "taskmanager.admingroups";
private List<String> superusers = new ArrayList<String>();
@Activate
@Modified
private void configure(Map<String, Object> properties) {
this.superusers.addAll(Arrays.asList((String[])properties.get("taskmanager.admingroups")));
}
public TaskManager getTaskManager(Session userSession, String rootPath) {
if (log.isDebugEnabled()) {
log.debug("Creating TaskManager for user: " + (userSession == null ? "no user" : userSession.getUserID()));
}
if (rootPath == null) {
return new TaskManagerImpl(userSession, this.eventAdminService, this.taskStorageProvider, this.repository, this.superusers);
}
TaskStorageProvider localStorageProvider = new TaskStorageProvider(this.repository, this.eventAdminService, rootPath, userSession);
return new TaskManagerImpl(userSession, this.eventAdminService, localStorageProvider, this.repository, this.superusers);
}
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (TaskManager.class == type) {
Session userSession = null;
String rootPath = null;
if (adaptable instanceof Session) {
userSession = (Session)adaptable;
} else if (adaptable instanceof ResourceResolver) {
userSession = (Session)((ResourceResolver)adaptable).adaptTo(Session.class);
} else if (adaptable instanceof Resource) {
Resource resource = (Resource)adaptable;
userSession = (Session)resource.getResourceResolver().adaptTo(Session.class);
rootPath = resource.getPath();
} else {
log.info("Can't adapt {} to TaskManager", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()));
}
if (userSession != null) {
return (AdapterType)this.getTaskManager(userSession, rootPath);
}
}
return null;
}
protected void bindTaskStorageProvider(TaskStorageProvider taskStorageProvider) {
this.taskStorageProvider = taskStorageProvider;
}
protected void unbindTaskStorageProvider(TaskStorageProvider taskStorageProvider) {
if (this.taskStorageProvider == taskStorageProvider) {
this.taskStorageProvider = null;
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindEventAdminService(EventAdmin eventAdmin) {
this.eventAdminService = eventAdmin;
}
protected void unbindEventAdminService(EventAdmin eventAdmin) {
if (this.eventAdminService == eventAdmin) {
this.eventAdminService = null;
}
}
}