Merge branch 'addActivitySummary_newTests' into 'master'

Add activity summary and new tests

See merge request cse1105/2018-2019/oopp-group-43/template!53
This commit is contained in:
Ceren Ugurlu
2019-03-31 14:12:44 +00:00
11 changed files with 372 additions and 102 deletions

View File

@@ -53,8 +53,7 @@ action plan:
<img src="https://user-images.githubusercontent.com/47633984/55274734-10398a80-52dc-11e9-9fce-5059ac2b3f3b.jpeg" width="100"/>
## Personal Development Plan:
- This is my core quadrant: <img src="https://user-images.githubusercontent.com/47633984/55274694-4296b800-52db-11e9-9cee-b8d1d5c58e6f.png" width="700"/>
<img src="https://user-images.githubusercontent.com/47633984/55274694-4296b800-52db-11e9-9cee-b8d1d5c58e6f.png" width="700"/>
My strong points:
- I am an ambitious person in order to achieve my goal I can study a lot

View File

@@ -11,11 +11,11 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
@@ -472,6 +472,18 @@ public class CalculatorController {
servicesLabel.getText().replace("€ / month", ""));
}
Float footprint = userService.saveFootprint(userService.currentUser.getName());
if(localProduceCheckbox.isSelected()) {
controller.localProduce.setSelected(true);
}
if(bikeCheckbox.isSelected()) {
controller.bike.setSelected(true);
}
if(temperatureCheckbox.isSelected()) {
controller.loweringTemp.setSelected(true);
}
if(solarPanelsCheckbox.isSelected()) {
controller.solarPanels.setSelected(true);
}
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();

View File

@@ -15,10 +15,7 @@ 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.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
@@ -29,6 +26,7 @@ import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* Class that controls the dashboard fxml file (the GUI Screen).
@@ -96,6 +94,60 @@ public class DashBoardController {
private PieChart pieChart;
@FXML
private Label usernameLabel;
@FXML
private TextField peopleNumber;
@FXML
private TextField income;
@FXML
private TextField electricityUsage;
@FXML
private TextField cleanEnergy;
@FXML
private TextField naturalGasUsage;
@FXML
private TextField heatingOilUsage;
@FXML
private TextField waterUsage;
@FXML
private TextField livingSpace;
@FXML
private TextField gasolineMiles;
@FXML
private TextField gasolineMpg;
@FXML
private TextField dieselMiles;
@FXML
private TextField dieselMpg;
@FXML
private TextField electricMiles;
@FXML
private TextField electricMpg;
@FXML
private TextField publicTransportation;
@FXML
private TextField airPlane;
@FXML
private TextField goodShopping;
@FXML
private TextField serviceShopping;
@FXML
private TextField meat;
@FXML
private TextField grains;
@FXML
private TextField dairy;
@FXML
private TextField fruits;
@FXML
private TextField snacks;
@FXML
public CheckBox localProduce;
@FXML
public CheckBox loweringTemp;
@FXML
public CheckBox bike;
@FXML
public CheckBox solarPanels;
/**
* Loads the the necessary things before anything else.
@@ -200,6 +252,30 @@ 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"));
electricityUsage.setText(inputMap.get("input_footprint_housing_electricity_dollars"));
cleanEnergy.setText(inputMap.get("input_footprint_housing_gco2_per_kwh"));
naturalGasUsage.setText(inputMap.get("input_footprint_housing_naturalgas_dollars"));
heatingOilUsage.setText(inputMap.get("input_footprint_housing_heatingoil_dollars"));
waterUsage.setText(inputMap.get("input_footprint_housing_watersewage"));
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"));
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal"));
goodShopping.setText(inputMap.get("input_footprint_shopping_goods_total"));
serviceShopping.setText(inputMap.get("input_footprint_shopping_services_total"));
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"));
}
/**
@@ -209,8 +285,7 @@ public class DashBoardController {
public void displayUser(ActionEvent event) {
System.out.println(userService.currentUser.getName());
System.out.println(userService.getFootprint(userService.currentUser.getName()));
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName())
+ "\n tons CO2/year");
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
usernameLabel.setText("" + userService.currentUser.getName());
addFadeTransition(userPane);
System.out.println("display user");

View File

@@ -1,5 +1,6 @@
package greenify.client.rest;
import com.sun.javafx.collections.MappingChange;
import greenify.common.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
@@ -12,7 +13,10 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.awt.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class UserService {
@@ -173,6 +177,23 @@ public class UserService {
.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 list of all users.
*/

View File

@@ -1,17 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?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.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
@@ -57,121 +52,225 @@
</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="#741010">
<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">
<font>
<Font size="14.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">
<font>
<Font size="14.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>
</children>
</Pane>
<Pane layoutX="310.0" layoutY="93.0" prefHeight="471.0" prefWidth="150.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">
<TextField fx:id="peopleNumber" layoutX="190.0" layoutY="70.0" prefHeight="40.0" prefWidth="62.0" />
<Label layoutX="14.0" layoutY="16.0" prefHeight="40.0" prefWidth="154.0" text="Number of people">
<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">
<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">
<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">
<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">
<TextField fx:id="income" layoutX="190.0" layoutY="16.0" prefHeight="40.0" prefWidth="62.0" />
<Label layoutX="14.0" layoutY="70.0" prefHeight="40.0" prefWidth="154.0" text="Household income">
<font>
<Font size="18.0" />
</font>
</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="20.0" layoutY="275.0" prefHeight="32.0" prefWidth="255.0" text="Home!" textAlignment="CENTER" textFill="#741010">
<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="15.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Done in total">
<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">
<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="totalLocalProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
<TextField fx:id="electricityUsage" layoutX="190.0" layoutY="26.0" prefHeight="40.0" prefWidth="62.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>
<TextField fx:id="cleanEnergy" layoutX="190.0" layoutY="74.0" prefHeight="40.0" prefWidth="62.0" />
<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="totalBikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
<TextField fx:id="naturalGasUsage" layoutX="190.0" layoutY="122.0" prefHeight="40.0" prefWidth="62.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="totalPublicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
<TextField fx:id="heatingOilUsage" layoutX="190.0" layoutY="168.0" prefHeight="40.0" prefWidth="62.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="totalTemperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
<TextField fx:id="waterUsage" layoutX="190.0" layoutY="216.0" prefHeight="40.0" prefWidth="62.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="totalSolarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
<TextField fx:id="livingSpace" layoutX="190.0" layoutY="264.0" prefHeight="40.0" prefWidth="62.0" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="290.0" layoutY="100.0" prefHeight="32.0" prefWidth="230.0" text="Travel!" textAlignment="CENTER" textFill="#741010">
<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>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline miles">
<font>
<Font size="18.0" />
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="gasolineMiles" layoutX="170.0" layoutY="11.0" prefHeight="27.0" prefWidth="50.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline mpg">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="gasolineMpg" layoutX="170.0" layoutY="55.0" prefHeight="27.0" prefWidth="50.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="99.0" prefHeight="27.0" prefWidth="149.0" text="Diesel miles">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="dieselMiles" layoutX="170.0" layoutY="99.0" prefHeight="27.0" prefWidth="50.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="143.0" prefHeight="27.0" prefWidth="149.0" text="Diesel mpg">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="dieselMpg" layoutX="170.0" layoutY="143.0" prefHeight="27.0" prefWidth="50.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="187.0" prefHeight="27.0" prefWidth="149.0" text="Electric miles">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="electricMiles" layoutX="170.0" layoutY="187.0" prefHeight="27.0" prefWidth="50.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="231.0" prefHeight="27.0" prefWidth="149.0" text="Electric mpg">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="electricMpg" layoutX="170.0" layoutY="231.0" prefHeight="27.0" prefWidth="50.0" />
<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>
<TextField fx:id="publicTransportation" layoutX="170.0" layoutY="275.0" prefHeight="27.0" prefWidth="50.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="319.0" prefHeight="27.0" prefWidth="149.0" text="Air plane">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="airPlane" layoutX="170.0" layoutY="319.0" prefHeight="27.0" prefWidth="50.0" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="290.0" layoutY="488.0" prefHeight="32.0" prefWidth="230.0" text="Shopping!" textAlignment="CENTER" textFill="#741010">
<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>
<TextField fx:id="goodShopping" layoutX="146.0" layoutY="18.0" prefHeight="40.0" prefWidth="70.0" />
<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>
<TextField fx:id="serviceShopping" layoutX="146.0" layoutY="80.0" prefHeight="40.0" prefWidth="70.0" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="545.0" layoutY="100.0" prefHeight="32.0" prefWidth="255.0" text="Food!" textAlignment="CENTER" textFill="#741010">
<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>
<TextField fx:id="meat" layoutX="150.0" layoutY="26.0" prefHeight="46.0" prefWidth="70.0" />
<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>
<TextField fx:id="grains" layoutX="150.0" layoutY="90.0" prefHeight="46.0" prefWidth="70.0" />
<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>
<TextField fx:id="dairy" layoutX="150.0" layoutY="154.0" prefHeight="46.0" prefWidth="70.0" />
<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>
<TextField fx:id="fruits" layoutX="150.0" layoutY="218.0" prefHeight="46.0" prefWidth="70.0" />
<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>
<TextField fx:id="snacks" layoutX="150.0" layoutY="282.0" prefHeight="46.0" prefWidth="70.0" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="545.0" layoutY="488.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#741010">
<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>
</children></AnchorPane>
@@ -275,16 +374,16 @@
</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>
<columns>
<TableColumn fx:id="globalUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="globalScore" prefWidth="124.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="124.0" text="Score" />
</columns>
<columns>
<TableColumn fx:id="friendUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="friendScore" 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>

View File

@@ -11,7 +11,9 @@ 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 {
@@ -86,6 +88,17 @@ public class UserServiceTest {
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 setInputTest() throws Exception {
userService.updateInput("Eric", "input_size", "5");

View File

@@ -10,8 +10,13 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.persistence.*;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
@Entity

View File

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
public class UserController {
@@ -102,6 +103,14 @@ public class UserController {
return users;
}
/**
* This method gets the input map of the user.
*/
@RequestMapping("/getInputs")
public Map<String, String> getInputs(@RequestParam(value = "name") String name) {
return userService.getInputMap(name);
}
/**
* This method adds friend for a user.
* @param name name of the user

View File

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class UserService {
@@ -114,6 +115,16 @@ public class UserService {
}
}
/**
* This method gets the map of the inputs.
* @param name of the user
* @return input map
*/
public Map<String, String> getInputMap(String name) {
User user = userRepository.findByName(name);
return user.getFootPrintInputs();
}
/**
* This method saves the footprint of a user.
* @param name name of the user

View File

@@ -94,6 +94,19 @@ public class UserControllerTest {
assertEquals("merel", arg2Captor.getValue());
}
@Test
public void getInputMapTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/getInputs")
.param("name", "ceren")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
verify(userService, times(1))
.getInputMap(arg1Captor.capture());
assertEquals("ceren", arg1Captor.getValue());
}
@Test
public void getAllUsersTest() throws Exception {
mvc.perform(get("/getAllUsers")

View File

@@ -20,7 +20,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(SpringRunner.class)
public class UserServiceTest {
@@ -136,6 +138,17 @@ public class UserServiceTest {
.getInput("alex", "input_footprint_shopping_food_dairy_default"));
}
@Test
public void getInputMapTest() {
Map<String, String> map = new HashMap<>();
User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName()))
.thenReturn(alex);
alex.setFootPrintInputs(map);
assertEquals(map, userService
.getInputMap("alex"));
}
@Test
public void getInputExceptionTest() {
assertThrows(ApplicationException.class, () -> userService.getInput("alex", "hello"));