ActivityComponentDataStorage.java
2.85 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.tsdk.common.ComponentDataStorage
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.testandtarget.impl.util;
import com.adobe.tsdk.common.ComponentDataStorage;
import java.util.Collections;
import java.util.Map;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ActivityComponentDataStorage
implements ComponentDataStorage {
private static final Logger LOG = LoggerFactory.getLogger(ActivityComponentDataStorage.class);
private ResourceResolverFactory rrf;
public ActivityComponentDataStorage(ResourceResolverFactory rrf) {
this.rrf = rrf;
}
public String read(String activityId, String propertyName) {
String propValue = null;
try {
ResourceResolver resolver = this.getResolver();
Resource activitySettingsRes = resolver.getResource(activityId + "/" + "jcr:content" + "/cq:ActivitySettings");
ValueMap activitySettingsProps = (ValueMap)activitySettingsRes.adaptTo(ValueMap.class);
propValue = (String)activitySettingsProps.get(propertyName, null);
}
catch (Exception e) {
LOG.error("Can't read property {} of activity {}!", (Object)new Object[]{propertyName, activityId}, (Object)e);
}
return propValue;
}
public void write(String activityId, String propertyName, String propertyValue) {
try {
ResourceResolver resolver = this.getResolver();
Resource activitySettingsRes = resolver.getResource(activityId + "/" + "jcr:content" + "/cq:ActivitySettings");
ModifiableValueMap activitySettingsProps = (ModifiableValueMap)activitySettingsRes.adaptTo(ModifiableValueMap.class);
activitySettingsProps.put((Object)propertyName, (Object)propertyValue);
resolver.commit();
}
catch (Exception e) {
LOG.error("Can't save property {} of activity {}!", (Object)new Object[]{propertyName, activityId}, (Object)e);
}
}
private ResourceResolver getResolver() throws LoginException {
return this.rrf.getServiceResourceResolver(Collections.singletonMap("sling.service.subservice", "target"));
}
}