Merge branch 'fixBugs_addLeaderboard' into 'master'
Fix bugs & add leaderboard See merge request cse1105/2018-2019/oopp-group-43/template!50
This commit is contained in:
45
README.md
45
README.md
@@ -1,13 +1,5 @@
|
|||||||
## Getting your weekly reports
|
# Merel Steenbergen (masteenbergen)
|
||||||
|
<img src="https://user-images.githubusercontent.com/47633984/55274602-13cc1200-52da-11e9-9bd7-686d84929b83.jpg" width="100"/>
|
||||||
**Jacoco**:
|
|
||||||
Run `maven install` ([Intellij](https://www.jetbrains.com/help/idea/2016.3/getting-started-with-maven.html#execute_maven_goal)/[Eclipse](http://imgur.com/a/6q7pV))
|
|
||||||
|
|
||||||
**Checkstyle**:
|
|
||||||
Run `maven site`
|
|
||||||
|
|
||||||
# Merel Steenbergen (masteenbergen)
|
|
||||||

|
|
||||||
|
|
||||||
## Personal Development Plan
|
## Personal Development Plan
|
||||||
|
|
||||||
@@ -19,26 +11,26 @@ everyone is keeping on track and if not, why is someone slacking?
|
|||||||
What are two of your weaker points?
|
What are two of your weaker points?
|
||||||
1. I’m a bit of a control freak. Sometimes I find it hard to let other people do things and to mind my own business.
|
1. I’m a bit of a control freak. Sometimes I find it hard to let other people do things and to mind my own business.
|
||||||
2. I’m competitive. This can be a good thing, because I’m very passionate and really give it 100% if I like something, but it can also lead to hurt feelings when I’m not paying attention.
|
2. I’m competitive. This can be a good thing, because I’m very passionate and really give it 100% if I like something, but it can also lead to hurt feelings when I’m not paying attention.
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### G - Goal
|
<img src="https://user-images.githubusercontent.com/47633984/55274622-2d6d5980-52da-11e9-8be0-ac1ef545f7d9.png" width="700"/>
|
||||||
|
|
||||||
|
### G - Goal
|
||||||
I want to improve on letting other people handle things that I actually want to do myself. I also want to improve my programming and am aiming to not make it a competition, but to really make it a group project. This is important, because you almost never work alone in software developing, which is what I want to do after the studies.
|
I want to improve on letting other people handle things that I actually want to do myself. I also want to improve my programming and am aiming to not make it a competition, but to really make it a group project. This is important, because you almost never work alone in software developing, which is what I want to do after the studies.
|
||||||
|
|
||||||
### R - Reality (Your current situation)
|
### R - Reality (Your current situation)
|
||||||
I’ve already been working on my teamwork skills since high school. I had a subject that had only projects. I’ve also worked with Scrum before, which really helps you focus on your development without letting your project out of sight. I’m better at working together and listening to tips than I was before.
|
I’ve already been working on my teamwork skills since high school. I had a subject that had only projects. I’ve also worked with Scrum before, which really helps you focus on your development without letting your project out of sight. I’m better at working together and listening to tips than I was before.
|
||||||
|
|
||||||
### O - Options (Look at possible options)
|
### O - Options (Look at possible options)
|
||||||
Actively watching myself and letting my teammates know that they need to be clear with me if they don’t like something I say or do are the best ways for me to improve. I would rather improve by myself, but for my goals it is better to let my team guide me. It’s about teamwork after all.
|
Actively watching myself and letting my teammates know that they need to be clear with me if they don’t like something I say or do are the best ways for me to improve. I would rather improve by myself, but for my goals it is better to let my team guide me. It’s about teamwork after all.
|
||||||
|
|
||||||
### W - Will (Motivation, plan of action)
|
### W - Will (Motivation, plan of action)
|
||||||
I’m just going to keep working on myself and hope my teammates will work with me. It also helps to work in different teams to get a much more diverse experience. Every team is different, so I’m just going to wait what this team will bring me and how I will have to adjust myself to make the team efficient.
|
I’m just going to keep working on myself and hope my teammates will work with me. It also helps to work in different teams to get a much more diverse experience. Every team is different, so I’m just going to wait what this team will bring me and how I will have to adjust myself to make the team efficient.
|
||||||
|
|
||||||
# Sem van der Hoeven (4896726, semvanderhoeve)
|
# Sem van der Hoeven (4896726, semvanderhoeve)
|
||||||

|
<img src="https://user-images.githubusercontent.com/47633984/55274658-d6b44f80-52da-11e9-9404-a4ae9a210b72.jpg" width="100"/>
|
||||||
|
|
||||||
## Personal development plan
|
## Personal development plan
|
||||||

|
<img src="https://user-images.githubusercontent.com/47633984/55274673-0a8f7500-52db-11e9-8d83-e1acbf22aeed.png" width="700"/>
|
||||||
|
|
||||||
### G - Goal
|
### G - Goal
|
||||||
My goal with this project is most of all to be able to efficiently work with a group of people. This is important to me because I have not worked on a (development) project with a (big) group of people before. I believe I have succeeded in this goal when our project is finished and we have got a passing grade.
|
My goal with this project is most of all to be able to efficiently work with a group of people. This is important to me because I have not worked on a (development) project with a (big) group of people before. I believe I have succeeded in this goal when our project is finished and we have got a passing grade.
|
||||||
@@ -58,12 +50,11 @@ action plan:
|
|||||||
⋅⋅* deliver things I need to do on time
|
⋅⋅* deliver things I need to do on time
|
||||||
|
|
||||||
# Ceren Ugurlu (4851609, cugurlu)
|
# Ceren Ugurlu (4851609, cugurlu)
|
||||||
|
<img src="https://user-images.githubusercontent.com/47633984/55274734-10398a80-52dc-11e9-9fce-5059ac2b3f3b.jpeg" width="100"/>
|
||||||

|
|
||||||
|
|
||||||
## Personal Development Plan:
|
## Personal Development Plan:
|
||||||
|
|
||||||
- This is my core quadrant: 
|
- This is my core quadrant: <img src="https://user-images.githubusercontent.com/47633984/55274694-4296b800-52db-11e9-9cee-b8d1d5c58e6f.png" width="700"/>
|
||||||
|
|
||||||
My strong points:
|
My strong points:
|
||||||
- I am an ambitious person in order to achieve my goal I can study a lot
|
- I am an ambitious person in order to achieve my goal I can study a lot
|
||||||
@@ -98,10 +89,10 @@ Action Plan:
|
|||||||
- While everyone is working on their part, to inform each other about the progress is very important because some parts can be connected. When two people's parts are connected they should act according to that otherwise it can lead problems or a non-compiling code)
|
- While everyone is working on their part, to inform each other about the progress is very important because some parts can be connected. When two people's parts are connected they should act according to that otherwise it can lead problems or a non-compiling code)
|
||||||
|
|
||||||
# Mika Wauben (4834739, mlwauben)
|
# Mika Wauben (4834739, mlwauben)
|
||||||

|
<img src="https://user-images.githubusercontent.com/47633984/55274742-29423b80-52dc-11e9-804d-69feec6d28e0.jpg" width="100"/>
|
||||||
|
|
||||||
## Personal Development Plan
|
## Personal Development Plan
|
||||||

|
<img src="https://user-images.githubusercontent.com/47633984/55274719-c18bf080-52db-11e9-9d3f-018ba68dd1f0.jpg" width="700"/>
|
||||||
|
|
||||||
My strong points:
|
My strong points:
|
||||||
1. I am observing and think before I speak.
|
1. I am observing and think before I speak.
|
||||||
@@ -111,14 +102,14 @@ Action Plan:
|
|||||||
1. I like to do things alone. I rather figure something out myself instead of asking for help, even if this takes way too long.
|
1. I like to do things alone. I rather figure something out myself instead of asking for help, even if this takes way too long.
|
||||||
2. I tend to stay quiet if I'm not absolutely sure my contribution is right or useful.
|
2. I tend to stay quiet if I'm not absolutely sure my contribution is right or useful.
|
||||||
|
|
||||||
### G - Goal
|
### G - Goal
|
||||||
My goal during this course is getting more experienced in working with things like github, libraries, scrumboard, etc. and asking for help if I need it, since being stuck on something isn’t going to help my groupmates.
|
My goal during this course is getting more experienced in working with things like github, libraries, scrumboard, etc. and asking for help if I need it, since being stuck on something isn’t going to help my groupmates.
|
||||||
|
|
||||||
### R - Reality
|
### R - Reality
|
||||||
Every minute that we’re working on the project, I’m also actively working on my goal.
|
Every minute that we’re working on the project, I’m also actively working on my goal.
|
||||||
|
|
||||||
### O - Options
|
### O - Options
|
||||||
By working on the project with the chosen programs, I’ll get more experienced in using them. Using those programs for other projects as well will only improve my knowledge. By being active in the groupchat and during the meetings, asking stuff will be easier.
|
By working on the project with the chosen programs, I’ll get more experienced in using them. Using those programs for other projects as well will only improve my knowledge. By being active in the groupchat and during the meetings, asking stuff will be easier.
|
||||||
|
|
||||||
### W - Will
|
### W - Will
|
||||||
I will reach my goal by working actively together with my teammates using lots of the useful programs given.
|
I will reach my goal by working actively together with my teammates using lots of the useful programs given.
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import javafx.beans.property.SimpleStringProperty;
|
|||||||
public class Friend {
|
public class Friend {
|
||||||
|
|
||||||
private SimpleStringProperty friend;
|
private SimpleStringProperty friend;
|
||||||
private SimpleFloatProperty friendScore;
|
private SimpleFloatProperty score;
|
||||||
|
|
||||||
public Friend(String friend, Float friendScore) {
|
public Friend(String friend, Float friendScore) {
|
||||||
this.friend = new SimpleStringProperty(friend);
|
this.friend = new SimpleStringProperty(friend);
|
||||||
this.friendScore = new SimpleFloatProperty(friendScore);
|
this.score = new SimpleFloatProperty(friendScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -22,11 +22,11 @@ public class Friend {
|
|||||||
this.friend = new SimpleStringProperty(name);
|
this.friend = new SimpleStringProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getFriendScore() {
|
public Float getScore() {
|
||||||
return friendScore.get();
|
return score.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(Float score) {
|
public void setScore(Float score) {
|
||||||
this.friendScore = new SimpleFloatProperty(score);
|
this.score = new SimpleFloatProperty(score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ import javafx.scene.control.ScrollPane;
|
|||||||
import javafx.scene.control.Slider;
|
import javafx.scene.control.Slider;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.Window;
|
import javafx.stage.Window;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
@@ -29,6 +30,9 @@ public class CalculatorController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
DashBoardController controller;
|
||||||
|
|
||||||
//navigation panes
|
//navigation panes
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane getStartedPane;
|
private AnchorPane getStartedPane;
|
||||||
@@ -119,6 +123,10 @@ public class CalculatorController {
|
|||||||
|
|
||||||
//shopping pane
|
//shopping pane
|
||||||
@FXML
|
@FXML
|
||||||
|
private Text goodsField;
|
||||||
|
@FXML
|
||||||
|
private Text servicesField;
|
||||||
|
@FXML
|
||||||
private Slider goodsSlider;
|
private Slider goodsSlider;
|
||||||
@FXML
|
@FXML
|
||||||
private Label goodsLabel;
|
private Label goodsLabel;
|
||||||
@@ -303,8 +311,7 @@ public class CalculatorController {
|
|||||||
* The method saves the calculation.
|
* The method saves the calculation.
|
||||||
* @param event user clicks to button
|
* @param event user clicks to button
|
||||||
*/
|
*/
|
||||||
public void saveCalc(ActionEvent event) {
|
public void saveCalc(ActionEvent event) throws InterruptedException {
|
||||||
Window owner = saveButton.getScene().getWindow();
|
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -336,7 +343,7 @@ public class CalculatorController {
|
|||||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg1",
|
"input_footprint_transportation_mpg1",
|
||||||
carTravelGasolineLabel.getText());
|
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||||
}
|
}
|
||||||
if (!carTravelDieselField.getText().equals("0")) {
|
if (!carTravelDieselField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
@@ -346,36 +353,36 @@ public class CalculatorController {
|
|||||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg2",
|
"input_footprint_transportation_mpg2",
|
||||||
carTravelDieselLabel.getText());
|
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||||
}
|
}
|
||||||
if (!carTravelElectricField.getText().equals("0")) {
|
if (!carTravelElectricField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles3",
|
"input_footprint_transportation_miles3",
|
||||||
peopleInHouseHoldLabel.getText());
|
carTravelElectricField.getText());
|
||||||
}
|
}
|
||||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg3",
|
"input_footprint_transportation_mpg3",
|
||||||
carTravelElectricLabel.getText());
|
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||||
}
|
}
|
||||||
if (!electricityField.getText().equals("0")) {
|
if (!electricityField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_electricity_dollars",
|
"input_footprint_housing_electricity_dollars",
|
||||||
electricityField.getText());
|
electricityField.getText());
|
||||||
}
|
}
|
||||||
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
|
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_housing_gco2_per_kwh",
|
"input_footprint_housing_gco2_per_kwh",
|
||||||
cleanEnergyPurchasedLabel.getText());
|
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
|
||||||
}
|
}
|
||||||
if (!naturalGasField.getText().equals("0")) {
|
if (!naturalGasField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_naturalgas_dollars",
|
"input_footprint_housing_naturalgas_dollars",
|
||||||
naturalGasField.getText());
|
naturalGasField.getText());
|
||||||
}
|
}
|
||||||
if (!heatingOilField.getText().equals("0")) {
|
if (!heatingOilField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_heatingoil_dollars",
|
"input_footprint_housing_heatingoil_dollars",
|
||||||
heatingOilField.getText());
|
heatingOilField.getText());
|
||||||
}
|
}
|
||||||
if (!livingSpaceField.getText().equals("0")) {
|
if (!livingSpaceField.getText().equals("0")) {
|
||||||
@@ -386,44 +393,49 @@ public class CalculatorController {
|
|||||||
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
|
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_housing_watersewage",
|
"input_footprint_housing_watersewage",
|
||||||
waterUsageLabel.getText());
|
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||||
}
|
}
|
||||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_meatfisheggs",
|
"input_footprint_shopping_food_meatfisheggs",
|
||||||
meatFishEggsLabel.getText());
|
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
}
|
||||||
if (!grainsBakedGoodsLabel.getText().replace(" daily servings per person", "").equals("4.4")) {
|
if (!grainsBakedGoodsLabel.getText()
|
||||||
|
.replace(" daily servings per person", "").equals("4.4")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_cereals",
|
"input_footprint_shopping_food_cereals",
|
||||||
grainsBakedGoodsLabel.getText());
|
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
}
|
||||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_dairy",
|
"input_footprint_shopping_food_dairy",
|
||||||
dairyLabel.getText());
|
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
}
|
||||||
if (!fruitsVegetablesLabel.getText().replace(" daily servings per person", "").equals("3.9")) {
|
if (!fruitsVegetablesLabel.getText()
|
||||||
|
.replace(" daily servings per person", "").equals("3.9")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_fruitvegetables",
|
"input_footprint_shopping_food_fruitvegetables",
|
||||||
fruitsVegetablesLabel.getText());
|
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
}
|
||||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_otherfood",
|
"input_footprint_shopping_food_otherfood",
|
||||||
snacksDrinksLabel.getText());
|
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
}
|
||||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_goods_total",
|
"input_footprint_shopping_goods_total",
|
||||||
snacksDrinksLabel.getText());
|
goodsLabel.getText().replace("€ / month", ""));
|
||||||
}
|
}
|
||||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_services_total",
|
"input_footprint_shopping_services_total",
|
||||||
snacksDrinksLabel.getText());
|
servicesLabel.getText().replace("€ / month", ""));
|
||||||
}
|
}
|
||||||
|
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||||
|
Window owner = saveButton.getScene().getWindow();
|
||||||
Stage current = (Stage) owner;
|
Stage current = (Stage) owner;
|
||||||
current.close();
|
current.close();
|
||||||
|
controller.updateLeaderboard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,12 +28,17 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that controls the dashboard fxml file (the GUI Screen).
|
* Class that controls the dashboard fxml file (the GUI Screen).
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
public class DashBoardController {
|
public class DashBoardController {
|
||||||
|
public static ObservableList<Friend> data = FXCollections.observableArrayList();
|
||||||
|
public ObservableList<Friend> friendLeaderData = FXCollections.observableArrayList();
|
||||||
|
public ObservableList<Friend> globalLeaderData = FXCollections.observableArrayList();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@@ -76,6 +81,18 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private TableColumn<Friend, Float> scoreColumn;
|
private TableColumn<Friend, Float> scoreColumn;
|
||||||
@FXML
|
@FXML
|
||||||
|
private TableView<Friend> globalLeaderboard;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Friend, String> globalUser;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Friend, Float> globalScore;
|
||||||
|
@FXML
|
||||||
|
private TableView<Friend> friendLeaderboard;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Friend, String> friendUser;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Friend, Float> friendScore;
|
||||||
|
@FXML
|
||||||
private PieChart pieChart;
|
private PieChart pieChart;
|
||||||
@FXML
|
@FXML
|
||||||
private Label usernameLabel;
|
private Label usernameLabel;
|
||||||
@@ -83,7 +100,7 @@ public class DashBoardController {
|
|||||||
/**
|
/**
|
||||||
* Loads the the necessary things before anything else.
|
* Loads the the necessary things before anything else.
|
||||||
*/
|
*/
|
||||||
public void initialize() {
|
public void initialize() throws InterruptedException {
|
||||||
//sets the text of the 'welcome back' text to include the username
|
//sets the text of the 'welcome back' text to include the username
|
||||||
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
|
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
|
||||||
//adds the slide transition to the menu bar
|
//adds the slide transition to the menu bar
|
||||||
@@ -95,8 +112,11 @@ public class DashBoardController {
|
|||||||
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
||||||
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||||
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||||
friendsTable.setItems(FriendController.getData());
|
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||||
if(pieChart != null) {
|
globalScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||||
|
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||||
|
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||||
|
if (pieChart != null) {
|
||||||
ObservableList<PieChart.Data> pieChartData =
|
ObservableList<PieChart.Data> pieChartData =
|
||||||
FXCollections.observableArrayList(
|
FXCollections.observableArrayList(
|
||||||
new PieChart.Data("Vegan Meal", 100),
|
new PieChart.Data("Vegan Meal", 100),
|
||||||
@@ -110,6 +130,37 @@ public class DashBoardController {
|
|||||||
pieChart.setMaxSize(1000, 1000);
|
pieChart.setMaxSize(1000, 1000);
|
||||||
pieChart.setData(pieChartData);
|
pieChart.setData(pieChartData);
|
||||||
}
|
}
|
||||||
|
List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
|
||||||
|
for (int i = 0; i < friendList.size(); i++) {
|
||||||
|
Friend friend = new Friend(friendList.get(i),
|
||||||
|
userService.getFootprint(friendList.get(i)));
|
||||||
|
data.add(friend);
|
||||||
|
}
|
||||||
|
friendsTable.setItems(data);
|
||||||
|
updateLeaderboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the scores of users.
|
||||||
|
* @param users the list of users
|
||||||
|
*/
|
||||||
|
public void sortScores(List<String> users) throws InterruptedException {
|
||||||
|
for (int i = 0; i < users.size(); i++) {
|
||||||
|
for (int j = 0; j < users.size(); j++) {
|
||||||
|
Float firstScore = userService.getFootprint(users.get(i));
|
||||||
|
Float secondScore = userService.getFootprint(users.get(j));
|
||||||
|
if (i > j && firstScore < secondScore) {
|
||||||
|
String temp = users.get(i);
|
||||||
|
users.set(i, users.get(j));
|
||||||
|
users.set(j, temp);
|
||||||
|
}
|
||||||
|
if (i < j && firstScore > secondScore) {
|
||||||
|
String temp = users.get(i);
|
||||||
|
users.set(i, users.get(j));
|
||||||
|
users.set(j, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +168,6 @@ public class DashBoardController {
|
|||||||
* @param node the node on which the transition needs to act
|
* @param node the node on which the transition needs to act
|
||||||
*/
|
*/
|
||||||
public void addFadeTransition(Node node) {
|
public void addFadeTransition(Node node) {
|
||||||
|
|
||||||
fadeTrans = new FadeTransition(Duration.millis(400), node);
|
fadeTrans = new FadeTransition(Duration.millis(400), node);
|
||||||
fadeTrans.setFromValue(0);
|
fadeTrans.setFromValue(0);
|
||||||
fadeTrans.setToValue(1.0);
|
fadeTrans.setToValue(1.0);
|
||||||
@@ -129,14 +179,14 @@ public class DashBoardController {
|
|||||||
* Displays the dashboard pane.
|
* Displays the dashboard pane.
|
||||||
* @param event the event (clicking the button)
|
* @param event the event (clicking the button)
|
||||||
*/
|
*/
|
||||||
public void displayDashboard(ActionEvent event) {
|
public void displayDashboard(ActionEvent event) throws InterruptedException {
|
||||||
addFadeTransition(dashboardPane);
|
addFadeTransition(dashboardPane);
|
||||||
System.out.println("display dashboard");
|
System.out.println("display dashboard");
|
||||||
dashboardPane.setVisible(true);
|
dashboardPane.setVisible(true);
|
||||||
userPane.setVisible(false);
|
userPane.setVisible(false);
|
||||||
activitiesPane.setVisible(false);
|
activitiesPane.setVisible(false);
|
||||||
friendsPane.setVisible(false);
|
friendsPane.setVisible(false);
|
||||||
|
updateLeaderboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -194,7 +244,7 @@ public class DashBoardController {
|
|||||||
* Opens the calculator.
|
* Opens the calculator.
|
||||||
* @throws IOException if the Application doesn't load.
|
* @throws IOException if the Application doesn't load.
|
||||||
*/
|
*/
|
||||||
public void openCalculator() throws IOException {
|
public void openCalculator() throws IOException, InterruptedException {
|
||||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||||
.getResource("fxml/calculator.fxml"));
|
.getResource("fxml/calculator.fxml"));
|
||||||
Scene scene = new Scene(calc);
|
Scene scene = new Scene(calc);
|
||||||
@@ -207,6 +257,10 @@ public class DashBoardController {
|
|||||||
calcStage.show();
|
calcStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* method opend addFriend scene.
|
||||||
|
* @throws IOException when file is not found
|
||||||
|
*/
|
||||||
public void openAddFriend() throws IOException {
|
public void openAddFriend() throws IOException {
|
||||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||||
.getResource("fxml/AddFriend.fxml"));
|
.getResource("fxml/AddFriend.fxml"));
|
||||||
@@ -217,6 +271,37 @@ public class DashBoardController {
|
|||||||
calcStage.show();
|
calcStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Leaderboard is updaating.
|
||||||
|
* @throws InterruptedException throws exception
|
||||||
|
*/
|
||||||
|
public void updateLeaderboard() throws InterruptedException {
|
||||||
|
friendLeaderboard.getItems().clear();
|
||||||
|
globalLeaderboard.getItems().clear();
|
||||||
|
//global leaderboard
|
||||||
|
globalLeaderData.removeAll();
|
||||||
|
List<String> userList = userService.getAllUsers();
|
||||||
|
sortScores(userList);
|
||||||
|
for (int j = 0; j < userList.size(); j++) {
|
||||||
|
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
|
||||||
|
globalLeaderData.add(user);
|
||||||
|
}
|
||||||
|
globalLeaderboard.setItems(globalLeaderData);
|
||||||
|
// friend leaderboard
|
||||||
|
friendLeaderData.removeAll();
|
||||||
|
String name = userService.currentUser.getName();
|
||||||
|
List<String> friendList = userService.getFriendNames(name);
|
||||||
|
friendList.add(name);
|
||||||
|
sortScores(friendList);
|
||||||
|
for (int i = 0; i < friendList.size(); i++) {
|
||||||
|
Friend friend = new Friend(friendList.get(i),
|
||||||
|
userService.getFootprint(friendList.get(i)));
|
||||||
|
friendLeaderData.add(friend);
|
||||||
|
}
|
||||||
|
friendLeaderboard.setItems(friendLeaderData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//class for the animations on the navigation buttons
|
//class for the animations on the navigation buttons
|
||||||
public class MyButtonSkin extends ButtonSkin {
|
public class MyButtonSkin extends ButtonSkin {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package greenify.client.controller;
|
|||||||
|
|
||||||
import greenify.client.Friend;
|
import greenify.client.Friend;
|
||||||
import greenify.client.rest.UserService;
|
import greenify.client.rest.UserService;
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.Window;
|
import javafx.stage.Window;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -17,7 +17,8 @@ public class FriendController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
public static ObservableList<Friend> data = FXCollections.observableArrayList();
|
@Autowired
|
||||||
|
DashBoardController controller;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button addButton;
|
private Button addButton;
|
||||||
@@ -29,7 +30,7 @@ public class FriendController {
|
|||||||
* @param event the click of the sign up button
|
* @param event the click of the sign up button
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void addFriend(ActionEvent event) {
|
public void addFriend(ActionEvent event) throws InterruptedException {
|
||||||
//set the window to the current window (for displaying the alerts)
|
//set the window to the current window (for displaying the alerts)
|
||||||
Window owner = addButton.getScene().getWindow();
|
Window owner = addButton.getScene().getWindow();
|
||||||
//check if the username field is empty
|
//check if the username field is empty
|
||||||
@@ -38,19 +39,28 @@ public class FriendController {
|
|||||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
|
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
|
||||||
"Please enter a username!");
|
"Please enter a username!");
|
||||||
return;
|
return;
|
||||||
|
} else if (userNameText.getText().equals(userService.currentUser.getName())) {
|
||||||
|
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
|
||||||
|
"Cannot add yourself as a friend!");
|
||||||
|
return;
|
||||||
|
} else if (userService.getFriendNames(userService.currentUser.getName())
|
||||||
|
.contains(userNameText.getText())) {
|
||||||
|
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
|
||||||
|
"Cannot add a friend twice!");
|
||||||
|
return;
|
||||||
|
} else if (!userService.getAllUsers().contains(userNameText.getText())) {
|
||||||
|
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
|
||||||
|
"The user does not exist!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//add friend to the current user
|
//add friend to the current user
|
||||||
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
||||||
Friend friend = new Friend(userNameText.getText(),
|
Friend friend = new Friend(userNameText.getText(),
|
||||||
userService.getFootprint(userNameText.getText()));
|
userService.getFootprint(userNameText.getText()));
|
||||||
data.add(friend);
|
DashBoardController.data.add(friend);
|
||||||
//close the register window after the user has entered all the credentials
|
//close the register window after the user has entered all the credentials
|
||||||
Stage current = (Stage) owner;
|
Stage current = (Stage) owner;
|
||||||
current.close();
|
current.close();
|
||||||
|
controller.updateLeaderboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObservableList<Friend> getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
public UserDto currentUser;
|
public UserDto currentUser;
|
||||||
@@ -117,6 +119,42 @@ public class UserService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the footprint of the user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return returns the footprint score
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public Float saveFootprint(String name) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFootprint")
|
||||||
|
.queryParam("name", name);
|
||||||
|
new HttpEntity<>(headers);
|
||||||
|
System.out.println(builder.build().encode().toUri());
|
||||||
|
Float result = this.restTemplate.getForObject(builder
|
||||||
|
.build().encode().toUri(), Float.class);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the friend list of the user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return returns the friend list
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public List<String> getFriendNames(String name) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFriends")
|
||||||
|
.queryParam("name", name);
|
||||||
|
new HttpEntity<>(headers);
|
||||||
|
System.out.println(builder.build().encode().toUri());
|
||||||
|
List<String> result = this.restTemplate.getForObject(builder
|
||||||
|
.build().encode().toUri(), List.class);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a friend to the user.
|
* Adds a friend to the user.
|
||||||
* @param name the username of the current user.
|
* @param name the username of the current user.
|
||||||
@@ -134,4 +172,19 @@ public class UserService {
|
|||||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||||
.encode().toUri(), String.class);
|
.encode().toUri(), String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of all users.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public List<String> getAllUsers() {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getAllUsers");
|
||||||
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
|
System.out.println(builder.build().encode().toUri());
|
||||||
|
List<String> result = this.restTemplate.getForObject(builder
|
||||||
|
.build().encode().toUri(), List.class);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.shape.*?>
|
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import javafx.geometry.*?>
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.image.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
@@ -50,9 +43,9 @@
|
|||||||
<Image url="@../icons/world.png" />
|
<Image url="@../icons/world.png" />
|
||||||
<!--image credits:
|
<!--image credits:
|
||||||
made by prettycons https://www.flaticon.com/authors/prettycons
|
made by prettycons https://www.flaticon.com/authors/prettycons
|
||||||
from https://www.flaticon.com/
|
from https://www.flaticon.com/
|
||||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||||
-->
|
-->
|
||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
@@ -108,7 +101,7 @@
|
|||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" onAction="#saveCalculation" text="Save">
|
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" onAction="#saveCalc" mnemonicParsing="false" text="Save">
|
||||||
<font>
|
<font>
|
||||||
<Font size="17.0" />
|
<Font size="17.0" />
|
||||||
</font></Button>
|
</font></Button>
|
||||||
@@ -146,9 +139,8 @@
|
|||||||
</opaqueInsets>
|
</opaqueInsets>
|
||||||
</Label>
|
</Label>
|
||||||
<Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" />
|
<Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" />
|
||||||
<Line endX="79.0" layoutX="188.0" layoutY="14.0" stroke="#38573e" />
|
|
||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
<AnchorPane fx:id="travelPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
<AnchorPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||||
<children>
|
<children>
|
||||||
<ScrollPane layoutX="158.0" layoutY="109.0" prefHeight="215.0" prefWidth="499.0">
|
<ScrollPane layoutX="158.0" layoutY="109.0" prefHeight="215.0" prefWidth="499.0">
|
||||||
<content>
|
<content>
|
||||||
@@ -159,7 +151,7 @@
|
|||||||
<Font size="16.0" />
|
<Font size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<TextField fx:id="carTravelGasolineField" layoutX="14.0" layoutY="38.0" prefHeight="31.0" prefWidth="405.0" promptText="16.400">
|
<TextField fx:id="carTravelGasolineField" layoutX="14.0" layoutY="38.0" prefHeight="31.0" prefWidth="405.0" promptText="16.400" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -202,7 +194,7 @@
|
|||||||
</Text>
|
</Text>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<TextField fx:id="carTravelDieselField" layoutX="14.0" layoutY="200.0" prefHeight="31.0" prefWidth="405.0" promptText="15.400">
|
<TextField fx:id="carTravelDieselField" layoutX="14.0" layoutY="200.0" prefHeight="31.0" prefWidth="405.0" promptText="15.400" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -217,7 +209,7 @@
|
|||||||
<Font size="16.0" />
|
<Font size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<TextField fx:id="carTravelElectricField" layoutX="14.0" layoutY="365.0" prefHeight="31.0" prefWidth="405.0" promptText="14.900">
|
<TextField fx:id="carTravelElectricField" layoutX="14.0" layoutY="365.0" prefHeight="31.0" prefWidth="405.0" promptText="14.900" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -258,7 +250,7 @@
|
|||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<TextField fx:id="publicTransitField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="394.0" prefHeight="31.0" prefWidth="499.0" promptText="0">
|
<TextField fx:id="publicTransitField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="394.0" prefHeight="31.0" prefWidth="499.0" promptText="0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font></TextField>
|
</font></TextField>
|
||||||
@@ -267,7 +259,7 @@
|
|||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<TextField fx:id="airplaneTravelField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="495.0" prefHeight="31.0" prefWidth="499.0" promptText="0">
|
<TextField fx:id="airplaneTravelField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="495.0" prefHeight="31.0" prefWidth="499.0" promptText="0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font></TextField>
|
</font></TextField>
|
||||||
@@ -290,10 +282,9 @@
|
|||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<Button fx:id="travelNextButton" layoutX="383.0" layoutY="559.0" mnemonicParsing="false" onAction="#displayHome" styleClass="nextButton" text="Next" />
|
<Button fx:id="travelNextButton" layoutX="383.0" layoutY="559.0" mnemonicParsing="false" onAction="#displayHome" styleClass="nextButton" text="Next" />
|
||||||
<Line endX="79.0" layoutX="273.0" layoutY="7.0" stroke="#38573e" />
|
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
<AnchorPane fx:id="homePane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
<AnchorPane fx:id="homePane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutX="245.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you use in your home?">
|
<Text layoutX="245.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you use in your home?">
|
||||||
<font>
|
<font>
|
||||||
@@ -305,7 +296,7 @@
|
|||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<TextField layoutX="177.0" layoutY="105.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570">
|
<TextField fx:id="electricityField" layoutX="177.0" layoutY="105.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -356,7 +347,7 @@
|
|||||||
</Text>
|
</Text>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<TextField layoutX="177.0" layoutY="262.0" prefHeight="31.0" prefWidth="434.0" promptText="2,000">
|
<TextField fx:id="naturalGasField" layoutX="177.0" layoutY="262.0" prefHeight="31.0" prefWidth="434.0" promptText="2,000" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -373,7 +364,7 @@
|
|||||||
</Text>
|
</Text>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<TextField layoutX="177.0" layoutY="325.0" prefHeight="31.0" prefWidth="434.0" promptText="3,100">
|
<TextField fx:id="heatingOilField" layoutX="177.0" layoutY="325.0" prefHeight="31.0" prefWidth="434.0" promptText="3,100" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -388,7 +379,7 @@
|
|||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<TextField layoutX="177.0" layoutY="390.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570">
|
<TextField fx:id="livingSpaceField" layoutX="177.0" layoutY="390.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -419,9 +410,8 @@
|
|||||||
</Label>
|
</Label>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<Line endX="79.0" layoutX="358.0" layoutY="7.0" stroke="#38573e" />
|
|
||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
<ScrollPane fx:id="foodPane" layoutY="92.0" pannable="true" prefHeight="611.0" prefWidth="820.0" visible="false">
|
<ScrollPane fx:id="foodPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||||
<content>
|
<content>
|
||||||
<AnchorPane prefHeight="1000.0" prefWidth="817.0">
|
<AnchorPane prefHeight="1000.0" prefWidth="817.0">
|
||||||
<children>
|
<children>
|
||||||
@@ -457,7 +447,7 @@
|
|||||||
</Text>
|
</Text>
|
||||||
<HBox alignment="CENTER" layoutX="299.0" layoutY="310.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="299.0" layoutY="310.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="grainsBakedGoodsLabel" text="4,4 daily servings per person">
|
<Label fx:id="grainsBakedGoodsLabel" text="4.4 daily servings per person">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -478,7 +468,7 @@
|
|||||||
<Slider fx:id="dairySlider" blockIncrement="2.5" layoutX="146.0" layoutY="527.0" majorTickUnit="2.5" max="7.5" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="dairySlider" blockIncrement="2.5" layoutX="146.0" layoutY="527.0" majorTickUnit="2.5" max="7.5" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="299.0" layoutY="471.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="299.0" layoutY="471.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="dairyLabel" text="2,4 daily servings per person">
|
<Label fx:id="dairyLabel" text="2.4 daily servings per person">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -497,7 +487,7 @@
|
|||||||
</Text>
|
</Text>
|
||||||
<HBox alignment="CENTER" layoutX="304.0" layoutY="810.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="304.0" layoutY="810.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="snacksDrinksLabel" text="3,7 daily servings per person">
|
<Label fx:id="snacksDrinksLabel" text="3.7 daily servings per person">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -518,7 +508,7 @@
|
|||||||
<Slider fx:id="fruitsVegetablesSlider" blockIncrement="3.9" layoutX="151.0" layoutY="705.0" majorTickUnit="3.9" max="11.6" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="fruitsVegetablesSlider" blockIncrement="3.9" layoutX="151.0" layoutY="705.0" majorTickUnit="3.9" max="11.6" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="304.0" layoutY="649.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="304.0" layoutY="649.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="fruitsVegetablesLabel" text="3,9 daily servings per person">
|
<Label fx:id="fruitsVegetablesLabel" text="3.9 daily servings per person">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -531,12 +521,11 @@
|
|||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<Button layoutX="378.0" layoutY="926.0" mnemonicParsing="false" onAction="#displayShopping" styleClass="nextButton" text="Next" />
|
<Button layoutX="378.0" layoutY="926.0" mnemonicParsing="false" onAction="#displayShopping" styleClass="nextButton" text="Next" />
|
||||||
<Line endX="79.0" layoutX="443.0" layoutY="7.0" stroke="#38573e" />
|
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
<AnchorPane fx:id="shoppingPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutX="133.0" layoutY="50.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you spend on each of the following?">
|
<Text layoutX="133.0" layoutY="50.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you spend on each of the following?">
|
||||||
<font>
|
<font>
|
||||||
@@ -566,7 +555,7 @@
|
|||||||
<Slider fx:id="goodsSlider" blockIncrement="1520.0" layoutX="133.0" layoutY="209.0" majorTickUnit="1520.0" max="4560.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="goodsSlider" blockIncrement="1520.0" layoutX="133.0" layoutY="209.0" majorTickUnit="1520.0" max="4560.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="335.0" layoutY="145.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="335.0" layoutY="145.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="goodsLabel" text="1.520 € / month">
|
<Label fx:id="goodsLabel" text="1520 € / month">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -575,7 +564,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER" layoutX="335.0" layoutY="348.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="335.0" layoutY="348.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="servicesLabel" text="3.428 € / month">
|
<Label fx:id="servicesLabel" text="3428 € / month">
|
||||||
<font>
|
<font>
|
||||||
<Font size="15.0" />
|
<Font size="15.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -583,7 +572,8 @@
|
|||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<Slider fx:id="servicesSlider" blockIncrement="3428.0" layoutX="133.0" layoutY="418.0" majorTickUnit="3428.0" max="10284.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="servicesSlider" blockIncrement="3428.0" layoutX="133.0" layoutY="418.0" majorTickUnit="3428.0" max="10284.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<Line endX="79.0" layoutX="528.0" layoutY="7.0" stroke="#38573e" />
|
|
||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import javafx.scene.chart.*?>
|
|
||||||
<?import javafx.scene.shape.*?>
|
|
||||||
<?import javafx.scene.chart.PieChart?>
|
<?import javafx.scene.chart.PieChart?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.image.*?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.control.TableColumn?>
|
||||||
|
<?import javafx.scene.control.TableView?>
|
||||||
|
<?import javafx.scene.image.Image?>
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.shape.Line?>
|
<?import javafx.scene.shape.Line?>
|
||||||
<?import javafx.scene.text.*?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
<?import javafx.scene.text.Text?>
|
||||||
|
|
||||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||||
<children>
|
<children>
|
||||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||||
<children>
|
<children>
|
||||||
@@ -263,6 +267,28 @@
|
|||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
</Button>
|
</Button>
|
||||||
|
<TableView fx:id="globalLeaderboard" layoutX="56.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||||
|
<columns>
|
||||||
|
<TableColumn fx:id="globalUser" prefWidth="75.0" text="User" />
|
||||||
|
<TableColumn fx:id="globalScore" prefWidth="75.0" text="Score" />
|
||||||
|
</columns>
|
||||||
|
</TableView>
|
||||||
|
<TableView fx:id="friendLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||||
|
<columns>
|
||||||
|
<TableColumn fx:id="friendUser" prefWidth="75.0" text="User" />
|
||||||
|
<TableColumn fx:id="friendScore" prefWidth="75.0" text="Score" />
|
||||||
|
</columns>
|
||||||
|
</TableView>
|
||||||
|
<Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label layoutX="315.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Friends Leaderboard" textAlignment="CENTER" textFill="#5e1515">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
<AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import org.mockito.Spy;
|
|||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
|
|
||||||
@@ -51,6 +54,38 @@ public class UserServiceTest {
|
|||||||
Assert.assertEquals(estimate, result);
|
Assert.assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void saveFootprint() throws Exception {
|
||||||
|
Float estimate = new Float(5);
|
||||||
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/saveFootprint?name=Eric"),
|
||||||
|
Float.class))
|
||||||
|
.thenReturn(estimate);
|
||||||
|
Float result = userService.saveFootprint("Eric");
|
||||||
|
Assert.assertEquals(estimate, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFriendNamesTest() throws Exception {
|
||||||
|
List<String> estimate = new ArrayList<String>();
|
||||||
|
estimate.add("alex");
|
||||||
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFriends?name=Eric"),
|
||||||
|
List.class))
|
||||||
|
.thenReturn(estimate);
|
||||||
|
List<String> result = userService.getFriendNames("Eric");
|
||||||
|
Assert.assertEquals(estimate, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllUsers() throws Exception {
|
||||||
|
List<String> estimate = new ArrayList<String>();
|
||||||
|
estimate.add("alex");
|
||||||
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getAllUsers"),
|
||||||
|
List.class))
|
||||||
|
.thenReturn(estimate);
|
||||||
|
List<String> result = userService.getAllUsers();
|
||||||
|
Assert.assertEquals(estimate, result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputTest() throws Exception {
|
public void setInputTest() throws Exception {
|
||||||
userService.updateInput("Eric", "input_size", "5");
|
userService.updateInput("Eric", "input_size", "5");
|
||||||
|
|||||||
@@ -4,127 +4,130 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class InputValidator {
|
public class InputValidator {
|
||||||
|
|
||||||
private static final List<InputItem> inputItems = Arrays.asList(
|
private static final List<InputItem> inputItems = Arrays.asList(
|
||||||
new InputItem("input_location", false, "Chicago"),
|
new InputItem("input_location", false, "Chicago"),
|
||||||
new InputItem("input_location_mode", false, "1"),
|
new InputItem("input_location_mode", false, "1"),
|
||||||
new InputItem("input_size", false, "3"),
|
new InputItem("input_size", false, "3"),
|
||||||
new InputItem("input_income", false, "3000"),
|
new InputItem("input_income", false, "3000"),
|
||||||
new InputItem("input_population", false, "1"),
|
new InputItem("input_population", false, "1"),
|
||||||
new InputItem("input_changed", false, "0"),
|
new InputItem("input_changed", false, "0"),
|
||||||
new InputItem("input_footprint_household_adults", false, "0"),
|
new InputItem("input_footprint_household_adults", false, "0"),
|
||||||
new InputItem("input_footprint_household_children", false, "0"),
|
new InputItem("input_footprint_household_children", false, "0"),
|
||||||
new InputItem("input_footprint_transportation_num_vehicles", false, "1"),
|
new InputItem("input_footprint_transportation_num_vehicles", false, "10"),
|
||||||
new InputItem("input_footprint_transportation_miles1", false, "16100", false),
|
new InputItem("input_footprint_transportation_miles1", false, "16100", false),
|
||||||
new InputItem("input_footprint_transportation_mpg1", false, "22", false),
|
new InputItem("input_footprint_transportation_mpg1", false, "22", false),
|
||||||
new InputItem("input_footprint_transportation_fuel1", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel1", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles2", false, "0", false),
|
new InputItem("input_footprint_transportation_miles2", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel2", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel2", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg2", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg2", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles3", false, "0", false),
|
new InputItem("input_footprint_transportation_miles3", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel3", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel3", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg3", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg3", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles4", false, "0", false),
|
new InputItem("input_footprint_transportation_miles4", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel4", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel4", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg4", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg4", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles5", false, "0", false),
|
new InputItem("input_footprint_transportation_miles5", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel5", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel5", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg5", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg5", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles6", false, "0", false),
|
new InputItem("input_footprint_transportation_miles6", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel6", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel6", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg6", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg6", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles7", false, "0", false),
|
new InputItem("input_footprint_transportation_miles7", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel7", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel7", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg7", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg7", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles8", false, "0", false),
|
new InputItem("input_footprint_transportation_miles8", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel8", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel8", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg8", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg8", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles9", false, "0", false),
|
new InputItem("input_footprint_transportation_miles9", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel9", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel9", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg9", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg9", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_miles10", false, "0", false),
|
new InputItem("input_footprint_transportation_miles10", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_fuel10", false, "0", false),
|
new InputItem("input_footprint_transportation_fuel10", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_mpg10", false, "0", false),
|
new InputItem("input_footprint_transportation_mpg10", false, "0", false),
|
||||||
new InputItem("input_footprint_transportation_groundtype", false, "0"),
|
new InputItem("input_footprint_transportation_groundtype", false, "0"),
|
||||||
new InputItem("input_footprint_transportation_publictrans", false, "436"),
|
new InputItem("input_footprint_transportation_publictrans", false, "436"),
|
||||||
new InputItem("input_footprint_transportation_bus", false, "174"),
|
new InputItem("input_footprint_transportation_bus", false, "174"),
|
||||||
new InputItem("input_footprint_transportation_transit", false, "131"),
|
new InputItem("input_footprint_transportation_transit", false, "131"),
|
||||||
new InputItem("input_footprint_transportation_commuter", false, "87"),
|
new InputItem("input_footprint_transportation_commuter", false, "87"),
|
||||||
new InputItem("input_footprint_transportation_intercity", false, "44"),
|
new InputItem("input_footprint_transportation_intercity", false, "44"),
|
||||||
new InputItem("input_footprint_transportation_airtype", false, "0"),
|
new InputItem("input_footprint_transportation_airtype", false, "0"),
|
||||||
new InputItem("input_footprint_transportation_airtotal", false, "6"),
|
new InputItem("input_footprint_transportation_airtotal", false, "6"),
|
||||||
new InputItem("input_footprint_transportation_airshort", false, "3"),
|
new InputItem("input_footprint_transportation_airshort", false, "3"),
|
||||||
new InputItem("input_footprint_transportation_airmedium", false, "3"),
|
new InputItem("input_footprint_transportation_airmedium", false, "3"),
|
||||||
new InputItem("input_footprint_transportation_airlong", false, "0"),
|
new InputItem("input_footprint_transportation_airlong", false, "0"),
|
||||||
new InputItem("input_footprint_transportation_airextended", false, "0"),
|
new InputItem("input_footprint_transportation_airextended", false, "0"),
|
||||||
new InputItem("input_footprint_housing_cdd", false, "40000"),
|
new InputItem("input_footprint_housing_cdd", false, "40000"),
|
||||||
new InputItem("input_footprint_housing_hdd", false, "40000"),
|
new InputItem("input_footprint_housing_hdd", false, "40000"),
|
||||||
new InputItem("input_footprint_housing_electricity_type", false, "0"),
|
new InputItem("input_footprint_housing_electricity_type", false, "0"),
|
||||||
new InputItem("input_footprint_housing_electricity_dollars", false, "1200"),
|
new InputItem("input_footprint_housing_electricity_dollars", false, "1200"),
|
||||||
new InputItem("input_footprint_housing_electricity_kwh", false, "12632"),
|
new InputItem("input_footprint_housing_electricity_kwh", false, "12632"),
|
||||||
new InputItem("input_footprint_housing_cleanpercent", false, "0"),
|
new InputItem("input_footprint_housing_cleanpercent", false, "0"),
|
||||||
new InputItem("input_footprint_housing_naturalgas_type", false, "0"),
|
new InputItem("input_footprint_housing_naturalgas_type", false, "0"),
|
||||||
new InputItem("input_footprint_housing_naturalgas_dollars", false, "600"),
|
new InputItem("input_footprint_housing_naturalgas_dollars", false, "600"),
|
||||||
new InputItem("input_footprint_housing_naturalgas_therms", false, "472"),
|
new InputItem("input_footprint_housing_naturalgas_therms", false, "472"),
|
||||||
new InputItem("input_footprint_housing_naturalgas_cuft", false, "472444"),
|
new InputItem("input_footprint_housing_naturalgas_cuft", false, "472444"),
|
||||||
new InputItem("input_footprint_housing_heatingoil_type", false, "0"),
|
new InputItem("input_footprint_housing_heatingoil_type", false, "0"),
|
||||||
new InputItem("input_footprint_housing_heatingoil_dollars", false, "220"),
|
new InputItem("input_footprint_housing_heatingoil_dollars", false, "220"),
|
||||||
new InputItem("input_footprint_housing_heatingoil_gallons", false, "73"),
|
new InputItem("input_footprint_housing_heatingoil_gallons", false, "73"),
|
||||||
new InputItem("input_footprint_housing_heatingoil_dollars_per_gallon", false, "40000"),
|
new InputItem("input_footprint_housing_heatingoil_dollars_per_gallon", false, "40000"),
|
||||||
new InputItem("input_footprint_housing_squarefeet", false, "1850"),
|
new InputItem("input_footprint_housing_squarefeet", false, "1850"),
|
||||||
new InputItem("input_footprint_housing_watersewage", false, "100"),
|
new InputItem("input_footprint_housing_watersewage", false, "100"),
|
||||||
new InputItem("input_footprint_housing_gco2_per_kwh", false, "0"),
|
new InputItem("input_footprint_housing_gco2_per_kwh", false, "0"),
|
||||||
new InputItem("input_footprint_shopping_food_meatfisheggs_default", true, "2.4"),
|
new InputItem("input_footprint_shopping_food_meatfisheggs_default", true, "2.4"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_beefpork_default", true, "1.1"),
|
new InputItem("input_footprint_shopping_food_meat_beefpork_default", true, "1.1"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_poultry_default", true, "0.7"),
|
new InputItem("input_footprint_shopping_food_meat_poultry_default", true, "0.7"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_fish_default", true, "0.3"),
|
new InputItem("input_footprint_shopping_food_meat_fish_default", true, "0.3"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_other_default", true, "0.3"),
|
new InputItem("input_footprint_shopping_food_meat_other_default", true, "0.3"),
|
||||||
new InputItem("input_footprint_shopping_food_fruitvegetables_default", true, "3.5"),
|
new InputItem("input_footprint_shopping_food_fruitvegetables_default", true, "3.5"),
|
||||||
new InputItem("input_footprint_shopping_food_dairy_default", true, "2.2"),
|
new InputItem("input_footprint_shopping_food_dairy_default", true, "2.2"),
|
||||||
new InputItem("input_footprint_shopping_food_cereals_default", true, "4.1"),
|
new InputItem("input_footprint_shopping_food_cereals_default", true, "4.1"),
|
||||||
new InputItem("input_footprint_shopping_food_otherfood_default", true, "3.4"),
|
new InputItem("input_footprint_shopping_food_otherfood_default", true, "3.4"),
|
||||||
new InputItem("input_footprint_shopping_food_meattype", true, "0"),
|
new InputItem("input_footprint_shopping_food_meattype", true, "0"),
|
||||||
new InputItem("input_footprint_shopping_food_meatfisheggs", true, "2.4"),
|
new InputItem("input_footprint_shopping_food_meatfisheggs", true, "2.4"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_beefpork", true, "2.4"),
|
new InputItem("input_footprint_shopping_food_meat_beefpork", true, "2.4"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_poultry", true, "2.4"),
|
new InputItem("input_footprint_shopping_food_meat_poultry", true, "2.4"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_fish", true, "2.4"),
|
new InputItem("input_footprint_shopping_food_meat_fish", true, "2.4"),
|
||||||
new InputItem("input_footprint_shopping_food_meat_other", true, "2.4"),
|
new InputItem("input_footprint_shopping_food_meat_other", true, "2.4"),
|
||||||
new InputItem("input_footprint_shopping_food_cereals", true, "4.1"),
|
new InputItem("input_footprint_shopping_food_cereals", true, "4.1"),
|
||||||
new InputItem("input_footprint_shopping_food_dairy", true, "2.2"),
|
new InputItem("input_footprint_shopping_food_dairy", true, "2.2"),
|
||||||
new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"),
|
new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"),
|
||||||
new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"),
|
new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"),
|
||||||
new InputItem("input_footprint_shopping_goods_default_furnitureappliances", false, "1310"),
|
new InputItem("input_footprint_shopping_goods_default_furnitureappliances",
|
||||||
new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"),
|
false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_default_other_entertainment", false, "1310"),
|
new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"),
|
new InputItem("input_footprint_shopping_goods_default_other_entertainment",
|
||||||
new InputItem("input_footprint_shopping_goods_default_other_personalcare", false, "1310"),
|
false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_default_other_autoparts", false, "1310"),
|
new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"),
|
new InputItem(
|
||||||
new InputItem("input_footprint_shopping_goods_type", false, "1310"),
|
"input_footprint_shopping_goods_default_other_personalcare", false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_total", false, "1310"),
|
new InputItem("input_footprint_shopping_goods_default_other_autoparts",
|
||||||
new InputItem("input_footprint_shopping_goods_furnitureappliances", false, "362"),
|
false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_clothing", false, "391"),
|
new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_type", false, "0"),
|
new InputItem("input_footprint_shopping_goods_type", false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_total", false, "1311"),
|
new InputItem("input_footprint_shopping_goods_total", false, "1310"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_entertainment", false, "200"),
|
new InputItem("input_footprint_shopping_goods_furnitureappliances", false, "362"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_office", false, "38"),
|
new InputItem("input_footprint_shopping_goods_clothing", false, "391"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_personalcare", false, "103"),
|
new InputItem("input_footprint_shopping_goods_other_type", false, "0"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_autoparts", false, "45"),
|
new InputItem("input_footprint_shopping_goods_other_total", false, "1311"),
|
||||||
new InputItem("input_footprint_shopping_goods_other_medical", false, "172"),
|
new InputItem("input_footprint_shopping_goods_other_entertainment", false, "200"),
|
||||||
new InputItem("input_footprint_shopping_services_type", false, "0"),
|
new InputItem("input_footprint_shopping_goods_other_office", false, "38"),
|
||||||
new InputItem("input_footprint_shopping_services_total", false, "2413"),
|
new InputItem("input_footprint_shopping_goods_other_personalcare", false, "103"),
|
||||||
new InputItem("input_footprint_shopping_services_healthcare", false, "841"),
|
new InputItem("input_footprint_shopping_goods_other_autoparts", false, "45"),
|
||||||
new InputItem("input_footprint_shopping_services_education", false, "122"),
|
new InputItem("input_footprint_shopping_goods_other_medical", false, "172"),
|
||||||
new InputItem("input_footprint_shopping_services_communications", false, "163"),
|
new InputItem("input_footprint_shopping_services_type", false, "0"),
|
||||||
new InputItem("input_footprint_shopping_services_vehicleservices", false, "180"),
|
new InputItem("input_footprint_shopping_services_total", false, "2413"),
|
||||||
new InputItem("input_footprint_shopping_services_finance", false, "566"),
|
new InputItem("input_footprint_shopping_services_healthcare", false, "841"),
|
||||||
new InputItem("input_footprint_shopping_services_household", false, "28"),
|
new InputItem("input_footprint_shopping_services_education", false, "122"),
|
||||||
new InputItem("input_footprint_shopping_services_charity", false, "146"),
|
new InputItem("input_footprint_shopping_services_communications", false, "163"),
|
||||||
new InputItem("input_footprint_shopping_services_miscservices", false, "114"),
|
new InputItem("input_footprint_shopping_services_vehicleservices", false, "180"),
|
||||||
new InputItem("internal_state_abbreviation", false, "US")
|
new InputItem("input_footprint_shopping_services_finance", false, "566"),
|
||||||
|
new InputItem("input_footprint_shopping_services_household", false, "28"),
|
||||||
|
new InputItem("input_footprint_shopping_services_charity", false, "146"),
|
||||||
|
new InputItem("input_footprint_shopping_services_miscservices", false, "114"),
|
||||||
|
new InputItem("internal_state_abbreviation", false, "US")
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,7 +152,7 @@ public class InputValidator {
|
|||||||
item = inputItem;
|
item = inputItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Objects.requireNonNull(item).getFloat()) {
|
if (item.getFloat()) {
|
||||||
try {
|
try {
|
||||||
Float.parseFloat(value);
|
Float.parseFloat(value);
|
||||||
} catch (NumberFormatException | NullPointerException nfe) {
|
} catch (NumberFormatException | NullPointerException nfe) {
|
||||||
@@ -177,4 +180,4 @@ public class InputValidator {
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,20 +5,13 @@ import greenify.server.InputValidator;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@@ -28,7 +21,7 @@ public class User {
|
|||||||
|
|
||||||
@Id
|
@Id
|
||||||
@NotNull
|
@NotNull
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.TABLE)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -44,8 +37,7 @@ public class User {
|
|||||||
private Map<String, String> footPrintInputs = new HashMap<>();
|
private Map<String, String> footPrintInputs = new HashMap<>();
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinColumn
|
private List<User> friends;
|
||||||
private Collection<User> friends;
|
|
||||||
|
|
||||||
public User() {}
|
public User() {}
|
||||||
|
|
||||||
@@ -147,15 +139,15 @@ public class User {
|
|||||||
* This method gets the friends of the user.
|
* This method gets the friends of the user.
|
||||||
* @return friends list of the user
|
* @return friends list of the user
|
||||||
*/
|
*/
|
||||||
public ArrayList<User> getFriends() {
|
public List<User> getFriends() {
|
||||||
return (ArrayList<User>)this.friends;
|
return this.friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the friend list of the user.
|
* This method sets the friend list of the user.
|
||||||
* @param friends friend list of the user
|
* @param friends friend list of the user
|
||||||
*/
|
*/
|
||||||
public void setFriends(Collection<User> friends) {
|
public void setFriends(List<User> friends) {
|
||||||
this.friends = friends;
|
this.friends = friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +156,7 @@ public class User {
|
|||||||
* @param user the friend you want to add.
|
* @param user the friend you want to add.
|
||||||
*/
|
*/
|
||||||
public void addFriend(User user) {
|
public void addFriend(User user) {
|
||||||
if (user.equals(this)) {
|
if (user.equals(this) || friends.contains(user)) {
|
||||||
throw new ApplicationException("Cannot add yourself as a friend");
|
throw new ApplicationException("Cannot add yourself as a friend");
|
||||||
} else {
|
} else {
|
||||||
friends.add(user);
|
friends.add(user);
|
||||||
@@ -182,21 +174,6 @@ public class User {
|
|||||||
+ this.password + ")";
|
+ this.password + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name and score of the friends in JSON. Needed for the leaderboard.
|
|
||||||
* @return a JSON object of the friendlist with only names and scores.
|
|
||||||
*/
|
|
||||||
public String friendsToString() {
|
|
||||||
String result = "friends=[";
|
|
||||||
for (User u : friends) {
|
|
||||||
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
|
|
||||||
}
|
|
||||||
if (result.endsWith(", ")) {
|
|
||||||
return result.substring(0, result.lastIndexOf(",")) + "]";
|
|
||||||
}
|
|
||||||
return result + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method checks whether two users are equal or not.
|
/** This method checks whether two users are equal or not.
|
||||||
* * @param other an other user
|
* * @param other an other user
|
||||||
* @return users are (not) equal
|
* @return users are (not) equal
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -47,7 +49,6 @@ public class UserController {
|
|||||||
public void setInput(@RequestParam(value = "name") String name,
|
public void setInput(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "inputName") String inputName,
|
@RequestParam(value = "inputName") String inputName,
|
||||||
@RequestParam(value = "value") String value) {
|
@RequestParam(value = "value") String value) {
|
||||||
System.out.println("Here is server controller");
|
|
||||||
userService.setInput(name, inputName, value);
|
userService.setInput(name, inputName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +73,35 @@ public class UserController {
|
|||||||
return footprint;
|
return footprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method saves footprint for a user.
|
||||||
|
* @param name name of the user
|
||||||
|
*/
|
||||||
|
@RequestMapping("/saveFootprint")
|
||||||
|
public Float saveFootprint(@RequestParam(value = "name") String name) {
|
||||||
|
Float footprint = userService.saveFootprint(name);
|
||||||
|
return footprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets friend list for a user.
|
||||||
|
* @param name name of the user
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getFriends")
|
||||||
|
public List<String> getFriendNames(@RequestParam(value = "name") String name) {
|
||||||
|
List<String> friends = userService.getFriends(name);
|
||||||
|
return friends;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the list of all users.
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getAllUsers")
|
||||||
|
public List<String> getAllUsers() {
|
||||||
|
List<String> users = userService.getAllUsers();
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds friend for a user.
|
* This method adds friend for a user.
|
||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
@@ -70,20 +71,11 @@ public class UserService {
|
|||||||
public void addFriend(String name, String friend) {
|
public void addFriend(String name, String friend) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
User add = userRepository.findByName(friend);
|
User add = userRepository.findByName(friend);
|
||||||
if (add == null) {
|
if (user == null || add == null ) {
|
||||||
throw new ApplicationException("User does not exist");
|
throw new ApplicationException("User does not exist");
|
||||||
}
|
}
|
||||||
user.addFriend(add);
|
user.addFriend(add);
|
||||||
}
|
userRepository.save(user);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the friendlist of the user in JSON.
|
|
||||||
* @param name the username of the user
|
|
||||||
* @return a userDTO of the logged in user
|
|
||||||
*/
|
|
||||||
public String getLeaderboard(String name) {
|
|
||||||
User user = userRepository.findByName(name);
|
|
||||||
return user.friendsToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,8 +93,6 @@ public class UserService {
|
|||||||
&& InputValidator.isValidItemValue(inputName, value)) {
|
&& InputValidator.isValidItemValue(inputName, value)) {
|
||||||
user.getFootPrintInputs().put(inputName, value);
|
user.getFootPrintInputs().put(inputName, value);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
user.setFootPrint(calculatorService.calculateFootprint(user));
|
|
||||||
userRepository.save(user);
|
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("Invalid input");
|
throw new ApplicationException("Invalid input");
|
||||||
}
|
}
|
||||||
@@ -125,11 +115,11 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the footprint of a user.
|
* This method saves the footprint of a user.
|
||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
* @return footprint of the user
|
* @return footprint of the user
|
||||||
*/
|
*/
|
||||||
public Float getFootprint(String name) {
|
public Float saveFootprint(String name) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
user.setFootPrint(calculatorService.calculateFootprint(user));
|
user.setFootPrint(calculatorService.calculateFootprint(user));
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
@@ -137,12 +127,40 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets a JSON of XML with all users.
|
* This method gets the footprint of a user.
|
||||||
* @return JSON/XML of all users
|
* @param name name of the user
|
||||||
|
* @return footprint of the user
|
||||||
*/
|
*/
|
||||||
@GetMapping(path = "/all")
|
public Float getFootprint(String name) {
|
||||||
@ResponseBody
|
User user = userRepository.findByName(name);
|
||||||
public Iterable<User> getAllUsers() {
|
return user.getFootPrint();
|
||||||
return userRepository.findAll();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the friends of a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return list of the friends
|
||||||
|
*/
|
||||||
|
public List<String> getFriends(String name) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
User user = userRepository.findByName(name);
|
||||||
|
List<User> friends = user.getFriends();
|
||||||
|
for (User person : friends) {
|
||||||
|
result.add(person.getName());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the list of all users.
|
||||||
|
* @return list of all users
|
||||||
|
*/
|
||||||
|
public List<String> getAllUsers() {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
Iterable<User> allUsers = userRepository.findAll();
|
||||||
|
for (User person : allUsers) {
|
||||||
|
result.add(person.getName());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import greenify.common.ApplicationException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
@@ -113,18 +113,21 @@ public class UserTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void friendsToStringTest() {
|
public void addTwiceTest() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User test = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "merel", "password");
|
List<User> friendList = new ArrayList<>();
|
||||||
first.addFriend(second);
|
friendList.add(test);
|
||||||
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
User user = new User(1L, "green", "pass");
|
||||||
|
user.setFriends(friendList);
|
||||||
|
assertThrows(ApplicationException.class, () -> {
|
||||||
|
user.addFriend(test);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setFriendTest() {
|
public void setFriendTest() {
|
||||||
Collection<User> friends = new ArrayList<>();
|
List<User> friends = new ArrayList<User>();
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "merel", "password");
|
User second = new User(1L, "merel", "password");
|
||||||
friends.add(second);
|
friends.add(second);
|
||||||
|
|||||||
@@ -94,6 +94,14 @@ public class UserControllerTest {
|
|||||||
assertEquals("merel", arg2Captor.getValue());
|
assertEquals("merel", arg2Captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllUsersTest() throws Exception {
|
||||||
|
mvc.perform(get("/getAllUsers")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInputTest() throws Exception {
|
public void getInputTest() throws Exception {
|
||||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import greenify.common.ApplicationException;
|
|||||||
import greenify.common.UserDto;
|
import greenify.common.UserDto;
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
import greenify.server.data.repository.UserRepository;
|
import greenify.server.data.repository.UserRepository;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
@@ -18,6 +20,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
@@ -118,7 +121,8 @@ public class UserServiceTest {
|
|||||||
when(calculatorService.calculateFootprint(alex))
|
when(calculatorService.calculateFootprint(alex))
|
||||||
.thenReturn(15f);
|
.thenReturn(15f);
|
||||||
userService.setInput("alex", "input_footprint_shopping_food_dairy_default", "6.5");
|
userService.setInput("alex", "input_footprint_shopping_food_dairy_default", "6.5");
|
||||||
assertEquals(15f, alex.getFootPrint(), 0.0);
|
Assert.assertTrue(alex.getFootPrintInputs()
|
||||||
|
.get("input_footprint_shopping_food_dairy_default").equals("6.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -139,18 +143,51 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFootprintTest() {
|
public void getFootprintTest() {
|
||||||
|
User alex = new User(1L, "alex", "password");
|
||||||
|
alex.setFootPrint(15F);
|
||||||
|
when(userRepository.findByName(alex.getName()))
|
||||||
|
.thenReturn(alex);
|
||||||
|
Assertions.assertEquals(15F, userService.getFootprint("alex"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void saveFootprintTest() {
|
||||||
User alex = new User(1L, "alex", "password");
|
User alex = new User(1L, "alex", "password");
|
||||||
when(userRepository.findByName(alex.getName()))
|
when(userRepository.findByName(alex.getName()))
|
||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
when(calculatorService.calculateFootprint(alex))
|
when(calculatorService.calculateFootprint(alex))
|
||||||
.thenReturn(15f);
|
.thenReturn(15f);
|
||||||
userService.setInput("alex", "input_footprint_shopping_food_dairy_default", "6.5");
|
userService.saveFootprint("alex");
|
||||||
assertEquals(15f, userService.getFootprint("alex"), 0.0);
|
Assertions.assertEquals(15f, userService.saveFootprint("alex"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFriendsTest() {
|
||||||
|
User alex = new User(1L, "alex", "password");
|
||||||
|
User lola = new User(2L, "lola", "pass");
|
||||||
|
when(userRepository.findByName(alex.getName()))
|
||||||
|
.thenReturn(alex);
|
||||||
|
when(userRepository.findByName(lola.getName()))
|
||||||
|
.thenReturn(lola);
|
||||||
|
alex.addFriend(lola);
|
||||||
|
List<String> friendList = new ArrayList<>();
|
||||||
|
friendList.add("lola");
|
||||||
|
assertEquals(friendList, userService.getFriends("alex"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAllUserTest() {
|
public void getAllUserTest() {
|
||||||
assertEquals(userRepository.findAll(), userService.getAllUsers());
|
User alex = new User(1L, "alex", "password");
|
||||||
|
User lola = new User(2L, "lola", "pass");
|
||||||
|
Iterable<User> users = new ArrayList<>();
|
||||||
|
((ArrayList<User>) users).add(alex);
|
||||||
|
((ArrayList<User>) users).add(lola);
|
||||||
|
when(userRepository.findAll())
|
||||||
|
.thenReturn(users);
|
||||||
|
List<String> userList = new ArrayList<>();
|
||||||
|
userList.add("alex");
|
||||||
|
userList.add("lola");
|
||||||
|
assertEquals(userList, userService.getAllUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -170,16 +207,12 @@ public class UserServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addFriendsExceptionTest() {
|
public void addFriendNullFriendTest() {
|
||||||
assertThrows(ApplicationException.class, () -> userService.addFriend("greenify", null));
|
assertThrows(ApplicationException.class, () -> userService.addFriend("alex", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void leaderboardTest() {
|
public void addFriendNullUserTest() {
|
||||||
User alex = userRepository.findByName("alex");
|
assertThrows(ApplicationException.class, () -> userService.addFriend(null, "password"));
|
||||||
User lola = userRepository.findByName("lola");
|
|
||||||
userService.addFriend("alex", "lola");
|
|
||||||
assertEquals(userService.getLeaderboard("alex"), "friends=[{name=lola, footprint=0.0}]");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user