DurboImportConfigurationProviderService.java 5.27 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Deactivate
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.osgi.service.component.ComponentContext
 */
package com.day.cq.replication.impl.content.durbo;

import com.day.cq.replication.impl.content.durbo.DurboImportConfiguration;
import com.day.cq.replication.impl.content.durbo.DurboImportConfigurationProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;

@Component(metatype=1)
@Service(value={DurboImportConfigurationProvider.class})
public class DurboImportConfigurationProviderService
implements DurboImportConfigurationProvider {
    @Property(boolValue={0})
    private static final String PRESERVE_HIERARCHYNODES = "preserve.hierarchy.nodes";
    @Property(label="Ignore versioning", description="Ignore mix:versionable node type on import", boolValue={0})
    private static final String IGNORE_VERSIONING_NODETYPES = "ignore.versioning";
    @Property(label="Import ACL", description="Flag to import ACL. Default false", boolValue={0})
    private static final String IMPORT_ACL = "import.acl";
    @Property(label="Save threshold", description="Number of nodes to import before issuing an intermediate save", intValue={-1})
    private static final String SAVE_THRESHOLD = "save.threshold";
    @Property(label="Preserve User Paths", description="Flag to preserve user paths when importing user nodes. Default false", boolValue={0})
    private static final String PRESERVE_USER_PATHS = "preserve.user.paths";
    @Property(label="Preserve UUIDs", description="Flag to preserve jcr:uuid property when importing nodes. Default true", boolValue={1})
    private static final String PRESERVE_UUID = "preserve.uuid";
    @Property(value={"dam:Asset"}, label="Preserve UUIDs for nodetypes", description="Preserve UUIDs for nodes imported with specified (primary) node-types ONLY")
    public static final String PRESERVE_UUID_NODETYPES = "preserve.uuid.nodetypes";
    @Property(value={"/content/dam/"}, label="Preserve UUIDs in subtree", description="Preserve UUIDs for nodes imported under specified repository-paths ONLY")
    public static final String PRESERVE_UUID_SUBTREE = "preserve.uuid.subtrees";
    private DurboImportConfiguration configuration;

    @Activate
    protected void activate(ComponentContext context) throws Exception {
        this.readConfiguration(context);
    }

    @Modified
    protected void modified(ComponentContext context) throws Exception {
        this.readConfiguration(context);
    }

    @Deactivate
    protected void deactivate() {
        this.configuration = null;
    }

    private void readConfiguration(ComponentContext context) {
        List<String> preservedNodeTypes;
        boolean preserveHierarchyNodes = Boolean.valueOf(String.valueOf(context.getProperties().get("preserve.hierarchy.nodes")));
        if (preserveHierarchyNodes) {
            preservedNodeTypes = new ArrayList(1);
            preservedNodeTypes.add("{http://www.jcp.org/jcr/nt/1.0}hierarchyNode");
        } else {
            preservedNodeTypes = Collections.emptyList();
        }
        boolean ignoreVersioningNodeTypes = Boolean.valueOf(String.valueOf(context.getProperties().get("ignore.versioning")));
        ArrayList<String> ignoredNodeTypes = new ArrayList<String>(1);
        if (ignoreVersioningNodeTypes) {
            ignoredNodeTypes.add("mix:versionable");
        }
        boolean importAcl = Boolean.valueOf(String.valueOf(context.getProperties().get("import.acl")));
        int saveThreshold = Integer.valueOf(String.valueOf(context.getProperties().get("save.threshold")));
        boolean preserveUserPaths = Boolean.valueOf(String.valueOf(context.getProperties().get("preserve.user.paths")));
        boolean preserveUUID = Boolean.valueOf(String.valueOf(context.getProperties().get("preserve.uuid")));
        HashSet<String> preserveUUIDForNodeTypes = new HashSet<String>(Arrays.asList(PropertiesUtil.toStringArray(context.getProperties().get("preserve.uuid.nodetypes"))));
        HashSet<String> preserveUUIDInSubtrees = new HashSet<String>(Arrays.asList(PropertiesUtil.toStringArray(context.getProperties().get("preserve.uuid.subtrees"))));
        this.configuration = new DurboImportConfiguration(Collections.<String>emptyList(), preservedNodeTypes, ignoredNodeTypes, importAcl, saveThreshold, preserveUserPaths, preserveUUID, preserveUUIDForNodeTypes, preserveUUIDInSubtrees);
    }

    @Override
    public DurboImportConfiguration getConfiguration() {
        return this.configuration;
    }
}