Cq60StartupCodeUpgrade.java 5.29 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  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.cq60;

import com.day.cq.compat.codeupgrade.CodeUpgradeTask;
import com.day.cq.compat.codeupgrade.impl.StatusNode;
import com.day.cq.compat.codeupgrade.impl.cq60.Cq60MSMContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq60.Cq60SocialContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq60.Cq60UIContentUpgrade;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
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="%Cq60StartupCodeUpgrade.name", description="%Cq60StartupCodeUpgrade.description")
@Service
@Property(name="service.ranking", intValue={600})
public class Cq60StartupCodeUpgrade
implements CodeUpgradeTask {
    private final Logger log;
    private StatusNode statusNode;
    private ProgressInfoProvider infoProvider;
    @Reference
    private SlingRepository repository;
    @Property(value={"/var/upgrade/status"})
    public static final String PROP_STATUS_NODE_PATH = "status.node.path";
    @Property(value={"Cq60StartupCodeUpgrade"})
    public static final String PROP_STATUS_PROPERTY_NAME = "status.property.name";

    public Cq60StartupCodeUpgrade() {
        this.log = LoggerFactory.getLogger(this.getClass());
        this.repository = null;
    }

    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"));
    }

    @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 {
            Cq60StartupCodeUpgrade cq60StartupCodeUpgrade;
            s = this.repository.loginService("compat-codeupgrade", null);
            try {
                Cq60UIContentUpgrade uicu = new Cq60UIContentUpgrade();
                cq60StartupCodeUpgrade = this;
                synchronized (cq60StartupCodeUpgrade) {
                    this.infoProvider = uicu;
                }
                uicu.doUpgrade(s);
            }
            catch (Exception e) {
                this.log.warn("Exception when trying to execute " + Cq60UIContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
            }
            try {
                Cq60SocialContentUpgrade scu = new Cq60SocialContentUpgrade();
                cq60StartupCodeUpgrade = this;
                synchronized (cq60StartupCodeUpgrade) {
                    this.infoProvider = scu;
                }
                scu.doUpgrade(s);
            }
            catch (Exception e) {
                this.log.warn("Exception when trying to execute " + Cq60SocialContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
            }
            try {
                Cq60MSMContentUpgrade msmcu = new Cq60MSMContentUpgrade();
                cq60StartupCodeUpgrade = this;
                synchronized (cq60StartupCodeUpgrade) {
                    this.infoProvider = msmcu;
                }
                msmcu.doUpgrade(s);
            }
            catch (Exception e2) {
                this.log.warn("Exception when trying to execute " + Cq60MSMContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e2);
            }
            Cq60StartupCodeUpgrade e2 = this;
            synchronized (e2) {
                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;
        }
    }
}