package com.collabnet.ctf.events.custom.events;

import com.vasoftware.sf.common.logger.Logger;
import com.collabnet.ce.soap60.webservices.cemain.ObjectSoapDO;

import com.collabnet.ctf.events.Asynchronous;
import com.collabnet.ctf.events.Synchronous;
import com.collabnet.ctf.events.EventContext;
import com.collabnet.ctf.events.EventListener;
import com.collabnet.ctf.events.SoapVersion;

@EventListener(version = SoapVersion.SOAP_60)
public class Event2Listener {

    private static final Logger log = Logger.getLogger(Event2Listener.class);
    /**
     * This method is called when the event needs to be processed. At this
     * point, the original and updated data, the event context and the session
     * key should be available to the event handler. If information needs to be
     * passed back to the user the addSuccessMessage and addErrorMessage calls
     * should be used.
     *
     * @throws Exception If something bad happening while processing the event.
     */
    @Asynchronous(topic = "object.item.Artifact.*", user = "system")
    public void asyncProcessEvent(final EventContext context) throws Exception {
        log.info("Async process event");
        log.info("Operation: " + context.getEventOperation());
        log.info("ProjectId: " + context.getProjectId());
        log.info("UserName: " + context.getUsername());
        log.info("Original Data Class: " + context.getOriginalData().getClass().toString());
        log.info("Updated Data Class: " + context.getUpdatedData().getClass().toString());
        log.info("One Time Token: " + context.getOneTimeToken());
        log.info("Integrated App Shared Key: " + context.getIntegratedAppSharedKey());
        ObjectSoapDO o = (ObjectSoapDO)context.getOriginalData();
        ObjectSoapDO u = (ObjectSoapDO)context.getUpdatedData();
        log.info("orig obj" + o);
        log.info("orig id " + o.getId());
        log.info("updated obj" + u);
    }

    @Synchronous(topic = "object.item.Artifact.*", user = "system")
    public void syncProcessEvent(final EventContext context) throws Exception {
        log.info("Sync process event");
        log.info("Operation: " + context.getEventOperation());
        log.info("ProjectId: " + context.getProjectId());
        log.info("UserName: " + context.getUsername());
        log.info("Original Data Class: " + context.getOriginalData().getClass().toString());
        log.info("Updated Data Class: " + context.getUpdatedData().getClass().toString());
        log.info("One Time Token: " + context.getOneTimeToken());
        log.info("Integrated App Shared Key: " + context.getIntegratedAppSharedKey());
        ObjectSoapDO o = (ObjectSoapDO)context.getOriginalData();
        ObjectSoapDO u = (ObjectSoapDO)context.getUpdatedData();
        log.info("orig obj" + o);
        log.info("orig id " + o.getId());
        log.info("updated obj" + u);
    }
}
