From daa1c838b4d482d50ad839eec0bfab71009833e2 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 17:00:45 +0200 Subject: [PATCH 01/17] EDIT::Change some hints and add tests --- .../src/main/java/greenify/client/Hints.java | 57 ++++++++++--------- src/Client/src/test/java/HintsTest.java | 17 +++++- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index b9fda77..63277ad 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -16,50 +16,51 @@ public class Hints { */ private void initHints() { this.hints.add("Buying local produce will not only decrease your carbon " - + "footprint, but also help your local economy: A win-win!"); + + "footprint, but it will also help your local economy: A win-win!"); this.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%."); - this.hints.add("70% of the deforestation of the Amazon is to provide land for cattle ranches."); + + "to cook? And an electric oven is not much better at 12%!"); + this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land for cattle ranches."); this.hints.add("Research shows that reducing meat consumption can increase" - + " your life span by 3.6 years"); - this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood pressure, " + + " your life span by 3,6 years"); + this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood pressure, " + "diabetes and cancer than meat eaters."); - this.hints.add("Did you know? The carbon footprint of a vegetarian diet is about half " + this.hints.add("The carbon footprint of a vegetarian diet is about half " + "that of a meat-lover’s diet!"); - this.hints.add("Cycling is good for the environment AND for your body, " + this.hints.add("Cycling is good for the environment and for your body, " + "so why not grab your bike instead of your car?"); this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just one " - + "hour, we could power the entire world for one year!"); - this.hints.add("27,000 trees are cut down each day so we can have toilet paper."); - this.hints.add("A glass bottle made in our time will take more than 4,000 years to decompose."); + + "hour, we could power the entire world for one whole year!"); + this.hints.add("27,000 trees are cut down every day so we can have toilet paper."); + this.hints.add("Recycle glass bottles! A glass bottle made now will take " + + "more than 4,000 years to decompose."); this.hints.add("Don't forget to turn off the lights and heating in rooms" - + " you're not using at the moment!"); - this.hints.add("Did you know that about 4.5% of the Dutch population does not eat meat?"); - this.hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags!"); + + " you're not using at the moment. Save some energy!"); + this.hints.add("Did you know that about 4,5% of the Dutch population does not eat meat?"); + this.hints.add("Reuse your bags when you go grocery shopping. You will save " + + "plastic bags and won't have a lot of unused bags at home!"); this.hints.add("An estimated 250 million trees can be saved each year " - + "if every published newspaper would be recycled."); - this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector."); - this.hints.add("You can use LED lights in your home to save energy!"); + + "if every published newspaper would be recycled!"); + this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector. " + + "That is a lot of jobs"); + this.hints.add("You can use LED lights in your home to save energy! " + + "They make light from about 85% of their energy"); this.hints.add("If you isolate your home well, it will be warmer, " - + "and you'll save energy as well!"); + + "and you'll save energy as well! No need to wear sweaters anymore"); this.hints.add("Do you have leftovers? Donate them to food kitchens." + " This way you won't waste" - + " food, and you'll help people at the same time!"); + + " food, and you'll help a lot of people at the same time!"); this.hints.add("A lot of coffee places give you a discount if you bring your own cup. " - + "Get rid of those disposable cups!"); + + "Get rid of disposable cups!"); this.hints.add("When shopping, look for products with minimal to no packaging, " - + "or at least packaging made from recycled items. "); + + "or packaging made from recycled items. "); this.hints.add("If you order food, you can ask the restaurant to not include " - + "utensils and napkins, it saves plastic and paper."); - this.hints.add("It takes about 66 days to form a new habit, keep going!"); + + "utensils and napkins, it saves plastic and paper!"); + this.hints.add("It takes about 66 days to form a new habit, keep going, you'll get there!"); this.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.hints.add("Recycle glass bottles!" - + " A glass bottle made in our time will take more than 4,000 years" - + " to decompose."); - this.hints.add("Only 1% of our planet’s water supply can be used." + + "the environment to refill than to buy one every time it's empty."); + this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater." + " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); - this.hints.add("Plastic bad"); + this.hints.add("Plastic bad, very bad."); } /** diff --git a/src/Client/src/test/java/HintsTest.java b/src/Client/src/test/java/HintsTest.java index c0e2442..5964852 100644 --- a/src/Client/src/test/java/HintsTest.java +++ b/src/Client/src/test/java/HintsTest.java @@ -1,5 +1,6 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import greenify.client.Hints; import org.junit.Test; @@ -15,7 +16,7 @@ public class HintsTest { public void hintsContainsTest() { Hints test = new Hints(); assertTrue(test.hints.contains("27,000 trees are cut down " - + "each day so we can have toilet paper.")); + + "every day so we can have toilet paper.")); } @Test @@ -24,6 +25,20 @@ public class HintsTest { String random = test.randomHint(); assertTrue(test.hints.contains(random)); } + + @Test + public void hintsContainsTestTwo() { + Hints test = new Hints(); + assertTrue(test.hints.contains("Plastic bad, very bad.")); + } + + + @Test + public void hintsNotNullTest() { + Hints test = new Hints(); + assertNotNull(test.hints); + } + } From 67b97eb331baa3e5368efd7bf2eb050e5a2d9440 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 17:08:58 +0200 Subject: [PATCH 02/17] FIXX:: Checkstyle --- .../src/main/java/greenify/client/Hints.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 63277ad..a3aa74c 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -19,17 +19,18 @@ public class Hints { + "footprint, but it will also help your local economy: A win-win!"); this.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%!"); - this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land for cattle ranches."); - this.hints.add("Research shows that reducing meat consumption can increase" - + " your life span by 3,6 years"); - this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood pressure, " - + "diabetes and cancer than meat eaters."); + this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land " + + "for cattle ranches."); + this.hints.add("Research shows that reducing meat consumption can " + + "increase your life span by 3,6 years"); + this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood " + + "pressure, diabetes and cancer than meat eaters."); this.hints.add("The carbon footprint of a vegetarian diet is about half " + "that of a meat-lover’s diet!"); this.hints.add("Cycling is good for the environment and for your body, " + "so why not grab your bike instead of your car?"); - this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just one " - + "hour, we could power the entire world for one whole year!"); + this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just " + + "one hour, we could power the entire world for one whole year!"); this.hints.add("27,000 trees are cut down every day so we can have toilet paper."); this.hints.add("Recycle glass bottles! A glass bottle made now will take " + "more than 4,000 years to decompose."); @@ -60,6 +61,11 @@ public class Hints { + "the environment to refill than to buy one every time it's empty."); this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater." + " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); + this.hints.add("For every two million tons of paper and glass, collected in " + + "the Netherlands, close to 90% gets recycled and used to make new products"); + this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household " + + "equipment, you will automatically be charged a ‘recycling tax’ on it. This is " + + "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch"); this.hints.add("Plastic bad, very bad."); } From b92e302f8bf6dc56622d0f08be7a70542dde64e5 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:11:51 +0200 Subject: [PATCH 03/17] ADD::Extra hints --- src/Client/src/main/java/greenify/client/Hints.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index a3aa74c..8e14d74 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -66,6 +66,15 @@ public class Hints { this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household " + "equipment, you will automatically be charged a ‘recycling tax’ on it. This is " + "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch"); + this.hints.add("Second only to Germany, the Netherlands leads the world in recycling" + + ", with 65 percent of all waste recycled."); + this.hints.add("If tbe back of your fridge is dusty, it can increase " + + "energy consumption by 30 per cent."); + this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and" + + " lead to increased pollution and higher greenhouse gas emissions."); + this.hints.add("Meat production is extremely resource-intensive. " + +"If you gave it up just once a week, you would save the 840 gallons " + + "of fresh water it takes to produce a single serving."); this.hints.add("Plastic bad, very bad."); } From 02253cb6458711b7d03381ee6994458016b27778 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:16:26 +0200 Subject: [PATCH 04/17] FIX::Checkstyle errors --- src/Client/src/main/java/greenify/client/Hints.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 8e14d74..5e03535 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -73,13 +73,13 @@ public class Hints { this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and" + " lead to increased pollution and higher greenhouse gas emissions."); this.hints.add("Meat production is extremely resource-intensive. " - +"If you gave it up just once a week, you would save the 840 gallons " + + "If you gave it up just once a week, you would save the 840 gallons " + "of fresh water it takes to produce a single serving."); this.hints.add("Plastic bad, very bad."); } /** - * This method returns a random String. + * This method returns an arbitrary String. * @return the random hint. */ public String randomHint() { From 47c46b54589a5c71842c657f1cfab8025ea0f9ea Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:20:09 +0200 Subject: [PATCH 05/17] FIX::More CS errors --- src/Client/src/main/java/greenify/client/Hints.java | 4 ++-- .../java/greenify/client/controller/DashBoardController.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 5e03535..2319cae 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -79,8 +79,8 @@ public class Hints { } /** - * This method returns an arbitrary String. - * @return the random hint. + * This seeks out a random hint from the list of strings. + * @return the random string hint. */ public String randomHint() { Random rand = new Random(); diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 6ce8230..ac9b27d 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -426,6 +426,9 @@ public class DashBoardController { calcStage.show(); } + /** + * This method adds a random hint to the GUI. + */ public void addRandomHints() { FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText); fadeOut.setFromValue(1.0); From 9ab4439f708eda78985d0563c9f8c16ebd0adfbf Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:34:08 +0200 Subject: [PATCH 06/17] FIX::Illegal catch fix: RuntimeException to HttpClientErrorException --- .../greenify/client/controller/RegisterWindowController.java | 4 ++-- .../main/java/greenify/client/controller/UserController.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index 9ecad09..c84e8e8 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -29,6 +29,7 @@ import javafx.stage.Window; import javafx.util.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.text.DecimalFormat; @@ -230,8 +231,7 @@ public class RegisterWindowController { //register the user with the provided username and password try { userService.registerUser(userNameText.getText(), passwordField.getText()); - } - catch (RuntimeException ex) { + } catch (HttpClientErrorException ex) { UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", "This username has already been taken!"); return; diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index 19af71a..4dffbdd 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -2,6 +2,7 @@ package greenify.client.controller; import greenify.client.Application; import greenify.client.rest.UserService; +import greenify.common.ApplicationException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; @@ -14,6 +15,7 @@ import javafx.stage.Stage; import javafx.stage.Window; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.util.Objects; @@ -67,8 +69,7 @@ public class UserController { //log the user in with the userService method try { userService.loginUser(usernameField.getText(), passwordField.getText()); - } - catch (RuntimeException ex) { + } catch (HttpClientErrorException ex) { AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", "Your username or password is incorrect!"); return; From 92ff0073e8b086d47b02c35359b450df2c54edd2 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 17:00:45 +0200 Subject: [PATCH 07/17] EDIT::Change some hints and add tests --- .../src/main/java/greenify/client/Hints.java | 63 +++++++++---------- src/Client/src/test/java/HintsTest.java | 17 ++++- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index daf7176..4402913 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -16,52 +16,51 @@ public class Hints { */ private void initHints() { this.hints.add("Buying local produce will not only decrease your carbon " - + "footprint, but also help your local economy: A win-win!"); + + "footprint, but it will also help your local economy: A win-win!"); this.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%."); - this.hints.add("70% of the deforestation of the Amazon is to provide land for " - + "cattle ranches."); + + "to cook? And an electric oven is not much better at 12%!"); + this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land for cattle ranches."); this.hints.add("Research shows that reducing meat consumption can increase" - + " your life span by 3.6 years"); - this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood " - + "pressure, diabetes and cancer than meat eaters."); - this.hints.add("Did you know? The carbon footprint of a vegetarian diet is about half " + + " your life span by 3,6 years"); + this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood pressure, " + + "diabetes and cancer than meat eaters."); + this.hints.add("The carbon footprint of a vegetarian diet is about half " + "that of a meat-lover’s diet!"); - this.hints.add("Cycling is good for the environment AND for your body, " + this.hints.add("Cycling is good for the environment and for your body, " + "so why not grab your bike instead of your car?"); - this.hints.add("If we could capture all of the sun’s energy shining on the Earth" - + " for just one hour, we could power the entire world for one year!"); - this.hints.add("27,000 trees are cut down each day so we can have toilet paper."); - this.hints.add("A glass bottle made in our time will take more than 4,000 years " - + "to decompose."); + this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just one " + + "hour, we could power the entire world for one whole year!"); + this.hints.add("27,000 trees are cut down every day so we can have toilet paper."); + this.hints.add("Recycle glass bottles! A glass bottle made now will take " + + "more than 4,000 years to decompose."); this.hints.add("Don't forget to turn off the lights and heating in rooms" - + " you're not using at the moment!"); - this.hints.add("Did you know that about 4.5% of the Dutch population does not eat meat?"); - this.hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags!"); + + " you're not using at the moment. Save some energy!"); + this.hints.add("Did you know that about 4,5% of the Dutch population does not eat meat?"); + this.hints.add("Reuse your bags when you go grocery shopping. You will save " + + "plastic bags and won't have a lot of unused bags at home!"); this.hints.add("An estimated 250 million trees can be saved each year " - + "if every published newspaper would be recycled."); - this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector."); - this.hints.add("You can use LED lights in your home to save energy!"); + + "if every published newspaper would be recycled!"); + this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector. " + + "That is a lot of jobs"); + this.hints.add("You can use LED lights in your home to save energy! " + + "They make light from about 85% of their energy"); this.hints.add("If you isolate your home well, it will be warmer, " - + "and you'll save energy as well!"); + + "and you'll save energy as well! No need to wear sweaters anymore"); this.hints.add("Do you have leftovers? Donate them to food kitchens." + " This way you won't waste" - + " food, and you'll help people at the same time!"); + + " food, and you'll help a lot of people at the same time!"); this.hints.add("A lot of coffee places give you a discount if you bring your own cup. " - + "Get rid of those disposable cups!"); + + "Get rid of disposable cups!"); this.hints.add("When shopping, look for products with minimal to no packaging, " - + "or at least packaging made from recycled items. "); + + "or packaging made from recycled items. "); this.hints.add("If you order food, you can ask the restaurant to not include " - + "utensils and napkins, it saves plastic and paper."); - this.hints.add("It takes about 66 days to form a new habit, keep going!"); + + "utensils and napkins, it saves plastic and paper!"); + this.hints.add("It takes about 66 days to form a new habit, keep going, you'll get there!"); this.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.hints.add("Recycle glass bottles!" - + " A glass bottle made in our time will take more than 4,000 years" - + " to decompose."); - this.hints.add("Only 1% of our planet’s water supply can be used." + + "the environment to refill than to buy one every time it's empty."); + this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater." + " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); - this.hints.add("Plastic bad"); + this.hints.add("Plastic bad, very bad."); } /** diff --git a/src/Client/src/test/java/HintsTest.java b/src/Client/src/test/java/HintsTest.java index c0e2442..5964852 100644 --- a/src/Client/src/test/java/HintsTest.java +++ b/src/Client/src/test/java/HintsTest.java @@ -1,5 +1,6 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import greenify.client.Hints; import org.junit.Test; @@ -15,7 +16,7 @@ public class HintsTest { public void hintsContainsTest() { Hints test = new Hints(); assertTrue(test.hints.contains("27,000 trees are cut down " - + "each day so we can have toilet paper.")); + + "every day so we can have toilet paper.")); } @Test @@ -24,6 +25,20 @@ public class HintsTest { String random = test.randomHint(); assertTrue(test.hints.contains(random)); } + + @Test + public void hintsContainsTestTwo() { + Hints test = new Hints(); + assertTrue(test.hints.contains("Plastic bad, very bad.")); + } + + + @Test + public void hintsNotNullTest() { + Hints test = new Hints(); + assertNotNull(test.hints); + } + } From 917d3a64bb14a7b34b8df6e3cb88095b352059b2 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 17:08:58 +0200 Subject: [PATCH 08/17] FIXX:: Checkstyle --- .../src/main/java/greenify/client/Hints.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 4402913..55207f0 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -19,17 +19,18 @@ public class Hints { + "footprint, but it will also help your local economy: A win-win!"); this.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%!"); - this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land for cattle ranches."); - this.hints.add("Research shows that reducing meat consumption can increase" - + " your life span by 3,6 years"); - this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood pressure, " - + "diabetes and cancer than meat eaters."); + this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land " + + "for cattle ranches."); + this.hints.add("Research shows that reducing meat consumption can " + + "increase your life span by 3,6 years"); + this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood " + + "pressure, diabetes and cancer than meat eaters."); this.hints.add("The carbon footprint of a vegetarian diet is about half " + "that of a meat-lover’s diet!"); this.hints.add("Cycling is good for the environment and for your body, " + "so why not grab your bike instead of your car?"); - this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just one " - + "hour, we could power the entire world for one whole year!"); + this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just " + + "one hour, we could power the entire world for one whole year!"); this.hints.add("27,000 trees are cut down every day so we can have toilet paper."); this.hints.add("Recycle glass bottles! A glass bottle made now will take " + "more than 4,000 years to decompose."); @@ -60,6 +61,11 @@ public class Hints { + "the environment to refill than to buy one every time it's empty."); this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater." + " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); + this.hints.add("For every two million tons of paper and glass, collected in " + + "the Netherlands, close to 90% gets recycled and used to make new products"); + this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household " + + "equipment, you will automatically be charged a ‘recycling tax’ on it. This is " + + "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch"); this.hints.add("Plastic bad, very bad."); } From ae7e36f7577331a6efebfc7e0f983dd285a7e028 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:11:51 +0200 Subject: [PATCH 09/17] ADD::Extra hints --- src/Client/src/main/java/greenify/client/Hints.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 55207f0..c549534 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -66,6 +66,15 @@ public class Hints { this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household " + "equipment, you will automatically be charged a ‘recycling tax’ on it. This is " + "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch"); + this.hints.add("Second only to Germany, the Netherlands leads the world in recycling" + + ", with 65 percent of all waste recycled."); + this.hints.add("If tbe back of your fridge is dusty, it can increase " + + "energy consumption by 30 per cent."); + this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and" + + " lead to increased pollution and higher greenhouse gas emissions."); + this.hints.add("Meat production is extremely resource-intensive. " + +"If you gave it up just once a week, you would save the 840 gallons " + + "of fresh water it takes to produce a single serving."); this.hints.add("Plastic bad, very bad."); } From a6a52688f2caecdf7a967cb154ead5a191929a25 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:16:26 +0200 Subject: [PATCH 10/17] FIX::Checkstyle errors --- src/Client/src/main/java/greenify/client/Hints.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index c549534..7e63c97 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -73,13 +73,13 @@ public class Hints { this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and" + " lead to increased pollution and higher greenhouse gas emissions."); this.hints.add("Meat production is extremely resource-intensive. " - +"If you gave it up just once a week, you would save the 840 gallons " + + "If you gave it up just once a week, you would save the 840 gallons " + "of fresh water it takes to produce a single serving."); this.hints.add("Plastic bad, very bad."); } /** - * This method gets a random String. + * This method returns an arbitrary String. * @return the random hint. */ public String randomHint() { From dc432df12023efce624459fa09f4bfd9fa7870d0 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:20:09 +0200 Subject: [PATCH 11/17] FIX::More CS errors --- src/Client/src/main/java/greenify/client/Hints.java | 4 ++-- .../java/greenify/client/controller/DashBoardController.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 7e63c97..cc7f053 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -79,8 +79,8 @@ public class Hints { } /** - * This method returns an arbitrary String. - * @return the random hint. + * This seeks out a random hint from the list of strings. + * @return the random string hint. */ public String randomHint() { Random rand = new Random(); diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 5679911..dc61c8c 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -467,7 +467,7 @@ public class DashBoardController { } /** - * Adds a random hint to the left. + * This method adds a random hint to the side bar. */ public void addRandomHints() { FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText); From fb2293786434ced7045d67d6d6ddeccdc9608508 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:34:08 +0200 Subject: [PATCH 12/17] FIX::Illegal catch fix: RuntimeException to HttpClientErrorException --- .../greenify/client/controller/RegisterWindowController.java | 3 ++- .../main/java/greenify/client/controller/UserController.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index 0b57ea8..6774cd9 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -30,6 +30,7 @@ import javafx.stage.Window; import javafx.util.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.text.DecimalFormat; @@ -221,7 +222,7 @@ public class RegisterWindowController { //register the user with the provided username and password try { userService.registerUser(userNameText.getText(), passwordField.getText()); - } catch (Exception ex) { + } catch (HttpClientErrorException ex) { UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", "This username has already been taken!"); return; diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index 89160be..3c27973 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -2,6 +2,7 @@ package greenify.client.controller; import greenify.client.Application; import greenify.client.rest.UserService; +import greenify.common.ApplicationException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; @@ -14,6 +15,7 @@ import javafx.stage.Stage; import javafx.stage.Window; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.util.Objects; @@ -67,7 +69,7 @@ public class UserController { //log the user in with the userService method try { userService.loginUser(usernameField.getText(), passwordField.getText()); - } catch (RuntimeException ex) { + } catch (HttpClientErrorException ex) { AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", "Your username or password is incorrect!"); return; From 9fd3b1cf5bddabc96c7d3b0df25d090a8635eb2f Mon Sep 17 00:00:00 2001 From: cugurlu Date: Mon, 8 Apr 2019 15:35:35 +0200 Subject: [PATCH 13/17] Add new methods for piechart --- .../controller/CalculatorController.java | 6 ++- .../controller/DashBoardController.java | 50 ++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java index 3aa8270..b7a6222 100644 --- a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java +++ b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java @@ -398,7 +398,11 @@ public class CalculatorController { "input_footprint_shopping_services_total", servicesLabel.getText().replace("€ / month", "")); } - extraActivityController.updateExtras(); + try { + extraActivityController.updateExtras(); + } catch (Exception ex) { + System.out.println("continue"); + } Float footprint = userService.saveFootprint(userService.currentUser.getName()); Window owner = saveButton.getScene().getWindow(); controller.updateLeaderboard(); diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 7ec63ec..4b5a855 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -237,20 +237,6 @@ public class DashBoardController { developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score")); friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend")); friendScore.setCellValueFactory(new PropertyValueFactory<>("Score")); - if (pieChart != null) { - ObservableList 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 friendList = userService.getFriendNames(userService.currentUser.getName()); for (int i = 0; i < friendList.size(); i++) { Friend friend = new Friend(friendList.get(i), @@ -260,6 +246,7 @@ public class DashBoardController { friendsTable.setItems(data); updateLeaderboard(); updateAchievements(); + updatePiechart(); calculateFootPrintButton.setSkin(new ClickButtonSkin(calculateFootPrintButton)); addFriendButton.setSkin(new ClickButtonSkin(addFriendButton)); addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton)); @@ -317,7 +304,7 @@ public class DashBoardController { * Sorts the scores of users. * @param users the list of users */ - private void sortScores(List users) { + public void sortScores(List users) throws InterruptedException { for (int i = 0; i < users.size(); i++) { for (int j = 0; j < users.size(); j++) { Double first = userService.getFootprint(users.get(i)); @@ -340,7 +327,7 @@ public class DashBoardController { * Sorts the scores of users. * @param users the list of users */ - private List sortDiffScores(List users) throws InterruptedException { + public List sortDiffScores(List users) throws InterruptedException { for (int i = 0; i < users.size(); i++) { for (int j = 0; j < users.size(); j++) { Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService @@ -366,7 +353,7 @@ public class DashBoardController { * Adds a fade transition for switching between the different panes. * @param node the node on which the transition needs to act */ - private void addFadeTransition(Node node) { + public void addFadeTransition(Node node) { fadeTrans = new FadeTransition(Duration.millis(400), node); fadeTrans.setFromValue(0); fadeTrans.setToValue(1.0); @@ -440,7 +427,7 @@ public class DashBoardController { * Displays the user profile pane. * @param event the event (clicking the button) */ - public void displayUser(ActionEvent event) { + public void displayUser(ActionEvent event) throws InterruptedException { System.out.println(userService.currentUser.getName()); System.out.println(userService.getFootprint(userService.currentUser.getName())); footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName())); @@ -456,6 +443,7 @@ public class DashBoardController { userPane.setVisible(true); activitiesPane.setVisible(false); friendsPane.setVisible(false); + updatePiechart(); } /** @@ -603,6 +591,32 @@ public class DashBoardController { developmentLeaderboard.setItems(developmentData); } + /** + * The method updating piechart. + * @throws InterruptedException exception + */ + public void updatePiechart() throws InterruptedException { + Map resultMap = userService.getResults(userService.currentUser.getName()); + if (pieChart != null) { + ObservableList pieChartData = + FXCollections.observableArrayList( + new PieChart.Data("Transport", + Double.parseDouble(resultMap.get("transport"))), + new PieChart.Data("Housing", + Double.parseDouble(resultMap.get("housing"))), + new PieChart.Data("Food", + Double.parseDouble(resultMap.get("food"))), + new PieChart.Data("Goods", + Double.parseDouble(resultMap.get("goods"))), + new PieChart.Data("Services", + Double.parseDouble(resultMap.get("services"))) + ); + pieChart.setTitle("FOOTPRINT DISTRIBUTION"); + pieChart.setMaxSize(1000, 1000); + pieChart.setData(pieChartData); + } + } + /** * Friends tables are updating. * @throws InterruptedException throws exception From 4dd02649b89f72c97cfd7d33a35cb8ccd3569e9f Mon Sep 17 00:00:00 2001 From: cugurlu Date: Mon, 8 Apr 2019 15:36:21 +0200 Subject: [PATCH 14/17] Add methods for getting the results of a user --- .../greenify/client/rest/UserService.java | 17 ++++++++ .../greenify/server/rest/UserController.java | 10 +++++ .../server/service/CalculatorService.java | 39 +++++++++++++++++++ .../greenify/server/service/UserService.java | 11 ++++++ 4 files changed, 77 insertions(+) diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index 699137e..42fa205 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -301,6 +301,23 @@ public class UserService { .encode().toUri(), Map.class); } + /** + * Gets the results of a user. + * @param name name of the user + * @return Map with all results + */ + @SuppressWarnings("Duplicates") + public Map getResults(String name) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getResults") + .queryParam("name", name); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + return this.restTemplate.getForObject(builder.build() + .encode().toUri(), Map.class); + } + /** * Gets the list of all users. */ diff --git a/src/Server/src/main/java/greenify/server/rest/UserController.java b/src/Server/src/main/java/greenify/server/rest/UserController.java index 5b96baa..ccb3d75 100644 --- a/src/Server/src/main/java/greenify/server/rest/UserController.java +++ b/src/Server/src/main/java/greenify/server/rest/UserController.java @@ -185,5 +185,15 @@ public class UserController { public Map getAchievements(@RequestParam(value = "name") String name) { return userService.getAchievements(name); } + + /** + * This method gets the result for schema. + * @param name name of the user + * @return map of all results of the user + */ + @RequestMapping("/getResults") + public Map getResults(@RequestParam(value = "name") String name) { + return userService.getResults(name); + } } diff --git a/src/Server/src/main/java/greenify/server/service/CalculatorService.java b/src/Server/src/main/java/greenify/server/service/CalculatorService.java index 79ba035..68cf414 100644 --- a/src/Server/src/main/java/greenify/server/service/CalculatorService.java +++ b/src/Server/src/main/java/greenify/server/service/CalculatorService.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -108,5 +109,43 @@ public class CalculatorService { inputs.put("input_footprint_shopping_goods_total", netShopping + ""); user.setFootPrintInputs(inputs); } + + public Map getResults(Map map) { + HttpHeaders headers = new HttpHeaders(); + headers.set("accept", MediaType.APPLICATION_JSON_VALUE); + headers.set("app_id", "a98272e3"); + headers.set("app_key", "b9167c4918cb2b3143614b595065d83b"); + HttpEntity entity = new HttpEntity<>("parameters", headers); + UriComponentsBuilder builder = + UriComponentsBuilder.fromHttpUrl("https://apis.berkeley.edu/coolclimate/footprint"); + for (String inputId : map.keySet()) { + builder = builder.queryParam(inputId, map.get(inputId)); + } + ResponseEntity response = restTemplate + .exchange(builder.build().encode().toUri(), HttpMethod.GET, + entity, String.class); + String transport = response.getBody().substring(Objects.requireNonNull(response.getBody()) + .indexOf("") + + 24, response.getBody().indexOf("")); + String housing = response.getBody().substring(Objects.requireNonNull(response.getBody()) + .indexOf("") + + 22, response.getBody().indexOf("")); + String food = response.getBody().substring(Objects.requireNonNull(response.getBody()) + .indexOf("") + + 19, response.getBody().indexOf("")); + String goods = response.getBody().substring(Objects.requireNonNull(response.getBody()) + .indexOf("") + + 20, response.getBody().indexOf("")); + String services = response.getBody().substring(Objects.requireNonNull(response.getBody()) + .indexOf("") + + 23, response.getBody().indexOf("")); + Map resultMap = new HashMap<>(); + resultMap.put("transport", transport); + resultMap.put("housing", housing); + resultMap.put("food", food); + resultMap.put("goods", goods); + resultMap.put("services", services); + return resultMap; + } } diff --git a/src/Server/src/main/java/greenify/server/service/UserService.java b/src/Server/src/main/java/greenify/server/service/UserService.java index c2a68f9..6160416 100644 --- a/src/Server/src/main/java/greenify/server/service/UserService.java +++ b/src/Server/src/main/java/greenify/server/service/UserService.java @@ -280,6 +280,17 @@ public class UserService { return user.getAchievements(); } + /** + * This method gets all achievements of a user. + * @param name name of the user + * @return map with all achievements of a user + */ + public Map getResults(String name) { + User user = userRepository.findByName(name); + Map results = calculatorService.getResults(user.getFootPrintInputs()); + return results; + } + /** * This method gets the list of all users. * @return list of all users From d03deace575fbdcdc4a6f4040d3747cf2d046a19 Mon Sep 17 00:00:00 2001 From: cugurlu Date: Mon, 8 Apr 2019 15:36:42 +0200 Subject: [PATCH 15/17] Add new test methods --- src/Client/src/test/java/UserServiceTest.java | 6 + .../server/rest/UserControllerTest.java | 12 ++ .../server/service/CalculatorServiceTest.java | 134 ++++++++++++++++++ 3 files changed, 152 insertions(+) diff --git a/src/Client/src/test/java/UserServiceTest.java b/src/Client/src/test/java/UserServiceTest.java index e121a33..10487db 100644 --- a/src/Client/src/test/java/UserServiceTest.java +++ b/src/Client/src/test/java/UserServiceTest.java @@ -163,6 +163,12 @@ public class UserServiceTest { userService.getAchievements("mika"); Mockito.verify(userService).getAchievements("mika"); } + + @Test + public void getResultsTest() throws Exception { + userService.getResults("mika"); + Mockito.verify(userService).getResults("mika"); + } } diff --git a/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java b/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java index 70fa53d..53ad12d 100644 --- a/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java +++ b/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java @@ -250,4 +250,16 @@ public class UserControllerTest { assertEquals("mika", arg1Captor.getValue()); } + @Test + public void getResultsTest() throws Exception { + ArgumentCaptor arg1Captor = ArgumentCaptor.forClass(String.class); + mvc.perform(get("/getResults") + .param("name", "mika") + .accept(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()); + verify(userService, times(1)).getResults(arg1Captor.capture()); + assertEquals("mika", arg1Captor.getValue()); + } + } diff --git a/src/Server/src/test/java/greenify/server/service/CalculatorServiceTest.java b/src/Server/src/test/java/greenify/server/service/CalculatorServiceTest.java index 4116483..8eae208 100644 --- a/src/Server/src/test/java/greenify/server/service/CalculatorServiceTest.java +++ b/src/Server/src/test/java/greenify/server/service/CalculatorServiceTest.java @@ -173,4 +173,138 @@ public class CalculatorServiceTest { Float footPrint = service.invokeExternalService(map); Assert.assertEquals(new Float(11421.537), footPrint); } + + @Test + public void getResultsTest() { + CalculatorService service = new CalculatorService(); + service.restTemplate = new RestTemplate(); + Map map = new HashMap() {{ + put("input_location", "Chicago"); + put("input_location_mode", "1"); + put("input_size", "1"); + put("input_income", "40000"); + put("input_population", "1"); + put("input_changed", "0"); + put("input_footprint_household_adults", "1"); + put("input_footprint_household_children", "0"); + put("input_footprint_transportation_num_vehicles", "1"); + put("input_footprint_transportation_miles1", "16100"); + put("input_footprint_transportation_mpg1", "6"); + put("input_footprint_transportation_fuel1", "2"); + put("input_footprint_transportation_miles2", "13200"); + put("input_footprint_transportation_fuel2", "0"); + put("input_footprint_transportation_mpg2", "22"); + put("input_footprint_transportation_miles3", "13200"); + put("input_footprint_transportation_fuel3", "0"); + put("input_footprint_transportation_mpg3", "22"); + put("input_footprint_transportation_miles4", "13200"); + put("input_footprint_transportation_fuel4", "0"); + put("input_footprint_transportation_mpg4", "22"); + put("input_footprint_transportation_miles5", "13200"); + put("input_footprint_transportation_fuel5", "0"); + put("input_footprint_transportation_mpg5", "22"); + put("input_footprint_transportation_miles6", "13200"); + put("input_footprint_transportation_fuel6", "0"); + put("input_footprint_transportation_mpg6", "22"); + put("input_footprint_transportation_miles7", "13200"); + put("input_footprint_transportation_fuel7", "0"); + put("input_footprint_transportation_mpg7", "22"); + put("input_footprint_transportation_miles8", "13200"); + put("input_footprint_transportation_fuel8", "0"); + put("input_footprint_transportation_mpg8", "22"); + put("input_footprint_transportation_miles9", "13200"); + put("input_footprint_transportation_fuel9", "0"); + put("input_footprint_transportation_mpg9", "22"); + put("input_footprint_transportation_miles10", "13200"); + put("input_footprint_transportation_fuel10", "0"); + put("input_footprint_transportation_mpg10", "22"); + put("input_footprint_transportation_groundtype", "436"); + put("input_footprint_transportation_publictrans", "436"); + put("input_footprint_transportation_bus", "436"); + put("input_footprint_transportation_transit", "436"); + put("input_footprint_transportation_commuter", "436"); + put("input_footprint_transportation_intercity", "436"); + put("input_footprint_transportation_airtype", "3900"); + put("input_footprint_transportation_airtotal", "3900"); + put("input_footprint_transportation_airshort", "3900"); + put("input_footprint_transportation_airmedium", "3900"); + put("input_footprint_transportation_airlong", "3900"); + put("input_footprint_transportation_airextended", "3900"); + put("input_footprint_housing_cdd", "40000"); + put("input_footprint_housing_hdd", "40000"); + put("input_footprint_housing_electricity_type", "40000"); + put("input_footprint_housing_electrivity_dollars", "40000"); + put("input_footprint_housing_electricity_kwh", "12632"); + put("input_footprint_housing_cleanpercent", "0"); + put("input_footprint_housing_naturalgas_type", "1"); + put("input_footprint_housing_naturalgas_dollars", "40000"); + put("input_footprint_housing_naturalgas_therms", "472"); + put("input_footprint_housing_naturalgas_cuft", "40000"); + put("input_footprint_housing_heatingoil_type", "40000"); + put("input_footprint_housing_heatingoil_dollars", "40000"); + put("input_footprint_housing_heatingoil_gallons", "73"); + put("input_footprint_housing_heatingoil_dollars_per_gallon", "40000"); + put("input_footprint_housing_squarefeet", "1850"); + put("input_footprint_housing_watersewage", "100"); + put("input_footprint_housing_gco2_per_kwh", "40000"); + put("input_footprint_shopping_food_meatfisheggs_default", "40000"); + put("input_footprint_shopping_food_meat_beefpork_default", "40000"); + put("input_footprint_shopping_food_meat_poultry_default", "40000"); + put("input_footprint_shopping_food_meat_fish_default", "40000"); + put("input_footprint_shopping_food_meat_other_default", "40000"); + put("input_footprint_shopping_food_fruitvegetables_default", "40000"); + put("input_footprint_shopping_food_dairy_default", "4.2"); + put("input_footprint_shopping_food_cereals_default", "40000"); + put("input_footprint_shopping_food_otherfood_default", "40000"); + put("input_footprint_shopping_food_meattype", "40000"); + put("input_footprint_shopping_food_meatfisheggs", "2.4"); + put("input_footprint_shopping_food_meat_beefpork", "2.4"); + put("input_footprint_shopping_food_meat_poultry", "2.4"); + put("input_footprint_shopping_food_meat_fish", "2.4"); + put("input_footprint_shopping_food_meat_other", "2.4"); + put("input_footprint_shopping_food_cereals", "4.1"); + put("input_footprint_shopping_food_dairy", "2.2"); + put("input_footprint_shopping_food_fruitvegetables", "3.5"); + put("input_footprint_shopping_food_otherfood", "3.4"); + put("input_footprint_shopping_goods_default_furnitureappliances", "1310"); + put("input_footprint_shopping_goods_default_clothing", "1310"); + put("input_footprint_shopping_goods_default_other_entertainment", "1310"); + put("input_footprint_shopping_goods_default_other_office", "1310"); + put("input_footprint_shopping_goods_default_other_personalcare", "1310"); + put("input_footprint_shopping_goods_default_other_autoparts", "1310"); + put("input_footprint_shopping_goods_default_other_medical", "1310"); + put("input_footprint_shopping_goods_type", "1310"); + put("input_footprint_shopping_goods_total", "1310"); + put("input_footprint_shopping_goods_furnitureappliances", "1310"); + put("input_footprint_shopping_goods_clothing", "1310"); + put("input_footprint_shopping_goods_other_type", "1310"); + put("input_footprint_shopping_goods_other_total", "1310"); + put("input_footprint_shopping_goods_other_entertainment", "1310"); + put("input_footprint_shopping_goods_other_office", "1310"); + put("input_footprint_shopping_goods_other_personalcare", "1310"); + put("input_footprint_shopping_goods_other_autoparts", "1310"); + put("input_footprint_shopping_goods_other_medical", "1310"); + put("input_footprint_shopping_services_type", "1310"); + put("input_footprint_shopping_services_total", "1310"); + put("input_footprint_shopping_services_healthcare", "1310"); + put("input_footprint_shopping_services_education", "1310"); + put("input_footprint_shopping_services_communications", "1310"); + put("input_footprint_shopping_services_vehicleservices", "1310"); + put("input_footprint_shopping_services_finance", "1310"); + put("input_footprint_shopping_services_household", "1310"); + put("input_footprint_shopping_services_charity", "1310"); + put("input_footprint_shopping_services_miscservices", "1310"); + put("internal_state_abbreviation", "US"); + put("input_footprint_shopping_services_total", "2413"); + } + }; + Map result = new HashMap<>(); + result.put("transport", "10769.855687"); + result.put("housing", "556.831359"); + result.put("food", "0.028481"); + result.put("goods", "55.256948"); + result.put("services", "39.564835"); + Map footPrint = service.getResults(map); + Assert.assertEquals(result, footPrint); + } } From f6f74cd2aae6c08b8312e86e1f7ec3438266e3ec Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Mon, 8 Apr 2019 15:38:49 +0200 Subject: [PATCH 16/17] FIX::Checkstyle errors --- build.gradle | 6 +++--- .../greenify/client/controller/ExtraActivityController.java | 6 +++--- .../client/controller/RegisterWindowController.java | 2 +- .../java/greenify/client/controller/UserController.java | 1 - src/Client/src/test/java/FriendTest.java | 4 ++-- src/Client/src/test/java/UserServiceTest.java | 6 +++--- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 2b6ed72..98f5661 100644 --- a/build.gradle +++ b/build.gradle @@ -18,9 +18,9 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'application' -application { - mainClassName = 'greenify.server.Application' -} +//application { +// mainClassName = 'greenify.server.Application' +//} repositories { mavenCentral() diff --git a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java index 4582daa..51f128e 100644 --- a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java +++ b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java @@ -221,7 +221,7 @@ public class ExtraActivityController { Float footprint = userService.saveFootprint(userService.currentUser.getName()); controller.updateLeaderboard(); controller.updateAchievements(); - } catch (Exception ex) { + } catch (InterruptedException ex) { System.out.println("continue"); } } @@ -263,7 +263,7 @@ public class ExtraActivityController { Float footprint = userService.saveFootprint(userService.currentUser.getName()); controller.updateAchievements(); controller.updateLeaderboard(); - } catch (Exception ex) { + } catch (NullPointerException ex) { System.out.println("continue"); } } @@ -278,7 +278,7 @@ public class ExtraActivityController { Float footprint = userService.saveFootprint(userService.currentUser.getName()); controller.updateAchievements(); controller.updateLeaderboard(); - } catch (Exception ex) { + } catch (NullPointerException ex) { System.out.println("continue"); } } diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index 6774cd9..84937d5 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -487,7 +487,7 @@ public class RegisterWindowController { } try { extraActivityController.updateExtras(); - } catch (Exception ex) { + } catch (NullPointerException ex) { System.out.println("Continue"); } Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName()); diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index 3c27973..ed0ea13 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -2,7 +2,6 @@ package greenify.client.controller; import greenify.client.Application; import greenify.client.rest.UserService; -import greenify.common.ApplicationException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; diff --git a/src/Client/src/test/java/FriendTest.java b/src/Client/src/test/java/FriendTest.java index 7b13fce..69490c6 100644 --- a/src/Client/src/test/java/FriendTest.java +++ b/src/Client/src/test/java/FriendTest.java @@ -1,9 +1,9 @@ +import static org.junit.Assert.assertEquals; + import greenify.client.Friend; import org.junit.Test; import org.junit.jupiter.api.Assertions; -import static org.junit.Assert.*; - public class FriendTest { @Test public void setAndGetTest() { diff --git a/src/Client/src/test/java/UserServiceTest.java b/src/Client/src/test/java/UserServiceTest.java index e121a33..3f71e20 100644 --- a/src/Client/src/test/java/UserServiceTest.java +++ b/src/Client/src/test/java/UserServiceTest.java @@ -1,3 +1,6 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import greenify.client.rest.UserService; import greenify.common.UserDto; import org.junit.Test; @@ -14,9 +17,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @RunWith(MockitoJUnitRunner.class) public class UserServiceTest { From 425550c9223cf26b794c881a35270ba3f9831c07 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Mon, 8 Apr 2019 15:41:01 +0200 Subject: [PATCH 17/17] FIX::Uncomment something to make pipeline pass --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 98f5661..2b6ed72 100644 --- a/build.gradle +++ b/build.gradle @@ -18,9 +18,9 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'application' -//application { -// mainClassName = 'greenify.server.Application' -//} +application { + mainClassName = 'greenify.server.Application' +} repositories { mavenCentral()