ActivityComponentDataStorage.java 2.85 KB
/*
 * 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"));
    }
}