package fgis.server.services;

import fgis.server.entity.fgis.Resource;
import fgis.server.entity.fgis.ResourceTrack;
import fgis.server.entity.fgis.dao.ResourceRepository;
import fgis.server.entity.fgis.dao.ResourceTrackRepository;
import java.util.Date;
import java.util.Random;
import javax.ejb.EJB;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import org.geolatte.geom.DimensionalFlag;
import org.geolatte.geom.Point;
import org.geolatte.geom.PointSequenceBuilder;
import org.geolatte.geom.PointSequenceBuilders;
import org.geolatte.geom.crs.CrsId;

@javax.ejb.Local
@Stateless
public class DataGeneratorEJB
{
  @EJB
  private ResourceRepository _resourceService;

  @EJB
  private ResourceTrackRepository _resourceTrackRepository;


  @Schedule( second = "*/5", minute = "*", hour = "*", persistent = false )
  public void insertData()
  {
    final String resourceName = "Peter";
    Resource resource = _resourceService.findByName( resourceName );
    if ( null == resource )
    {
      resource = new Resource( "Person", resourceName );
      _resourceService.persist( resource );
    }
    final Random random = new Random();

    final PointSequenceBuilder builder =
      PointSequenceBuilders.variableSized( DimensionalFlag.d2D, CrsId.UNDEFINED );
    final double latPosition = 144.92978643046 + random.nextDouble() / 1;
    final double longPosition = -37.794939500455 + random.nextDouble() / 1;
    builder.add( latPosition , longPosition );

    System.out.println( "Generating point " + latPosition + ", " + longPosition +
                        " for resource " + resource.getName() );

    final Point point = new Point( builder.toPointSequence() );
    _resourceTrackRepository.persist( new ResourceTrack( resource, new Date(), point ) );
    resource.setLocation( point );
  }
}

@@ -249,16 +249,39 @@
 l.Date;%0A
+import java.util.List;%0A
 import j
@@ -1159,24 +1159,80 @@
  Random();%0A%0A
+    final Point lastLocation = resource.getLocation();%0A%0A
     final Po
@@ -1260,16 +1260,16 @@
 ilder =%0A
-
       Po
@@ -1364,21 +1364,39 @@
 ble 
-latPosi
+startX = null == lastLoca
 tion 
-=
+?
  144
@@ -1408,17 +1408,170 @@
 8643046 
-+
+: lastLocation.getX();%0A    final double startY = null == lastLocation ? -37.794939500455 : lastLocation.getY();%0A%0A    final double latPosition = startX + (
  random.
@@ -1582,24 +1582,36 @@
 Double() / 1
+00 ) - 0.005
 ;%0A    final 
@@ -1636,26 +1636,18 @@
 n = 
--37.794939500455 +
+startY + (
  ran
@@ -1666,16 +1666,28 @@
 le() / 1
+00 ) - 0.005
 ;%0A    bu
@@ -1724,24 +1724,25 @@
 osition );%0A%0A
+%0A
     System.o

Move the position close to where it was in the past