package com.celements.mandatory;

import java.util.Arrays;
import java.util.List;

import org.xwiki.bridge.event.WikiCreatedEvent;
import org.xwiki.bridge.event.WikiEvent;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.Requirement;
import org.xwiki.context.Execution;
import org.xwiki.observation.EventListener;
import org.xwiki.observation.event.Event;

import com.xpn.xwiki.XWikiContext;

@Component("celements.mandatory.WikiCreatedEventListener")
public class WikiCreatedEventListener implements EventListener {

  @Requirement
  IMandatoryDocumentCompositorRole mandatoryDocCmp;

  @Requirement
  private Execution execution;

  protected XWikiContext getContext() {
    return (XWikiContext)execution.getContext().getProperty("xwikicontext");
  }

  public String getName() {
    return "celements.mandatory.WikiCreatedEventListener";
  }

  public List<Event> getEvents() {
    return Arrays.<Event>asList(new WikiCreatedEvent());
  }

  public void onEvent(Event event, Object source, Object data) {
    String saveDbName = getContext().getDatabase();
    try {
      WikiEvent wikiEvent = (WikiEvent) event;
      String newDbName = wikiEvent.getWikiId();
      getContext().setDatabase(newDbName);
      mandatoryDocCmp.checkAllMandatoryDocuments();
    } finally {
      getContext().setDatabase(saveDbName);
    }
  }

}

@@ -72,24 +72,109 @@
 util.List;%0A%0A
+import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A
 import org.x
@@ -634,16 +634,123 @@
 ener %7B%0A%0A
+  private static Log LOGGER = LogFactory.getFactory().getInstance(%0A      WikiCreatedEventListener.class);%0A%0A
   @Requi
@@ -1442,69 +1442,352 @@
     
-mandatoryDocCmp.checkAllMandatoryDocuments();%0A    %7D finally %7B
+LOGGER.info(%22received wikiEvent %5B%22 + wikiEvent.getClass() + %22%5D for wikiId %5B%22%0A          + newDbName + %22%5D now executing checkAllMandatoryDocuments.%22);%0A      mandatoryDocCmp.checkAllMandatoryDocuments();%0A    %7D finally %7B%0A      LOGGER.debug(%22finishing onEvent in WikiCreatedEventListener for wikiId %5B%22%0A          + getContext().getDatabase() + %22%5D.%22);
 %0A   

add logging to WikiCreatedEventListener