RolloutExceptionHandlerImpl.java 2.56 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.audit.AuditLog
 *  com.day.cq.audit.AuditLogEntry
 *  com.day.cq.wcm.msm.api.RolloutExceptionHandler
 *  com.day.cq.wcm.msm.api.RolloutExceptionHandler$RolloutInfo
 *  com.day.cq.wcm.msm.api.RolloutManager
 *  javax.jcr.lock.LockException
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.msm.impl;

import com.day.cq.audit.AuditLog;
import com.day.cq.audit.AuditLogEntry;
import com.day.cq.wcm.msm.api.RolloutExceptionHandler;
import com.day.cq.wcm.msm.api.RolloutManager;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.lock.LockException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service
public class RolloutExceptionHandlerImpl
implements RolloutExceptionHandler {
    private final Logger log;
    @Reference
    private AuditLog auditLog;
    public static final String AUDIT_LOG_CATEGORY = RolloutManager.class.getName();
    public static final String AUDIT_LOG_TYPE = "rollout.page.locked";

    public RolloutExceptionHandlerImpl() {
        this.log = LoggerFactory.getLogger(this.getClass());
    }

    public boolean handleException(Exception orig, RolloutExceptionHandler.RolloutInfo info) {
        boolean result = false;
        for (Throwable t = orig; t != null; t = t.getCause()) {
            result = t instanceof LockException;
            if (!result) continue;
            HashMap<String, String> props = new HashMap<String, String>();
            props.put("exception", t.toString());
            props.put("exceptionMessage", t.getMessage());
            props.put("target", info.target);
            props.put("operation", info.operation);
            this.auditLog.add(new AuditLogEntry(AUDIT_LOG_CATEGORY, new Date(), info.user, info.src, "rollout.page.locked", props));
            this.log.info("Exception is (or was caused by) a LockException, info written to AuditLog, rollout can continue", (Throwable)orig);
            break;
        }
        return result;
    }

    protected void bindAuditLog(AuditLog auditLog) {
        this.auditLog = auditLog;
    }

    protected void unbindAuditLog(AuditLog auditLog) {
        if (this.auditLog == auditLog) {
            this.auditLog = null;
        }
    }
}