FIX:: (possible) merge conficts

This commit is contained in:
mlwauben
2019-04-03 22:05:48 +02:00
parent 28f9f72f07
commit 3aad682394
17 changed files with 1657 additions and 286 deletions

View File

@@ -0,0 +1,32 @@
package greenify.client;
import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleStringProperty;
public class Friend {
private SimpleStringProperty friend;
private SimpleFloatProperty score;
public Friend(String friend, Float friendScore) {
this.friend = new SimpleStringProperty(friend);
this.score = new SimpleFloatProperty(friendScore);
}
public String getFriend() {
return friend.get();
}
public void setFriend(String name) {
this.friend = new SimpleStringProperty(name);
}
public Float getScore() {
return score.get();
}
public void setScore(Float score) {
this.score = new SimpleFloatProperty(score);
}
}

View File

@@ -0,0 +1,68 @@
package greenify.client;
import java.util.ArrayList;
import java.util.Random;
public class Hints {
public ArrayList<String> hints;
public Hints() {
this.hints = new ArrayList<String>();
initHints();
}
/**
* This method adds all the Strings to the arraylist.
*/
private void initHints() {
hints.add("Buying local produce will not only decrease your carbon "
+ "footprint, but also help your local economy: A win-win!");
hints.add("Did you know that a gas oven only uses 6% of its energy "
+ "to cook? And an electric oven is not much better at 12%.");
hints.add("70% of the deforestation of the Amazon is to provide land for cattle ranches.");
hints.add("Research shows that reducing meat consumption can increase"
+ " your life span by 3.6 years");
hints.add("Vegetarians have a lower risk of getting heart disease, high blood pressure, "
+ "diabetes and cancer than meat eaters.");
hints.add("Did you know? The carbon footprint of a vegetarian diet is about half "
+ "that of a meat-lovers diet!");
hints.add("Cycling is good for the environment AND for your body, "
+ "so why not grab your bike instead of your car?");
hints.add("If we could capture all of the suns energy shining on the Earth for just one "
+ "hour, we could power the entire world for one year!");
hints.add("27,000 trees are cut down each day so we can have toilet paper.");
hints.add("A glass bottle made in our time will take more than 4,000 years to decompose.");
hints.add("Don't forget to turn off the lights and heating in rooms"
+ " you're not using at the moment!");
hints.add("Did you know that about 4.5% of the Dutch population does not eat meat");
hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags.");
hints.add("An estimated 250 million trees can be save each year "
+ "if every published newspaper is recycled.");
hints.add("About 88,000 jobs were created in 2015 through the wind power sector.");
hints.add("You can use LED lights in your home to safe energy!");
hints.add("If you isolate your home well, it will be warmer "
+ "and you'll save energy as well!");
hints.add("Do you have leftovers? Donate them to food kitchens. This way you won't waste "
+ "food and help people at the same time.");
hints.add("A lot of coffee places give you a discount if you bring your own cup. "
+ "Get rid of those disposable cups!");
hints.add("When shopping, look for products with minimal to no packaging, "
+ "or at least packaging made from recycled items. ");
hints.add("If you order food, you can ask the restaurant to not include "
+ "utensils and napkins, it saves plastic and paper.");
hints.add("It takes about 66 days to form a new habit, keep going!");
hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for "
+ "the environment to refill than to buy a new one every time it's empty.");
}
/**
* This method gets a random hint from the list of hints.
* @return the random hint.
*/
public String randomHint() {
Random rand = new Random();
int index = rand.nextInt(hints.size());
return hints.get(index);
}
}

View File

@@ -2,17 +2,25 @@ package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application;
import greenify.client.Friend;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.PathTransition;
import javafx.animation.ScaleTransition;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
@@ -22,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
@@ -29,6 +38,11 @@ import java.util.Map;
*/
@Controller
public class DashBoardController {
public static ObservableList<Friend> data = FXCollections.observableArrayList();
public ObservableList<Friend> friendLeaderData = FXCollections.observableArrayList();
public ObservableList<Friend> globalLeaderData = FXCollections.observableArrayList();
public ObservableList<Friend> developmentData = FXCollections.observableArrayList();
@Autowired
UserService userService;
@@ -57,18 +71,110 @@ public class DashBoardController {
@FXML
private AnchorPane menuBar;
@FXML
private Button addNewActivityButton;
@FXML
private Button calculateFootPrintButton;
@FXML
private Label footprintLabel;
@FXML
private Label firstFootprintLabel;
@FXML
private Label differenceLabel;
@FXML
private Button addFriendButton;
@FXML
private TableView<Friend> friendsTable;
@FXML
private TableColumn<Friend, String> friendsColumn;
@FXML
private TableColumn<Friend, Float> scoreColumn;
@FXML
private TableView<Friend> globalLeaderboard;
@FXML
private TableColumn<Friend, String> globalUser;
@FXML
private TableColumn<Friend, Float> globalScore;
@FXML
private TableView<Friend> developmentLeaderboard;
@FXML
private TableColumn<Friend, String> developmentUser;
@FXML
private TableColumn<Friend, Float> developmentScore;
@FXML
private TableView<Friend> friendLeaderboard;
@FXML
private TableColumn<Friend, String> friendUser;
@FXML
private TableColumn<Friend, Float> friendScore;
@FXML
private PieChart pieChart;
@FXML
private Label usernameLabel;
@FXML
private Label peopleNumber;
@FXML
private Label income;
@FXML
private Label electricityUsage;
@FXML
private Label cleanEnergy;
@FXML
private Label naturalGasUsage;
@FXML
private Label heatingOilUsage;
@FXML
private Label waterUsage;
@FXML
private Label livingSpace;
@FXML
private Label gasolineMiles;
@FXML
private Label gasolineMpg;
@FXML
private Label dieselMiles;
@FXML
private Label dieselMpg;
@FXML
private Label electricMiles;
@FXML
private Label electricMpg;
@FXML
private Label publicTransportation;
@FXML
private Label airPlane;
@FXML
private Label goodShopping;
@FXML
private Label serviceShopping;
@FXML
private Label meat;
@FXML
private Label grains;
@FXML
private Label dairy;
@FXML
private Label fruits;
@FXML
private Label snacks;
@FXML
private ImageView achiev1image;
@FXML
private CheckBox localProduce;
@FXML
private CheckBox loweringTemp;
@FXML
private CheckBox bike;
@FXML
private CheckBox solarPanels;
/**
* Loads the the necessary things before anything else.
* @throws InterruptedException exception if interrupted
*/
public void initialize() {
public void initialize() throws InterruptedException {
//set the dashboardPane to visible
dashboardPane.setVisible(true);
userPane.setVisible(false);
activitiesPane.setVisible(false);
friendsPane.setVisible(false);
//sets the text of the 'welcome back' text to include the username
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
//adds the slide transition to the menu bar
@@ -78,15 +184,92 @@ public class DashBoardController {
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
userButton.setSkin(new MyButtonSkin(userButton));
friendsButton.setSkin(new MyButtonSkin(friendsButton));
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
globalScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
developmentUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
if (pieChart != null) {
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Vegan Meal", 100),
new PieChart.Data("Public Transport", 200),
new PieChart.Data("Home Temperature", 50),
new PieChart.Data("Bike", 75),
new PieChart.Data("Local Product", 110),
new PieChart.Data("Solar Panel", 300)
);
pieChart.setTitle("FOOTPRINT DISTRIBUTION");
pieChart.setMaxSize(1000, 1000);
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();
updateAchievements();
}
/**
* 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);
}
}
}
}
/**
* Sorts the scores of users.
* @param users the list of users
*/
public void sortDiffScores(List<String> users) throws InterruptedException {
for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size(); j++) {
Float firstDiff = userService.getFirstFootprint(users.get(i)) - userService
.getFootprint(users.get(i));
Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService
.getFootprint(users.get(j));
if (i < j && firstDiff < secondDiff) {
String temp = users.get(i);
users.set(i, users.get(j));
users.set(j, temp);
}
if (i > j && firstDiff > secondDiff) {
String temp = users.get(i);
users.set(i, users.get(j));
users.set(j, temp);
}
}
}
}
/**
* Adds a fade transition for switching between the different panes.
* @param node the node on which the transition needs to act
*/
public void addFadeTransition(Node node) {
fadeTrans = new FadeTransition(Duration.millis(400), node);
fadeTrans.setFromValue(0);
fadeTrans.setToValue(1.0);
@@ -98,13 +281,14 @@ public class DashBoardController {
* Displays the dashboard pane.
* @param event the event (clicking the button)
*/
public void displayDashboard(ActionEvent event) {
public void displayDashboard(ActionEvent event) throws InterruptedException {
addFadeTransition(dashboardPane);
System.out.println("display dashboard");
dashboardPane.setVisible(true);
userPane.setVisible(false);
activitiesPane.setVisible(false);
friendsPane.setVisible(false);
updateLeaderboard();
updateAchievements();
}
@@ -119,6 +303,46 @@ public class DashBoardController {
userPane.setVisible(false);
activitiesPane.setVisible(true);
friendsPane.setVisible(false);
Map<String, String> inputMap = userService.getInputs(userService.currentUser.getName());
peopleNumber.setText(inputMap.get("input_size"));
income.setText(inputMap.get("input_income") + " €/yr");
electricityUsage.setText(inputMap.get("input_footprint_housing_electricity_dollars")
+ " €/yr");
cleanEnergy.setText(inputMap.get("input_footprint_housing_gco2_per_kwh"));
naturalGasUsage.setText(inputMap.get("input_footprint_housing_naturalgas_dollars")
+ " €/yr");
heatingOilUsage.setText(inputMap.get("input_footprint_housing_heatingoil_dollars")
+ " €/yr");
waterUsage.setText(inputMap.get("input_footprint_housing_watersewage") + " €/yr");
livingSpace.setText(inputMap.get("input_footprint_housing_squarefeet") + "");
gasolineMiles.setText(inputMap.get("input_footprint_transportation_miles1"));
gasolineMpg.setText(inputMap.get("input_footprint_transportation_mpg1"));
dieselMiles.setText(inputMap.get("input_footprint_transportation_miles2"));
dieselMpg.setText(inputMap.get("input_footprint_transportation_mpg2"));
electricMiles.setText(inputMap.get("input_footprint_transportation_miles3"));
electricMpg.setText(inputMap.get("input_footprint_transportation_mpg3"));
publicTransportation.setText(inputMap.get("input_footprint_transportation_publictrans")
+ " km/yr");
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " km/yr");
goodShopping.setText(inputMap.get("input_footprint_shopping_goods_total") + " €/mo");
serviceShopping.setText(inputMap.get("input_footprint_shopping_services_total") + " €/mo");
meat.setText(inputMap.get("input_footprint_shopping_food_meatfisheggs"));
grains.setText(inputMap.get("input_footprint_shopping_food_cereals"));
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
if (userService.getExtraInputs(userService.currentUser.getName()).get("local_produce")) {
localProduce.setSelected(true);
}
if (userService.getExtraInputs(userService.currentUser.getName()).get("bike")) {
bike.setSelected(true);
}
if (userService.getExtraInputs(userService.currentUser.getName()).get("temperature")) {
loweringTemp.setSelected(true);
}
if (userService.getExtraInputs(userService.currentUser.getName()).get("solar_panels")) {
solarPanels.setSelected(true);
}
}
/**
@@ -129,6 +353,12 @@ public class DashBoardController {
System.out.println(userService.currentUser.getName());
System.out.println(userService.getFootprint(userService.currentUser.getName()));
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
firstFootprintLabel.setText("" + userService
.getFirstFootprint(userService.currentUser.getName()));
Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
.getFootprint(userService.currentUser.getName());
differenceLabel.setText( "" + diff);
usernameLabel.setText("" + userService.currentUser.getName());
addFadeTransition(userPane);
System.out.println("display user");
dashboardPane.setVisible(false);
@@ -142,14 +372,14 @@ public class DashBoardController {
* Displays the friends pane.
* @param event the event (clicking the button)
*/
public void displayFriends(ActionEvent event) {
public void displayFriends(ActionEvent event) throws InterruptedException {
addFadeTransition(friendsPane);
System.out.println("display friends");
dashboardPane.setVisible(false);
userPane.setVisible(false);
activitiesPane.setVisible(false);
friendsPane.setVisible(true);
updateFriends();
}
//sets the slide in transition for startup
@@ -162,7 +392,7 @@ public class DashBoardController {
* Opens the calculator.
* @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()
.getResource("fxml/calculator.fxml"));
Scene scene = new Scene(calc);
@@ -175,6 +405,92 @@ public class DashBoardController {
calcStage.show();
}
/**
* Opens extra activities.
* @param event the event (clicking the button)
* @throws IOException if the Application doesn't load.
*/
public void openExtraActivities(ActionEvent event) throws IOException {
Parent extra = Application.load(this.getClass().getClassLoader()
.getResource("fxml/extraActivities.fxml"));
Scene scene = new Scene(extra);
Stage extraStage = new Stage();
extraStage.setScene(scene);
extraStage.setTitle("Add extra activity - " + userService.currentUser.getName());
extraStage.show();
}
/**
* method opens addFriend scene.
* @throws IOException when file is not found
*/
public void openAddFriend() throws IOException {
Parent calc = Application.load(this.getClass().getClassLoader()
.getResource("fxml/AddFriend.fxml"));
Scene scene = new Scene(calc);
Stage calcStage = new Stage();
calcStage.setScene(scene);
calcStage.setTitle("Add a new friend - " + userService.currentUser.getName());
calcStage.show();
}
/**
* Leaderboard is updating.
* @throws InterruptedException throws exception
*/
public void updateLeaderboard() throws InterruptedException {
List<String> userList = userService.getAllUsers();
//global leaderboard
globalLeaderboard.getItems().clear();
globalLeaderData.removeAll();
sortScores(userList);
//development leaderboard
developmentLeaderboard.getItems().clear();
developmentData.removeAll();
sortDiffScores(userList);
for (int j = 0; j < userList.size(); j++) {
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
Friend diffUser = new Friend(userList.get(j), userService
.getFirstFootprint(userList.get(j))
- userService.getFootprint(userList.get(j)));
globalLeaderData.add(user);
developmentData.add(diffUser);
}
globalLeaderboard.setItems(globalLeaderData);
developmentLeaderboard.setItems(developmentData);
}
/**
* Friends tables are updating.
* @throws InterruptedException throws exception
*/
public void updateFriends() throws InterruptedException {
List<String> wholeList = userService.getFriendNames(userService.currentUser.getName());
wholeList.add(userService.currentUser.getName());
//friend list
friendsTable.getItems().clear();
data.removeAll();
List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
sortScores(friendList);
//friends leaderboard
friendLeaderboard.getItems().clear();
friendLeaderData.removeAll();
sortDiffScores(wholeList);
for (int i = 0; i < friendList.size(); i++) {
Friend user = new Friend(friendList.get(i), userService
.getFootprint(friendList.get(i)));
data.add(user);
}
for (int j = 0; j < wholeList.size(); j++) {
Friend diffUser = new Friend(wholeList.get(j),
userService.getFirstFootprint(wholeList.get(j))
- userService.getFootprint(wholeList.get(j)));
friendLeaderData.add(diffUser);
}
friendsTable.setItems(data);
friendLeaderboard.setItems(friendLeaderData);
}
/**
* Updates the achievements.
*/
@@ -209,6 +525,5 @@ public class DashBoardController {
scaleDown.setToX(1.0);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
}

View File

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.List;
import java.util.Map;
@Service
@@ -101,6 +102,26 @@ public class UserService {
.encode().toUri(), String.class);
}
/**
* Updates the extra input of the user.
* @param name name of the user
* @param inputName name of the input
* @param value value of the input
*/
@SuppressWarnings("Duplicates")
public void updateExtraInput(String name, String inputName, Boolean value) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
.queryParam("name", name)
.queryParam("inputName", inputName)
.queryParam("value",value);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
}
/**
* Gets the footprint of the user.
* @param name name of the user
@@ -119,6 +140,78 @@ public class UserService {
return result;
}
/**
* Gets the first footprint of the user.
* @param name name of the user
* @return returns the footprint score
*/
public Float getFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Float footprint = this.restTemplate.getForObject(builder
.build().encode().toUri(), Float.class);
return footprint;
}
/**
* 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;
}
/**
* Saves the first footprint of the user.
* @param name name of the user
* @return returns the footprint score
*/
@SuppressWarnings("Duplicates")
public Float saveFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFirstFootprint")
.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.
* @param name the username of the current user.
@@ -137,6 +230,58 @@ public class UserService {
.encode().toUri(), String.class);
}
/**
* Removes a friend from the friendslist of the user.
* @param name the username of the current user.
* @param friend the username of the friend you want to remove.
*/
@SuppressWarnings("Duplicates")
public void removeFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/removeFriend")
.queryParam("name", name)
.queryParam("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
}
/**
* Gets the footprint inputs of the user.
* @param name the username of the current user.
*/
@SuppressWarnings("Duplicates")
public Map<String, String> getInputs(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getInputs")
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Map<String, String> result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class);
return result;
}
/**
* Gets the footprint inputs of the user.
* @param name the username of the current user.
*/
@SuppressWarnings("Duplicates")
public Map<String, Boolean> getExtraInputs(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class);
return result;
}
/**
* Gets the achievements of a user.
* @param name name of the user
@@ -154,4 +299,18 @@ public class UserService {
.encode().toUri(), Map.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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?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.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
@@ -47,127 +48,242 @@
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
</children>
</AnchorPane>
</children></AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.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">
<children>
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Activity Summary" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font>
<Font size="30.0" />
</font>
</Text>
<Pane layoutX="20.0" layoutY="93.0" prefHeight="471.0" prefWidth="280.0" style="-fx-background-color: #f4fff4;">
<Label alignment="CENTER" layoutX="20.0" layoutY="100.0" prefHeight="32.0" prefWidth="255.0" text="Get Started!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="20.0" layoutY="130.0" prefHeight="142.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children>
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="55.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Eating a vegetarian meal" textFill="#e0ffe1">
<Label layoutX="14.0" layoutY="16.0" prefHeight="40.0" prefWidth="154.0" text="Number of people">
<font>
<Font size="14.0" />
<Font size="18.0" />
</font>
</Button>
<Button fx:id="localProduceButton" layoutX="71.0" layoutY="100.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Buying local produce" textFill="#e0ffe1">
</Label>
<Label layoutX="14.0" layoutY="70.0" prefHeight="40.0" prefWidth="154.0" text="Household income">
<font>
<Font size="14.0" />
<Font size="18.0" />
</font>
</Button>
<Button fx:id="bikeButton" layoutX="48.0" layoutY="145.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Using a bike instead of a car" textFill="#e0ffe1">
<font>
<Font size="14.0" />
</font>
</Button>
<Button fx:id="publicTransportButton" layoutX="18.0" layoutY="190.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Using public transport instead of a car" textFill="#e0ffe1">
<font>
<Font size="14.0" />
</font>
</Button>
<Button fx:id="temperatureButton" layoutX="31.0" layoutY="235.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Lowering your home temperature" textFill="#e0ffe1">
<font>
<Font size="14.0" />
</font>
</Button>
<Button fx:id="solarPanelButton" layoutX="68.0" layoutY="280.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Installing solar panels" textFill="#e0ffe1">
<font>
<Font size="14.0" />
</font>
</Button>
</Label>
<Label fx:id="peopleNumber" layoutX="207.0" layoutY="28.0" styleClass="activityField" text=" " textAlignment="CENTER" />
<Label fx:id="income" layoutX="204.0" layoutY="82.0" styleClass="activityField" text=" " textAlignment="CENTER" />
</children>
</Pane>
<Pane layoutX="310.0" layoutY="93.0" prefHeight="471.0" prefWidth="150.0" style="-fx-background-color: #f4fff4;">
<Label alignment="CENTER" layoutX="20.0" layoutY="275.0" prefHeight="32.0" prefWidth="255.0" text="Home!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="20.0" layoutY="307.0" prefHeight="342.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children>
<Text layoutX="11.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Done recently" textAlignment="CENTER">
<font>
<Font size="21.0" />
</font>
</Text>
<Label fx:id="veganMealCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="26.0" prefHeight="40.0" prefWidth="149.0" text="Electricity usage">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="localProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="74.0" prefHeight="40.0" prefWidth="149.0" text="\% of clean energy prog.">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="122.0" prefHeight="40.0" prefWidth="149.0" text="Natural gas usage">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="bikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="168.0" prefHeight="40.0" prefWidth="149.0" text="Heating oil usage">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="publicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="216.0" prefHeight="40.0" prefWidth="149.0" text="Water usage">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="temperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="solarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="264.0" prefHeight="40.0" prefWidth="149.0" text="Living space area">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="electricityUsage" layoutX="207.0" layoutY="38.0" styleClass="activityField" text="Label" />
<Label fx:id="cleanEnergy" layoutX="207.0" layoutY="86.0" styleClass="activityField" text="Label" />
<Label fx:id="naturalGasUsage" layoutX="207.0" layoutY="134.0" styleClass="activityField" text="Label" />
<Label fx:id="heatingOilUsage" layoutX="207.0" layoutY="180.0" styleClass="activityField" text="Label" />
<Label fx:id="waterUsage" layoutX="207.0" layoutY="228.0" styleClass="activityField" text="Label" />
<Label fx:id="livingSpace" layoutX="207.0" layoutY="276.0" styleClass="activityField" text="Label" />
</children>
</Pane>
<Pane layoutX="470.0" layoutY="93.0" prefHeight="471.0" prefWidth="150.0" style="-fx-background-color: #f4fff4;">
<Label alignment="CENTER" layoutX="290.0" layoutY="100.0" prefHeight="32.0" prefWidth="230.0" text="Travel!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="290.0" layoutY="130.0" prefHeight="342.0" prefWidth="230.0" style="-fx-background-color: #f4fff4;">
<children>
<Text layoutX="15.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Done in total">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline miles">
<font>
<Font size="21.0" />
</font>
</Text>
<Label fx:id="totalVeganMealCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="30.0" prefWidth="115.0" text="0">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<Label fx:id="totalLocalProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline mpg">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<Label fx:id="totalBikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="99.0" prefHeight="27.0" prefWidth="149.0" text="Diesel miles">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<Label fx:id="totalPublicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="143.0" prefHeight="27.0" prefWidth="149.0" text="Diesel mpg">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<Label fx:id="totalTemperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="187.0" prefHeight="27.0" prefWidth="149.0" text="Electric miles">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<Label fx:id="totalSolarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="231.0" prefHeight="27.0" prefWidth="149.0" text="Electric mpg">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="275.0" prefHeight="27.0" prefWidth="149.0" text="Public transportation">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="319.0" prefHeight="27.0" prefWidth="149.0" text="Airplane">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="gasolineMiles" layoutX="181.0" layoutY="16.0" styleClass="activityField" text="Label" />
<Label fx:id="gasolineMpg" layoutX="181.0" layoutY="60.0" styleClass="activityField" text="Label" />
<Label fx:id="dieselMiles" layoutX="181.0" layoutY="104.0" styleClass="activityField" text="Label" />
<Label fx:id="dieselMpg" layoutX="181.0" layoutY="148.0" styleClass="activityField" text="Label" />
<Label fx:id="electricMiles" layoutX="181.0" layoutY="192.0" styleClass="activityField" text="Label" />
<Label fx:id="electricMpg" layoutX="181.0" layoutY="236.0" styleClass="activityField" text="Label" />
<Label fx:id="publicTransportation" layoutX="181.0" layoutY="280.0" styleClass="activityField" text="Label" />
<Label fx:id="airPlane" layoutX="181.0" layoutY="324.0" styleClass="activityField" text="Label" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="290.0" layoutY="488.0" prefHeight="32.0" prefWidth="230.0" text="Shopping!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="290.0" layoutY="520.0" prefHeight="129.0" prefWidth="230.0" style="-fx-background-color: #f4fff4;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="59.0" prefWidth="115.0" text="Goods &#10;shopping" textAlignment="CENTER">
<font>
<Font size="16.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="75.0" prefHeight="59.0" prefWidth="115.0" text="Services &#10;shopping" textAlignment="CENTER">
<font>
<Font size="16.0" />
</font>
</Label>
<Label fx:id="goodShopping" layoutX="167.0" layoutY="32.0" styleClass="activityField" text="Label" />
<Label fx:id="serviceShopping" layoutX="167.0" layoutY="96.0" styleClass="activityField" text="Label" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="545.0" layoutY="100.0" prefHeight="32.0" prefWidth="255.0" text="Food!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="545.0" layoutY="130.0" prefHeight="342.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="26.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="90.0" prefHeight="46.0" prefWidth="115.0" text="Grains/baked &#10;foods" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="154.0" prefHeight="46.0" prefWidth="115.0" text="Dairy">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="218.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="282.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="meat" layoutX="171.0" layoutY="41.0" styleClass="activityField" text="Label" />
<Label fx:id="grains" layoutX="171.0" layoutY="105.0" styleClass="activityField" text="Label" />
<Label fx:id="dairy" layoutX="171.0" layoutY="169.0" styleClass="activityField" text="Label" />
<Label fx:id="fruits" layoutX="171.0" layoutY="233.0" styleClass="activityField" text="Label" />
<Label fx:id="snacks" layoutX="171.0" layoutY="297.0" styleClass="activityField" text="Label" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="545.0" layoutY="488.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="545.0" layoutY="520.0" prefHeight="129.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="7.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
</children>
</Pane>
<Button contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219">
<graphic>
<ImageView fitHeight="69.0" fitWidth="61.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold Italic" size="14.0" />
</font>
</Button>
</children></AnchorPane>
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.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">
<children>
@@ -176,28 +292,77 @@
<Font size="30.0" />
</font>
</Text>
<VBox layoutX="517.0" layoutY="28.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<VBox layoutX="80.0" layoutY="150.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<children>
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Score" textAlignment="CENTER" wrappingWidth="100.79296875">
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Username" textAlignment="CENTER" wrappingWidth="267.1929016113281">
<font>
<Font size="24.0" />
</font>
</Text>
<Label fx:id="scoreField" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="101.0" text="score" textAlignment="CENTER">
<Label fx:id="usernameLabel" alignment="CENTER" contentDisplay="CENTER" layoutX="50.0" prefHeight="27.0" prefWidth="267.0" text="username" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" layoutX="517.0" layoutY="121.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<VBox alignment="CENTER" layoutX="80.0" layoutY="250.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<children>
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Last CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
<font>
<Font size="24.0" />
</font>
</Text>
<Label fx:id="footprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
<Label fx:id="footprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="co2 footprint" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="tons CO2 / year" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" layoutX="80.0" layoutY="400.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<children>
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="First CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
<font>
<Font size="24.0" />
</font>
</Text>
<Label fx:id="firstFootprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="co2 footprint" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="tons CO2 / year" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</VBox>
<PieChart fx:id="pieChart" layoutX="441.0" layoutY="300.0" prefHeight="352.0" prefWidth="363.0" />
<ImageView fitHeight="163.0" fitWidth="200.0" layoutX="550.0" layoutY="47.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/butterfly.png" />
</image>
</ImageView>
<VBox alignment="CENTER" layoutX="80.0" layoutY="550.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<children>
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Development" textAlignment="CENTER" wrappingWidth="161.79296875">
<font>
<Font size="24.0" />
</font>
</Text>
<Label fx:id="differenceLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="239.0" text="co2 footprint difference" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="tons CO2 / year" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
@@ -207,30 +372,17 @@
</children></AnchorPane>
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="703.0" prefWidth="820.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.0" />
<Label fx:id="welcomebacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font>
<Font size="30.0" />
</font>
</Label>
<Button fx:id="addNewActivityButton" contentDisplay="RIGHT" layoutX="577.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add a new activity" textFill="#29721a">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="81.0" fitWidth="74.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
<Text fill="#797676" layoutX="60.0" layoutY="105.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How will you make the world greener today?">
<font>
<Font size="15.0" />
</font>
</Text>
<Button fx:id="calculateFootPrintButton" contentDisplay="RIGHT" layoutX="572.0" layoutY="124.0" mnemonicParsing="false" onAction="#openCalculator" prefHeight="74.0" prefWidth="205.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Calculate your &#10;CO2 footprint" textFill="#29721a">
<Button fx:id="calculateFootPrintButton" contentDisplay="RIGHT" layoutX="573.0" layoutY="40.0" mnemonicParsing="false" onAction="#openCalculator" prefHeight="74.0" prefWidth="205.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Calculate your &#10;CO2 footprint" textFill="#29721a">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
@@ -246,12 +398,58 @@
</ImageView>
</graphic>
</Button>
<ImageView fx:id="achiev1image" fitHeight="150.0" fitWidth="200.0" layoutX="126.0" layoutY="431.0" pickOnBounds="true" preserveRatio="true">
<Button fx:id="addFriendButton" contentDisplay="RIGHT" layoutX="592.0" layoutY="134.0" mnemonicParsing="false" onAction="#openAddFriend" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add friend" textFill="#29721a">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="74.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/friend2.png" />
</image>
</ImageView>
</graphic>
</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="124.0" text="Score" />
</columns>
</TableView>
<TableView fx:id="developmentLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="developmentUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="developmentScore" prefWidth="124.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="279.0" layoutY="177.0" prefHeight="46.0" prefWidth="266.0" text="Development Leaderboard" textAlignment="CENTER" textFill="#5e1515">
<font>
<Font size="20.0" />
</font>
</Label>
<Button contentDisplay="RIGHT" layoutX="568.0" layoutY="223.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity" textFill="#147219">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="80.0" fitWidth="79.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
<Label fx:id="achiev1text" layoutX="579.0" layoutY="379.0" prefHeight="17.0" prefWidth="181.0" text="Achievement test label" />
<ImageView fx:id="achiev1image" fitHeight="150.0" fitWidth="200.0" layoutX="579.0" layoutY="396.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../achiev1pic.jpg" />
</image>
</ImageView>
<Label fx:id="achiev1text" layoutX="126.0" layoutY="414.0" prefHeight="18.0" prefWidth="181.0" text="Achievement 1 " />
</children>
</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">
@@ -261,11 +459,33 @@
<Font size="30.0" />
</font>
</Text>
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="130.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
<Text layoutX="117.0" layoutY="155.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Friend List">
<font>
<Font size="20.0" />
</font>
</Text>
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
<columns>
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<Text layoutX="315.0" layoutY="155.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Friend Leaderboard">
<font>
<Font size="20.0" />
</font>
</Text>
<TableView fx:id="friendLeaderboard" layoutX="300.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
<columns>
<TableColumn fx:id="friendUser" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="friendScore" prefWidth="108.0" text="Score" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@@ -10,6 +10,11 @@ import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(MockitoJUnitRunner.class)
public class UserServiceTest {
@@ -51,18 +56,106 @@ public class UserServiceTest {
Assert.assertEquals(estimate, result);
}
@Test
public void getFirstFootprint() throws Exception {
Float estimate = new Float(5);
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
Float.class))
.thenReturn(estimate);
Float result = userService.getFirstFootprint("Eric");
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 saveFirstFootprint() throws Exception {
Float estimate = new Float(5);
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/saveFirstFootprint?name=Eric"),
Float.class))
.thenReturn(estimate);
Float result = userService.saveFirstFootprint("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
public void getInputsTest() throws Exception {
Map<String, String> estimate = new HashMap<>();
estimate.put("Eric", "3");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getInputs?name=Eric"),
Map.class))
.thenReturn(estimate);
Map<String, String> result = userService.getInputs("Eric");
Assert.assertEquals(estimate, result);
}
@Test
public void getExtraInputsTest() throws Exception {
Map<String, Boolean> estimate = new HashMap<>();
estimate.put("solar_panels", true);
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
Map.class))
.thenReturn(estimate);
Map<String, Boolean> result = userService.getExtraInputs("Eric");
Assert.assertEquals(estimate, result);
}
@Test
public void setInputTest() throws Exception {
userService.updateInput("Eric", "input_size", "5");
Mockito.verify(userService).updateInput("Eric", "input_size", "5");
}
@Test
public void setExtraInputTest() throws Exception {
userService.updateExtraInput("Eric", "solar_panels", true);
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
}
@Test
public void addFriendTest() throws Exception {
userService.addFriend("Eric", "Ceren");
Mockito.verify(userService).addFriend("Eric", "Ceren");
}
@Test
public void removeFriendTest() throws Exception {
userService.addFriend("Eric", "Ceren");
Mockito.verify(userService).addFriend("Eric", "Ceren");
userService.removeFriend("Eric", "Ceren");
Mockito.verify(userService).removeFriend("Eric", "Ceren");
}
@Test
public void getAchievementsTest() throws Exception {
userService.getAchievements("mika");