81 Commits

Author SHA1 Message Date
Mika Wauben
533a5e9631 Merge branch 'Update/readme' into 'master'
UPDATE:: screenshots and 'getting started'

See merge request cse1105/2018-2019/oopp-group-43/template!93
2019-04-15 12:27:04 +00:00
Sem van der Hoeven
b266160e93 ADD::added animations to buttons on friends pane 2019-04-15 14:17:22 +02:00
Mika Wauben
2f1d07f008 UPDATE:: screenshots and 'getting started' 2019-04-15 12:05:02 +00:00
Sem van der Hoeven
af65142bf4 FIX::typo in extra activities 2019-04-15 14:01:23 +02:00
mlwauben
e2be018816 FIX:: explanation button 2019-04-15 11:18:19 +02:00
mlwauben
36fbcfedb8 ADD:: javadoc 2019-04-15 11:11:03 +02:00
Sem van der Hoeven
2b985344dc ADD::added button to display/hide explanation
Merge branch 'master' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template
2019-04-15 10:57:34 +02:00
Sem van der Hoeven
c030bf3a8e ADD::added button to display/hide explanation 2019-04-15 10:56:50 +02:00
Mika Wauben
8150537aa5 Merge branch 'Add/docLastSprint' into 'master'
ADD:: doc sprint7

See merge request cse1105/2018-2019/oopp-group-43/template!92
2019-04-15 08:53:08 +00:00
Mika Wauben
694d58924c ADD:: doc sprint7 2019-04-15 08:53:08 +00:00
Mika Wauben
2ed6192090 Merge branch 'add_checkstyle_coverage' into 'master'
Upload weekly reports

See merge request cse1105/2018-2019/oopp-group-43/template!91
2019-04-15 08:18:56 +00:00
cugurlu
5ef716330c Upload weekly reports 2019-04-15 08:59:48 +02:00
Mika Wauben
facebc1334 Merge branch 'Fix/LastCheckstyles' into 'master'
FIX:: checkstyle error button and missing javadoc

See merge request cse1105/2018-2019/oopp-group-43/template!90
2019-04-15 05:44:50 +00:00
Mika Wauben
84793dc924 FIX:: checkstyle error button and missing javadoc 2019-04-15 05:44:49 +00:00
Ceren Ugurlu
dd184a1398 Update build.gradle 2019-04-14 16:42:57 +00:00
Ceren Ugurlu
b959484185 Merge branch 'hashPassword' into 'master'
Add password hashing & deploy heroku

See merge request cse1105/2018-2019/oopp-group-43/template!89
2019-04-14 16:37:56 +00:00
Ceren Ugurlu
69d80b1f7c Update build.gradle 2019-04-14 16:30:36 +00:00
cugurlu
f8799c06fb Add new plugins for heroku 2019-04-14 18:28:29 +02:00
cugurlu
f20f010cb8 Remove unnecessary prints 2019-04-14 18:28:04 +02:00
cugurlu
048253a9d3 Add password hashing 2019-04-14 18:27:37 +02:00
cugurlu
8d029fe21c Fix removeFriend image 2019-04-14 18:26:54 +02:00
Mika Wauben
60f8b2a9d9 Merge branch 'Update/leaderBoards' into 'master'
Update/leader boards

See merge request cse1105/2018-2019/oopp-group-43/template!88
2019-04-13 10:38:58 +00:00
Mika Wauben
66c2b44be6 Merge branch 'master' into 'Update/leaderBoards'
# Conflicts:
#   src/Client/src/main/java/greenify/client/controller/CalculatorController.java
#   src/Client/src/main/resources/fxml/dashboard.fxml
#   src/Server/src/main/java/greenify/server/service/CalculatorService.java
2019-04-13 10:38:58 +00:00
Ceren Ugurlu
f0d6b04e30 Merge branch 'removeFriend' into 'master'
Add remove friend

See merge request cse1105/2018-2019/oopp-group-43/template!87
2019-04-11 16:43:59 +00:00
cugurlu
6084338525 Fix checkstyle errors 2019-04-11 14:24:07 +02:00
cugurlu
9006588eed Add new methods to controllers to remove a friend 2019-04-11 14:23:40 +02:00
cugurlu
367daa1eff Edit dashboard.fxml 2019-04-11 14:22:58 +02:00
cugurlu
a2af22facb Add fxml file and image for removeFriend property 2019-04-11 14:22:41 +02:00
cugurlu
abdaa14679 Fix small problem in AchievementService 2019-04-11 14:22:13 +02:00
Merel Steenbergen
8c5f177704 Merge branch 'Add/docs' into 'master'
Add final report and agenda

See merge request cse1105/2018-2019/oopp-group-43/template!86
2019-04-11 09:53:15 +00:00
Merel Steenbergen
00718a1cf2 Update 20190408_agenda 2019-04-11 09:49:29 +00:00
Merel Steenbergen
e73c419c55 ADD::Agenda for 08-04-2019 that I forgot to upload, sorry. 2019-04-11 09:49:05 +00:00
Merel Steenbergen
f4cc37a34b Upload final report 2019-04-11 09:45:49 +00:00
Merel Steenbergen
461b3bd329 Merge branch 'Feature/explanation' into 'master'
Explanation in first calculator screen

See merge request cse1105/2018-2019/oopp-group-43/template!84
2019-04-10 20:43:41 +00:00
Sem van der Hoeven
f56a959720 Merge branch 'add/more_animations' into 'master'
Add/more animations

See merge request cse1105/2018-2019/oopp-group-43/template!85
2019-04-10 19:25:41 +00:00
Merel Steenbergen
796deadb8c Merge branch 'Feature/delete_my_account' into 'master'
Feature/delete my account

See merge request cse1105/2018-2019/oopp-group-43/template!83
2019-04-10 14:20:49 +00:00
Merel Steenbergen
2b1c6cf780 FIX::Import that gave a CheckStyle error.java 2019-04-10 13:40:39 +00:00
Merel Steenbergen
eed4f7903d FIX::Small typing error in method name.java 2019-04-10 13:40:08 +00:00
Sem van der Hoeven
377db10f13 EDIT::changed color of register window button 2019-04-10 12:24:11 +02:00
Sem van der Hoeven
50fb2078b0 EDIT::fixed checkstyle import 2019-04-10 12:22:23 +02:00
Sem van der Hoeven
123a767a75 ADD::added style to button in register window 2019-04-10 12:19:31 +02:00
Sem van der Hoeven
e0e6744c95 EDIT::removed lines from background of vegetarian meals achievement picture 2019-04-10 12:07:07 +02:00
Sem van der Hoeven
cfc238af73 ADD::Added animations to switching panes in extra activities 2019-04-10 12:04:17 +02:00
Sem van der Hoeven
78e050751f ADD::added animations to buttons in login and register screen 2019-04-10 11:49:31 +02:00
Merel Steenbergen
81f48ca0b6 FIX::Checkstyle errors 2019-04-09 17:40:26 +02:00
Merel Steenbergen
d97ae9b53a FIX::Checkstyle error 2019-04-09 17:38:44 +02:00
Merel Steenbergen
2a136b6a07 ADD::Client.UserServiceTest 2019-04-09 17:37:51 +02:00
Merel Steenbergen
080053765c ADD::server.UserControllerTest 2019-04-09 17:35:39 +02:00
Merel Steenbergen
21ab3d5b79 ADD::server.userService Tests 2019-04-09 17:30:58 +02:00
Merel Steenbergen
8e747e54be ADD::Clientside method 2019-04-09 17:03:56 +02:00
Merel Steenbergen
99899dfc88 Add serverside methods 2019-04-09 17:00:51 +02:00
Merel Steenbergen
867eae66f4 ADD::Explanation in first calculator screen 2019-04-09 16:28:17 +02:00
Mika Wauben
37d43c8247 Merge branch 'Update/activitiesPane' into 'master'
UPDATE:: activities pane (added all extra activities)

See merge request cse1105/2018-2019/oopp-group-43/template!82
2019-04-09 13:37:28 +00:00
Mika Wauben
a704522a63 UPDATE:: activities pane (added all extra activities) 2019-04-09 13:37:28 +00:00
Mika Wauben
cefc4d2b4b Merge branch 'Update/readme' into 'master'
Update/readme

See merge request cse1105/2018-2019/oopp-group-43/template!79
2019-04-09 07:30:08 +00:00
Mika Wauben
222489a316 Update/readme 2019-04-09 07:30:07 +00:00
Merel Steenbergen
4b949db919 Merge branch 'Delete/forgot_password' into 'master'
DELETE 'forgot password' button

See merge request cse1105/2018-2019/oopp-group-43/template!80
2019-04-08 14:44:30 +00:00
Sem van der Hoeven
c8cbb25f5d Merge branch 'update/notes_week9' into 'master'
Update/notes week9

See merge request cse1105/2018-2019/oopp-group-43/template!81
2019-04-08 14:19:03 +00:00
Merel Steenbergen
c8d5dd99ae DELETE 'forgot password' button 2019-04-08 15:59:23 +02:00
Sem van der Hoeven
6d7e73586f Merge branch 'master' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template
Sourcetree needed to merge this?
2019-04-08 15:52:20 +02:00
Sem van der Hoeven
12ca633461 EDIT::suppressed some duplicate warnings 2019-04-08 15:51:44 +02:00
Merel Steenbergen
7b6b8ead65 Merge branch 'Feature/more_hints' into 'master'
Feature/more hints

See merge request cse1105/2018-2019/oopp-group-43/template!78
2019-04-08 13:46:40 +00:00
Ceren Ugurlu
a206625082 Merge branch 'add_piechart' into 'master'
Add piechart

See merge request cse1105/2018-2019/oopp-group-43/template!77
2019-04-08 13:45:17 +00:00
Merel Steenbergen
425550c922 FIX::Uncomment something to make pipeline pass 2019-04-08 15:41:01 +02:00
Merel Steenbergen
e6ecda5471 FIX::Small merge conflict 2019-04-08 15:39:53 +02:00
Merel Steenbergen
f6f74cd2aa FIX::Checkstyle errors 2019-04-08 15:38:49 +02:00
cugurlu
d03deace57 Add new test methods 2019-04-08 15:36:42 +02:00
cugurlu
4dd02649b8 Add methods for getting the results of a user 2019-04-08 15:36:21 +02:00
cugurlu
9fd3b1cf5b Add new methods for piechart 2019-04-08 15:35:35 +02:00
Merel Steenbergen
fb22937864 FIX::Illegal catch fix: RuntimeException to HttpClientErrorException 2019-04-08 15:32:09 +02:00
Merel Steenbergen
dc432df120 FIX::More CS errors 2019-04-08 15:31:34 +02:00
Merel Steenbergen
a6a52688f2 FIX::Checkstyle errors 2019-04-08 15:30:37 +02:00
Merel Steenbergen
ae7e36f757 ADD::Extra hints 2019-04-08 15:30:21 +02:00
Merel Steenbergen
917d3a64bb FIXX:: Checkstyle 2019-04-08 15:30:21 +02:00
Merel Steenbergen
92ff0073e8 EDIT::Change some hints and add tests 2019-04-08 15:30:21 +02:00
Merel Steenbergen
9ab4439f70 FIX::Illegal catch fix: RuntimeException to HttpClientErrorException 2019-04-05 19:34:08 +02:00
Merel Steenbergen
47c46b5458 FIX::More CS errors 2019-04-05 19:20:09 +02:00
Merel Steenbergen
02253cb645 FIX::Checkstyle errors 2019-04-05 19:16:26 +02:00
Merel Steenbergen
b92e302f8b ADD::Extra hints 2019-04-05 19:11:51 +02:00
Merel Steenbergen
67b97eb331 FIXX:: Checkstyle 2019-04-05 17:08:58 +02:00
Merel Steenbergen
daa1c838b4 EDIT::Change some hints and add tests 2019-04-05 17:00:45 +02:00
42 changed files with 1058 additions and 253 deletions

View File

@@ -36,12 +36,12 @@ test:
- .gradle - .gradle
# Code coverage badge # Code coverage badge
# code-coverage: #deploy:
# stage: code-coverage # stage: code-coverage
# script: # script:
# - mvn -B clean verify # - gradle clean check
# after_script: # after_script:
# - awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% instructrions covered" }' target/site/jacoco/jacoco.csv # - awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% instructrions covered" }' target/site/jacoco/jacoco.csv
# - awk -F"," '{ instructions += $6 + $7; covered += $7 } END { print covered, "/", instructions, " branches covered"; print 100*covered/instructions, "% branches covered" }' target/site/jacoco/jacoco.csv # - awk -F"," '{ instructions += $6 + $7; covered += $7 } END { print covered, "/", instructions, " branches covered"; print 100*covered/instructions, "% branches covered" }' target/site/jacoco/jacoco.csv
# - echo \"$(cat target/site/jacoco/jacoco.csv)% covered\" # - echo \"$(cat target/site/jacoco/jacoco.csv)% covered\"
# coverage: '/(\d+.\d+) % +branches covered/' # coverage: '/(\d+.\d+) % +branches covered/'

View File

@@ -1,35 +1,24 @@
# Greenify # Greenify
The easiest way to save CO2 and help the environment! Enter your activities and find out your carbon footprint. The easiest way to save CO2 and help the environment! Enter your activities and find out your carbon footprint.
![loginScreen](/uploads/e4812575794836a217a3a21ceb676c6a/loginScreen.png)
![you](/uploads/093956805aede6de942bcbfeecd84eb7/you.png)
## Badges
[![build status](https://gitlab.ewi.tudelft.nl/cse1105/2018-2019/oopp-group-43/template/badges/master/build.svg)](https://gitlab.ewi.tudelft.nl/cse1105/2018-2019/oopp-group-43/template)
## Getting started ## Getting started
You can install greenify with gradle, if you already have gradle on your machine, run: To start Greenify:
``` ```
gradle install something tralala cd <FILE-LOCATION>/greenify/src/Client/build/libs
``` java -Dserver.address="https://greenify43.herokuapp.com" -jar greenify-1.0.0.jar
Do you not have gradle on your machine, run:
```
./gradlew install something tralala
```
With the following you can start the application
```
gradle greenify bootrun
```
or without gradle on your device:
```
./gradlew greenify bootrun
``` ```
## Running the tests ## Running the tests
The tests cover all non-GUI code: The tests cover all non-GUI code:
``` ```
cd <FILE-LOCATION>/greenify
gradle check gradle check
``` ```

View File

@@ -46,7 +46,6 @@ dependencies {
testCompile("junit:junit") testCompile("junit:junit")
compileOnly 'org.projectlombok:lombok:1.18.6' compileOnly 'org.projectlombok:lombok:1.18.6'
compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
annotationProcessor 'org.projectlombok:lombok:1.18.6' annotationProcessor 'org.projectlombok:lombok:1.18.6'
testCompile( testCompile(
'junit:junit:4.12', 'junit:junit:4.12',

View File

@@ -0,0 +1,43 @@
# Meeting 8
## Opening
> Check if everyone is present:
- ~~Nivard Jansen~~
- ~~Kristin Peneva~~
- ~~Daan Sneep~~
- [x] Merel SteenBergen
- [x] Ceren Ugurlu
- [x] Mika Wauben
- [x] Sem van der Hoeven
- Chair: Merel Steenbergen
- Secretary: Sem van der Hoeven
## Points of action
- First of all, discuss problems we have faced and if somebody is halted because of a problem
- if so, try to work out the problem
### pre/during meeting
- Discuss what we did last week (see scrumboard)
- Does anyone have blocking issues?
- Coverage reports
- Checkstyle reports
- Show demo to the TA, since Mitchell isn't here, a different TA will visit us, so we'll show him the entire application.
- Discuss about the presentation
- Discuss about final things that need to be done
### post meeting
- Focus on the presentation
- Focus on the final report
- Focus on things we get points for according to the rubric
## Any other business
> If anybody has something that should be discussed but came up with that after the agenda was finalized, he/she should bring that up now so that it can be discussed after all.
## Question round
- Questions for the TA
- How to get the code coverage badge, since we use Gradle and we've got the Maven code.
## Closing
> We're almost finished!

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

View File

@@ -0,0 +1,13 @@
# Sprint Review
## Main problems Encountered
### Problem 1:
## Adjustments from previous sprints
Our project is completely finished and we're very happy with the result.
## Adjustments for next sprint
This is the last sprint for this project!

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

View File

@@ -39,8 +39,8 @@ test {
} }
bootJar { bootJar {
baseName = 'gs-consuming-rest' baseName = 'greenify'
version = '0.1.0' version = '1.0.0'
} }
repositories { repositories {
@@ -48,6 +48,7 @@ repositories {
} }
dependencies { dependencies {
compile "org.bouncycastle:bcprov-jdk16:1.46", "org.bouncycastle:bcpg-jdk16:1.46", "org.bouncycastle:bcmail-jdk16:1.46", "org.bouncycastle:bctsp-jdk16:1.46"
compile("org.springframework.boot:spring-boot-starter") compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-web") compile("org.springframework:spring-web")
compile("com.fasterxml.jackson.core:jackson-databind") compile("com.fasterxml.jackson.core:jackson-databind")

View File

@@ -1,18 +1,34 @@
package greenify.client; package greenify.client;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
public class Friend { public class Friend {
private SimpleIntegerProperty place;
private SimpleStringProperty friend; private SimpleStringProperty friend;
private SimpleDoubleProperty score; private SimpleDoubleProperty score;
public Friend(String friend, Double friendScore) { /**
* Constructor for a friend.
* @param place place in the leaderboard
* @param friend name of the user
* @param friendScore score of the user
*/
public Friend(Integer place, String friend, Double friendScore) {
this.place = new SimpleIntegerProperty(place);
this.friend = new SimpleStringProperty(friend); this.friend = new SimpleStringProperty(friend);
this.score = new SimpleDoubleProperty(friendScore); this.score = new SimpleDoubleProperty(friendScore);
} }
public Integer getPlace() {
return place.get();
}
public void setPlace(Integer place) {
this.place = new SimpleIntegerProperty(place);
}
public String getFriend() { public String getFriend() {
return friend.get(); return friend.get();

View File

@@ -16,57 +16,71 @@ public class Hints {
*/ */
private void initHints() { private void initHints() {
this.hints.add("Buying local produce will not only decrease your carbon " 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 " 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%."); + "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 " this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land "
+ "cattle ranches."); + "for cattle ranches.");
this.hints.add("Research shows that reducing meat consumption can increase" this.hints.add("Research shows that reducing meat consumption can "
+ " your life span by 3.6 years"); + "increase your life span by 3,6 years");
this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood " this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood "
+ "pressure, diabetes and cancer than meat eaters."); + "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-lovers diet!"); + "that of a meat-lovers 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?"); + "so why not grab your bike instead of your car?");
this.hints.add("If we could capture all of the suns energy shining on the Earth" this.hints.add("If we could capture all of the suns energy shining on the Earth for just "
+ " for just one hour, we could power the entire world for one year!"); + "one hour, we could power the entire world for one whole year!");
this.hints.add("27,000 trees are cut down each day so we can have toilet paper."); this.hints.add("27,000 trees are cut down every day so we can have toilet paper.");
this.hints.add("A glass bottle made in our time will take more than 4,000 years " this.hints.add("Recycle glass bottles! A glass bottle made now will take "
+ "to decompose."); + "more than 4,000 years to decompose.");
this.hints.add("Don't forget to turn off the lights and heating in rooms" this.hints.add("Don't forget to turn off the lights and heating in rooms"
+ " you're not using at the moment!"); + " 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("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!"); 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 " this.hints.add("An estimated 250 million trees can be saved each year "
+ "if every published newspaper would be recycled."); + "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("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!"); + "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, " 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.hints.add("Do you have leftovers? Donate them to food kitchens."
+ " This way you won't waste" + " 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. " 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, " 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 " this.hints.add("If you order food, you can ask the restaurant to not include "
+ "utensils and napkins, it saves plastic and paper."); + "utensils and napkins, it saves plastic and paper!");
this.hints.add("It takes about 66 days to form a new habit, keep going!"); 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 " 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."); + "the environment to refill than to buy one every time it's empty.");
this.hints.add("Recycle glass bottles!" this.hints.add("Only 1% of our planets water supply can be used a drinkwater."
+ " A glass bottle made in our time will take more than 4,000 years"
+ " to decompose.");
this.hints.add("Only 1% of our planets water supply can be used."
+ " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); + " 97% is ocean water and 2% is frozen solid in the Arctic, for now.");
this.hints.add("Plastic bad"); 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("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.");
} }
/** /**
* This method gets a random String. * This seeks out a random hint from the list of strings.
* @return the random hint. * @return the random string hint.
*/ */
public String randomHint() { public String randomHint() {
Random rand = new Random(); Random rand = new Random();

View File

@@ -398,7 +398,11 @@ public class CalculatorController {
"input_footprint_shopping_services_total", "input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", "")); servicesLabel.getText().replace("€ / month", ""));
} }
extraActivityController.updateExtras(); try {
extraActivityController.updateExtras();
} catch (NullPointerException ex) {
System.out.println("continue");
}
Float footprint = userService.saveFootprint(userService.currentUser.getName()); Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow(); Window owner = saveButton.getScene().getWindow();
controller.updateLeaderboard(); controller.updateLeaderboard();

View File

@@ -93,6 +93,10 @@ public class DashBoardController {
@FXML @FXML
private Button addFriendButton; private Button addFriendButton;
@FXML @FXML
private Button addFriend;
@FXML
private Button removeFriend;
@FXML
private Button addExtraActivityButton; private Button addExtraActivityButton;
@FXML @FXML
private Button addExtraActivityButton2; private Button addExtraActivityButton2;
@@ -105,18 +109,24 @@ public class DashBoardController {
@FXML @FXML
private TableView<Friend> globalLeaderboard; private TableView<Friend> globalLeaderboard;
@FXML @FXML
private TableColumn<Friend, Integer> globalPlace;
@FXML
private TableColumn<Friend, String> globalUser; private TableColumn<Friend, String> globalUser;
@FXML @FXML
private TableColumn<Friend, Float> globalScore; private TableColumn<Friend, Float> globalScore;
@FXML @FXML
private TableView<Friend> developmentLeaderboard; private TableView<Friend> developmentLeaderboard;
@FXML @FXML
private TableColumn<Friend, Integer> developmentPlace;
@FXML
private TableColumn<Friend, String> developmentUser; private TableColumn<Friend, String> developmentUser;
@FXML @FXML
private TableColumn<Friend, Float> developmentScore; private TableColumn<Friend, Float> developmentScore;
@FXML @FXML
private TableView<Friend> friendLeaderboard; private TableView<Friend> friendLeaderboard;
@FXML @FXML
private TableColumn<Friend, Integer> friendPlace;
@FXML
private TableColumn<Friend, String> friendUser; private TableColumn<Friend, String> friendUser;
@FXML @FXML
private TableColumn<Friend, Float> friendScore; private TableColumn<Friend, Float> friendScore;
@@ -185,14 +195,18 @@ public class DashBoardController {
@FXML @FXML
private Label hintText; private Label hintText;
@FXML @FXML
private Label solarPanels; private Label veganMeal;
@FXML @FXML
private Label localProduce; private Label localProduce;
@FXML @FXML
private Label bike; private Label bike;
@FXML @FXML
private Label publicTrans;
@FXML
private Label loweringTemp; private Label loweringTemp;
@FXML @FXML
private Label solarPanels;
@FXML
private Button achiev1Tip; private Button achiev1Tip;
@FXML @FXML
private Button achiev2Tip; private Button achiev2Tip;
@@ -231,39 +245,31 @@ public class DashBoardController {
logOutButton.setSkin(new MyButtonSkin(logOutButton)); logOutButton.setSkin(new MyButtonSkin(logOutButton));
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend")); friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score")); scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
globalPlace.setCellValueFactory(new PropertyValueFactory<>("Place"));
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend")); globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
globalScore.setCellValueFactory(new PropertyValueFactory<>("Score")); globalScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
developmentUser.setCellValueFactory(new PropertyValueFactory<>("Friend")); developmentUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
developmentPlace.setCellValueFactory(new PropertyValueFactory<>("Place"));
developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score")); developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
friendPlace.setCellValueFactory(new PropertyValueFactory<>("Place"));
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend")); friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score")); 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()); List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
for (int i = 0; i < friendList.size(); i++) { for (int i = 0; i < friendList.size(); i++) {
Friend friend = new Friend(friendList.get(i), Friend friend = new Friend(i, friendList.get(i),
userService.getFootprint(friendList.get(i))); userService.getFootprint(friendList.get(i)));
data.add(friend); data.add(friend);
} }
friendsTable.setItems(data); friendsTable.setItems(data);
updateLeaderboard(); updateLeaderboard();
updateAchievements(); updateAchievements();
updatePiechart();
calculateFootPrintButton.setSkin(new ClickButtonSkin(calculateFootPrintButton)); calculateFootPrintButton.setSkin(new ClickButtonSkin(calculateFootPrintButton));
addFriendButton.setSkin(new ClickButtonSkin(addFriendButton)); addFriendButton.setSkin(new ClickButtonSkin(addFriendButton));
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton)); addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2)); addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
addFriend.setSkin(new ClickButtonSkin(addFriend));
removeFriend.setSkin(new ClickButtonSkin(removeFriend));
addRandomHints(); addRandomHints();
Tooltip tooltip = new Tooltip("tip"); Tooltip tooltip = new Tooltip("tip");
@@ -317,7 +323,7 @@ public class DashBoardController {
* Sorts the scores of users. * Sorts the scores of users.
* @param users the list of users * @param users the list of users
*/ */
private void sortScores(List<String> users) { public void sortScores(List<String> users) throws InterruptedException {
for (int i = 0; i < users.size(); i++) { for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size(); j++) { for (int j = 0; j < users.size(); j++) {
Double first = userService.getFootprint(users.get(i)); Double first = userService.getFootprint(users.get(i));
@@ -340,7 +346,7 @@ public class DashBoardController {
* Sorts the scores of users. * Sorts the scores of users.
* @param users the list of users * @param users the list of users
*/ */
private List<String> sortDiffScores(List<String> users) throws InterruptedException { public List<String> sortDiffScores(List<String> users) throws InterruptedException {
for (int i = 0; i < users.size(); i++) { for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size(); j++) { for (int j = 0; j < users.size(); j++) {
Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService
@@ -366,7 +372,7 @@ public class DashBoardController {
* Adds a fade transition for switching between the different panes. * Adds a fade transition for switching between the different panes.
* @param node the node on which the transition needs to act * @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 = new FadeTransition(Duration.millis(400), node);
fadeTrans.setFromValue(0); fadeTrans.setFromValue(0);
fadeTrans.setToValue(1.0); fadeTrans.setToValue(1.0);
@@ -430,17 +436,19 @@ public class DashBoardController {
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood")); snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
Map<String, String> extraMap = userService Map<String, String> extraMap = userService
.getExtraInputs(userService.currentUser.getName()); .getExtraInputs(userService.currentUser.getName());
veganMeal.setText(extraMap.get("vegan"));
localProduce.setText(extraMap.get("local_produce")); localProduce.setText(extraMap.get("local_produce"));
bike.setText(extraMap.get("bike")); bike.setText(extraMap.get("bike"));
solarPanels.setText(extraMap.get("solar_panels")); publicTrans.setText(extraMap.get("public_transport"));
loweringTemp.setText(extraMap.get("temperature")); loweringTemp.setText(extraMap.get("temperature"));
solarPanels.setText(extraMap.get("solar_panels"));
} }
/** /**
* Displays the user profile pane. * Displays the user profile pane.
* @param event the event (clicking the button) * @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.currentUser.getName());
System.out.println(userService.getFootprint(userService.currentUser.getName())); System.out.println(userService.getFootprint(userService.currentUser.getName()));
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName())); footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
@@ -456,6 +464,7 @@ public class DashBoardController {
userPane.setVisible(true); userPane.setVisible(true);
activitiesPane.setVisible(false); activitiesPane.setVisible(false);
friendsPane.setVisible(false); friendsPane.setVisible(false);
updatePiechart();
} }
/** /**
@@ -472,6 +481,7 @@ public class DashBoardController {
updateFriends(); updateFriends();
} }
/** /**
* Logs out the user. * Logs out the user.
* @param event the event (clicking the button) * @param event the event (clicking the button)
@@ -491,6 +501,9 @@ public class DashBoardController {
//development leaderboard //development leaderboard
developmentLeaderboard.getItems().clear(); developmentLeaderboard.getItems().clear();
developmentData.removeAll(); developmentData.removeAll();
//friends leaderboard
friendLeaderboard.getItems().clear();
friendLeaderData.removeAll();
//load the fxml file //load the fxml file
Parent dash = Application.load(this.getClass().getClassLoader() Parent dash = Application.load(this.getClass().getClassLoader()
@@ -516,6 +529,7 @@ public class DashBoardController {
* Opens the calculator. * Opens the calculator.
* @throws IOException if the Application doesn't load. * @throws IOException if the Application doesn't load.
*/ */
@SuppressWarnings("Duplicates")
public void openCalculator() throws IOException, InterruptedException { public void openCalculator() throws IOException, InterruptedException {
Parent calc = Application.load(this.getClass().getClassLoader() Parent calc = Application.load(this.getClass().getClassLoader()
.getResource("fxml/calculator.fxml")); .getResource("fxml/calculator.fxml"));
@@ -530,7 +544,7 @@ public class DashBoardController {
} }
/** /**
* Adds a random hint to the left. * This method adds a random hint to the side bar.
*/ */
public void addRandomHints() { public void addRandomHints() {
FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText); FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText);
@@ -575,10 +589,25 @@ public class DashBoardController {
calcStage.show(); calcStage.show();
} }
/**
* method opens removeFriend scene.
* @throws IOException when file is not found
*/
public void openRemoveFriend() throws IOException {
Parent calc = Application.load(this.getClass().getClassLoader()
.getResource("fxml/RemoveFriend.fxml"));
Scene scene = new Scene(calc);
Stage calcStage = new Stage();
calcStage.setScene(scene);
calcStage.setTitle("Remove your friend - " + userService.currentUser.getName());
calcStage.show();
}
/** /**
* Leaderboard is updating. * Leaderboard is updating.
* @throws InterruptedException throws exception * @throws InterruptedException throws exception
*/ */
@SuppressWarnings("Duplicates")
public void updateLeaderboard() throws InterruptedException { public void updateLeaderboard() throws InterruptedException {
//global leaderboard //global leaderboard
globalLeaderboard.getItems().clear(); globalLeaderboard.getItems().clear();
@@ -589,24 +618,52 @@ public class DashBoardController {
List<String> userList = userService.getAllUsers(); List<String> userList = userService.getAllUsers();
sortScores(userList); sortScores(userList);
for (int i = userList.size() - 1; i >= 0; i--) { for (int i = userList.size() - 1; i >= 0; i--) {
Friend user = new Friend(userList.get(i), userService.getFootprint(userList.get(i))); Friend user = new Friend(userList.size() - i, userList.get(i),
userService.getFootprint(userList.get(i)));
globalLeaderData.add(user); globalLeaderData.add(user);
} }
List<String> secondList = sortDiffScores(userList); List<String> secondList = sortDiffScores(userList);
for (int j = 0; j < userList.size(); j++) { for (int j = 0; j < userList.size(); j++) {
double diff = Math.round((userService.getFirstFootprint(secondList.get(j)) double diff = Math.round((userService.getFirstFootprint(secondList.get(j))
- userService.getFootprint(secondList.get(j))) * 10) / 10.0; - userService.getFootprint(secondList.get(j))) * 10) / 10.0;
Friend diffUser = new Friend(secondList.get(j), diff); Friend diffUser = new Friend(j + 1, secondList.get(j), diff);
developmentData.add(diffUser); developmentData.add(diffUser);
} }
globalLeaderboard.setItems(globalLeaderData); globalLeaderboard.setItems(globalLeaderData);
developmentLeaderboard.setItems(developmentData); developmentLeaderboard.setItems(developmentData);
} }
/**
* The method updating piechart.
* @throws InterruptedException exception
*/
public void updatePiechart() throws InterruptedException {
Map<String, String> resultMap = userService.getResults(userService.currentUser.getName());
if (pieChart != null) {
ObservableList<PieChart.Data> 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. * Friends tables are updating.
* @throws InterruptedException throws exception * @throws InterruptedException throws exception
*/ */
@SuppressWarnings("Duplicates")
public void updateFriends() throws InterruptedException { public void updateFriends() throws InterruptedException {
List<String> wholeList = userService.getFriendNames(userService.currentUser.getName()); List<String> wholeList = userService.getFriendNames(userService.currentUser.getName());
wholeList.add(userService.currentUser.getName()); wholeList.add(userService.currentUser.getName());
@@ -620,14 +677,14 @@ public class DashBoardController {
friendLeaderData.removeAll(); friendLeaderData.removeAll();
sortDiffScores(wholeList); sortDiffScores(wholeList);
for (int i = friendList.size() - 1; i >= 0 ; i--) { for (int i = friendList.size() - 1; i >= 0 ; i--) {
Friend user = new Friend(friendList.get(i), userService Friend user = new Friend(i, friendList.get(i), userService
.getFootprint(friendList.get(i))); .getFootprint(friendList.get(i)));
data.add(user); data.add(user);
} }
for (int j = 0; j < wholeList.size(); j++) { for (int j = 0; j < wholeList.size(); j++) {
double diff = Math.round((userService.getFirstFootprint(wholeList.get(j)) double diff = Math.round((userService.getFirstFootprint(wholeList.get(j))
- userService.getFootprint(wholeList.get(j))) * 10) / 10.0; - userService.getFootprint(wholeList.get(j))) * 10) / 10.0;
Friend diffUser = new Friend(wholeList.get(j), diff); Friend diffUser = new Friend(j + 1, wholeList.get(j), diff);
friendLeaderData.add(diffUser); friendLeaderData.add(diffUser);
} }
friendsTable.setItems(data); friendsTable.setItems(data);

View File

@@ -2,12 +2,15 @@ package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin; import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.rest.UserService; import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition; import javafx.animation.ScaleTransition;
import javafx.animation.TranslateTransition; import javafx.animation.TranslateTransition;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
@@ -129,12 +132,30 @@ public class ExtraActivityController {
}); });
} }
/**
* add transition animation.
* @param node adding animation
*/
public void addFadeTransAnimation(Node node) {
FadeTransition fade = new FadeTransition(Duration.millis(350), node);
fade.setFromValue(0);
fade.setToValue(1.0);
TranslateTransition trans = new TranslateTransition(Duration.millis(350), node);
trans.setFromX(-800);
trans.setToX(0);
ParallelTransition par = new ParallelTransition();
par.setNode(node);
par.getChildren().addAll(fade, trans);
par.play();
}
/** /**
* displays the vegetarian meal section. * displays the vegetarian meal section.
* @param event the click of the designated button * @param event the click of the designated button
*/ */
public void displayVeganMeal(ActionEvent event) { public void displayVeganMeal(ActionEvent event) {
// System.out.println("display vm"); // System.out.println("display vm");
addFadeTransAnimation(veganMealPane);
veganMealPane.setVisible(true); veganMealPane.setVisible(true);
bikePane.setVisible(false); bikePane.setVisible(false);
temperaturePane.setVisible(false); temperaturePane.setVisible(false);
@@ -149,6 +170,7 @@ public class ExtraActivityController {
*/ */
public void displayBike(ActionEvent event) { public void displayBike(ActionEvent event) {
// System.out.println("display b"); // System.out.println("display b");
addFadeTransAnimation(bikePane);
veganMealPane.setVisible(false); veganMealPane.setVisible(false);
bikePane.setVisible(true); bikePane.setVisible(true);
temperaturePane.setVisible(false); temperaturePane.setVisible(false);
@@ -163,6 +185,7 @@ public class ExtraActivityController {
*/ */
public void displayTemperature(ActionEvent event) { public void displayTemperature(ActionEvent event) {
// System.out.println("display t"); // System.out.println("display t");
addFadeTransAnimation(temperaturePane);
veganMealPane.setVisible(false); veganMealPane.setVisible(false);
bikePane.setVisible(false); bikePane.setVisible(false);
temperaturePane.setVisible(true); temperaturePane.setVisible(true);
@@ -177,6 +200,7 @@ public class ExtraActivityController {
*/ */
public void displaySolarPanel(ActionEvent event) { public void displaySolarPanel(ActionEvent event) {
// System.out.println("display sp"); // System.out.println("display sp");
addFadeTransAnimation(solarPanelPane);
veganMealPane.setVisible(false); veganMealPane.setVisible(false);
bikePane.setVisible(false); bikePane.setVisible(false);
temperaturePane.setVisible(false); temperaturePane.setVisible(false);
@@ -190,6 +214,7 @@ public class ExtraActivityController {
* @param event the click of the designated button * @param event the click of the designated button
*/ */
public void displayLocalProduce(ActionEvent event) { public void displayLocalProduce(ActionEvent event) {
addFadeTransAnimation(localProducePane);
veganMealPane.setVisible(false); veganMealPane.setVisible(false);
bikePane.setVisible(false); bikePane.setVisible(false);
temperaturePane.setVisible(false); temperaturePane.setVisible(false);
@@ -203,6 +228,7 @@ public class ExtraActivityController {
* @param event the click of the designated button * @param event the click of the designated button
*/ */
public void displayPublicTransport(ActionEvent event) { public void displayPublicTransport(ActionEvent event) {
addFadeTransAnimation(publicTransportPane);
veganMealPane.setVisible(false); veganMealPane.setVisible(false);
bikePane.setVisible(false); bikePane.setVisible(false);
temperaturePane.setVisible(false); temperaturePane.setVisible(false);
@@ -221,7 +247,7 @@ public class ExtraActivityController {
Float footprint = userService.saveFootprint(userService.currentUser.getName()); Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateLeaderboard(); controller.updateLeaderboard();
controller.updateAchievements(); controller.updateAchievements();
} catch (Exception ex) { } catch (InterruptedException ex) {
System.out.println("continue"); System.out.println("continue");
} }
} }
@@ -263,7 +289,7 @@ public class ExtraActivityController {
Float footprint = userService.saveFootprint(userService.currentUser.getName()); Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements(); controller.updateAchievements();
controller.updateLeaderboard(); controller.updateLeaderboard();
} catch (Exception ex) { } catch (NullPointerException ex) {
System.out.println("continue"); System.out.println("continue");
} }
} }
@@ -278,7 +304,7 @@ public class ExtraActivityController {
Float footprint = userService.saveFootprint(userService.currentUser.getName()); Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements(); controller.updateAchievements();
controller.updateLeaderboard(); controller.updateLeaderboard();
} catch (Exception ex) { } catch (NullPointerException ex) {
System.out.println("continue"); System.out.println("continue");
} }
} }

View File

@@ -23,9 +23,13 @@ public class FriendController {
private Button addButton; private Button addButton;
@FXML @FXML
private TextField userNameText; private TextField userNameText;
@FXML
private Button removeButton;
@FXML
private TextField removeUserNameText;
/** /**
* Signs up the user. * Add a new friend.
* @param event the click of the sign up button * @param event the click of the sign up button
*/ */
@FXML @FXML
@@ -58,8 +62,48 @@ public class FriendController {
String friendName = userNameText.getText(); String friendName = userNameText.getText();
Stage current = (Stage) owner; Stage current = (Stage) owner;
dashBoardController.updateAchievements(); dashBoardController.updateAchievements();
dashBoardController.updateFriends();
current.close(); current.close();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend added!", UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend added!",
userNameText.getText() + " is now your friend!"); userNameText.getText() + " is now your friend!");
} }
/**
* Removes one of the friends of the user.
* @param event the click of the sign up button
*/
@FXML
public void removeFriend(ActionEvent event) throws InterruptedException {
//set the window to the current window (for displaying the alerts)
Window owner = removeButton.getScene().getWindow();
//check if the username field is empty
if (removeUserNameText.getText().isEmpty()) {
//if so, display an alert
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
"Please enter a username!");
return;
} else if (removeUserNameText.getText().equals(userService.currentUser.getName())) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
"You are not your friend!");
return;
} else if (!userService.getFriendNames(userService.currentUser.getName())
.contains(removeUserNameText.getText())) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
"You do not have a friend with this username!");
return;
} else if (!userService.getAllUsers().contains(removeUserNameText.getText())) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
"The user does not exist!");
return;
}
//add friend to the current user
userService.removeFriend(userService.currentUser.getName(), removeUserNameText.getText());
//close the register window after the user has entered all the credentials
Stage current = (Stage) owner;
dashBoardController.updateFriends();
dashBoardController.updateAchievements();
current.close();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend removed!",
removeUserNameText.getText() + " is not your friend anymore!");
}
} }

View File

@@ -1,5 +1,6 @@
package greenify.client.controller; package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application; import greenify.client.Application;
import greenify.client.rest.UserService; import greenify.client.rest.UserService;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
@@ -7,8 +8,10 @@ import javafx.animation.Interpolator;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.KeyValue; import javafx.animation.KeyValue;
import javafx.animation.ParallelTransition; import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.animation.TranslateTransition; import javafx.animation.TranslateTransition;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
@@ -30,8 +33,10 @@ import javafx.stage.Window;
import javafx.util.Duration; import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.client.HttpClientErrorException;
import java.io.IOException; import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -46,6 +51,8 @@ public class RegisterWindowController {
@Autowired @Autowired
ExtraActivityController extraActivityController; ExtraActivityController extraActivityController;
@FXML
private Text explainText;
//navigation panes //navigation panes
@FXML @FXML
private AnchorPane getStartedPane; private AnchorPane getStartedPane;
@@ -159,6 +166,8 @@ public class RegisterWindowController {
private PasswordField passwordField2; private PasswordField passwordField2;
@FXML @FXML
private Button signUpButton; private Button signUpButton;
//@FXML //@FXML
//private Line uNamePathLine; //private Line uNamePathLine;
@@ -171,6 +180,8 @@ public class RegisterWindowController {
addSlideAnimation(1100, passwordField, 300); addSlideAnimation(1100, passwordField, 300);
TimeUnit.MILLISECONDS.sleep(300); TimeUnit.MILLISECONDS.sleep(300);
addSlideAnimation(1100, passwordField2, -420); addSlideAnimation(1100, passwordField2, -420);
signUpButton.setSkin(new RegisterButtonSkin(signUpButton));
} }
/** /**
@@ -186,12 +197,24 @@ public class RegisterWindowController {
slideIn.play(); slideIn.play();
} }
/**
* Shows an explanation of the application.
* @param event the click of the question mark button
*/
public void showExplanation(ActionEvent event) {
if (explainText.isVisible()) {
explainText.setVisible(false);
} else {
explainText.setVisible(true);
}
}
/** /**
* Signs up the user. * Signs up the user.
* @param event the click of the sign up button * @param event the click of the sign up button
*/ */
@FXML @FXML
public void handleSignUpButton(ActionEvent event) throws IOException { public void handleSignUpButton(ActionEvent event) throws IOException, NoSuchAlgorithmException {
//set the window to the current window (for displaying the alerts) //set the window to the current window (for displaying the alerts)
Window owner = signUpButton.getScene().getWindow(); Window owner = signUpButton.getScene().getWindow();
//check if the username field is empty //check if the username field is empty
@@ -221,7 +244,7 @@ public class RegisterWindowController {
//register the user with the provided username and password //register the user with the provided username and password
try { try {
userService.registerUser(userNameText.getText(), passwordField.getText()); userService.registerUser(userNameText.getText(), passwordField.getText());
} catch (Exception ex) { } catch (HttpClientErrorException ex) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
"This username has already been taken!"); "This username has already been taken!");
return; return;
@@ -486,7 +509,7 @@ public class RegisterWindowController {
} }
try { try {
extraActivityController.updateExtras(); extraActivityController.updateExtras();
} catch (Exception ex) { } catch (NullPointerException ex) {
System.out.println("Continue"); System.out.println("Continue");
} }
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName()); Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
@@ -612,4 +635,41 @@ public class RegisterWindowController {
carTravelElectricLabel.getText().replace(" km/Le", "")); carTravelElectricLabel.getText().replace(" km/Le", ""));
} }
} }
@SuppressWarnings("Duplicates")
public class RegisterButtonSkin extends ButtonSkin {
/**
* registers button skins.
* @param button clicking
*/
public RegisterButtonSkin(Button button) {
super(button);
ScaleTransition scaleUp = new ScaleTransition(Duration.millis(140));
scaleUp.setToX(1.2);
scaleUp.setToY(1.2);
scaleUp.setNode(button);
button.setOnMouseEntered(e -> scaleUp.playFromStart());
ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
scaleMiddleDown.setToX(1.1);
scaleMiddleDown.setToY(1.1);
scaleMiddleDown.setNode(button);
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
scaleMiddleUp.setToX(1.2);
scaleMiddleUp.setToY(1.2);
scaleMiddleUp.setNode(button);
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
ScaleTransition scaleDown = new ScaleTransition(Duration.millis(200));
scaleDown.setToX(1.0);
scaleDown.setToY(1.0);
scaleDown.setNode(button);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
} }

View File

@@ -1,7 +1,9 @@
package greenify.client.controller; package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application; import greenify.client.Application;
import greenify.client.rest.UserService; import greenify.client.rest.UserService;
import javafx.animation.ScaleTransition;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Parent; import javafx.scene.Parent;
@@ -12,10 +14,13 @@ import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.Window; import javafx.stage.Window;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.client.HttpClientErrorException;
import java.io.IOException; import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Objects; import java.util.Objects;
/** /**
@@ -35,6 +40,11 @@ public class UserController {
@FXML @FXML
private Button signUpButton; private Button signUpButton;
public void initialize() {
loginButton.setSkin(new LoginButtonSkin(loginButton));
signUpButton.setSkin(new LoginButtonSkin(signUpButton));
}
/** /**
* Handles when the user clicks on the login button. * Handles when the user clicks on the login button.
* it checks if the username and password fields are filled * it checks if the username and password fields are filled
@@ -43,8 +53,8 @@ public class UserController {
* @throws IOException an exception for logging in the user * @throws IOException an exception for logging in the user
*/ */
@FXML @FXML
protected void handleLoginButtonAction(ActionEvent event) throws IOException { protected void handleLoginButtonAction(ActionEvent event)
throws IOException, NoSuchAlgorithmException {
Window owner = loginButton.getScene().getWindow(); //get the current window Window owner = loginButton.getScene().getWindow(); //get the current window
if (usernameField.getText().isEmpty()) { if (usernameField.getText().isEmpty()) {
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
@@ -67,7 +77,7 @@ public class UserController {
//log the user in with the userService method //log the user in with the userService method
try { try {
userService.loginUser(usernameField.getText(), passwordField.getText()); userService.loginUser(usernameField.getText(), passwordField.getText());
} catch (RuntimeException ex) { } catch (HttpClientErrorException ex) {
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
"Your username or password is incorrect!"); "Your username or password is incorrect!");
return; return;
@@ -135,11 +145,51 @@ public class UserController {
Parent registerWindow = Application.load(this.getClass().getClassLoader() Parent registerWindow = Application.load(this.getClass().getClassLoader()
.getResource("fxml/RegisterWindow.fxml")); .getResource("fxml/RegisterWindow.fxml"));
Scene registerScene = new Scene(registerWindow); Scene registerScene = new Scene(registerWindow);
registerScene.getStylesheets().add(this.getClass().getClassLoader()
.getResource("stylesheets/registerWindowStyle.css").toExternalForm());
Stage registerStage = new Stage(); Stage registerStage = new Stage();
registerStage.setScene(registerScene); registerStage.setScene(registerScene);
registerStage.setTitle("Enter register credentials"); registerStage.setTitle("Enter register credentials");
registerStage.show(); registerStage.show();
} }
@SuppressWarnings("Duplicates")
public class LoginButtonSkin extends ButtonSkin {
/**
* method for the skin of login button.
* @param button clicking
*/
public LoginButtonSkin(Button button) {
super(button);
ScaleTransition scaleUp = new ScaleTransition(Duration.millis(140));
scaleUp.setToX(1.1);
scaleUp.setToY(1.1);
scaleUp.setNode(button);
button.setOnMouseEntered(e -> scaleUp.playFromStart());
ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
scaleMiddleDown.setFromX(1.1);
scaleMiddleDown.setFromY(1.1);
scaleMiddleDown.setToX(1.05);
scaleMiddleDown.setToY(1.05);
scaleMiddleDown.setNode(button);
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
scaleMiddleUp.setFromX(1.05);
scaleMiddleUp.setFromY(1.05);
scaleMiddleUp.setToX(1.1);
scaleMiddleUp.setToY(1.1);
scaleMiddleUp.setNode(button);
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
ScaleTransition scaleDown = new ScaleTransition(Duration.millis(200));
scaleDown.setToX(1.0);
scaleDown.setToY(1.0);
scaleDown.setNode(button);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
} }

View File

@@ -2,6 +2,7 @@ package greenify.client.rest;
import greenify.common.UserDto; import greenify.common.UserDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
@@ -12,6 +13,9 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -19,6 +23,9 @@ import java.util.Map;
public class UserService { public class UserService {
public UserDto currentUser; public UserDto currentUser;
@Value( "${server.address:http://localhost:8080}" )
String serverAddress = "http://localhost:8080";
@Autowired @Autowired
RestTemplate restTemplate; RestTemplate restTemplate;
@@ -36,16 +43,17 @@ public class UserService {
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
//this suppressWarnings is to get rid of the errors of duplicate code //this suppressWarnings is to get rid of the errors of duplicate code
//because the methods are very similar //because the methods are very similar
public UserDto registerUser(String name, String password) { public UserDto registerUser(String name, String password) throws NoSuchAlgorithmException {
//headers for http //headers for http
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
//set the accept header in JSON value //set the accept header in JSON value
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
//connect to the server with the needed url //connect to the server with the needed url
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/registerUser")
.queryParam("name", name) .queryParam("name", name)
//getting the name from the database //getting the name from the database
.queryParam("password", password); .queryParam("password", hashPassword(password));
//getting the password from the database //getting the password from the database
//create a http entity to be sent //create a http entity to be sent
@@ -67,13 +75,14 @@ public class UserService {
* @return a userDTO * @return a userDTO
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public UserDto loginUser(String name, String password) { public UserDto loginUser(String name, String password) throws NoSuchAlgorithmException {
//this method is almost the same as the registerUser one, but with a different link //this method is almost the same as the registerUser one, but with a different link
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/loginUser")
.queryParam("name", name) .queryParam("name", name)
.queryParam("password", password); .queryParam("password", hashPassword(password));
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
UserDto result = this.restTemplate.getForObject(builder.build() UserDto result = this.restTemplate.getForObject(builder.build()
@@ -92,7 +101,7 @@ public class UserService {
public void updateInput(String name, String inputName, String value) { public void updateInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(serverAddress + "/setInput")
.queryParam("name", name) .queryParam("name", name)
.queryParam("inputName", inputName) .queryParam("inputName", inputName)
.queryParam("value",value); .queryParam("value",value);
@@ -112,7 +121,8 @@ public class UserService {
public void updateExtraInput(String name, String inputName, String value) { public void updateExtraInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/setExtraInput")
.queryParam("name", name) .queryParam("name", name)
.queryParam("inputName", inputName) .queryParam("inputName", inputName)
.queryParam("value", value); .queryParam("value", value);
@@ -131,7 +141,8 @@ public class UserService {
public double getFootprint(String name) { public double getFootprint(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getFootprint")
.queryParam("name", name); .queryParam("name", name);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -149,7 +160,7 @@ public class UserService {
public double getFirstFootprint(String name) { public double getFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(serverAddress + "/getFirst")
.queryParam("name", name); .queryParam("name", name);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -168,7 +179,8 @@ public class UserService {
public Float saveFootprint(String name) { public Float saveFootprint(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFootprint") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/saveFootprint")
.queryParam("name", name); .queryParam("name", name);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -187,7 +199,8 @@ public class UserService {
public Float saveFirstFootprint(String name) { public Float saveFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFirstFootprint") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/saveFirstFootprint")
.queryParam("name", name); .queryParam("name", name);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -205,7 +218,8 @@ public class UserService {
public List<String> getFriendNames(String name) { public List<String> getFriendNames(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFriends") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getFriends")
.queryParam("name", name); .queryParam("name", name);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -223,7 +237,8 @@ public class UserService {
public void addFriend(String name, String friend) { public void addFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/addFriend")
.queryParam("name", name) .queryParam("name", name)
.queryParam("friend",friend); .queryParam("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
@@ -241,7 +256,8 @@ public class UserService {
public void removeFriend(String name, String friend) { public void removeFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/removeFriend") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/removeFriend")
.queryParam("name", name) .queryParam("name", name)
.queryParam("friend",friend); .queryParam("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
@@ -258,7 +274,8 @@ public class UserService {
public Map<String, String> getInputs(String name) { public Map<String, String> getInputs(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getInputs") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getInputs")
.queryParam("name", name); .queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -275,7 +292,8 @@ public class UserService {
public Map<String, String> getExtraInputs(String name) { public Map<String, String> getExtraInputs(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getExtraInputs")
.queryParam("name", name); .queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -293,7 +311,26 @@ public class UserService {
public Map getAchievements(String name) { public Map getAchievements(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getAchievements") UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getAchievements")
.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 results of a user.
* @param name name of the user
* @return Map with all results
*/
@SuppressWarnings("Duplicates")
public Map<String, String> getResults(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getResults")
.queryParam("name", name); .queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
@@ -308,11 +345,50 @@ public class UserService {
public List<String> getAllUsers() { public List<String> getAllUsers() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getAllUsers"); UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getAllUsers");
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
List<String> result = this.restTemplate.getForObject(builder List<String> result = this.restTemplate.getForObject(builder
.build().encode().toUri(), List.class); .build().encode().toUri(), List.class);
return result; return result;
} }
/**
* Removes a user from the database.
* @param name the username of the current user.
*/
@SuppressWarnings("Duplicates")
public void deleteAccount(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/deleteAccount")
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
}
/**
* Hashes the password of a user.
* @param password password of the user
* @return hashed password
* @throws NoSuchAlgorithmException when there is no such algorithm
*/
public String hashPassword(String password)
throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] encodedHash = digest.digest(password.getBytes(StandardCharsets.UTF_8));
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < encodedHash.length; i++) {
String hex = Integer.toHexString(0xff & encodedHash[i]);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
} }

View File

@@ -1,11 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?> <?import java.lang.*?>
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?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.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController"> <AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
<children> <children>
@@ -146,6 +161,24 @@
</Label> </Label>
<Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" /> <Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" />
<Line endX="79.0" layoutX="147.0" layoutY="14.0" stroke="#545b54" /> <Line endX="79.0" layoutX="147.0" layoutY="14.0" stroke="#545b54" />
<Text layoutX="296.0" layoutY="51.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome to Greenify!">
<font>
<Font name="System Bold" size="22.0" />
</font>
</Text>
<Text fx:id="explainText" layoutX="52.0" layoutY="456.0" strokeType="OUTSIDE" strokeWidth="0.0" text="This application will help you decrease your CO2-footprint. In the next screen, you will be asked to fill in certain things, like your yearly energy costs. These values will help us calculate your CO2-footprint. Warning: If you don't fill anything in, the calculator will use a default value based on averages, so if you want a value to be zero, please fill in zero. After that, you'll be able to see your score and compare your footprint to those of your friends. Let's go green and save the planet!" textAlignment="CENTER" visible="false" wrappingWidth="714.0">
<font>
<Font size="14.0" />
</font></Text>
<Button fx:id="showExplanation" layoutX="31.0" layoutY="534.0" mnemonicParsing="false" onAction="#showExplanation" prefHeight="63.0" prefWidth="52.0" style="-fx-background-color: transparent; -fx-padding: 0 0 0 0;">
<graphic>
<ImageView fitHeight="62.0" fitWidth="83.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/questionmark.png" />
</image>
</ImageView>
</graphic>
</Button>
</children></AnchorPane> </children></AnchorPane>
<AnchorPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false"> <AnchorPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
<children> <children>

View File

@@ -23,12 +23,7 @@
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" /> <Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" />
<Button fx:id="signUpButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" /> <Button fx:id="signUpButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" />
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" /> <PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
<Hyperlink alignment="CENTER" layoutX="384.0" layoutY="301.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="#3db25a" textOverrun="LEADING_WORD_ELLIPSIS"> <Text fill="#23773d" layoutX="20.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not a member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
<font>
<Font name="Corbel Bold" size="18.0" />
</font>
</Hyperlink>
<Text fill="#23773d" layoutX="20.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
<font> <font>
<Font name="Californian FB" size="20.0" /> <Font name="Californian FB" size="20.0" />
</font> </font>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
@@ -24,7 +25,7 @@
<Font size="13.0" /> <Font size="13.0" />
</font> </font>
</TextField> </TextField>
<Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9"> <Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" text="Sign up!" textFill="#c4eec9">
<font> <font>
<Font name="Corbel Bold" size="14.0" /> <Font name="Corbel Bold" size="14.0" />
</font> </font>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="287.0" prefWidth="187.0" style="-fx-background-color: #e2f0c8;" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.FriendController">
<children>
<Text fill="#00650d" layoutX="114.0" layoutY="64.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Remove Friend" textAlignment="CENTER" wrappingWidth="234.96600341796875">
<font>
<Font size="30.0" />
</font>
</Text>
<TextField fx:id="removeUserNameText" layoutX="140.0" layoutY="100.0" prefHeight="35.0" prefWidth="183.0" promptText="Username">
<font>
<Font size="13.0" />
</font>
</TextField>
<Button fx:id="removeButton" layoutX="206.0" layoutY="154.0" mnemonicParsing="false" onAction="#removeFriend" style="-fx-background-color: #005e07;" text="Remove!" textFill="#c4eec9">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
</Button>
<ImageView fitHeight="80.0" fitWidth="349.0" layoutY="211.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/grass.png"/>
</image>
</ImageView>
<ImageView fitHeight="150.0" fitWidth="200.0" layoutY="43.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/friends.png" />
</image>
</ImageView>
</children>
</AnchorPane>

View File

@@ -1,12 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?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.chart.PieChart?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
@@ -23,9 +16,8 @@
<?import javafx.scene.shape.Line?> <?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<?import javafx.scene.control.Tooltip?>
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController"> <AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
<children> <children>
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;"> <AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
<children> <children>
@@ -63,7 +55,6 @@
<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="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 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" /> <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" />
<Line endX="104.0" layoutX="105.0" layoutY="271.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
<Line endX="104.0" layoutX="106.0" layoutY="270.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" /> <Line endX="104.0" layoutX="106.0" layoutY="270.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4"> <Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4">
<font> <font>
@@ -84,6 +75,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Line endX="104.0" layoutX="108.0" layoutY="88.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
</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"> <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> <children>
@@ -241,71 +233,83 @@
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
</Label> </Label>
<Pane layoutX="545.0" layoutY="130.0" prefHeight="342.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;"> <Pane layoutX="545.0" layoutY="130.0" prefHeight="255.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children> <children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="26.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="14.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </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"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="60.0" prefHeight="46.0" prefWidth="115.0" text="Grains/baked &#10;foods" textAlignment="CENTER">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="154.0" prefHeight="46.0" prefWidth="115.0" text="Dairy"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="106.0" prefHeight="46.0" prefWidth="115.0" text="Dairy">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="218.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="152.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="282.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="198.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label fx:id="meat" layoutX="171.0" layoutY="41.0" styleClass="activityField" text="Label" /> <Label fx:id="meat" layoutX="171.0" layoutY="29.0" styleClass="activityField" text="Label" />
<Label fx:id="grains" layoutX="171.0" layoutY="105.0" styleClass="activityField" text="Label" /> <Label fx:id="grains" layoutX="171.0" layoutY="75.0" styleClass="activityField" text="Label" />
<Label fx:id="dairy" layoutX="171.0" layoutY="169.0" styleClass="activityField" text="Label" /> <Label fx:id="dairy" layoutX="171.0" layoutY="121.0" styleClass="activityField" text="Label" />
<Label fx:id="fruits" layoutX="171.0" layoutY="233.0" styleClass="activityField" text="Label" /> <Label fx:id="fruits" layoutX="171.0" layoutY="167.0" styleClass="activityField" text="Label" />
<Label fx:id="snacks" layoutX="171.0" layoutY="297.0" styleClass="activityField" text="Label" /> <Label fx:id="snacks" layoutX="171.0" layoutY="213.0" styleClass="activityField" text="Label" />
</children> </children>
</Pane> </Pane>
<Label alignment="CENTER" layoutX="545.0" layoutY="488.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222"> <Label alignment="CENTER" layoutX="545.0" layoutY="385.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
</Label> </Label>
<Pane layoutX="545.0" layoutY="520.0" prefHeight="129.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;"> <Pane layoutX="545.0" layoutY="412.0" prefHeight="238.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children> <children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="7.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.0" layoutY="56.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="localProduce" layoutX="189.0" layoutY="56.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"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.0" layoutY="92.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="bike" layoutX="189.0" layoutY="92.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"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="164.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="loweringTemp" layoutX="188.0" layoutY="164.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"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="200.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<Label fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="solarPanels" layoutX="188.0" layoutY="200.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="128.0" prefHeight="27.0" prefWidth="183.0" text="Using public transport">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="publicTrans" layoutX="188.0" layoutY="128.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="11.0" layoutY="20.0" prefHeight="27.0" prefWidth="183.0" text="Eating vegetarian meal">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="veganMeal" layoutX="188.0" layoutY="20.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
</children> </children>
</Pane> </Pane>
<Button fx:id="addExtraActivityButton2" contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219"> <Button fx:id="addExtraActivityButton2" contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219">
@@ -447,16 +451,11 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<TableView fx:id="globalLeaderboard" layoutX="56.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0"> <TableView fx:id="globalLeaderboard" layoutX="53.0" layoutY="220.0" prefHeight="334.0" prefWidth="207.0">
<columns> <columns>
<TableColumn fx:id="globalPlace" prefWidth="30.0" text="#" />
<TableColumn fx:id="globalUser" prefWidth="75.0" text="User" /> <TableColumn fx:id="globalUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="globalScore" prefWidth="124.0" text="Score" /> <TableColumn fx:id="globalScore" prefWidth="100.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> </columns>
</TableView> </TableView>
<Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616"> <Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616">
@@ -558,6 +557,13 @@
</Button> </Button>
</children> </children>
</GridPane> </GridPane>
<TableView fx:id="developmentLeaderboard" layoutX="292.0" layoutY="220.0" prefHeight="334.0" prefWidth="207.0">
<columns>
<TableColumn fx:id="developmentPlace" prefWidth="30.0" text="#" />
<TableColumn fx:id="developmentUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="developmentScore" prefWidth="100.0" text="Score" />
</columns>
</TableView>
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
@@ -572,7 +578,7 @@
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
</Text> </Text>
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;"> <TableView fx:id="friendsTable" layoutX="60.0" layoutY="170.0" prefHeight="426.0" prefWidth="214.0" style="-fx-background-color: #e1fcd9;">
<columns> <columns>
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" /> <TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" /> <TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
@@ -586,15 +592,40 @@
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
</Text> </Text>
<TableView fx:id="friendLeaderboard" layoutX="300.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;"> <TableView fx:id="friendLeaderboard" layoutX="300.0" layoutY="170.0" prefHeight="426.0" prefWidth="232.0" style="-fx-background-color: #e1fcd9;">
<columns> <columns>
<TableColumn fx:id="friendUser" prefWidth="107.0" text="Friend" /> <TableColumn fx:id="friendPlace" prefWidth="30.0" resizable="false" text="#" />
<TableColumn fx:id="friendScore" prefWidth="108.0" text="Score" /> <TableColumn fx:id="friendUser" minWidth="30.0" prefWidth="100.0" resizable="false" text="Friend" />
<TableColumn fx:id="friendScore" minWidth="30.0" prefWidth="100.0" resizable="false" text="Score" />
</columns> </columns>
<columnResizePolicy> <columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy> </columnResizePolicy>
</TableView> </TableView>
<Button fx:id="addFriend" contentDisplay="RIGHT" layoutX="575.0" layoutY="75.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>
<Button fx:id="removeFriend" contentDisplay="RIGHT" layoutX="560.0" layoutY="150.0" mnemonicParsing="false" onAction="#openRemoveFriend" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Remove friend" textFill="#29721a">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="70.0" fitWidth="60.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/remove_friend.png" />
</image>
</ImageView>
</graphic>
</Button>
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
@@ -8,63 +9,6 @@
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController"> <AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
<children> <children>
<AnchorPane prefHeight="611.0" prefWidth="107.0">
<children>
<Button fx:id="displayVeganMealButton" contentDisplay="TOP" layoutX="14.0" layoutY="62.0" mnemonicParsing="false" onAction="#displayVeganMeal" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
<image>
<Image url="@../icons/icons8-vegan-food-100.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayLocalProduceButton" contentDisplay="TOP" layoutX="14.0" layoutY="143.0" mnemonicParsing="false" onAction="#displayLocalProduce" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
<image>
<Image url="@../icons/localProduce.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayBikeButton" contentDisplay="TOP" layoutX="14.0" layoutY="224.0" mnemonicParsing="false" onAction="#displayBike" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-bicycle-filled-100.png" />
</image>
</ImageView>
</graphic></Button>
<Button fx:id="displaySolarPanelButton" contentDisplay="TOP" layoutX="14.0" layoutY="467.0" mnemonicParsing="false" onAction="#displaySolarPanel" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-solar-panel-filled-100.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayTemperatureButton" contentDisplay="TOP" layoutX="14.0" layoutY="386.0" mnemonicParsing="false" onAction="#displayTemperature" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-temperature-inside-64.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayPublicTransportButton" contentDisplay="TOP" layoutX="14.0" layoutY="305.0" mnemonicParsing="false" onAction="#displayPublicTransport" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
<image>
<Image url="@../icons/publicTransport.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="veganMealPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0"> <AnchorPane fx:id="veganMealPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0">
<children> <children>
<Line fx:id="line1" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" /> <Line fx:id="line1" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
@@ -223,7 +167,7 @@
<AnchorPane fx:id="publicTransportPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false"> <AnchorPane fx:id="publicTransportPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
<children> <children>
<Line fx:id="line21" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" /> <Line fx:id="line21" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
<Text layoutX="153.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Using your public transport instead of your car"> <Text layoutX="153.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Using public transport instead of your car">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@@ -257,5 +201,62 @@
</HBox> </HBox>
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane prefHeight="611.0" prefWidth="107.0">
<children>
<Button fx:id="displayVeganMealButton" contentDisplay="TOP" layoutX="14.0" layoutY="62.0" mnemonicParsing="false" onAction="#displayVeganMeal" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
<image>
<Image url="@../icons/icons8-vegan-food-100.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayLocalProduceButton" contentDisplay="TOP" layoutX="14.0" layoutY="143.0" mnemonicParsing="false" onAction="#displayLocalProduce" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
<image>
<Image url="@../icons/localProduce.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayBikeButton" contentDisplay="TOP" layoutX="14.0" layoutY="224.0" mnemonicParsing="false" onAction="#displayBike" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-bicycle-filled-100.png" />
</image>
</ImageView>
</graphic></Button>
<Button fx:id="displaySolarPanelButton" contentDisplay="TOP" layoutX="14.0" layoutY="467.0" mnemonicParsing="false" onAction="#displaySolarPanel" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-solar-panel-filled-100.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayTemperatureButton" contentDisplay="TOP" layoutX="14.0" layoutY="386.0" mnemonicParsing="false" onAction="#displayTemperature" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-temperature-inside-64.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="displayPublicTransportButton" contentDisplay="TOP" layoutX="14.0" layoutY="305.0" mnemonicParsing="false" onAction="#displayPublicTransport" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
<graphic>
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
<image>
<Image url="@../icons/publicTransport.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
</children> </children>
</AnchorPane> </AnchorPane>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -3,3 +3,11 @@
-fx-text-fill: #c4eec9; -fx-text-fill: #c4eec9;
-fx-font-weight: bold; -fx-font-weight: bold;
} }
.button:hover {
-fx-background-color: #027009;
}
.button:pressed {
-fx-background-color: #1ba023;
}

View File

@@ -1,15 +1,17 @@
import static org.junit.Assert.assertEquals;
import greenify.client.Friend; import greenify.client.Friend;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import static org.junit.Assert.*;
public class FriendTest { public class FriendTest {
@Test @Test
public void setAndGetTest() { public void setAndGetTest() {
Friend test = new Friend("ceren", 10.0); Friend test = new Friend(1,"ceren", 10.0);
test.setPlace(1);
test.setFriend("greenify"); test.setFriend("greenify");
test.setScore(15.0); test.setScore(15.0);
Assertions.assertEquals(test.getPlace(), 1);
assertEquals(test.getFriend(), "greenify"); assertEquals(test.getFriend(), "greenify");
Assertions.assertEquals(test.getScore(), 15.0); Assertions.assertEquals(test.getScore(), 15.0);
} }

View File

@@ -1,5 +1,6 @@
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import greenify.client.Hints; import greenify.client.Hints;
import org.junit.Test; import org.junit.Test;
@@ -15,7 +16,7 @@ public class HintsTest {
public void hintsContainsTest() { public void hintsContainsTest() {
Hints test = new Hints(); Hints test = new Hints();
assertTrue(test.hints.contains("27,000 trees are cut down " 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 @Test
@@ -24,6 +25,20 @@ public class HintsTest {
String random = test.randomHint(); String random = test.randomHint();
assertTrue(test.hints.contains(random)); 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);
}
} }

View File

@@ -1,3 +1,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import greenify.client.rest.UserService; import greenify.client.rest.UserService;
import greenify.common.UserDto; import greenify.common.UserDto;
import org.junit.Test; import org.junit.Test;
@@ -14,9 +17,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class UserServiceTest { public class UserServiceTest {
@@ -30,7 +30,7 @@ public class UserServiceTest {
@Test @Test
public void userRegisterTest() throws Exception { public void userRegisterTest() throws Exception {
UserDto testUser = new UserDto(1L, "Eric"); UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=password"), Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"),
UserDto.class)) UserDto.class))
.thenReturn(testUser); .thenReturn(testUser);
@@ -41,7 +41,7 @@ public class UserServiceTest {
@Test @Test
public void userLoginTest() throws Exception { public void userLoginTest() throws Exception {
UserDto testUser = new UserDto(1L, "Eric"); UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"), Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"),
UserDto.class)) UserDto.class))
.thenReturn(testUser); .thenReturn(testUser);
UserDto user = userService.loginUser("Eric", "password"); UserDto user = userService.loginUser("Eric", "password");
@@ -152,8 +152,6 @@ public class UserServiceTest {
@Test @Test
public void removeFriendTest() throws Exception { public void removeFriendTest() throws Exception {
userService.addFriend("Eric", "Ceren");
Mockito.verify(userService).addFriend("Eric", "Ceren");
userService.removeFriend("Eric", "Ceren"); userService.removeFriend("Eric", "Ceren");
Mockito.verify(userService).removeFriend("Eric", "Ceren"); Mockito.verify(userService).removeFriend("Eric", "Ceren");
} }
@@ -163,6 +161,18 @@ public class UserServiceTest {
userService.getAchievements("mika"); userService.getAchievements("mika");
Mockito.verify(userService).getAchievements("mika"); Mockito.verify(userService).getAchievements("mika");
} }
@Test
public void getResultsTest() throws Exception {
userService.getResults("mika");
Mockito.verify(userService).getResults("mika");
}
@Test
public void deleteAccountTest() throws Exception {
userService.deleteAccount("merel");
Mockito.verify(userService).deleteAccount("merel");
}
} }

View File

@@ -7,6 +7,19 @@ buildscript {
} }
} }
plugins {
id "com.heroku.sdk.heroku-gradle" version "1.0.4"
}
heroku {
appName = "greenify43"
includes = ["${buildDir}/libs/greenify-server-1.0.0.jar"]
includeBuildDir = false
processTypes(
web: "java -Dserver.port=\$PORT -jar src/Server/build/libs/greenify-server-1.0.0.jar"
)
}
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'idea' apply plugin: 'idea'
@@ -16,8 +29,8 @@ apply plugin: 'jacoco'
apply plugin: 'checkstyle' apply plugin: 'checkstyle'
bootJar { bootJar {
baseName = 'gs-rest-service' baseName = 'greenify-server'
version = '0.1.0' version = '1.0.0'
} }
test { test {

View File

@@ -209,7 +209,6 @@ public class User {
throw new ApplicationException("Cannot add yourself as a friend"); throw new ApplicationException("Cannot add yourself as a friend");
} else { } else {
friends.add(user); friends.add(user);
System.out.print("Friend added!");
} }
} }
@@ -222,7 +221,6 @@ public class User {
throw new ApplicationException("This user is not your friend!"); throw new ApplicationException("This user is not your friend!");
} else { } else {
friends.remove(user); friends.remove(user);
System.out.print("Friend removed");
} }
} }

View File

@@ -114,7 +114,6 @@ public class UserController {
*/ */
@RequestMapping("/getFirst") @RequestMapping("/getFirst")
public Float getFirstFootprint(@RequestParam(value = "name") String name) { public Float getFirstFootprint(@RequestParam(value = "name") String name) {
System.out.println("hello");
Float footprint = userService.getFirstFootprint(name); Float footprint = userService.getFirstFootprint(name);
return footprint; return footprint;
} }
@@ -185,5 +184,24 @@ public class UserController {
public Map<String, Boolean> getAchievements(@RequestParam(value = "name") String name) { public Map<String, Boolean> getAchievements(@RequestParam(value = "name") String name) {
return userService.getAchievements(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<String, String> getResults(@RequestParam(value = "name") String name) {
return userService.getResults(name);
}
/**
* This method deletes a user from the database.
* @param name name of the user
*/
@RequestMapping("/deleteAccount")
public void deleteAccount(@RequestParam(value = "name") String name) {
userService.deleteAccount(name);
}
} }

View File

@@ -38,6 +38,8 @@ public class AchievementService {
public void achieveSocialButterfly(User user) { public void achieveSocialButterfly(User user) {
if (user.getFriends().size() >= 3) { if (user.getFriends().size() >= 3) {
userService.setAchievement(user.getName(), "Social butterfly", true); userService.setAchievement(user.getName(), "Social butterfly", true);
} else {
userService.setAchievement(user.getName(), "Social butterfly", false);
} }
} }
@@ -48,6 +50,8 @@ public class AchievementService {
public void achieveGreenSaver(User user) { public void achieveGreenSaver(User user) {
if (20 > user.getFootPrint()) { if (20 > user.getFootPrint()) {
userService.setAchievement(user.getName(), "Green saver", true); userService.setAchievement(user.getName(), "Green saver", true);
} else {
userService.setAchievement(user.getName(), "Green saver", false);
} }
} }
@@ -59,6 +63,8 @@ public class AchievementService {
int vegan = Integer.parseInt(user.getExtraInputs().get("vegan")); int vegan = Integer.parseInt(user.getExtraInputs().get("vegan"));
if (vegan > 10) { if (vegan > 10) {
userService.setAchievement(user.getName(), "Animal friend", true); userService.setAchievement(user.getName(), "Animal friend", true);
} else {
userService.setAchievement(user.getName(), "Animal friend", false);
} }
} }
@@ -70,6 +76,8 @@ public class AchievementService {
int bike = Integer.parseInt(user.getExtraInputs().get("bike")); int bike = Integer.parseInt(user.getExtraInputs().get("bike"));
if (bike > 15) { if (bike > 15) {
userService.setAchievement(user.getName(), "Tom Dumoulin", true); userService.setAchievement(user.getName(), "Tom Dumoulin", true);
} else {
userService.setAchievement(user.getName(), "Tom Dumoulin", false);
} }
} }
@@ -78,9 +86,11 @@ public class AchievementService {
* @param user user for whom achiev6 changes * @param user user for whom achiev6 changes
*/ */
public void achieveLetItShine(User user) { public void achieveLetItShine(User user) {
int solar_panels = Integer.parseInt(user.getExtraInputs().get("solar_panels")); int solarPanels = Integer.parseInt(user.getExtraInputs().get("solar_panels"));
if (solar_panels >= 2) { if (solarPanels >= 2) {
userService.setAchievement(user.getName(), "Let it shine", true); userService.setAchievement(user.getName(), "Let it shine", true);
} else {
userService.setAchievement(user.getName(), "Let it shine", false);
} }
} }

View File

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -62,7 +63,6 @@ public class CalculatorService {
.indexOf("<result_grand_total>") .indexOf("<result_grand_total>")
+ 20, response.getBody().indexOf("</result_grand_total>")); + 20, response.getBody().indexOf("</result_grand_total>"));
// to do: in not HTTP 200 or exception case throws exception // to do: in not HTTP 200 or exception case throws exception
System.out.println(Float.parseFloat(result));
return Float.parseFloat(result); return Float.parseFloat(result);
} }
@@ -108,5 +108,48 @@ public class CalculatorService {
inputs.put("input_footprint_shopping_goods_total", netShopping + ""); inputs.put("input_footprint_shopping_goods_total", netShopping + "");
user.setFootPrintInputs(inputs); user.setFootPrintInputs(inputs);
} }
/**
* Gets the result of the CO2-calculation from the CoolClimate website
* @param map results that the user filled in
* @return the results from the website.
*/
public Map<String, String> getResults(Map<String, String> map) {
HttpHeaders headers = new HttpHeaders();
headers.set("accept", MediaType.APPLICATION_JSON_VALUE);
headers.set("app_id", "a98272e3");
headers.set("app_key", "b9167c4918cb2b3143614b595065d83b");
HttpEntity<String> 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<String> response = restTemplate
.exchange(builder.build().encode().toUri(), HttpMethod.GET,
entity, String.class);
String transport = response.getBody().substring(Objects.requireNonNull(response.getBody())
.indexOf("<result_transport_total>")
+ 24, response.getBody().indexOf("</result_transport_total>"));
String housing = response.getBody().substring(Objects.requireNonNull(response.getBody())
.indexOf("<result_housing_total>")
+ 22, response.getBody().indexOf("</result_housing_total>"));
String food = response.getBody().substring(Objects.requireNonNull(response.getBody())
.indexOf("<result_food_total>")
+ 19, response.getBody().indexOf("</result_food_total>"));
String goods = response.getBody().substring(Objects.requireNonNull(response.getBody())
.indexOf("<result_goods_total>")
+ 20, response.getBody().indexOf("</result_goods_total>"));
String services = response.getBody().substring(Objects.requireNonNull(response.getBody())
.indexOf("<result_services_total>")
+ 23, response.getBody().indexOf("</result_services_total>"));
Map<String, String> 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;
}
} }

View File

@@ -280,6 +280,17 @@ public class UserService {
return user.getAchievements(); 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<String, String> getResults(String name) {
User user = userRepository.findByName(name);
Map<String, String> results = calculatorService.getResults(user.getFootPrintInputs());
return results;
}
/** /**
* This method gets the list of all users. * This method gets the list of all users.
* @return list of all users * @return list of all users
@@ -292,4 +303,15 @@ public class UserService {
} }
return result; return result;
} }
/**
* This method gets the list of all users.
*/
public void deleteAccount(String name) {
User user = userRepository.findByName(name);
if (user == null) {
throw new ApplicationException("User doesn't exist");
}
userRepository.delete(user);
}
} }

View File

@@ -250,4 +250,28 @@ public class UserControllerTest {
assertEquals("mika", arg1Captor.getValue()); assertEquals("mika", arg1Captor.getValue());
} }
@Test
public void getResultsTest() throws Exception {
ArgumentCaptor<String> 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());
}
@Test
public void deleteAccountTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/deleteAccount")
.param("name", "merel")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
verify(userService, times(1)).deleteAccount(arg1Captor.capture());
assertEquals("merel", arg1Captor.getValue());
}
} }

View File

@@ -173,4 +173,138 @@ public class CalculatorServiceTest {
Float footPrint = service.invokeExternalService(map); Float footPrint = service.invokeExternalService(map);
Assert.assertEquals(new Float(11421.537), footPrint); Assert.assertEquals(new Float(11421.537), footPrint);
} }
@Test
public void getResultsTest() {
CalculatorService service = new CalculatorService();
service.restTemplate = new RestTemplate();
Map<String,String> map = new HashMap<String, String>() {{
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<String, String> 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<String, String> footPrint = service.getResults(map);
Assert.assertEquals(result, footPrint);
}
} }

View File

@@ -2,6 +2,9 @@ package greenify.server.service;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import greenify.common.ApplicationException; import greenify.common.ApplicationException;
@@ -326,4 +329,17 @@ public class UserServiceTest {
public void getAchievementsTest() { public void getAchievementsTest() {
assertEquals(AllAchievements.getDefaults(), userService.getAchievements("alex")); assertEquals(AllAchievements.getDefaults(), userService.getAchievements("alex"));
} }
@Test
public void deleteAccountException() {
assertThrows(ApplicationException.class, () -> userService.deleteAccount("merel"));
}
@Test
public void deleteAccount() {
User alex = new User(1L, "alex", "password");
doNothing().when(userRepository).delete(alex);
userService.deleteAccount("alex");
verify(userRepository, times(1)).delete(alex);
}
} }