package org.chtijbug.drools.platform.backend.service.runtimeevent.impl.knowledgeSession;

import org.apache.log4j.Logger;
import org.chtijbug.drools.entity.history.HistoryEvent;
import org.chtijbug.drools.entity.history.session.SessionFireAllRulesMaxNumberReachedEvent;
import org.chtijbug.drools.platform.backend.service.runtimeevent.AbstractEventHandlerStrategy;
import org.chtijbug.drools.platform.persistence.PlatformRuntimeInstanceRepository;
import org.chtijbug.drools.platform.persistence.SessionExecutionRepository;
import org.chtijbug.drools.platform.persistence.pojo.SessionExecution;
import org.chtijbug.drools.platform.persistence.pojo.SessionExecutionStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * Date: 25/03/14
 * Time: 15:07
 * To change this template use File | Settings | File Templates.
 */

@Component
public class KnowledgeSessionFireAllRulesAndStartProcessEventStrategy extends AbstractEventHandlerStrategy {
    private static final Logger LOG = Logger.getLogger(KnowledgeSessionFireAllRulesAndStartProcessEventStrategy.class);

    @Autowired
    PlatformRuntimeInstanceRepository platformRuntimeInstanceRepository;

    @Autowired
    SessionExecutionRepository sessionExecutionRepository;

    @Override
    @Transactional
    protected void handleMessageInternally(HistoryEvent historyEvent) {
        SessionFireAllRulesMaxNumberReachedEvent sessionFireAllRulesMaxNumberReachedEvent = (SessionFireAllRulesMaxNumberReachedEvent) historyEvent;
        SessionExecution existingSessionRutime = sessionExecutionRepository.findByRuleBaseIDAndSessionIdAndEndDateIsNull(historyEvent.getRuleBaseID(), historyEvent.getSessionId());
        if (existingSessionRutime != null) {
            existingSessionRutime.setEndDate(new Date());
            existingSessionRutime.setSessionExecutionStatus(SessionExecutionStatus.CRASHED);
            sessionExecutionRepository.save(existingSessionRutime);
        }

        LOG.debug("SessionFireAllRulesMaxNumberReachedEvent " + sessionFireAllRulesMaxNumberReachedEvent.toString());
    }

    @Override
    public boolean isEventSupported(HistoryEvent historyEvent) {

        return historyEvent instanceof SessionFireAllRulesMaxNumberReachedEvent;
    }
}

@@ -521,156 +521,8 @@
 ry;%0A
-import org.chtijbug.drools.platform.persistence.pojo.SessionExecution;%0Aimport org.chtijbug.drools.platform.persistence.pojo.SessionExecutionStatus;%0A
 impo
@@ -699,32 +699,8 @@
 l;%0A%0A
-import java.util.Date;%0A%0A
 /**%0A
@@ -1492,24 +1492,28 @@
 vent;%0A      
+  //
   SessionExe
@@ -1681,16 +1681,20 @@
 ;%0A      
+  //
   if (ex
@@ -1723,37 +1723,41 @@
  null) %7B%0A       
+ //
      
+ 
 existingSessionR
@@ -1788,24 +1788,28 @@
 e());%0A      
+  //
       existi
@@ -1885,24 +1885,28 @@
 HED);%0A      
+  //
       sessio
@@ -1959,24 +1959,26 @@
 e);%0A        
+//
 %7D%0A%0A        L

remove code to avoid errors