Cq56StartupCodeUpgrade.java 5.24 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.security.UserManager
 *  com.day.cq.security.UserManagerFactory
 *  com.day.cq.workflow.WorkflowService
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.jcr.api.SlingRepository
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.compat.codeupgrade.impl.cq56;

import com.day.cq.compat.codeupgrade.CodeUpgradeTask;
import com.day.cq.compat.codeupgrade.impl.StatusNode;
import com.day.cq.compat.codeupgrade.impl.cq56.Workflow54ModelUpgrade;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import com.day.cq.security.UserManager;
import com.day.cq.security.UserManagerFactory;
import com.day.cq.workflow.WorkflowService;
import java.util.Dictionary;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=1, metatype=1, label="%Cq56StartupCodeUpgrade.name", description="%Cq56StartupCodeUpgrade.description")
@Service
@Property(name="service.ranking", intValue={560})
public class Cq56StartupCodeUpgrade
implements CodeUpgradeTask {
    private final Logger log;
    private StatusNode statusNode;
    private ProgressInfoProvider infoProvider;
    private boolean doWorkflowUpgrade;
    @Reference
    private SlingRepository repository;
    @Reference
    private WorkflowService workflowService;
    @Reference
    private UserManagerFactory userManagerFactory;
    @Property(value={"/var/upgrade/status"})
    public static final String PROP_STATUS_NODE_PATH = "status.node.path";
    @Property(value={"Cq56StartupCodeUpgrade"})
    public static final String PROP_STATUS_PROPERTY_NAME = "status.property.name";
    @Property(value={"false"})
    public static final String PROP_DO54MODELUPGRADE = "do54ModelUpgrade";

    public Cq56StartupCodeUpgrade() {
        this.log = LoggerFactory.getLogger(this.getClass());
        this.doWorkflowUpgrade = false;
    }

    public String toString() {
        return this.getClass().getSimpleName();
    }

    public void activate(ComponentContext ctx) throws Exception {
        Dictionary properties = ctx.getProperties();
        this.statusNode = new StatusNode((String)properties.get("status.node.path"), (String)properties.get("status.property.name"));
        String doUpgrade = (String)properties.get("do54ModelUpgrade");
        this.doWorkflowUpgrade = Boolean.parseBoolean(doUpgrade);
    }

    @Override
    public void cancelUpgrade() {
    }

    @Override
    public synchronized String getProgressInfo() {
        if (this.infoProvider == null) {
            return "No info from " + this.getClass().getName();
        }
        return this.infoProvider.getProgressInfo();
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public void run() {
        Session s = null;
        try {
            s = this.repository.loginService("compat-codeupgrade", null);
            Object wmu = new Workflow54ModelUpgrade(this.doWorkflowUpgrade);
            Cq56StartupCodeUpgrade cq56StartupCodeUpgrade = this;
            synchronized (cq56StartupCodeUpgrade) {
                this.infoProvider = wmu;
            }
            wmu.doUpgrade(s, this.workflowService, this.userManagerFactory.createUserManager(s));
            wmu = this;
            synchronized (wmu) {
                this.infoProvider = null;
            }
            this.statusNode.recordUpgrade(this.repository);
        }
        catch (Exception e) {
            this.log.warn("Exception in " + this.getClass().getSimpleName() + ".run()", (Throwable)e);
        }
        finally {
            if (s != null) {
                s.logout();
            }
        }
    }

    @Override
    public boolean upgradeNeeded() {
        return this.statusNode.upgradeNeeded(this.repository);
    }

    protected void bindRepository(SlingRepository slingRepository) {
        this.repository = slingRepository;
    }

    protected void unbindRepository(SlingRepository slingRepository) {
        if (this.repository == slingRepository) {
            this.repository = null;
        }
    }

    protected void bindWorkflowService(WorkflowService workflowService) {
        this.workflowService = workflowService;
    }

    protected void unbindWorkflowService(WorkflowService workflowService) {
        if (this.workflowService == workflowService) {
            this.workflowService = null;
        }
    }

    protected void bindUserManagerFactory(UserManagerFactory userManagerFactory) {
        this.userManagerFactory = userManagerFactory;
    }

    protected void unbindUserManagerFactory(UserManagerFactory userManagerFactory) {
        if (this.userManagerFactory == userManagerFactory) {
            this.userManagerFactory = null;
        }
    }
}