MACTenantConfigurationResolverImpl.java
7 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
149
150
151
152
153
154
155
156
157
158
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserManagementService
* com.day.cq.dam.api.Asset
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.dam.mac.sync.helper.impl;
import com.adobe.cq.dam.mac.sync.helper.impl.MACTenantConfiguration;
import com.adobe.cq.dam.mac.sync.helper.impl.MACTenantConfigurationImpl;
import com.adobe.cq.dam.mac.sync.helper.impl.MACTenantConfigurationResolver;
import com.adobe.granite.security.user.UserManagementService;
import com.day.cq.dam.api.Asset;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import java.util.Iterator;
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.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
@Component(metatype=0, label="%com.adobe.cq.dam.mac.sync.mactenantconfigresolver.label", description="%com.adobe.cq.dam.mac.sync.mactenantconfigresolver.description")
@Service
public class MACTenantConfigurationResolverImpl
implements MACTenantConfigurationResolver {
@Reference
private ConfigurationManagerFactory configurationManagerFactory;
@Reference
private UserManagementService userManagementService;
@Override
public MACTenantConfiguration getConfiguration(ResourceResolver resolver, String path) {
Configuration configuration;
ConfigurationManager configurationManager = this.configurationManagerFactory.getConfigurationManager(resolver);
MACTenantConfigurationImpl mtc = null;
if (path != null && (configuration = configurationManager.getConfiguration(path)) != null) {
mtc = new MACTenantConfigurationImpl(configuration, this.userManagementService);
}
return mtc;
}
@Override
public MACTenantConfiguration getConfigurationForResource(Resource resource) {
return this.getTenantConfigurationForResource(resource, "macConfig");
}
@Override
public MACTenantConfiguration getMPConfigurationForResource(Resource resource) {
return this.getTenantConfigurationForResource(resource, "mpConfig");
}
private MACTenantConfiguration getTenantConfigurationForResource(Resource resource, String property) {
MACTenantConfiguration mtc = null;
if (resource != null) {
while (mtc == null && !"/".equals(resource.getPath())) {
ValueMap resourceProperties = (ValueMap)resource.adaptTo(ValueMap.class);
String cloudConfigPath = (String)resourceProperties.get(property, String.class);
mtc = this.getConfiguration(resource.getResourceResolver(), cloudConfigPath);
resource = resource.getParent();
}
}
return mtc;
}
@Override
public MACTenantConfiguration getConfigurationForPath(ResourceResolver resolver, String path) {
return this.getTenantConfigurationForPath(resolver, path, "macConfig");
}
@Override
public MACTenantConfiguration getMPConfigurationForPath(ResourceResolver resolver, String path) {
return this.getTenantConfigurationForPath(resolver, path, "mpConfig");
}
private MACTenantConfiguration getTenantConfigurationForPath(ResourceResolver resolver, String path, String property) {
MACTenantConfiguration mtc = null;
if (path != null) {
while (!"/".equals(path) && path.length() > 0 && mtc == null) {
Resource resource = resolver.getResource(path);
if (resource != null) {
String configPath;
ValueMap properties;
if (null == resource.adaptTo(Asset.class)) {
properties = (ValueMap)resource.adaptTo(ValueMap.class);
configPath = (String)properties.get(property, String.class);
mtc = this.getConfiguration(resolver, configPath);
} else {
properties = (ValueMap)resource.getChild("jcr:content").adaptTo(ValueMap.class);
configPath = (String)properties.get(property, String.class);
mtc = this.getConfiguration(resolver, configPath);
}
}
path = path.substring(0, path.lastIndexOf("/"));
}
}
return mtc;
}
@Override
public MACTenantConfiguration getDefaultConfig(ResourceResolver resolver) {
return this.getDefaultTenantConfig(resolver, "/etc/cloudservices/marketingcloud");
}
@Override
public MACTenantConfiguration getDefaultMPConfig(ResourceResolver resolver) {
return this.getDefaultTenantConfig(resolver, "/etc/cloudservices/mediaportal");
}
private MACTenantConfiguration getDefaultTenantConfig(ResourceResolver resolver, String configRootPath) {
Resource configRoot = resolver.getResource(configRootPath);
if (configRoot != null) {
ConfigurationManager configurationManager = this.configurationManagerFactory.getConfigurationManager(resolver);
Iterator iterator = configRoot.listChildren();
while (iterator.hasNext()) {
MACTenantConfigurationImpl mtc;
Resource child = (Resource)iterator.next();
Configuration configuration = configurationManager.getConfiguration(child.getPath());
if (configuration == null || !(mtc = new MACTenantConfigurationImpl(configuration, this.userManagementService)).isSyncEnabled()) continue;
return mtc;
}
}
return null;
}
protected void bindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.configurationManagerFactory = configurationManagerFactory;
}
protected void unbindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.configurationManagerFactory == configurationManagerFactory) {
this.configurationManagerFactory = null;
}
}
protected void bindUserManagementService(UserManagementService userManagementService) {
this.userManagementService = userManagementService;
}
protected void unbindUserManagementService(UserManagementService userManagementService) {
if (this.userManagementService == userManagementService) {
this.userManagementService = null;
}
}
}