package se.citerus.dddsample.config;

import com.pathfinder.api.GraphTraversalService;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.transaction.PlatformTransactionManager;
import se.citerus.dddsample.application.ApplicationEvents;
import se.citerus.dddsample.application.BookingService;
import se.citerus.dddsample.application.CargoInspectionService;
import se.citerus.dddsample.application.HandlingEventService;
import se.citerus.dddsample.application.impl.BookingServiceImpl;
import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
import se.citerus.dddsample.application.util.SampleDataGenerator;
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
import se.citerus.dddsample.domain.model.location.LocationRepository;
import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
import se.citerus.dddsample.domain.service.RoutingService;
import se.citerus.dddsample.infrastructure.routing.ExternalRoutingService;

@Configuration
@ImportResource({
        "classpath:context-interfaces.xml",
        "classpath:context-infrastructure-messaging.xml",
        "classpath:context-infrastructure-persistence.xml"})
public class DDDSampleApplicationContext {

    @Autowired
    CargoRepository cargoRepository;

    @Autowired
    LocationRepository locationRepository;

    @Autowired
    VoyageRepository voyageRepository;

    @Autowired
    RoutingService routingService;

    @Autowired
    HandlingEventRepository handlingEventRepository;

    @Autowired
    HandlingEventFactory handlingEventFactory;

    @Autowired
    ApplicationEvents applicationEvents;

    @Autowired
    GraphTraversalService graphTraversalService;

    @Autowired
    PlatformTransactionManager platformTransactionManager;

    @Autowired
    SessionFactory sessionFactory;

    @Bean
    public BookingService bookingService() {
        return new BookingServiceImpl(cargoRepository, locationRepository, routingService);
    }

    @Bean
    public CargoInspectionService cargoInspectionService() {
        return new CargoInspectionServiceImpl(applicationEvents, cargoRepository, handlingEventRepository);
    }

    @Bean
    public HandlingEventService handlingEventService() {
        return new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
    }

    @Bean
    public HandlingEventFactory handlingEventFactory() {
        return new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
    }

    @Bean
    public RoutingService routingService() {
        ExternalRoutingService routingService = new ExternalRoutingService();
        routingService.setGraphTraversalService(graphTraversalService);
        routingService.setLocationRepository(locationRepository);
        routingService.setVoyageRepository(voyageRepository);
        return routingService;
    }

    @Bean
    public SampleDataGenerator sampleDataGenerator() {
        return new SampleDataGenerator(platformTransactionManager, sessionFactory, cargoRepository, voyageRepository, locationRepository, handlingEventRepository);
    }
}

@@ -1819,32 +1819,97 @@
 ageRepository;%0A%0A
+    @Autowired%0A    GraphTraversalService graphTraversalService;%0A%0A
     @Autowired%0A 
@@ -1971,30 +1971,27 @@
 andlingEvent
-Reposi
+Fac
 tory handlin
@@ -1992,30 +1992,27 @@
 andlingEvent
-Reposi
+Fac
 tory;%0A%0A    @
@@ -2030,35 +2030,38 @@
    HandlingEvent
-Fac
+Reposi
 tory handlingEve
@@ -2054,35 +2054,38 @@
 ry handlingEvent
-Fac
+Reposi
 tory;%0A%0A    @Auto
@@ -2136,73 +2136,8 @@
 s;%0A%0A
-    @Autowired%0A    GraphTraversalService graphTraversalService;%0A%0A
     

Fix bean init order.