AggregationRule.java 1.5 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.api.resource.PersistenceException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 */
package com.adobe.cq.mobile.index.impl.builder;

import com.adobe.cq.mobile.index.impl.builder.AggregationRuleEntry;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

public class AggregationRule {
    private String primaryType;
    private List<AggregationRuleEntry> ruleEntryList;

    public AggregationRule(String primaryType, List<AggregationRuleEntry> ruleEntryList) {
        this.primaryType = primaryType;
        this.ruleEntryList = ruleEntryList;
    }

    public void build(Resource resource) throws PersistenceException {
        ResourceResolver resolver = resource.getResourceResolver();
        Resource aggregateNode = resolver.create(resource, this.primaryType, new HashMap());
        int i = 0;
        for (AggregationRuleEntry entry : this.ruleEntryList) {
            HashMap<String, Object> properties = new HashMap<String, Object>();
            properties.put(entry.getName(), entry.getValue());
            if (entry.isRelative()) {
                properties.put("relativeNode", true);
            }
            resolver.create(aggregateNode, "include" + i++, properties);
        }
    }
}