# Neo4j Pathfinder with road type prefference

Hi All, Today I would like to post on how the graph database (Neo4j) can be used for path finding. As you know that in the real world there are so many type of road for example private road, normal road or toll. Since we have these type of choices then we shall be allowed to choose which road preference we would to travel from start point to end point. As you know that path finding algorithm A* or Djikstra always calculate for shortest path between nodes, So the question is how do we manage the road preference using the same algorithm. We know that there will be distance between each point in the graph. The algorithm will calculate this distance to pop out the shortest one. So the idea is to manage the preference by manipulating the distance calculated which we can setup multiplier to the non-preferred road type thus will give the total accumulated distance between nodes higher than the preferred one. I have the road network path as below, I try to demonstrated that we would like to travel from Balikpapan Center to Ace Hardware. There are some ways to travel but here I would like to show you 2 scenarios. The first one is to travel with the preference going with the shortest distance. The red line give you the path that the algorithm shall go. The second one is to travel with the preference going by toll road that is represented by blue line.

The algorithm that I would like to use in this sample is djikstra. To create the path finding algorithm in the Neo4j is just like the code below

```public void run() {
if (template != null) {

PathFinder pathFinder = GraphAlgoFactory.dijkstra(new MeExpander(), new MyCostCalc());
WeightedPath path = pathFinder.findSinglePath(template.getNode(0),template.getNode(9));
if (path != null) {
for (Node n : path.nodes()) {
System.out.print(" " + n.getProperty("name"));
}
}
System.out.println("");
}
}
```

Djikstra algorithm creation get 2 parameters which is the first is the expander and cost estimation. To manage the road preference we can re-implement the calculation by implementing the Cost Evaluator class. Back to the scenario, The code below is the implementation for the 1st scenario.

```public class MyCostCalc implements CostEvaluator {

public Double getCost(Relationship relationship, Direction direction) {
Double a = Double.valueOf(relationship.getProperty("distance").toString());
return a;
}

}
```

We can read above code that I don’t do anything to the distance gathered between nodes. Just return it as it is. But it is different with the code written below (For scenario 2), I do manage the distance gathered and do the trick. I multiply (*4) the distance for the road categorized as normal so that every time the traverser travelling through normal road then it will multiply the distance in result that algorithm will see it is longer distance as the impact the road preferred will have smaller distance.

```public class TollPreffCostCalc implements CostEvaluator {
public Double getCost(Relationship relationship, Direction direction) {
Double a = Double.valueOf(relationship.getProperty("distance").toString());
if(relationship.getProperty("type").toString().equals("normal")){
a = Double.valueOf(relationship.getProperty("distance").toString())*4;
}
return a;
}
```

So, I hope you can get the idea of this sample. I think this is the most simple trick to be adopt in order to manage road preference in the path finding. This trick is just to trick the algorithm either djikstra or A* to return the preferred road by manipulating the distance traveled. Ho you enjoy.

# Neo4j Traverser into table

Hi All,

Today, I would like to post a bit of my creation on the data Neo4j traversal. As you know that Neo4j traversal is one of powerful engine which may traverse a million of hops in just milliseconds. I created a class that uses the Neo4j traversal and show  the traversed node in the form of table. For some people it is easier to have their data shown in the table such as excel as below

To create this class, I use 3 component which are PathExpander, Traverser and Evaluators. The combination of them are just amazing. To create the data are able to show into table form as shown above, I use library downloaded from google code called BTC-ASCII-Table.

Here are my full class.

```
package neo4j.mytraversal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.neo4j.cypher.internal.pipes.matching.MyEvaluator;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.traversal.Evaluation;
import org.neo4j.graphdb.traversal.Evaluator;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.kernel.StandardExpander;
import org.neo4j.kernel.Uniqueness;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.Neo4jTemplate;

import com.bethecoder.ascii_table.ASCIITable;

public class Runner {

@Autowired
Neo4jTemplate template;
Iterator<Path> path;

final MeExpander expander;

Map<Integer, List<String>> level;

public Runner() {
// TODO Auto-generated constructor stub
expander = new MeExpander();
level = new HashMap<Integer, List<String>>();
}

Direction direction, Integer depth) {
depth);
}

public void showField(int depth, String[] fields) {
level.put(depth, Arrays.asList(fields));
}

public void print() {

List<Map<String, String>> valuList = new ArrayList<Map<String, String>>();

while (path.hasNext()) {
Path temp = path.next();
Iterator<Node> nodeIterator = temp.nodes().iterator();
int itCount = 0;
Map<String, String> tempValue = new HashMap<String, String>();
while (nodeIterator.hasNext()) {
Node node = nodeIterator.next();
Iterator<Integer> i = level.keySet().iterator();
while (i.hasNext()) {
int key = i.next();
if (itCount == key) {
List<String> val = level.get(key);
List<String> newVal = new ArrayList<String>();

String firstItem = newVal.get(0);

if (firstItem.equals("*")) {
Iterator<String> itProp = node.getPropertyKeys()
.iterator();
while (itProp.hasNext()) {
String fieldExtract = itProp.next();
if (!newVal.contains(itCount + "-"
+ fieldExtract)) {
}
tempValue.put(itCount + "-" + fieldExtract,
node.getProperty(fieldExtract)
.toString());
}
} else {
for (int checkfieldit = 0; checkfieldit < newVal
.size(); checkfieldit++) {
if (node.hasProperty(newVal.get(checkfieldit))) {
tempValue.put(
itCount + "-"
+ newVal.get(checkfieldit),
node.getProperty(
newVal.get(checkfieldit))
.toString());
if (!newVal.contains(itCount + "-"
+ newVal.get(checkfieldit))) {

}
if (!path.hasNext()) {
newVal.remove(newVal.get(checkfieldit));
}
}
}
}

if (!path.hasNext()) {
newVal.remove("*");
}

level.put(key, newVal);

}
}
itCount++;
}
}

}

public void traverse(Long nodeID) {
if (template != null) {
TraversalDescription desc = template.traversalDescription()
public Evaluation evaluate(Path path) {
return Evaluation.INCLUDE_AND_CONTINUE;
}
}).expand(expander).evaluator(Evaluators.excludeStartPosition());

path = desc.traverse(template.getNode(nodeID)).iterator();
}

}

public List<String> upHeader(Map<Integer, List<String>> level) {
List<String> temp = new ArrayList<String>();
Iterator<Integer> ii = level.keySet().iterator();
while (ii.hasNext()) {
List<String> a = level.get(ii.next());
for (int i = 0; i < a.size(); i++) {
if (!temp.contains(a.get(i))) {
}
}
}
return temp;
}

public void printTable(List<String> header, List<Map<String, String>> row) {

for (int i = 0; i < header.size(); i++) {
}

for (int i = 0; i < row.size(); i++) {
for (int ii = 0; ii < header.size(); ii++) {
result[i][ii] = "";
}
}

for (int i = 0; i < row.size(); i++) {
Map<String, String> valueRow = row.get(i);
for (int ii = 0; ii < header.size(); ii++) {
}
}
}

}

}

```

The above class is the main class which do the trick which do the traversal and print the data into table. In order to use the application correctly here is sample

```public class Runner {

@Autowired
Neo4jTemplate template;
Iterator<Path> path;
final MeExpander expander;
Map<Integer, List<String>> level;

public Runner() {

expander = new MeExpander();
level = new HashMap<Integer, List<String>>();
}

public void addRealtionshipSequence(String relationsipName, Direction direction, Integer depth) {
}

public void showField(int depth, String[] fields) {
level.put(depth, Arrays.asList(fields));
}

public void print() {
List<Map<String, String>> valuList = new ArrayList<Map<String, String>>();

while (path.hasNext()) {
Path temp = path.next();
Iterator<Node> nodeIterator = temp.nodes().iterator();
int itCount = 0;
Map<String, String> tempValue = new HashMap<String, String>();
while (nodeIterator.hasNext()) {
Node node = nodeIterator.next();
Iterator<Integer> i = level.keySet().iterator();

while (i.hasNext()) {
int key = i.next();
if (itCount == key) {
List<String> val = level.get(key);
List<String> newVal = new ArrayList<String>();
String firstItem = newVal.get(0);

if (firstItem.equals("*")) {
Iterator<String> itProp = node.getPropertyKeys().iterator();
while (itProp.hasNext()) {
String fieldExtract = itProp.next();
if (!newVal.contains(itCount + "-"+ fieldExtract)) {
}
tempValue.put(itCount + "-" + fieldExtract, node.getProperty(fieldExtract).toString());
}
} else {
for (int checkfieldit = 0; checkfieldit < newVal.size(); checkfieldit++) {
if (node.hasProperty(newVal.get(checkfieldit))) {
tempValue.put(itCount + "-"+ newVal.get(checkfieldit),node.getProperty(newVal.get(checkfieldit)).toString());
if (!newVal.contains(itCount + "-"+ newVal.get(checkfieldit))) {
}
if (!path.hasNext()) {
newVal.remove(newVal.get(checkfieldit));
}
}
}
}

if (!path.hasNext()) {
newVal.remove("*");
}

level.put(key, newVal);

}
}
itCount++;
}
}

}

public void traverse(Long nodeID) {
if (template != null) {
TraversalDescription desc = template.traversalDescription().breadthFirst().evaluator(new Evaluator() {
public Evaluation evaluate(Path path) {
return Evaluation.INCLUDE_AND_CONTINUE;
}
}).expand(expander).evaluator(Evaluators.excludeStartPosition());

path = desc.traverse(template.getNode(nodeID)).iterator();
}

}

public List<String> upHeader(Map<Integer, List<String>> level) {
List<String> temp = new ArrayList<String>();
Iterator<Integer> ii = level.keySet().iterator();
while (ii.hasNext()) {
List<String> a = level.get(ii.next());
for (int i = 0; i < a.size(); i++) {
if (!temp.contains(a.get(i))) {
}
}
}
return temp;
}

public void printTable(List<String> header, List<Map<String, String>> row) {

for (int i = 0; i < header.size(); i++) {
}

for (int i = 0; i < row.size(); i++) {
for (int ii = 0; ii < header.size(); ii++) {
result[i][ii] = "";
}
}

for (int i = 0; i < row.size(); i++) {
Map<String, String> valueRow = row.get(i);
for (int ii = 0; ii < header.size(); ii++) {
}
}
}

}

}
```

The above code will show the table as below

But if you wanted to change only viewing dome of the column then you may be able to change the * to the field name you want to show. As example below

`<br />runner.showField(2, new String[]{"*"});<br />runner.showField(1, new String[]{"*"});<br />runner.showField(0, new String[]{"name"});<br />`

# Integration Vaadin and Activiti BPM by Spring framework

In some of my project in the past I remembered that in order to do a business flow we need to do it manually in the coding level so that it gives your project  risk when you are managing  big project since business process in the organization might change during your software development and for sure it is not good for your development.

Finally, I found a simple tools called JBoss BPM 3.0 on that time, This tools was so good and useful helping the software designer integrating the business process defined by the business with the application code. Playing with the BPM is so fun. Lately, I found an application called Activiti BPM. Put some hand on it for several days give me a lot of fun. Since then I use this BPM as my base engine to manage the process management. I think it is time to share some basic after 1 years worked on it.

I will explain the very basic configuration to integrate Vaadin and Activiti with spring framework.

1. Setup your eclipse and Jboss AS configuration

2. Setup a Vaadin project from Maven

3. Configure your web.xml as below to enable the spring bean injection

```<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<context-param>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-spring.xml</param-value>
</context-param>
<listener>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
<init-param>
<param-name>application</param-name>
</init-param>
</servlet>
<servlet-mapping>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
```

2. Configure the applicationContext-spring.xml to manage the activiti bean creation and database connection

```<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:spring-configured />
<context:annotation-config />

<context:component-scan base-package="study.ActivitiExclusive" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<property name="targetDataSource">
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/activiti" />
<property name="driverClass" value="com.mysql.jdbc.Driver" />
</bean>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="databaseType" value="mysql" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="history" value="full" />
<property name="jobExecutorActivate" value="false" />
<property name="deploymentResources" value="/WEB-INF/MyProcess.bpmn" />

</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<bean id="identityService" factory-bean="processEngine"
factory-method="getIdentityService" />

<bean id="Printing" class="study.ActivitiExclusive.Printing" />

</beans>

```

3. Configure your maven POM to enable the all library completed

```<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>study</groupId>
<artifactId>ActivitiExclusive</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gwt.version>2.3.0</gwt.version>
<gwt.plugin.version>2.2.0</gwt.plugin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
</repository>
<repository>
<id>activiti</id>
<name>Activiti Repository</name>
<url>https://maven.alfresco.com/nexus/content/repositories/activiti/</url>
</repository>
</repositories>

<dependencies>
<dependency>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.10</version>
</dependency>

<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.10</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.35</version>
</dependency>
</dependencies>

</project>
```

5. Create a simple activiti BPM as a sample “MyProcess.BPMN” in the WEB-INF directory

```<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="process1" name="process1">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<endEvent id="endevent2" name="End"></endEvent>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_process1">
<bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35" width="35" x="170" y="40"></omgdc:Bounds>
</bpmndi:BPMNShape>
<omgdc:Bounds height="55" width="105" x="140" y="210"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35" width="35" x="460" y="220"></omgdc:Bounds>
</bpmndi:BPMNShape>
<omgdc:Bounds height="55" width="105" x="300" y="210"></omgdc:Bounds>
</bpmndi:BPMNShape>
<omgdc:Bounds height="55" width="105" x="460" y="210"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
<omgdc:Bounds height="35" width="35" x="620" y="220"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="187" y="75"></omgdi:waypoint>
<omgdi:waypoint x="192" y="210"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="245" y="237"></omgdi:waypoint>
<omgdi:waypoint x="300" y="237"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="405" y="237"></omgdi:waypoint>
<omgdi:waypoint x="460" y="237"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="565" y="237"></omgdi:waypoint>
<omgdi:waypoint x="620" y="237"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
```

6. Finally in the application  I can autowire all the necessary activity bean from the spring context. (Please refer on how to create the injection for vaadin in my previous article)

```package study.ActivitiExclusive;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.springframework.beans.factory.annotation.Autowired;

public class MyWindow extends Window {

@Autowired
RepositoryService repositoryService;

@Autowired
RuntimeService runtimeService;

@Autowired

@Autowired
IdentityService identityService;
public MyWindow() {

Inject.Inject(this);
}

}
```

7. Yeah just follow the configuration above then you can start playing Activiti BPM with Vaadin. In the above configuration don’t forget that you should have configure your Mysql database with the specified schema and DB.

Have a nice try all …

# Vaadin and Spring simple autowire

I have been using vaadin and spring in some of my projects but I don’t any find a simple way to manage autowiring for the spring bean to vaadin. I tried the add-on from the vaadin to integrate spring and vaadin into one context but it fail and to many changes in the configuration and I have tried the autowiringbeanfactory.java to become the servlet of vaadin but it only serve autowiring for the main application. If you have so many autowired annotation spread in your bean then all the above solution will not work.

I found a simple way to manage the autowiring by adding a very minimum configuration changes and it becomes my favorite solution to my next project. Please check below the configuration

1. Setup the Vaadin maven project in eclipse + JbossAS installation

2. Configure the pom as below

```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>study</groupId>
<artifactId>testIntegrate</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gwt.version>2.3.0</gwt.version>
<gwt.plugin.version>2.2.0</gwt.plugin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
</repository>
</repositories>

<dependencies>
<dependency>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.2.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.2.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.35</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
</project>
```

3. Create the application-context.xml and put it into the WEB-INF with text below, please noted that to ensure the “annotation-config” is there because it will activate the autowiring via spring annotation such as @Autowire, @Component and etc

```
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:spring-configured />
<context:annotation-config />

<context:component-scan base-package="study.testIntegrate" />

</beans>

```

4. Edit your web.xml in order to spring aware of context creation from the beginning, please follow as below

```
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<context-param>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-spring.xml</param-value>
</context-param>

<listener>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
<init-param>
<param-name>application</param-name>
</init-param>
</servlet>
<servlet-mapping>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

```

5.  In order to make the injection to the autowiring to your bean working as expected then you should create a helper class to allow the spring knows your vaadin bean. You can include this class below into your source

```
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class Inject {

static Application application;
static ApplicationContext applicationContext;

public static void Inject(Object object) {
if (applicationContext == null) {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
HttpSession session = request.getSession(false);
applicationContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(session
.getServletContext());
}

AutowireCapableBeanFactory beanFactory = applicationContext
.getAutowireCapableBeanFactory();
beanFactory.autowireBeanProperties(object,
AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);

}

}

```

6. In order to use the helper class you my just call this static function “Inject” and pass the class you want to autowire, Please follow the sample class below

```
public class MyWindow extends Window {

@Autowired
MyTest myTest;

Button button;

public MyWindow() {

Inject.Inject(this);

button = new Button();
}

public void Check(Button.ClickEvent event) {
if (myTest != null) {
}
}
}

```

7. Then by calling the inject and pass the class itself then spring will autowire all the properties with the @autowire annotation for you. Here is the magic then. Very simple right to make the Vaadin aware to Spring autowiring with a very less configuration changes.

8. Here is my vaadin application init method

```
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.WebApplicationContextUtils;

@SuppressWarnings("serial")
public class MyVaadinApplication extends Application {
private MyWindow window;

@Override
public void init() {
window = new MyWindow();
setMainWindow(window);
}

}

```

9. The last but not least is you dont forget to annotate your class with the @Component or @Service in order to let the spring bean scanner able to detect that it is a spring bean that need to be managed or autowired.

Hopefully my tutorial will make the integration of the vaadin and spring become easier so that the power of spring framework will available in combination with Vaadin superb technology.

# Vaadin + Springdata + Neo4j Basic Conf with Spring Context

Hi all, Recently I checked out the Vaadin web and browsed the add-on directory. Wow it looks so fun to see this framework is getting bigger since alot of new add-on are coming in.

This time I am going to show the basic configuration for Vaadin + Springdata and Neo4j. I have post this kind of information in my previous post but in this tutorial is quite different since this basic configuration will use the spring contect rather than Vaadin’s

As usual my web application server is based on JBoss AS 7 so that I expected that you have had the basic knowledge of JBoss AS basic configuration

OK Lets get it start

2. Create the vaadin project via Maven

3. Manage the POM.xml and setup as the entry below

<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>study</groupId>
<artifactId>springIntegration</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gwt.version>2.3.0</gwt.version>
<gwt.plugin.version>2.2.0</gwt.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshot</id>
<name>Spring Maven SNAPSHOT Repository</name>
<url>http://repo.springsource.org/libs-milestone</url&gt;
</repository>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-release-repository</id>
<name>Neo4j Maven 2 release repository</name>
<url>http://m2.neo4j.org/releases</url&gt;
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
</repository>
<repository>
<id>springsource-repo</id>
<name>SpringSource Repository</name>
<url>http://repo.springsource.org/release</url&gt;
</repository>
</repositories>
<dependencies>
<dependency>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<version>2.1.0.RC3</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-rest-graphdb</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.35</version>
</dependency>
<dependency>
<version>1.0.507</version>
</dependency>
</dependencies>
</project>

4. Create file for the spring application-context.xml under the WEB-INF/classes

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xmlns=”http://java.sun.com/xml/ns/javaee&#8221; xmlns:web=”http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;
id=”WebApp_ID” version=”2.5″>
<context-param>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-spring.xml</param-value>
</context-param>
<listener>
</listener>

<servlet>
<init-param>
<param-name>application</param-name>
<param-value>study.springIntegration.HelloWorld</param-value>
</init-param>
</servlet>
<servlet-mapping>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

6. Yes all the configuration that you need it is now done and what you need is to create the hellowworld application

package study.springIntegration;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.context.ConfigurableWebApplicationContext;

public class HelloWorld extends SpringContextApplication implements
BeanFactoryAware, InitializingBean, DisposableBean {
public void destroy() throws Exception {
// TODO Auto-generated method stub

}

public void afterPropertiesSet() throws Exception {
// TODO Auto-generated method stub

}

public void setBeanFactory(BeanFactory arg0) throws BeansException {
// TODO Auto-generated method stub

}

@Override
protected void initSpringApplication(ConfigurableWebApplicationContext arg0) {
// TODO Auto-generated method stub
Window mainWindow = new Window(“Vaadin+Spring Demo #3”);
Label test = new Label();
test.setValue(“Hahahah”);
setMainWindow(mainWindow);
}

}

That is all the basic configuration for the Vaadin application that uses the spring context that is combined with the neo4j installation. Be careful that you should use at least the neo4j version 2.1 to be able to start the spring context unless you will face error in creation of bean REST in neo4j.

# Vaadin + Springdata + MySQL + Hbncontainer

Hi Guys,

I’m recently a small project that required me to put my attention to the RDBMS after some long times ago develop application with Graph Database.

Playing again with it was like dejavu to me. OK, without any further a do so just get hand on to the all tools that is mentioned in the subject.

Today, I am going to put the step by step of using Vaadin with the combination of Springdata to access MySQL. Since I don’t like to get my hands dirty to create database table directly so that I use ORM as the bridge between my object and database. Here I use hibernate to manage the all query things and database table creation.

Let start the step below.

1. Setting up your environment (Jboss AS, Eclipse and Etc)

2. Create Vaadin project from maven

3. Follow the following dependencies to  POM.xml. Please ensure that you are using hibernate 4 and the latest sporingdata because the Hbncontainer is only suit with these requirement.

```<properties></pre>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gwt.version>2.3.0</gwt.version>
<gwt.plugin.version>2.2.0</gwt.plugin.version>
</properties>

<dependencies>
<dependency>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.20</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.1.Final</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
<scope>runtime</scope>
</dependency>

<dependency>
<artifactId>hbncontainer</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
<pre>```

4. Create the datasource-bean.xml in the application classpath as highlighted below

5. Here is the datasource-bean.xml looks like

```
<?xml version="1.0" encoding="UTF-8"?></pre>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="sessionFactoryhibernate"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="mySqlDataSource" />

<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>study.mehibernate.Biodata</value>
</list>
</property>
</bean>
<bean id="mySqlDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/myappllication" />
</bean>
<property name="sessionFactory" ref="sessionFactoryhibernate" />
</bean>

</beans>

```

6. Create the hibernate helper. This hibernate helper will manage the session management

```
package study.mehibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class HibernateDAO {
SessionFactory sessionFactory = null;
Session session = null;

public SessionFactory getFactory() {
return sessionFactory;
}

public SessionFactory getSessionFactory() {
return sessionFactory;
}

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

public Session getSession() {
return session;
}

public void setSession(Session session) {
this.session = session;
}
}```

7. Create the spring context helper

```
package study.mehibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTransactionManager;

public class ContextHelper {

public static ApplicationContext ctx = null;
public static Session session = null;
private static HibernateDAO dao = null;

public static ApplicationContext getCtx() {

if(ctx == null){
ctx = new ClassPathXmlApplicationContext("datasource-bean.xml");
}
return ctx;
}

public static Session getSession(){
if(ctx == null){
getCtx();
}
if(dao == null){
}
if(session == null){
session = dao.getSessionFactory().openSession();
}
if(!session.getTransaction().isActive()){
session.beginTransaction();
}
return session;
}

public static void InitHibernate(){
if(ctx == null){
getCtx();
}
if(dao == null){
}
}
}
```

8. Don’t forget to implement the vaadin hibernate util session manager

```</pre>
package study.mehibernate;

import org.hibernate.Session;

public class DataSource implements SessionManager {

public Session getSession() {
// TODO Auto-generated method stub
return ContextHelper.getSession();
}

}

```

9. Create the Hibernate entity, I use a very simple one to become example

```</pre>
package study.mehibernate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Biodata {

int id;
String name;
int age;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Column(name = "name", unique = false, nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

@Column(name = "age", unique = false, nullable = false)
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

```

10. Finaly for the preparation above is all complete, so we can now create the application. Follow my example

```</pre>
package study.mehibernate;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* The Application's "main" class
*/
@SuppressWarnings("serial")
{
private Window window;

@Override
public void init()
{
ContextHelper.InitHibernate();
window = new MyWindow();
setMainWindow(window);

}
}

```

11. Create my own window

```
package study.mehibernate;

import java.util.Collection;
import java.util.List;

import org.hibernate.Session;

public class MyWindow extends Window {

Session session;
Table table;
HbnContainer<Biodata> container;
List<Biodata> temp;
ComboBox combo;

public MyWindow() {
// TODO Auto-generated constructor stub
session = ContextHelper.getSession();

table = new Table();
container = new HbnContainer<Biodata>(Biodata.class, new DataSource());
table.setContainerDataSource(container);
table.setVisibleColumns(new String[] {"name", "age"});
combo = new ComboBox();

combo.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_EXPLICIT);
combo.setItemCaptionPropertyId("name");

combo.setContainerDataSource(container);

//initTable();
}

public void initTable(){
session.beginTransaction();

Biodata bio1 = new Biodata();
bio1.setName("Rio");
bio1.setAge(29);

Biodata bio2 = new Biodata();
bio2.setName("Annis");
bio2.setAge(27);

Biodata bio3 = new Biodata();
bio3.setName("Daanish");
bio3.setAge(2);

session.save(bio1);
session.save(bio2);
session.save(bio3);

session.getTransaction().commit();

}

}

```

Yes this is it all the code that you need .. and the result of the application is just like the picture below

# Vaadin + Spring Data + Neo4j (with REST)

Hi, I’m finally back to write a very simple tutorial for the one who love vaadin and neo4j. In this tutorial I changed a bit of the configuration of the database from the embedded to become REST thus give a better handling.

In this application my scenario is to create a very simple registration which involve of saving process and retrieving back the data.

OK, without any further intro here are the steps.

2. Setup a Vaadin maven project (please check my previous tutorial on how to create the Vaadin maven project)

```<dependencies>
<dependency>
<version>6.7.8</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.12</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.35</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>\${spring.version}</version>
</dependency>
<dependency>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<version>2.0.0.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>jersey-server</artifactId>
<groupId>com.sun.jersey</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
```

4. Edit the applicationContext-spring.xml and add the Neo4j url path and bean creation

```<bean id="restGraphDatabase"
class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data/" />
</bean>

<neo4j:config graphDatabaseService="restGraphDatabase" />
```

5. Create SpringContextHelper Class as below codes, this class is needed in order to get the object that created by the spring context so that Vaadin may be able to use the object

```package spring.neosample;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContext;

public class SpringContextHelper {

private ApplicationContext context;

public SpringContextHelper(Application application) {

ServletContext servletContext = ((WebApplicationContext) application
.getContext()).getHttpSession().getServletContext();
context = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
}

public Object getBean(final String beanRef) {
return context.getBean(beanRef);
}

}
```

6. Create a simple vaadin window, this window is to simulate the registration form

```package spring.neosample;

public class MyWindow extends Window {

Button createAccount;
Button testAccount;

this.impl = impl;

//Manage the visible item in form
ManageFormItem();

//Create Button for action query and creation save to database
CreateButton();
}

void ManageFormItem(){
String titleTobeShown [] = new String[] {"userName"};
}

void CreateButton(){
createAccount = new Button("Create Account");

testAccount = new Button("Test Account");

}

public void TestAccount(ClickEvent event){

}else {
}
}

public void CreateAccount(ClickEvent event){

}

}
```

7. Modify the vaadin application class to become look like below

```</pre>
package spring.neosample;

/**
* The Application's "main" class
*/
@SuppressWarnings("serial")
{
private Window window;

@Override
public void init()
{
SpringContextHelper contextHelper = new SpringContextHelper(this);

window = new MyWindow(impl);

setMainWindow(window);
}

}
<pre>```

8. Create the Neo4j graph repository, this repository is needed to do the database transaction such as saving and query. Please create the class as below

```package spring.neosample;</pre>
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;

@NodeEntity

@GraphId
Long id;

@Indexed

}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

}

}
}
<pre>```

```</pre>
package spring.neosample;

}

```
```
&nbsp;

package spring.neosample;

import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.NamedIndexRepository;

}

```
```
package spring.neosample;

import org.springframework.beans.factory.annotation.Autowired;

@Autowired

neoGraph.save(object);
}

if(result == null){
return false;
}
return true;
}

}

```

```
<neo4j:repositories base-package="spring.neosample"></neo4j:repositories>

<tx:annotation-driven mode="aspectj" />

```

10.  Try to deploy and run your application. BUT don’t forget to start your neo4j server before deploying your application since the application context will search the defined server during application start up or deployment.

Testing the application

1. Try to put any user name and click button “Test Account”, there should a notification that account not found

2. Try to put any user name e.g “Rio” then click on the button “Create Account”, there should notification says that the account is created

3. Try to put the user name that you’ve just created e.g “Rio” and click on the button “Test Account” and then now there should be a notification saying that “Account is found”

OK I think that is all. Just give me message any time there is something that doesn’t work in this tutorial. I’ll be happy to share my knowledge.

Please find the full code here.

http://goo.gl/i1BH2