Skip to content
Open

rzq #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions TourGuide/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
image: java:8-jdk
before_script:
- cd TourGuide
stages:
- build
- test


variables:
GRADLE_USER_HOME: "${CI_PROJECT_DIR}/.gradle"

cache:
paths:
- .gradle/wrapper
- .gradle/caches


build:
stage: build
script:
- ./gradlew assemble
artifacts:
paths:
- build/libs/*.jar
only:
- main


test:
stage: test
script:
- ./gradlew test
23 changes: 11 additions & 12 deletions TourGuide/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile group: 'org.javamoney', name: 'moneta', version: '1.3'
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')
testCompile("junit:junit")
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.6.RELEASE'
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation group: 'org.javamoney', name: 'moneta', version: '1.3'
implementation group: 'com.jsoniter', name: 'jsoniter', version: '0.9.23'

implementation name:'gpsUtil', ext:'jar'
implementation name:'RewardCentral', ext:'jar'
implementation name:'TripPricer', ext:'jar'

testImplementation "junit:junit"
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.6.RELEASE'
}


Expand All @@ -66,7 +66,6 @@ jacocoTestCoverageVerification {
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.5
}
}
}
Expand Down
Empty file modified TourGuide/gradlew
100644 → 100755
Empty file.
32 changes: 7 additions & 25 deletions TourGuide/src/main/java/tourGuide/TourGuideController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,24 @@ public String getLocation(@RequestParam String userName) {
VisitedLocation visitedLocation = tourGuideService.getUserLocation(getUser(userName));
return JsonStream.serialize(visitedLocation.location);
}

// TODO: Change this method to no longer return a List of Attractions.
// Instead: Get the closest five tourist attractions to the user - no matter how far away they are.
// Return a new JSON object that contains:
// Name of Tourist attraction,
// Tourist attractions lat/long,
// The user's location lat/long,
// The distance in miles between the user's location and each of the attractions.
// The reward points for visiting each Attraction.
// Note: Attraction reward points can be gathered from RewardsCentral
@RequestMapping("/getNearbyAttractions")

@RequestMapping("/getNearbyAttractions")
public String getNearbyAttractions(@RequestParam String userName) {
VisitedLocation visitedLocation = tourGuideService.getUserLocation(getUser(userName));
return JsonStream.serialize(tourGuideService.getNearByAttractions(visitedLocation));
return JsonStream.serialize((tourGuideService.getNearByAttractions(getUser(userName))));
}

@RequestMapping("/getRewards")
public String getRewards(@RequestParam String userName) {
return JsonStream.serialize(tourGuideService.getUserRewards(getUser(userName)));
}


@RequestMapping("/getAllCurrentLocations")
public String getAllCurrentLocations() {
// TODO: Get a list of every user's most recent location as JSON
//- Note: does not use gpsUtil to query for their current location,
// but rather gathers the user's current location from their stored location history.
//
// Return object should be the just a JSON mapping of userId to Locations similar to:
// {
// "019b04a9-067a-4c76-8817-ee75088c3822": {"longitude":-48.188821,"latitude":74.84371}
// ...
// }

return JsonStream.serialize("");
return JsonStream.serialize(tourGuideService.getAllCurrentLocations().toString());
}



@RequestMapping("/getTripDeals")
public String getTripDeals(@RequestParam String userName) {
List<Provider> providers = tourGuideService.getTripDeals(getUser(userName));
Expand Down
9 changes: 6 additions & 3 deletions TourGuide/src/main/java/tourGuide/TourGuideModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import org.springframework.context.annotation.Configuration;

import gpsUtil.GpsUtil;
import org.springframework.context.annotation.Primary;
import rewardCentral.RewardCentral;
import tourGuide.service.GpsUtilService;
import tourGuide.service.RewardsService;

@Configuration
public class TourGuideModule {


@Primary
@Bean
public GpsUtil getGpsUtil() {
return new GpsUtil();
public GpsUtilService getGpsUtil() {
return new GpsUtilService();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package tourGuide.dto;

public class Dto5NearAttractionByUser
{
private String attractionName;
private double attractionLatitude;
private double attractionLongitude;
private double userLatitude;
private double userLongitude;
private Double distanceFromUser;
private int rewardPoints;

public void setAttractionName(String attractionName) {
this.attractionName = attractionName;
}

public void setAttractionLatitude(double attractionLatitude) {
this.attractionLatitude = attractionLatitude;
}

public void setAttractionLongitude(double attractionLongitude) {
this.attractionLongitude = attractionLongitude;
}

public void setUserLatitude(double userLatitude) {
this.userLatitude = userLatitude;
}

public void setUserLongitude(double userLongitude) {
this.userLongitude = userLongitude;
}

public void setDistanceFromUser(Double distanceFromUser) {
this.distanceFromUser = distanceFromUser;
}

public void setRewardPoints(int rewardPoints) {
this.rewardPoints = rewardPoints;
}

public String getAttractionName() {
return attractionName;
}

public double getAttractionLatitude() {
return attractionLatitude;
}

public double getAttractionLongitude() {
return attractionLongitude;
}

public double getUserLatitude() {
return userLatitude;
}

public double getUserLongitude() {
return userLongitude;
}

public Double getDistanceFromUser() {
return distanceFromUser;
}

public int getRewardPoints() {
return rewardPoints;
}

public Dto5NearAttractionByUser(String attractionName, double attractionLatitude, double attractionLongitude, double userLatitude, double userLongitude, Double distanceFromUser, int rewardPoints) {
this.attractionName = attractionName;
this.attractionLatitude = attractionLatitude;
this.attractionLongitude = attractionLongitude;
this.userLatitude = userLatitude;
this.userLongitude = userLongitude;
this.distanceFromUser = distanceFromUser;
this.rewardPoints = rewardPoints;
}

public Dto5NearAttractionByUser() {
}

@Override
public String toString() {
return "Tourist attraction:" + attractionName + ", Tourist attractions latitude :" + attractionLatitude + ", Tourist attractions longitude :" + attractionLongitude
+ ", User's location latitude:" + userLatitude + ", User's location longitude:" + userLongitude + ", Distance between the user's location and attraction:" + distanceFromUser + ", Reward Points:"
+ rewardPoints;
}
}
39 changes: 39 additions & 0 deletions TourGuide/src/main/java/tourGuide/dto/LocationDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tourGuide.dto;

public class LocationDto {

double longitude;

double latitude;
public double getLongitude() {
return longitude;
}

public double getLatitude() {
return latitude;
}

public void setLongitude(double longitude) {
this.longitude = longitude;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public LocationDto() {
}

public LocationDto(double longitude, double latitude) {
this.longitude = longitude;
this.latitude = latitude;
}

@Override
public String toString() {
return '{' +
"\'longitude\'" + ":"+ longitude + ',' +
"\'latitude\'" + ":"+ latitude +
'}';
}
}
38 changes: 38 additions & 0 deletions TourGuide/src/main/java/tourGuide/dto/UserLocationDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tourGuide.dto;

public class UserLocationDto {

private String userId;

private LocationDto location;

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public void setLocation(LocationDto location) {
this.location = location;
}

public LocationDto getLocation() {
return location;
}

public UserLocationDto() {
}

public UserLocationDto(String userId, LocationDto location) {
this.userId = userId;
this.location = location;
}

@Override
public String toString() {
return userId + ":" + location;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class InternalTestHelper {

// Set this default up to 100,000 for testing
private static int internalUserNumber = 100;
private static int internalUserNumber = 1000 ;

public static void setInternalUserNumber(int internalUserNumber) {
InternalTestHelper.internalUserNumber = internalUserNumber;
Expand Down
56 changes: 56 additions & 0 deletions TourGuide/src/main/java/tourGuide/service/GpsUtilService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package tourGuide.service;

import gpsUtil.GpsUtil;
import gpsUtil.location.Attraction;
import gpsUtil.location.VisitedLocation;
import org.springframework.stereotype.Service;
import tourGuide.user.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class GpsUtilService {
private static final Logger logger = LoggerFactory.getLogger(GpsUtilService.class);


private GpsUtil gpsUtil;

private ExecutorService executor = Executors.newFixedThreadPool(10000);

public GpsUtilService() {
gpsUtil = new GpsUtil();
}

public List<Attraction> getAttractions() {
return gpsUtil.getAttractions();
}
public VisitedLocation getUserLocation(UUID userId) {
VisitedLocation visitedLocation;
try {
visitedLocation = gpsUtil.getUserLocation(userId);
} catch (NumberFormatException nfe) {
visitedLocation = null;
}
return visitedLocation;
}


public void trackUserLocationAsync(User user, TourGuideService tourGuideService) {
CompletableFuture.supplyAsync(() -> gpsUtil.getUserLocation(user.getUserId()), executor)
.thenAccept(visitedLocation -> {
if (visitedLocation != null) {
tourGuideService.trackUserLocation(user);
}
})
.exceptionally(ex -> {
logger.error("Error tracking user location", ex);
return null;
});
}

}
Loading