Sfoglia il codice sorgente

Changed application context configuration from XML to Java-based and removed RMI dependency between booking and routing context.

marlin 9 anni fa
parent
commit
34c2b8432a

+ 3
- 6
src/main/java/com/pathfinder/api/GraphTraversalService.java Vedi File

@@ -1,7 +1,5 @@
1 1
 package com.pathfinder.api;
2 2
 
3
-import java.rmi.Remote;
4
-import java.rmi.RemoteException;
5 3
 import java.util.List;
6 4
 import java.util.Properties;
7 5
 
@@ -10,17 +8,16 @@ import java.util.Properties;
10 8
  * and used by us (booking and tracking team).
11 9
  *
12 10
  */
13
-public interface GraphTraversalService extends Remote {
11
+public interface GraphTraversalService {
14 12
 
15 13
   /**
16 14
    * @param originUnLocode origin UN Locode
17 15
    * @param destinationUnLocode destination UN Locode
18 16
    * @param limitations restrictions on the path selection, as key-value according to some API specification
19
-   * @return A list of transit paths
20
-   * @throws RemoteException RMI problem
17
+   * @return A list of transit pathss
21 18
    */
22 19
   List<TransitPath> findShortestPath(String originUnLocode,
23 20
                                      String destinationUnLocode,
24
-                                     Properties limitations) throws RemoteException;
21
+                                     Properties limitations);
25 22
 
26 23
 }

+ 20
- 0
src/main/java/com/pathfinder/config/PathfinderApplicationContext.java Vedi File

@@ -0,0 +1,20 @@
1
+package com.pathfinder.config;
2
+
3
+import com.pathfinder.api.GraphTraversalService;
4
+import com.pathfinder.internal.GraphDAO;
5
+import com.pathfinder.internal.GraphTraversalServiceImpl;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+
9
+@Configuration
10
+public class PathfinderApplicationContext {
11
+
12
+    private GraphDAO graphDAO() {
13
+        return new GraphDAO();
14
+    }
15
+
16
+    @Bean
17
+    public GraphTraversalService graphTraversalService() {
18
+        return new GraphTraversalServiceImpl(graphDAO());
19
+    }
20
+}

+ 7
- 36
src/main/java/se/citerus/dddsample/Application.java Vedi File

@@ -1,57 +1,28 @@
1 1
 package se.citerus.dddsample;
2 2
 
3
-import org.hibernate.SessionFactory;
3
+import com.pathfinder.config.PathfinderApplicationContext;
4 4
 import org.springframework.beans.factory.annotation.Autowired;
5 5
 import org.springframework.boot.SpringApplication;
6 6
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
7
-import org.springframework.context.annotation.Bean;
8 7
 import org.springframework.context.annotation.Configuration;
9
-import org.springframework.context.annotation.ImportResource;
10
-import org.springframework.transaction.PlatformTransactionManager;
8
+import org.springframework.context.annotation.Import;
11 9
 import se.citerus.dddsample.application.util.SampleDataGenerator;
12
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
13
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
14
-import se.citerus.dddsample.domain.model.location.LocationRepository;
15
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
10
+import se.citerus.dddsample.config.DDDSampleApplicationContext;
16 11
 
17 12
 import javax.annotation.PostConstruct;
18 13
 
19 14
 @Configuration
20
-@ImportResource({
21
-        "classpath:/com/pathfinder/internal/applicationContext.xml",
22
-        "classpath:context-infrastructure.xml",
23
-        "classpath:context-application.xml",
24
-        "classpath:context-domain.xml",
25
-        "classpath:context-interfaces.xml"})
15
+@Import({DDDSampleApplicationContext.class,
16
+        PathfinderApplicationContext.class})
26 17
 @EnableAutoConfiguration
27 18
 public class Application {
28 19
 
29 20
     @Autowired
30
-    PlatformTransactionManager platformTransactionManager;
31
-
32
-    @Autowired
33
-    SessionFactory sessionFactory;
34
-
35
-    @Autowired
36
-    CargoRepository cargoRepository;
37
-
38
-    @Autowired
39
-    VoyageRepository voyageRepository;
40
-
41
-    @Autowired
42
-    LocationRepository locationRepository;
43
-
44
-    @Autowired
45
-    HandlingEventRepository handlingEventRepository;
46
-
47
-    @Bean
48
-    public SampleDataGenerator sampleDataGenerator() {
49
-        return new SampleDataGenerator(platformTransactionManager, sessionFactory, cargoRepository, voyageRepository, locationRepository, handlingEventRepository);
50
-    }
21
+    SampleDataGenerator sampleDataGenerator;
51 22
 
52 23
     @PostConstruct
53 24
     public void init() {
54
-        sampleDataGenerator().generate();
25
+        sampleDataGenerator.generate();
55 26
     }
56 27
 
57 28
     public static void main(String[] args) throws Exception {

+ 96
- 0
src/main/java/se/citerus/dddsample/config/DDDSampleApplicationContext.java Vedi File

@@ -0,0 +1,96 @@
1
+package se.citerus.dddsample.config;
2
+
3
+import com.pathfinder.api.GraphTraversalService;
4
+import org.hibernate.SessionFactory;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+import org.springframework.context.annotation.ImportResource;
9
+import org.springframework.transaction.PlatformTransactionManager;
10
+import se.citerus.dddsample.application.ApplicationEvents;
11
+import se.citerus.dddsample.application.BookingService;
12
+import se.citerus.dddsample.application.CargoInspectionService;
13
+import se.citerus.dddsample.application.HandlingEventService;
14
+import se.citerus.dddsample.application.impl.BookingServiceImpl;
15
+import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
16
+import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
17
+import se.citerus.dddsample.application.util.SampleDataGenerator;
18
+import se.citerus.dddsample.domain.model.cargo.CargoRepository;
19
+import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
20
+import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
21
+import se.citerus.dddsample.domain.model.location.LocationRepository;
22
+import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
23
+import se.citerus.dddsample.domain.service.RoutingService;
24
+import se.citerus.dddsample.infrastructure.routing.ExternalRoutingService;
25
+
26
+@Configuration
27
+@ImportResource({
28
+        "classpath:context-interfaces.xml",
29
+        "classpath:context-infrastructure-messaging.xml",
30
+        "classpath:context-infrastructure-persistence.xml"})
31
+public class DDDSampleApplicationContext {
32
+
33
+    @Autowired
34
+    CargoRepository cargoRepository;
35
+
36
+    @Autowired
37
+    LocationRepository locationRepository;
38
+
39
+    @Autowired
40
+    VoyageRepository voyageRepository;
41
+
42
+    @Autowired
43
+    RoutingService routingService;
44
+
45
+    @Autowired
46
+    HandlingEventRepository handlingEventRepository;
47
+
48
+    @Autowired
49
+    HandlingEventFactory handlingEventFactory;
50
+
51
+    @Autowired
52
+    ApplicationEvents applicationEvents;
53
+
54
+    @Autowired
55
+    GraphTraversalService graphTraversalService;
56
+
57
+    @Autowired
58
+    PlatformTransactionManager platformTransactionManager;
59
+
60
+    @Autowired
61
+    SessionFactory sessionFactory;
62
+
63
+    @Bean
64
+    public BookingService bookingService() {
65
+        return new BookingServiceImpl(cargoRepository, locationRepository, routingService);
66
+    }
67
+
68
+    @Bean
69
+    public CargoInspectionService cargoInspectionService() {
70
+        return new CargoInspectionServiceImpl(applicationEvents, cargoRepository, handlingEventRepository);
71
+    }
72
+
73
+    @Bean
74
+    public HandlingEventService handlingEventService() {
75
+        return new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
76
+    }
77
+
78
+    @Bean
79
+    public HandlingEventFactory handlingEventFactory() {
80
+        return new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
81
+    }
82
+
83
+    @Bean
84
+    public RoutingService routingService() {
85
+        ExternalRoutingService routingService = new ExternalRoutingService();
86
+        routingService.setGraphTraversalService(graphTraversalService);
87
+        routingService.setLocationRepository(locationRepository);
88
+        routingService.setVoyageRepository(voyageRepository);
89
+        return routingService;
90
+    }
91
+
92
+    @Bean
93
+    public SampleDataGenerator sampleDataGenerator() {
94
+        return new SampleDataGenerator(platformTransactionManager, sessionFactory, cargoRepository, voyageRepository, locationRepository, handlingEventRepository);
95
+    }
96
+}

+ 0
- 7
src/main/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingService.java Vedi File

@@ -15,9 +15,7 @@ import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
15 15
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
16 16
 import se.citerus.dddsample.domain.service.RoutingService;
17 17
 
18
-import java.rmi.RemoteException;
19 18
 import java.util.ArrayList;
20
-import java.util.Collections;
21 19
 import java.util.List;
22 20
 import java.util.Properties;
23 21
 
@@ -45,16 +43,11 @@ public class ExternalRoutingService implements RoutingService {
45 43
     limitations.setProperty("DEADLINE", routeSpecification.arrivalDeadline().toString());
46 44
 
47 45
     final List<TransitPath> transitPaths;
48
-    try {
49 46
       transitPaths = graphTraversalService.findShortestPath(
50 47
       origin.unLocode().idString(),
51 48
       destination.unLocode().idString(),
52 49
       limitations
53 50
     );
54
-    } catch (RemoteException e) {
55
-      log.error(e, e);
56
-      return Collections.EMPTY_LIST;
57
-    }
58 51
 
59 52
     /*
60 53
      The returned result is then translated back into our domain model.

+ 0
- 24
src/main/resources/com/pathfinder/internal/applicationContext.xml Vedi File

@@ -1,24 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6
-
7
-  <bean id="internalGraphTraversalService" class="com.pathfinder.internal.GraphTraversalServiceImpl">
8
-    <constructor-arg ref="graphDAO"/>
9
-  </bean>
10
-
11
-  <bean id="graphDAO" class="com.pathfinder.internal.GraphDAO"/>
12
-
13
-  <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
14
-    <property name="port" value="1199"/>
15
-  </bean>
16
-
17
-  <bean id="rmiGraphTraversalService" class="org.springframework.remoting.rmi.RmiServiceExporter">
18
-    <property name="serviceInterface" value="com.pathfinder.api.GraphTraversalService"/>
19
-    <property name="service" ref="internalGraphTraversalService"/>
20
-    <property name="serviceName" value="PathFinder"/>
21
-    <property name="registry" ref="registry"/>
22
-  </bean>
23
-
24
-</beans>

+ 0
- 25
src/main/resources/context-application.xml Vedi File

@@ -1,25 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6
-
7
-  <bean id="bookingService" class="se.citerus.dddsample.application.impl.BookingServiceImpl">
8
-    <constructor-arg ref="cargoRepository"/>
9
-    <constructor-arg ref="locationRepository"/>
10
-    <constructor-arg ref="routingService"/>
11
-  </bean>
12
-
13
-  <bean id="cargoInspectionService" class="se.citerus.dddsample.application.impl.CargoInspectionServiceImpl">
14
-    <constructor-arg ref="cargoRepository"/>
15
-    <constructor-arg ref="applicationEvents"/>
16
-    <constructor-arg ref="handlingEventRepository"/>
17
-  </bean>
18
-
19
-  <bean id="handlingEventService" class="se.citerus.dddsample.application.impl.HandlingEventServiceImpl">
20
-    <constructor-arg ref="handlingEventRepository"/>
21
-    <constructor-arg ref="handlingEventFactory"/>
22
-    <constructor-arg ref="applicationEvents"/>
23
-  </bean>
24
-
25
-</beans>

+ 0
- 13
src/main/resources/context-domain.xml Vedi File

@@ -1,13 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6
-
7
-  <bean id="handlingEventFactory" class="se.citerus.dddsample.domain.model.handling.HandlingEventFactory">
8
-    <constructor-arg ref="cargoRepository"/>
9
-    <constructor-arg ref="voyageRepository"/>
10
-    <constructor-arg ref="locationRepository"/>
11
-  </bean>
12
-
13
-</beans>

+ 0
- 23
src/main/resources/context-infrastructure.xml Vedi File

@@ -1,23 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6
-
7
-  <import resource="context-infrastructure-persistence.xml"/>
8
-  <import resource="context-infrastructure-messaging.xml"/>
9
-
10
-  <!-- External graph traversal routing service  -->
11
-
12
-  <bean id="routingService" class="se.citerus.dddsample.infrastructure.routing.ExternalRoutingService">
13
-    <property name="graphTraversalService" ref="internalGraphTraversalService"/>
14
-    <property name="locationRepository" ref="locationRepository"/>
15
-    <property name="voyageRepository" ref="voyageRepository"/>
16
-  </bean>
17
-
18
-  <bean id="graphTraversalService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
19
-    <property name="serviceUrl" value="rmi://localhost:1199/PathFinder"/>
20
-    <property name="serviceInterface" value="com.pathfinder.api.GraphTraversalService"/>
21
-  </bean>
22
-
23
-</beans>

+ 2
- 2
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java Vedi File

@@ -1,7 +1,7 @@
1 1
 package se.citerus.dddsample.infrastructure.persistence.hibernate;
2 2
 
3
-import org.hibernate.SessionFactory;
4 3
 import org.hibernate.Session;
4
+import org.hibernate.SessionFactory;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;
7 7
 import org.junit.runner.RunWith;
@@ -38,7 +38,7 @@ import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
38 38
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM004;
39 39
 
40 40
 @RunWith(SpringJUnit4ClassRunner.class)
41
-@ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
41
+@ContextConfiguration(value = {"/context-infrastructure-persistence.xml"})
42 42
 @TransactionConfiguration(transactionManager = "transactionManager")
43 43
 @Transactional
44 44
 public class CargoRepositoryTest {

+ 1
- 1
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CarrierMovementRepositoryTest.java Vedi File

@@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
23 23
 import static org.junit.Assert.assertNotNull;
24 24
 
25 25
 @RunWith(SpringJUnit4ClassRunner.class)
26
-@ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
26
+@ContextConfiguration(value = {"/context-infrastructure-persistence.xml"})
27 27
 @TransactionConfiguration(transactionManager = "transactionManager")
28 28
 @Transactional
29 29
 public class CarrierMovementRepositoryTest {

+ 2
- 2
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java Vedi File

@@ -1,7 +1,7 @@
1 1
 package se.citerus.dddsample.infrastructure.persistence.hibernate;
2 2
 
3
-import org.hibernate.SessionFactory;
4 3
 import org.hibernate.Session;
4
+import org.hibernate.SessionFactory;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;
7 7
 import org.junit.runner.RunWith;
@@ -32,7 +32,7 @@ import java.util.Map;
32 32
 import static org.junit.Assert.assertEquals;
33 33
 
34 34
 @RunWith(SpringJUnit4ClassRunner.class)
35
-@ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
35
+@ContextConfiguration(value = {"/context-infrastructure-persistence.xml"})
36 36
 @TransactionConfiguration(transactionManager = "transactionManager")
37 37
 @Transactional
38 38
 public class HandlingEventRepositoryTest {

+ 1
- 1
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/LocationRepositoryTest.java Vedi File

@@ -22,7 +22,7 @@ import java.util.List;
22 22
 import static org.junit.Assert.*;
23 23
 
24 24
 @RunWith(SpringJUnit4ClassRunner.class)
25
-@ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
25
+@ContextConfiguration(value = {"/context-infrastructure-persistence.xml"})
26 26
 @TransactionConfiguration(transactionManager = "transactionManager")
27 27
 @Transactional
28 28
 public class LocationRepositoryTest {