Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Dec 14, 2021
2 parents 0a25806 + 8f07263 commit 8933069
Show file tree
Hide file tree
Showing 19 changed files with 283 additions and 188 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ logs/
*.iml
*.ipr
*.gradle
!build.gradle

### NetBeans ###
/nbproject/private/
Expand Down
6 changes: 3 additions & 3 deletions TourGuide/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.2")
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.1")
}
}

Expand All @@ -16,7 +16,7 @@ apply plugin: "jacoco"

bootJar {
baseName = 'tourGuide'
version = '0.0.5'
version = '0.1.0'
}

repositories {
Expand All @@ -32,11 +32,11 @@ targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-log4j2")
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '3.1.0'
compile("org.springframework.boot:spring-boot-starter-actuator")
compile group: 'org.javamoney', name: 'moneta', version: '1.4.2'
compile group: 'com.jsoniter', name: 'jsoniter', version: '0.9.23'

compile(name:'gpsUtil', ext:'jar')
compile(name:'RewardCentral', ext:'jar')
compile(name:'TripPricer', ext:'jar')

Expand Down
168 changes: 84 additions & 84 deletions TourGuide/gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
2 changes: 2 additions & 0 deletions TourGuide/src/main/java/tourGuide/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

/** Autoconfigure and start the application.
*/
@SpringBootApplication
@EnableFeignClients("tourGuide")
public class Application {

/** Application entry point.
Expand Down
16 changes: 3 additions & 13 deletions TourGuide/src/main/java/tourGuide/config/TourGuideModule.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
package tourGuide.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import gpsUtil.GpsUtil;
import rewardCentral.RewardCentral;
import tourGuide.proxy.GpsUtilProxy;
import tourGuide.service.RewardsService;

/** TourGuide modules configurer.
*/
@Configuration
public class TourGuideModule {

@Bean
public GpsUtil getGpsUtil() {

return new GpsUtil();
}

@Bean
public RewardsService getRewardsService() {

return new RewardsService(getGpsUtil(), getRewardCentral());
}

@Bean
public RewardCentral getRewardCentral() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import java.util.List;
import java.util.UUID;

import gpsUtil.location.Location;
import tourGuide.model.Location;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jsoniter.output.JsonStream;

import gpsUtil.location.VisitedLocation;
import tourGuide.model.VisitedLocation;
import tourGuide.dto.RecentLocationDto;
import tourGuide.service.TourGuideService;
import tourGuide.model.User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tourGuide.dto;

import gpsUtil.location.Location;
import tourGuide.model.Location;

import java.util.List;
import java.util.UUID;
Expand Down
20 changes: 20 additions & 0 deletions TourGuide/src/main/java/tourGuide/model/Attraction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tourGuide.model;

import tourGuide.model.Location;

import java.util.UUID;

public class Attraction extends Location {
public final String attractionName;
public final String city;
public final String state;
public final UUID attractionId;

public Attraction(String attractionName, String city, String state, double latitude, double longitude) {
super(latitude, longitude);
this.attractionName = attractionName;
this.city = city;
this.state = state;
this.attractionId = UUID.randomUUID();
}
}
12 changes: 12 additions & 0 deletions TourGuide/src/main/java/tourGuide/model/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tourGuide.model;

public class Location {

public final double longitude;
public final double latitude;

public Location(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
}
12 changes: 9 additions & 3 deletions TourGuide/src/main/java/tourGuide/model/Tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import tourGuide.proxy.GpsUtilProxy;
import tourGuide.service.TourGuideService;

public class Tracker extends Thread {

private Logger logger = LogManager.getLogger(Tracker.class);
private static final long trackingPollingInterval = TimeUnit.MINUTES.toSeconds(5);
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private GpsUtilProxy gpsUtilProxy;
private final TourGuideService tourGuideService;
private boolean stop = false;

Expand All @@ -22,6 +24,7 @@ public class Tracker extends Thread {
*/
public Tracker(TourGuideService tourGuideService) {

this.gpsUtilProxy = gpsUtilProxy;
this.tourGuideService = tourGuideService;
executorService.submit(this);
}
Expand Down Expand Up @@ -56,9 +59,12 @@ public void run() {
stopWatch.start();

// Tracks asynchronously each user's location
CompletableFuture<?>[] trackFutureUserLocations = users.stream()
.map(tourGuideService::trackUserLocation)
.toArray(CompletableFuture[]::new);
CompletableFuture<?>[] trackFutureUserLocations = new
CompletableFuture<?>[users.size()];
for (int i = 0; i<users.size(); i++) {
VisitedLocation visitedLocation = tourGuideService.trackUserLocation(users.get(i));
trackFutureUserLocations[i] = CompletableFuture.supplyAsync(() -> visitedLocation);
}
CompletableFuture.allOf(trackFutureUserLocations).join();

stopWatch.stop();
Expand Down
2 changes: 1 addition & 1 deletion TourGuide/src/main/java/tourGuide/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import gpsUtil.location.VisitedLocation;
import tourGuide.model.VisitedLocation;
import tripPricer.Provider;

/** Represents the model.
Expand Down
4 changes: 2 additions & 2 deletions TourGuide/src/main/java/tourGuide/model/UserReward.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tourGuide.model;

import gpsUtil.location.Attraction;
import gpsUtil.location.VisitedLocation;
import tourGuide.model.Attraction;
import tourGuide.model.VisitedLocation;

/** Represents the model reward.
*/
Expand Down
17 changes: 17 additions & 0 deletions TourGuide/src/main/java/tourGuide/model/VisitedLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tourGuide.model;

import java.util.Date;
import java.util.UUID;

public class VisitedLocation {

public final UUID userId;
public final Location location;
public final Date timeVisited;

public VisitedLocation(UUID userId, Location location, Date timeVisited) {
this.userId = userId;
this.location = location;
this.timeVisited = timeVisited;
}
}
Loading

0 comments on commit 8933069

Please sign in to comment.