Przeglądaj źródła

Initial import of HandlingEvent registration application

jorgen_falk 18 lat temu
rodzic
commit
17a7baa2c2

+ 10
- 0
register-app/.classpath Wyświetl plik

@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="src" path="src/main/java"/>
4
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
5
+	<classpathentry kind="src" path="src/main/resources"/>
6
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
8
+	<classpathentry kind="lib" path="dddsample-1.0-SNAPSHOT.jar"/>
9
+	<classpathentry kind="output" path="target/classes"/>
10
+</classpath>

+ 23
- 0
register-app/.project Wyświetl plik

@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>register-app</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.maven.ide.eclipse.maven2Builder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.jdt.core.javabuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+	</buildSpec>
19
+	<natures>
20
+		<nature>org.eclipse.jdt.core.javanature</nature>
21
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
22
+	</natures>
23
+</projectDescription>

BIN
register-app/dddsample-1.0-SNAPSHOT.jar Wyświetl plik


+ 67
- 0
register-app/pom.xml Wyświetl plik

@@ -0,0 +1,67 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
+  <modelVersion>4.0.0</modelVersion>
6
+  <groupId>se.citerus</groupId>
7
+  <artifactId>register-app</artifactId>
8
+  <name>register-app</name>
9
+  <version>1.0-SNAPSHOT</version>
10
+  <url>http://maven.apache.org</url>
11
+    <repositories>
12
+    <repository>
13
+      <id>maven2-repository.dev.java.net</id>
14
+      <name>Java.net Repository for Maven</name>
15
+      <url>http://download.java.net/maven/2/</url>
16
+      <layout>default</layout>
17
+    </repository>
18
+   </repositories>
19
+     <pluginRepositories>
20
+    <pluginRepository>
21
+      <id>maven2-repository.dev.java.net</id>
22
+      <name>Java.net Repository for Maven</name>
23
+      <url>http://download.java.net/maven/2/</url>
24
+    </pluginRepository>
25
+  </pluginRepositories>
26
+  <build>
27
+     <plugins>
28
+      <!-- Compiler -->
29
+      <plugin>
30
+        <artifactId>maven-compiler-plugin</artifactId>
31
+        <configuration>
32
+          <source>1.5</source>
33
+          <target>1.5</target>
34
+          <encoding>UTF-8</encoding>
35
+        </configuration>
36
+      </plugin>
37
+     </plugins>
38
+   </build> 
39
+  <dependencies>
40
+    <dependency>
41
+      <groupId>junit</groupId>
42
+      <artifactId>junit</artifactId>
43
+      <version>3.8.1</version>
44
+      <scope>test</scope>
45
+    </dependency>
46
+    <dependency>
47
+      <groupId>org.springframework</groupId>
48
+      <artifactId>spring</artifactId>
49
+      <version>2.5</version>
50
+    </dependency>
51
+    <dependency>
52
+      <groupId>com.jgoodies</groupId>
53
+      <artifactId>forms</artifactId>
54
+      <version>1.0.7</version>
55
+    </dependency>
56
+    <dependency>
57
+      <groupId>com.jgoodies</groupId>
58
+      <artifactId>looks</artifactId>
59
+      <version>2.1.2</version>
60
+    </dependency>   
61
+        <dependency>
62
+      <groupId>com.sun.xml.ws</groupId>
63
+      <artifactId>jaxws-rt</artifactId>
64
+      <version>2.1.3</version>
65
+    </dependency>
66
+  </dependencies>
67
+</project>

+ 40
- 0
register-app/src/main/java/se/citerus/App.java Wyświetl plik

@@ -0,0 +1,40 @@
1
+package se.citerus;
2
+
3
+import org.springframework.context.ApplicationContext;
4
+import org.springframework.context.support.ClassPathXmlApplicationContext;
5
+
6
+import se.citerus.registerapp.RegisterApp;
7
+
8
+/**
9
+ * The application main class
10
+ *
11
+ */
12
+public class App {
13
+  private static RegisterApp app;
14
+  
15
+  public static void main(String[] args) {
16
+    app = getRegisterApp();
17
+    
18
+    //Schedule a job for the event-dispatching thread:
19
+    //creating and showing this application's GUI.
20
+    javax.swing.SwingUtilities.invokeLater(new Runnable() {
21
+        public void run() {
22
+            app.show();
23
+        }
24
+    });
25
+  }
26
+
27
+  private static RegisterApp getRegisterApp() {
28
+    return (RegisterApp)getBean("registerApp");
29
+  }
30
+
31
+  public static Object getBean(String bean){
32
+    ApplicationContext context = getContext(); 
33
+
34
+    return context.getBean(bean);
35
+}
36
+
37
+public static ClassPathXmlApplicationContext getContext() {
38
+    return new ClassPathXmlApplicationContext(new String[] {"context-app.xml"});
39
+}
40
+}

+ 150
- 0
register-app/src/main/java/se/citerus/registerapp/RegisterApp.java Wyświetl plik

@@ -0,0 +1,150 @@
1
+package se.citerus.registerapp;
2
+
3
+import java.awt.event.ActionEvent;
4
+import java.awt.event.ActionListener;
5
+import java.text.SimpleDateFormat;
6
+import java.util.Date;
7
+
8
+import javax.swing.JButton;
9
+import javax.swing.JComponent;
10
+import javax.swing.JFormattedTextField;
11
+import javax.swing.JFrame;
12
+import javax.swing.UIManager;
13
+import javax.swing.WindowConstants;
14
+import javax.swing.text.DefaultFormatter;
15
+
16
+import se.citerus.registerapp.service.HandlingEventService;
17
+
18
+import com.jgoodies.forms.builder.PanelBuilder;
19
+import com.jgoodies.forms.layout.CellConstraints;
20
+import com.jgoodies.forms.layout.FormLayout;
21
+
22
+public class RegisterApp {
23
+  private static final DefaultFormatter DEFAULT_FORMATTER = new DefaultFormatter();
24
+  private static final SimpleDateFormat ISO8601_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS.SSS");
25
+  private static final String TITLE = "Handling Event Registration";
26
+  private JFrame frame;
27
+  private JFormattedTextField completionTimeField;
28
+  private JFormattedTextField trackingIdField;
29
+  private JFormattedTextField carrierMovementField;
30
+  private JFormattedTextField locationField;
31
+  private JFormattedTextField eventTypeField;
32
+  private JButton registerButton;
33
+  
34
+  private HandlingEventService handlingEventService;
35
+
36
+  /////////////////////////////////////////////////////////////////////////////
37
+  // GUI EVENT HANDLING
38
+  /////////////////////////////////////////////////////////////////////////////
39
+  protected void onRegister() {
40
+    assert handlingEventService != null : "No HandlingEventService available";
41
+    
42
+    handlingEventService.register(ISO8601_DATE_FORMAT.format(completionTimeField.getValue()), 
43
+                                  trackingIdField.getValue().toString(), 
44
+                                  carrierMovementField.getValue().toString(), 
45
+                                  locationField.getValue().toString(), 
46
+                                  eventTypeField.getValue().toString());
47
+    
48
+    clearForm();
49
+  }
50
+  
51
+  
52
+  /////////////////////////////////////////////////////////////////////////////
53
+  // PUBLIC API
54
+  /////////////////////////////////////////////////////////////////////////////
55
+  public void show() {
56
+    try {
57
+      UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
58
+    } catch (Exception e) {
59
+      // Likely PlasticXP is not in the class path; ignore.
60
+    }
61
+    
62
+    initComponents();
63
+    JComponent panel = createMainPanel();
64
+    
65
+    frame = createFrame(panel);
66
+    frame.pack();
67
+    frame.setVisible(true);
68
+    
69
+    clearForm();
70
+  }
71
+
72
+
73
+  public void setHandlingEventService(HandlingEventService handlingEventService) {
74
+    this.handlingEventService = handlingEventService;
75
+  }
76
+
77
+
78
+  /////////////////////////////////////////////////////////////////////////////
79
+  // GUI SETUP
80
+  /////////////////////////////////////////////////////////////////////////////
81
+  private void clearForm() {
82
+    completionTimeField.setText(ISO8601_DATE_FORMAT.format(new Date()));
83
+    trackingIdField.setText("");
84
+    carrierMovementField.setText("");
85
+    locationField.setText("");
86
+    eventTypeField.setText("");
87
+  }
88
+  
89
+  private void initComponents(){
90
+    completionTimeField = new JFormattedTextField(ISO8601_DATE_FORMAT);
91
+    trackingIdField = new JFormattedTextField(DEFAULT_FORMATTER);
92
+    carrierMovementField = new JFormattedTextField(DEFAULT_FORMATTER);
93
+    locationField = new JFormattedTextField(DEFAULT_FORMATTER);
94
+    eventTypeField = new JFormattedTextField(DEFAULT_FORMATTER);
95
+    
96
+    registerButton = new JButton("Register");
97
+    registerButton.addActionListener(new ActionListener(){
98
+      public void actionPerformed(ActionEvent e) {
99
+        onRegister();
100
+      }
101
+    });
102
+  }
103
+
104
+
105
+  private JFrame createFrame(JComponent panel) {
106
+    JFrame f = new JFrame();
107
+    f.setTitle(TITLE);
108
+    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
109
+    f.getContentPane().add(panel);
110
+    
111
+    return f;
112
+  }
113
+
114
+  private JComponent createMainPanel() {
115
+    FormLayout layout = createFormLayout();
116
+    PanelBuilder builder = createBuilder(layout);
117
+    
118
+ // Obtain a reusable constraints object to place components in the grid.
119
+    CellConstraints cc = new CellConstraints();
120
+    
121
+    builder.addLabel("Completion Time",         cc.xy (1,  1   ));
122
+    builder.add(completionTimeField,            cc.xyw(3,  1, 3));
123
+    builder.addLabel("Tracking Id",             cc.xy (1,  3   ));
124
+    builder.add(trackingIdField,                cc.xyw(3,  3, 3));
125
+    builder.addLabel("Carrier Movement",        cc.xy (1,  5   ));
126
+    builder.add(carrierMovementField,           cc.xyw(3,  5, 3));
127
+    builder.addLabel("Location",                cc.xy (1,  7   ));
128
+    builder.add(locationField,                  cc.xyw(3,  7, 3));
129
+    builder.addLabel("Event Type",              cc.xy (1,  9   ));
130
+    builder.add(eventTypeField,                 cc.xyw(3,  9, 3));
131
+    builder.add(registerButton,                 cc.xy (5,  11  ));
132
+    
133
+    return builder.getPanel();
134
+  }
135
+
136
+  private PanelBuilder createBuilder(FormLayout layout) {
137
+    PanelBuilder builder = new PanelBuilder(layout);
138
+    builder.setDefaultDialogBorder();
139
+    
140
+    return builder;
141
+  }
142
+
143
+  private FormLayout createFormLayout() {
144
+    FormLayout layout = new FormLayout(
145
+        "right:pref, 3dlu, 100dlu, 3dlu, pref",                  // columns
146
+        "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu"); // rows
147
+    
148
+    return layout;
149
+  }
150
+}

+ 14
- 0
register-app/src/main/java/se/citerus/registerapp/service/HandlingEventService.java Wyświetl plik

@@ -0,0 +1,14 @@
1
+package se.citerus.registerapp.service;
2
+
3
+public interface HandlingEventService {
4
+  /**
5
+   * Register an cargo handling event.
6
+   *
7
+   * @param completionTime time when event occured, for example a the loading of cargo was completed
8
+   * @param trackingId tracking id of the cargo
9
+   * @param carrierMovementId carrier movement id, if applicable
10
+   * @param unlocode United Nations Location Code for the location where the event occured
11
+   * @param eventType type of event
12
+   */
13
+  void register(String completionTime, String trackingId, String carrierMovementId, String unlocode, String eventType);
14
+}

+ 17
- 0
register-app/src/main/java/se/citerus/registerapp/service/HandlingEventServiceWs.java Wyświetl plik

@@ -0,0 +1,17 @@
1
+package se.citerus.registerapp.service;
2
+
3
+import se.citerus.dddsample.ws.HandlingEventServiceEndpoint;
4
+
5
+
6
+public class HandlingEventServiceWs implements HandlingEventService {
7
+  private HandlingEventServiceEndpoint endPoint;
8
+  
9
+  public void register(String completionTime, String trackingId, String carrierMovementId, String unlocode, String eventType){
10
+    System.out.println(completionTime);
11
+    endPoint.register(completionTime, trackingId, carrierMovementId, unlocode, eventType);
12
+  }
13
+
14
+  public void setEndPoint(HandlingEventServiceEndpoint endPoint) {
15
+    this.endPoint = endPoint;
16
+  }
17
+}

+ 25
- 0
register-app/src/main/resources/context-app.xml Wyświetl plik

@@ -0,0 +1,25 @@
1
+<?xml version="1.0"?>
2
+
3
+<beans xmlns="http://www.springframework.org/schema/beans"
4
+       xmlns:tx="http://www.springframework.org/schema/tx"
5
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+       xsi:schemaLocation="
7
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
8
+        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
9
+
10
+  <bean id="registerApp" class="se.citerus.registerapp.RegisterApp">
11
+    <property name="handlingEventService" ref="handlingEventServiceWs"/>
12
+  </bean>
13
+
14
+  <bean id="handlingEventServiceWs" class="se.citerus.registerapp.service.HandlingEventServiceWs">
15
+    <property name="endPoint" ref="handlingEventWebServiceEndPoint"></property>
16
+  </bean>
17
+
18
+  <bean id="handlingEventWebServiceEndPoint" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
19
+    <property name="serviceInterface" value="se.citerus.dddsample.ws.HandlingEventServiceEndpoint" />
20
+    <property name="wsdlDocumentUrl" value="http://localhost:8080/dddsample/ws/RegisterEvent?wsdl" />
21
+    <property name="namespaceUri" value="http://ws.dddsample.citerus.se/" />
22
+    <property name="serviceName" value="HandlingEventServiceEndpointImplService" />
23
+    <property name="portName" value="HandlingEventServiceEndpointImplPort" />
24
+  </bean>
25
+</beans>

+ 23
- 0
register-app/src/main/resources/log4j.properties Wyświetl plik

@@ -0,0 +1,23 @@
1
+# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
2
+# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
3
+log4j.rootLogger=info, stdout, logfile
4
+
5
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
6
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
8
+
9
+log4j.appender.logfile=org.apache.log4j.RollingFileAppender
10
+log4j.appender.logfile.File=${java.io.tmpdir}/registration-app.log
11
+log4j.appender.logfile.MaxFileSize=512KB
12
+# Keep three backup files.
13
+log4j.appender.logfile.MaxBackupIndex=3
14
+# Pattern to output: date priority [category] - message
15
+log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
16
+log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
17
+
18
+log4j.logger.se.citerus.dddsample=debug
19
+log4j.logger.net.sf.ehcache.config.ConfigurationFactory=error
20
+log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=debug
21
+
22
+#log4j.logger.org.springframework.orm=debug
23
+#log4j.logger.org.springframework.transaction=debug

+ 38
- 0
register-app/src/test/java/se/citerus/AppTest.java Wyświetl plik

@@ -0,0 +1,38 @@
1
+package se.citerus;
2
+
3
+import junit.framework.Test;
4
+import junit.framework.TestCase;
5
+import junit.framework.TestSuite;
6
+
7
+/**
8
+ * Unit test for simple App.
9
+ */
10
+public class AppTest 
11
+    extends TestCase
12
+{
13
+    /**
14
+     * Create the test case
15
+     *
16
+     * @param testName name of the test case
17
+     */
18
+    public AppTest( String testName )
19
+    {
20
+        super( testName );
21
+    }
22
+
23
+    /**
24
+     * @return the suite of tests being tested
25
+     */
26
+    public static Test suite()
27
+    {
28
+        return new TestSuite( AppTest.class );
29
+    }
30
+
31
+    /**
32
+     * Rigourous Test :-)
33
+     */
34
+    public void testApp()
35
+    {
36
+        assertTrue( true );
37
+    }
38
+}

+ 0
- 0
register-app/target/jaxws/stale/.staleFlag Wyświetl plik