ContentStructureProgressiveStrategy.java 10.5 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.ReferencePolicy
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ValueMap
 *  org.osgi.service.component.ComponentContext
 */
package com.adobe.aemds.guide.service.impl;

import com.adobe.aemds.guide.progressive.GuideProgressiveCompletionInfo;
import com.adobe.aemds.guide.progressive.GuideProgressiveField;
import com.adobe.aemds.guide.progressive.GuideProgressiveSectionInfo;
import com.adobe.aemds.guide.service.GuideProgressiveStrategy;
import com.adobe.aemds.guide.utils.NodeStructureUtils;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
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.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.ComponentContext;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(immediate=1, label="Content Structure based Progressive Strategy", description="Content Structure Progressive Strategy Service")
@Service(value={GuideProgressiveStrategy.class})
public class ContentStructureProgressiveStrategy
implements GuideProgressiveStrategy {
    @Reference(policy=ReferencePolicy.DYNAMIC)
    private ResourceResolverHelper resourceResolverHelper;
    private String name;
    private String displayName;
    private String serviceType;

    protected void activate(ComponentContext context) {
        this.name = "contentStructureStrategy";
        this.displayName = "Content based Progressive Strategy";
        this.serviceType = "static";
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public String getDisplayName() {
        return this.displayName;
    }

    @Override
    public String getServiceType() {
        return this.serviceType;
    }

    private GuideProgressiveCompletionInfo getCompletionInfo(ValueMap completionSectionValueMap) {
        return new GuideProgressiveCompletionInfo((String)completionSectionValueMap.get("completionTitle", (Object)""), (String)completionSectionValueMap.get("completionBeforeMessage", (Object)""), (String)completionSectionValueMap.get("completionAfterMessage", (Object)""), (String)completionSectionValueMap.get("completionScript", (Object)""), (String)completionSectionValueMap.get("completionButtonText", (Object)""), (String)completionSectionValueMap.get("completionSuccessScript", (Object)""), (String)completionSectionValueMap.get("completionFailureScript", (Object)""));
    }

    @Override
    public List<Object> getAllSections(Map<String, String> paramMap) {
        String serviceContentStructurePath = paramMap.get("strategyJcrPath");
        ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
        Resource strategyResource = resourceResolver.getResource(serviceContentStructurePath);
        ArrayList<Object> allSections = new ArrayList<Object>();
        GuideProgressiveCompletionInfo completionInfo = null;
        ValueMap completionSectionValueMap = ResourceUtil.getValueMap((Resource)strategyResource);
        Boolean isCompletionSectionAsProperty = (String)completionSectionValueMap.get((Object)"completionTitle") != null;
        if (isCompletionSectionAsProperty.booleanValue()) {
            completionInfo = this.getCompletionInfo(completionSectionValueMap);
        }
        for (Resource section : strategyResource.getChildren()) {
            ValueMap sectionValueMap = ResourceUtil.getValueMap((Resource)section);
            String sectionId = section.getName();
            if ("guideProgressiveSection".equals(sectionValueMap.get("guideNodeClass", (Object)""))) {
                Object fieldArray = null;
                String repeatablePanelPath = (String)sectionValueMap.get("repeatablePanelPath", (Object)"");
                String repeatablePanelId = "";
                if (repeatablePanelPath != null && !repeatablePanelPath.isEmpty()) {
                    Resource repeatablePanelResource = resourceResolver.getResource(repeatablePanelPath);
                    repeatablePanelId = NodeStructureUtils.getGuideNodeHtmlId(repeatablePanelResource);
                }
                ArrayList<GuideProgressiveField> fields = new ArrayList<GuideProgressiveField>();
                Resource items = section.getChild(section.getPath() + "/items");
                for (Resource childSection : items.getChildren()) {
                    ValueMap childSectionValueMap = ResourceUtil.getValueMap((Resource)childSection);
                    String path = (String)childSectionValueMap.get((Object)"path");
                    String id = (String)childSectionValueMap.get((Object)"id");
                    String prefixId = (String)childSectionValueMap.get((Object)"prefixId");
                    GuideProgressiveField field = new GuideProgressiveField(id, path, prefixId, resourceResolver);
                    fields.add(field);
                }
                GuideProgressiveSectionInfo sectionInfo = new GuideProgressiveSectionInfo(sectionId, (String)sectionValueMap.get("jcr:title", (Object)""), (String)sectionValueMap.get((Object)"name"), fields, repeatablePanelPath, repeatablePanelId);
                allSections.add(sectionInfo);
                continue;
            }
            if (!"guideProgressiveCompletionSection".equals(sectionValueMap.get("guideNodeClass", (Object)""))) continue;
            completionInfo = this.getCompletionInfo(sectionValueMap);
        }
        if (completionInfo != null) {
            allSections.add(completionInfo);
        }
        return allSections;
    }

    @Override
    public GuideProgressiveSectionInfo getNextSection(String afPath, String currentSectionId, Map<String, String> data) {
        String strategyJcrPath = data.get("strategyJcrPath");
        Boolean renderCurrentSection = Boolean.valueOf(data.get("renderCurrentSection"));
        ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
        Resource strategyResource = resourceResolver.getResource(strategyJcrPath);
        boolean selectSection = false;
        for (Resource section : strategyResource.getChildren()) {
            ValueMap sectionValueMap = ResourceUtil.getValueMap((Resource)section);
            String sectionId = section.getName();
            if (!"guideProgressiveSection".equals(sectionValueMap.get("guideNodeClass", (Object)""))) continue;
            if (currentSectionId == null || currentSectionId.isEmpty()) {
                selectSection = true;
            } else if (currentSectionId != null && currentSectionId.equals(sectionId)) {
                selectSection = true;
                if (!renderCurrentSection.booleanValue()) continue;
            }
            if (!selectSection) continue;
            String repeatablePanelPath = (String)sectionValueMap.get("repeatablePanelPath", (Object)"");
            String repeatablePanelId = "";
            if (repeatablePanelPath != null && !repeatablePanelPath.isEmpty()) {
                Resource repeatablePanelResource = resourceResolver.getResource(repeatablePanelPath);
                repeatablePanelId = NodeStructureUtils.getGuideNodeHtmlId(repeatablePanelResource);
            }
            ArrayList<GuideProgressiveField> fields = new ArrayList<GuideProgressiveField>();
            Resource items = section.getChild(section.getPath() + "/items");
            for (Resource childSection : items.getChildren()) {
                ValueMap childSectionValueMap = ResourceUtil.getValueMap((Resource)childSection);
                String path = (String)childSectionValueMap.get((Object)"path");
                String id = (String)childSectionValueMap.get((Object)"id");
                String prefixId = (String)childSectionValueMap.get((Object)"prefixId");
                GuideProgressiveField field = new GuideProgressiveField(id, path, prefixId, resourceResolver);
                fields.add(field);
            }
            GuideProgressiveSectionInfo sectionInfo = new GuideProgressiveSectionInfo(sectionId, (String)sectionValueMap.get("jcr:title", (Object)""), (String)sectionValueMap.get((Object)"name"), fields, repeatablePanelPath, repeatablePanelId, Boolean.valueOf(data.get("fetchedFromService")));
            return sectionInfo;
        }
        return null;
    }

    @Override
    public GuideProgressiveCompletionInfo getCompletionSection(String afpath, Map<String, String> data) {
        String strategyJcrPath = data.get("strategyJcrPath");
        GuideProgressiveCompletionInfo completionInfo = null;
        ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
        Resource strategyResource = resourceResolver.getResource(strategyJcrPath);
        ValueMap strategyValueMap = ResourceUtil.getValueMap((Resource)strategyResource);
        Boolean isCompletionSectionAsProperty = (String)strategyValueMap.get((Object)"completionTitle") != null;
        if (isCompletionSectionAsProperty.booleanValue()) {
            completionInfo = this.getCompletionInfo(strategyValueMap);
        } else {
            for (Resource section : strategyResource.getChildren()) {
                ValueMap sectionValueMap = ResourceUtil.getValueMap((Resource)section);
                if (!"guideProgressiveCompletionSection".equals(sectionValueMap.get("guideNodeClass", (Object)""))) continue;
                completionInfo = this.getCompletionInfo(sectionValueMap);
            }
        }
        return completionInfo;
    }

    protected void bindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
        this.resourceResolverHelper = resourceResolverHelper;
    }

    protected void unbindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
        if (this.resourceResolverHelper == resourceResolverHelper) {
            this.resourceResolverHelper = null;
        }
    }
}