204 Commits
v0.2 ... master

Author SHA1 Message Date
Merel Steenbergen
dfb65131e2 Merge branch 'Test/common' into 'master'
Add/package in client to make code coverage clearer.

See merge request cse1105/2018-2019/oopp-group-43/template!94
2019-04-15 12:40:21 +00:00
Merel Steenbergen
6faa5edd57 FIX::Checkstyle error.java 2019-04-15 12:38:57 +00:00
Ceren Ugurlu
2f2a9ba9fc Replace coverage report 2019-04-15 12:34:30 +00:00
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
Merel Steenbergen
f31449508e ADD::Package for features to make test coverage clearer 2019-04-15 14:24:20 +02:00
Sem van der Hoeven
b266160e93 ADD::added animations to buttons on friends pane 2019-04-15 14:17:22 +02:00
Merel Steenbergen
a44907865c ADD:: Test for ApplicationException. 2019-04-15 14:16:18 +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
Sem van der Hoeven
5653800d47 ADD::Added notes for week 9 2019-04-08 16:15:44 +02: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
Sem van der Hoeven
a715babcd9 ADD::added first part of notes week 9 2019-04-08 15:50:08 +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
Sem van der Hoeven
9fc42247da EDIT::added required values to saving co2 and using bike achievements 2019-04-08 15:33:18 +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
Sem van der Hoeven
3cc01e4f4a EDIT::added style to logout button 2019-04-08 15:02:15 +02:00
Ceren Ugurlu
7043f7253d Merge branch 'fix/sorting_bugs' into 'master'
Fix sorting bugs

See merge request cse1105/2018-2019/oopp-group-43/template!76
2019-04-08 12:37:57 +00:00
Sem van der Hoeven
83611c4ecc Merge branch 'add/activity_tooltips' into 'master'
Add/activity tooltips

See merge request cse1105/2018-2019/oopp-group-43/template!75
2019-04-08 12:36:45 +00:00
cugurlu
b99b66b87b Fix sorting errors 2019-04-08 14:34:38 +02:00
Sem van der Hoeven
3e7fbeae75 EDIT::Update .gitlab-ci.yml
undid code coverage part
2019-04-08 12:27:06 +00:00
Sem van der Hoeven
839292ad91 EDIT::Update .gitlab-ci.yml
added code coverage
2019-04-08 12:26:23 +00:00
Sem van der Hoeven
6ba21c331d FIX::fixed compileJava build failing
the last merge undid the change of this line, this should fix it
2019-04-08 14:21:20 +02:00
Sem van der Hoeven
0cda63cacb Merge branch 'add/activity_tooltips' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template into add/activity_tooltips
sourceTree needed to merge this?
2019-04-08 14:19:06 +02:00
Sem van der Hoeven
79fd69503c FIX::fixed complieJava build failing 2019-04-08 14:17:06 +02:00
Sem van der Hoeven
cbf15d9574 Merge branch 'master' into 'add/activity_tooltips'
# Conflicts:
#   src/Client/src/main/java/greenify/client/controller/DashBoardController.java
#   src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java
2019-04-08 12:13:44 +00:00
Mika Wauben
8667f65e33 Merge branch 'update/doc' into 'master'
Update/doc

See merge request cse1105/2018-2019/oopp-group-43/template!74
2019-04-08 12:07:27 +00:00
Mika Wauben
544b756e70 Update/doc 2019-04-08 12:07:27 +00:00
Sem van der Hoeven
18a0973af4 EDIT::added style to tooltips and reduced delay between hovering over the achievement and the tooltip appearing
EDIT::fixed some checkstyle warnings
2019-04-08 14:00:21 +02:00
Sem van der Hoeven
9e37421d6d ADD::added tooltip texts to all achievements 2019-04-08 13:08:20 +02:00
Sem van der Hoeven
31def99398 ADD::added buttons to apply tooltips to for the activities
because you can't apply tooltips to imageviews, I added the achievement images to buttons to which you can add tooltips
2019-04-08 12:55:32 +02:00
Ceren Ugurlu
dbe6fc4e33 Delete README.md 2019-04-08 10:38:36 +00:00
Ceren Ugurlu
231c580f7a Merge branch 'connect_new_extras' into 'master'
Fix errors for new extras and upload docs

See merge request cse1105/2018-2019/oopp-group-43/template!73
2019-04-08 09:27:16 +00:00
cugurlu
7867853cdb Upload coverage report 2019-04-08 11:18:04 +02:00
cugurlu
39b108626b Upload checkstyle report 2019-04-08 11:17:49 +02:00
cugurlu
8195650226 Fix all errors for extra activities 2019-04-08 11:17:34 +02:00
cugurlu
9310674301 Fix checkstyle errors 2019-04-08 11:17:02 +02:00
Sem van der Hoeven
2025fd02cc Merge branch 'feature/localProduce_and_publicTransport' into 'master'
feature/buying local produce and using public transport

See merge request cse1105/2018-2019/oopp-group-43/template!70
2019-04-07 17:57:01 +00:00
Ceren Ugurlu
55fe2b6795 Merge branch 'develop_achievements' into 'master'
Develop achievements

See merge request cse1105/2018-2019/oopp-group-43/template!72
2019-04-07 16:00:55 +00:00
Sem van der Hoeven
b05b0ecaf7 DELETE::deleted the confirm methods for the extra activities
this should fix the build failing
2019-04-07 17:55:57 +02:00
cugurlu
e1489bda27 Update controllers for new properties of achievements 2019-04-07 15:51:27 +02:00
cugurlu
a2805c2a9f Update dashboard.fxml 2019-04-07 15:50:31 +02:00
cugurlu
16fb86c513 Update achievements in userService 2019-04-07 15:49:51 +02:00
cugurlu
1cd46940cf Add new achievement photos 2019-04-07 15:48:55 +02:00
Sem van der Hoeven
e9efdf5f24 Merge branch 'master' into 'feature/localProduce_and_publicTransport'
# Conflicts:
#   src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java
#   src/Client/src/main/resources/fxml/extraActivities.fxml
2019-04-07 12:16:42 +00:00
Ceren Ugurlu
86ec4bbd7d Merge branch 'update_calculator' into 'master'
Update calculator and new tests

See merge request cse1105/2018-2019/oopp-group-43/template!71
2019-04-06 21:57:33 +00:00
cugurlu
d210e22788 Fix ButtonSkin error 2019-04-06 22:35:13 +02:00
cugurlu
1cf3af45be Add many new tests 2019-04-06 22:30:46 +02:00
cugurlu
24be00d28a Update methods for extras 2019-04-06 21:29:49 +02:00
cugurlu
e30f312c6a Update calculator methods for new changes 2019-04-06 21:26:52 +02:00
cugurlu
95d5b2b971 Fix the number of decimal points of footprints 2019-04-06 21:26:17 +02:00
Sem van der Hoeven
c0e0063465 ADD::added animations to buttons in login and register window 2019-04-06 21:05:19 +02:00
Sem van der Hoeven
61a99d47d1 ADD::added local produce and public transport sections to the extra activities section
added the panes and designated buttons

ADD::added placeholder methods for communicating adding the activities to the server
2019-04-06 20:20:01 +02:00
Sem van der Hoeven
6cbabbdf8d Merge branch 'update/achievements' into 'master'
Update/achievements

See merge request cse1105/2018-2019/oopp-group-43/template!68
2019-04-06 17:20:49 +00:00
Mika Wauben
2a873a78c9 Merge branch 'master' into 'update/achievements'
# Conflicts:
#   src/Server/src/main/java/greenify/server/service/AchievementService.java
2019-04-06 14:18:45 +00:00
mlwauben
0e546bc25c FIX:: checkstyle 2019-04-06 16:14:17 +02:00
mlwauben
4293790ece FIX:: wrong test 2019-04-06 15:42:14 +02:00
Mika Wauben
290694c5f1 Merge branch 'Feature/logoutbutton' into 'master'
ADD:: logout button

See merge request cse1105/2018-2019/oopp-group-43/template!67
2019-04-06 13:37:35 +00:00
mlwauben
eeb0fd9d57 ADD:: extra achievements and tests 2019-04-06 15:36:44 +02:00
Ceren Ugurlu
733c0c5920 Merge branch 'Test/achievement' into 'master'
Test/achievement

See merge request cse1105/2018-2019/oopp-group-43/template!66
2019-04-06 10:40:14 +00:00
mlwauben
238c00ff46 DEBUG:: logoutbutton 2019-04-06 11:05:06 +02:00
mlwauben
4433d509bb ADD:: new achievements 2019-04-06 10:33:36 +02:00
mlwauben
0f9cd14036 ADD:: line thingy above the logout button 2019-04-06 09:18:24 +02:00
mlwauben
9af14e6015 ADD:: logout button 2019-04-06 09:00:20 +02:00
Merel Steenbergen
bce08eb6f2 DELETE::Wrong import that gave an error 2019-04-05 20:40:50 +02:00
Merel Steenbergen
dcb8404ae7 ADD::Method for achievement social butterfly 2019-04-05 20:37:54 +02:00
Merel Steenbergen
82fd016590 FIX::No longer use Mockito for AchievementService in AchievementServiceTest 2019-04-05 20:30:31 +02:00
Merel Steenbergen
ccbe5968da EDIT::Finding bugs in tests and try to fix them 2019-04-05 20:21:42 +02:00
Merel Steenbergen
adb8406d4e ADD::Some tests to achievement class 2019-04-05 19:59:57 +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
Merel Steenbergen
7228252169 Merge branch 'add/add_random_hints_to_GUI' into 'master'
add/added hints to GUI

See merge request cse1105/2018-2019/oopp-group-43/template!65
2019-04-05 14:49:28 +00:00
Merel Steenbergen
27a18659f8 Merge branch 'Feature/alerts' into 'master'
Feature/alerts

See merge request cse1105/2018-2019/oopp-group-43/template!64
2019-04-05 14:49:23 +00:00
Merel Steenbergen
f2501f3624 FIX::Resolve a merge conflict with DashBoardController 2019-04-05 13:18:21 +00:00
Sem van der Hoeven
2b7d51a5ed EDIT::edited font size of random hints 2019-04-05 13:13:27 +02:00
Sem van der Hoeven
75faf4ae8c ADD:added nodes and methods to display random hints to on the GUI
ADD::added refresh button to get a new hint

EDIT::edited hints to work with the GUI
2019-04-05 13:11:17 +02:00
Sem van der Hoeven
06daa4776f ADD::added animations to buttons on dashboard screen
EDIT::changed labels of distance in activities overview to km and km/L

EDIT::made firstCalculator.fxml have the right distance units and added the new extra activities screen
2019-04-05 09:54:34 +02:00
Sem van der Hoeven
4b07aa8072 EDIT::changed achievement picture, removed trademark and added it into the code 2019-04-05 09:24:58 +02:00
Merel Steenbergen
8927b78098 FIX:: Forgot to uncomment something. Pipeline should now work 2019-04-04 21:02:06 +02:00
Merel Steenbergen
1f12291398 FIX::Import error 2019-04-04 21:00:37 +02:00
Merel Steenbergen
1684068385 FIX::More CheckStyle errors 2019-04-04 20:59:08 +02:00
Merel Steenbergen
e929680477 Merge branch 'Feature/alerts' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template into Feature/alerts 2019-04-04 20:55:10 +02:00
Merel Steenbergen
f23fc2cbea FIX::Checkstyle errors 2019-04-04 20:54:50 +02:00
Merel Steenbergen
4fa2707add FIX:: Fixed small typing error in alert 2019-04-04 18:51:04 +00:00
Merel Steenbergen
7ac5b1efda FIX:: Small bug fix, pipeline should now run 2019-04-04 20:45:10 +02:00
Merel Steenbergen
b08174b2ee ADD:: Alerts: username is now your friend and calculation saved. 2019-04-04 20:42:25 +02:00
Merel Steenbergen
04db410293 FIX::Merge conflict fix in DashBoardController 2019-04-04 20:36:37 +02:00
Merel Steenbergen
c5e7ff2884 ADD::Alert for incorrect password/username at login. 2019-04-04 20:35:02 +02:00
Merel Steenbergen
c8521feaf8 ADD:: Alert 'Footprint saved. Still has a bug.' 2019-04-04 13:26:36 +02:00
Merel Steenbergen
25a66832a5 ADD:: Alert for taken username 2019-04-04 13:26:36 +02:00
Merel Steenbergen
a55e4cecef Added class Hints, including tests 2019-04-04 13:26:35 +02:00
Merel Steenbergen
5c85c56d78 Merge branch 'Feature/alerts' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template into Feature/alerts 2019-04-04 13:23:00 +02:00
Merel Steenbergen
c79a98c57d ADD:: Alert 'Footprint saved. Still has a bug.' 2019-04-04 13:20:47 +02:00
Merel Steenbergen
81701758d7 ADD:: Alert for taken username 2019-04-04 13:20:47 +02:00
Merel Steenbergen
4b04487a25 Added class Hints, including tests 2019-04-04 13:20:47 +02:00
Sem van der Hoeven
50c27cf420 FIX::fixed checkstyle errors
Merge branch 'master' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template

# Conflicts:
#	src/Client/src/main/java/greenify/client/Hints.java
#	src/Client/src/main/java/greenify/client/controller/DashBoardController.java
#	src/Server/src/main/java/greenify/server/service/CalculatorService.java
2019-04-04 13:16:33 +02:00
Sem van der Hoeven
5526c8f467 FIX::fixed checkstyle errors 2019-04-04 13:14:03 +02:00
Mika Wauben
922a7d1fae Merge branch 'Feature/achievements' into 'master'
Feature/achievements

See merge request cse1105/2018-2019/oopp-group-43/template!63
2019-04-04 11:05:22 +00:00
Sem van der Hoeven
6ced05278b ADD::added animations to extra activities section 2019-04-04 10:43:32 +02:00
Sem van der Hoeven
9e6505dfa3 ADD::added animations to switching sections in calculator 2019-04-04 10:01:07 +02:00
Sem van der Hoeven
86f1b724c7 Merge branch 'master' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template 2019-04-04 09:27:52 +02:00
Sem van der Hoeven
90d50624f6 EDIT::added imports to dashboard.fxml 2019-04-04 09:27:09 +02:00
mlwauben
82eb5575ee FIX:: checkstyle errors (except Cyclomatic Complexity ones) 2019-04-04 08:00:47 +02:00
Mika Wauben
84154fca3a Merge branch 'master' into 'Feature/achievements'
# Conflicts:
#   src/Client/src/main/java/greenify/client/Friend.java
#   src/Client/src/main/java/greenify/client/Hints.java
#   src/Client/src/main/java/greenify/client/controller/DashBoardController.java
#   src/Client/src/main/java/greenify/client/rest/UserService.java
#   src/Client/src/main/resources/fxml/dashboard.fxml
#   src/Client/src/test/java/UserServiceTest.java
#   src/Server/src/main/java/greenify/server/data/model/User.java
#   src/Server/src/main/java/greenify/server/rest/UserController.java
#   src/Server/src/main/java/greenify/server/service/UserService.java
#   src/Server/src/test/java/greenify/server/rest/UserControllerTest.java
#   src/Server/src/test/java/greenify/server/service/UserServiceTest.java
2019-04-04 05:45:17 +00:00
mlwauben
3aad682394 FIX:: (possible) merge conficts 2019-04-03 22:05:48 +02:00
Merel Steenbergen
b5c834fc52 ADD:: Alert 'Footprint saved. Still has a bug.' 2019-04-03 21:51:35 +02:00
Merel Steenbergen
1ff84ce3d8 ADD:: Alert for taken username 2019-04-03 21:44:50 +02:00
Sem van der Hoeven
c5f7cac9db Merge branch 'add_details_extra_activities' into 'master'
add/added extra activities GUI

See merge request cse1105/2018-2019/oopp-group-43/template!62
2019-04-03 19:15:46 +00:00
Sem van der Hoeven
19fef1d4c8 FIX::resolved merge conflict and this fixed the issue where it wouldn't set the children of the extra pane
Merge branch 'master' into 'add_details_extra_activities'

# Conflicts:
#   src/Client/src/main/java/greenify/client/controller/CalculatorController.java
2019-04-03 19:11:51 +00:00
mlwauben
28f9f72f07 UPDATE:: achievement things, tests/checkstyle and it actually works now 2019-04-03 20:34:04 +02:00
Merel Steenbergen
f5250aa2a0 Merge branch 'Feature/hints' into 'master'
Added some 'Green hints'

See merge request cse1105/2018-2019/oopp-group-43/template!61
2019-04-03 18:08:09 +00:00
Sem van der Hoeven
d5af8816e9 ADD::added extra activities section to calculator
added section to calculator, and buttons to activities and dashboard to open it seperately
2019-04-03 19:32:40 +02:00
Merel Steenbergen
6a2eb27627 Merge branch 'Feature/delete_a_friend' into 'master'
Feature/remove a friend

See merge request cse1105/2018-2019/oopp-group-43/template!60
2019-04-03 14:29:36 +00:00
Merel Steenbergen
01e03782c2 Remove addFriend part from removeFriendTest from UserControllerTest.java 2019-04-03 13:40:53 +00:00
Merel Steenbergen
bb6d887036 Added class Hints, including tests 2019-04-03 15:33:26 +02:00
Merel Steenbergen
7b6457b286 ADD::RemoveFriend method and test in server.userController 2019-04-03 14:19:30 +02:00
Sem van der Hoeven
54d0537f95 EDIT::changed miles to kilometres in calculator 2019-04-03 11:52:03 +02:00
Ceren Ugurlu
b781727703 Delete suppression.xml 2019-04-01 17:54:41 +00:00
cugurlu
4c50eea99a Add meeting notes for week 8 2019-04-01 19:54:09 +02:00
Ceren Ugurlu
a38cd45e2a Merge branch 'add_weekly_reports' into 'master'
Add weekly reports

See merge request cse1105/2018-2019/oopp-group-43/template!59
2019-04-01 17:12:52 +00:00
Merel Steenbergen
e48264a667 EDIT:: Uncomment build.gradle mainClassName 2019-04-01 16:53:16 +02:00
Merel Steenbergen
12b05f3b73 ADD:: RemoveFriend method and test in client.userService 2019-04-01 16:46:01 +02:00
Merel Steenbergen
6d37b99c14 ADD:: RemoveFriend method and tests in Server.UserService 2019-04-01 16:43:10 +02:00
Merel Steenbergen
52291ac10f ADD:: Friend remove methods and tests in server.User 2019-04-01 16:36:12 +02:00
cugurlu
ae5d4a1496 Add coverage and checkstyle reports 2019-04-01 14:22:31 +02:00
Ceren Ugurlu
d7454345be Delete 20190401_checkstyle.png 2019-04-01 12:19:37 +00:00
mlwauben
973e8aba69 UPDATE:: checkstyle fixes 2019-03-30 17:16:24 +01:00
mlwauben
7656b60fcf UPDATE:: achievements and tests 2019-03-30 16:43:24 +01:00
mlwauben
ca11cd3c9a DEBUG:: achievement things (tests all work now) 2019-03-30 11:29:39 +01:00
mlwauben
f5d9bd5010 UPDATE:: added achievements to user class 2019-03-30 09:25:12 +01:00
mlwauben
3d61cd061a ADD:: class of achievements list 2019-03-30 09:02:02 +01:00
mlwauben
393bfc9445 ADD:: achievement class 2019-03-30 08:23:54 +01:00
mlwauben
c62e4719ea ADD:: test fxml+controller 2019-03-28 23:11:58 +01:00
84 changed files with 3386 additions and 555 deletions

View File

@@ -35,3 +35,13 @@ test:
- build
- .gradle
# Code coverage badge
#deploy:
# stage: code-coverage
# script:
# - gradle clean check
# 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 += $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\"
# 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.
![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
You can install greenify with gradle, if you already have gradle on your machine, run:
To start Greenify:
```
gradle install something tralala
```
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
cd <FILE-LOCATION>/greenify/src/Client/build/libs
java -Dserver.address="https://greenify43.herokuapp.com" -jar greenify-1.0.0.jar
```
## Running the tests
The tests cover all non-GUI code:
```
cd <FILE-LOCATION>/greenify
gradle check
```

View File

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

Binary file not shown.

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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 KiB

View File

@@ -1,5 +0,0 @@
# Checkstyle folder
At the end of the week, please commit a readable screenshot that shows the Checkstyle results.
Make sure that the file follows the naming convention; `20190213_checkstyle.xyz` for February 13th.
`.xyz` can be either `.jpg` or `.png`.

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

View File

@@ -0,0 +1,14 @@
# Sprint Review
## Main problems Encountered
### Problem 1:
## Adjustments from previous sprints
There were no big problems this week. We made some last minute changes and added some extra features. Next week we're going to focus on our other exams, so we're
not really working on the project anymore.
## Adjustments for next sprint

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: 108 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -1,3 +0,0 @@
<module name="SuppressionFilter">
<property name="file" value="quality/checkstyle/suppressions.xml" />
</module>

View File

@@ -39,8 +39,8 @@ test {
}
bootJar {
baseName = 'gs-consuming-rest'
version = '0.1.0'
baseName = 'greenify'
version = '1.0.0'
}
repositories {
@@ -48,6 +48,7 @@ repositories {
}
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:spring-web")
compile("com.fasterxml.jackson.core:jackson-databind")

View File

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

View File

@@ -1,17 +1,21 @@
package greenify.client.controller;
import greenify.client.Application;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.ParallelTransition;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Alert;
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;
@@ -24,6 +28,7 @@ import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.text.DecimalFormat;
@Controller
@@ -34,6 +39,9 @@ public class CalculatorController {
@Autowired
DashBoardController controller;
@Autowired
ExtraActivityController extraActivityController;
//navigation panes
@FXML
private AnchorPane getStartedPane;
@@ -139,20 +147,13 @@ public class CalculatorController {
//extra pane
@FXML
private AnchorPane extraPane;
@FXML
private CheckBox localProduceCheckbox;
@FXML
private CheckBox bikeCheckbox;
@FXML
private CheckBox temperatureCheckbox;
@FXML
private CheckBox solarPanelsCheckbox;
/**
* initializes the window, performs some actions before loading all other things.
* it sets the sliders to snap to the ticks.
* it adds listeners to all the sliders for updating the label they are associated with.
*/
@SuppressWarnings("Duplicates")
public void initialize() {
peopleInHouseholdSlider.setSnapToTicks(true);
//add listener to slider for amount of people in household
@@ -173,9 +174,9 @@ public class CalculatorController {
}
});
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
@@ -218,6 +219,7 @@ public class CalculatorController {
});
}
@SuppressWarnings("Duplicates")
private void addSliderListenerDailyServing(Slider slider, Label label) {
DecimalFormat df = new DecimalFormat("0.0");
slider.valueProperty().addListener(new ChangeListener<Number>() {
@@ -239,6 +241,23 @@ public class CalculatorController {
});
}
/**
* adds a fade transition to the given node.
* @param node the node to add the transition to
*/
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.setFromY(800);
trans.setToY(0);
ParallelTransition par = new ParallelTransition();
par.setNode(travelPane);
par.getChildren().addAll(fade, trans);
par.play();
}
private void addSlideInAnimation(Node node) {
Timeline timeline = new Timeline();
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
@@ -254,6 +273,7 @@ public class CalculatorController {
*/
@SuppressWarnings("Duplicates")
public void displayGetStarted(ActionEvent event) {
addFadeTransAnimation(getStartedPane);
getStartedPane.setVisible(true);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -270,7 +290,7 @@ public class CalculatorController {
*/
@SuppressWarnings("Duplicates")
public void displayTravel(ActionEvent event) {
addSlideInAnimation(travelPane);
addFadeTransAnimation(travelPane);
getStartedPane.setVisible(false);
travelPane.setVisible(true);
homePane.setVisible(false);
@@ -287,6 +307,7 @@ public class CalculatorController {
*/
@SuppressWarnings("Duplicates")
public void displayHome(ActionEvent event) {
addFadeTransAnimation(homePane);
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(true);
@@ -302,6 +323,7 @@ public class CalculatorController {
*/
@SuppressWarnings("Duplicates")
public void displayFood(ActionEvent event) {
addFadeTransAnimation(foodPane);
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -317,6 +339,7 @@ public class CalculatorController {
*/
@SuppressWarnings("Duplicates")
public void displayShopping(ActionEvent event) {
addFadeTransAnimation(shoppingPane);
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -331,14 +354,16 @@ public class CalculatorController {
* @param event the click of the designated button
*/
@SuppressWarnings("Duplicates")
public void displayExtra(ActionEvent event) {
public void displayExtra(ActionEvent event) throws IOException {
addFadeTransAnimation(extraPane);
extraPane.getChildren().setAll((Node) Application.load(this.getClass()
.getClassLoader().getResource("fxml/extraActivities.fxml")));
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
foodPane.setVisible(false);
shoppingPane.setVisible(false);
extraPane.setVisible(true);
}
/**
@@ -360,46 +385,73 @@ public class CalculatorController {
userService.updateInput(userService.currentUser.getName(), "input_size",
peopleInHouseHoldLabel.getText());
}
if (!publicTransitField.getText().equals("0")) {
checkTransportLabels();
checkHousingLabels();
checkFoodLabels();
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_publictrans",
publicTransitField.getText());
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!airplaneTravelField.getText().equals("0")) {
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_airtotal",
airplaneTravelField.getText());
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
if (!carTravelGasolineField.getText().equals("0")) {
try {
extraActivityController.updateExtras();
} catch (NullPointerException ex) {
System.out.println("continue");
}
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
controller.updateLeaderboard();
controller.updateAchievements();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
owner, "Footprint saved!", "Your footprint is saved!");
Stage current = (Stage) owner;
current.close();
}
/**
* Checks the food labels.
*/
@SuppressWarnings("Duplicates")
private void checkFoodLabels() {
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles1",
carTravelGasolineField.getText());
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg1",
carTravelGasolineLabel.getText().replace(" mpg", ""));
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelDieselField.getText().equals("0")) {
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles2",
carTravelDieselField.getText());
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg2",
carTravelDieselLabel.getText().replace(" mpg", ""));
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelElectricField.getText().equals("0")) {
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles3",
carTravelElectricField.getText());
}
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg3",
carTravelElectricLabel.getText().replace(" mpge", ""));
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
}
/**
* Checks the house labels.
*/
@SuppressWarnings("Duplicates")
private void checkHousingLabels() {
if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars",
@@ -430,67 +482,52 @@ public class CalculatorController {
"input_footprint_housing_watersewage",
waterUsageLabel.getText().replace("% of similar households", ""));
}
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
}
/**
* Checks the transport labels.
*/
@SuppressWarnings("Duplicates")
private void checkTransportLabels() {
if (!publicTransitField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
"input_footprint_transportation_publictrans",
publicTransitField.getText());
}
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
if (!airplaneTravelField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
"input_footprint_transportation_airtotal",
airplaneTravelField.getText());
}
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
if (!carTravelGasolineField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
"input_footprint_transportation_miles1",
carTravelGasolineField.getText());
}
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
"input_footprint_transportation_mpg1",
carTravelGasolineLabel.getText().replace(" km/L", ""));
}
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
if (!carTravelDieselField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
"input_footprint_transportation_miles2",
carTravelDieselField.getText());
}
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
"input_footprint_transportation_mpg2",
carTravelDieselLabel.getText().replace(" km/L", ""));
}
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
if (!carTravelElectricField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
"input_footprint_transportation_miles3",
carTravelElectricField.getText());
}
if (localProduceCheckbox.isSelected()) {
localProduceCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"local_produce", true);
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg3",
carTravelElectricLabel.getText().replace(" km/Le", ""));
}
if (bikeCheckbox.isSelected()) {
bikeCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"bike", true);
}
if (temperatureCheckbox.isSelected()) {
temperatureCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"temperature", true);
}
if (solarPanelsCheckbox.isSelected()) {
solarPanelsCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels", true);
}
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
controller.updateLeaderboard();
}
}

View File

@@ -2,11 +2,14 @@ package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application;
import greenify.client.Friend;
import greenify.client.features.Friend;
import greenify.client.features.Hints;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.PathTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
@@ -15,22 +18,28 @@ import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Class that controls the dashboard fxml file (the GUI Screen).
@@ -45,6 +54,8 @@ public class DashBoardController {
@Autowired
UserService userService;
Hints hints = new Hints();
private FadeTransition fadeTrans; //transition for switching between the different panels
@FXML
@@ -66,6 +77,8 @@ public class DashBoardController {
@FXML
private Button friendsButton;
@FXML
private Button logOutButton;
@FXML
private Line pathLine;
@FXML
private AnchorPane menuBar;
@@ -80,6 +93,14 @@ public class DashBoardController {
@FXML
private Button addFriendButton;
@FXML
private Button addFriend;
@FXML
private Button removeFriend;
@FXML
private Button addExtraActivityButton;
@FXML
private Button addExtraActivityButton2;
@FXML
private TableView<Friend> friendsTable;
@FXML
private TableColumn<Friend, String> friendsColumn;
@@ -88,18 +109,24 @@ public class DashBoardController {
@FXML
private TableView<Friend> globalLeaderboard;
@FXML
private TableColumn<Friend, Integer> globalPlace;
@FXML
private TableColumn<Friend, String> globalUser;
@FXML
private TableColumn<Friend, Float> globalScore;
@FXML
private TableView<Friend> developmentLeaderboard;
@FXML
private TableColumn<Friend, Integer> developmentPlace;
@FXML
private TableColumn<Friend, String> developmentUser;
@FXML
private TableColumn<Friend, Float> developmentScore;
@FXML
private TableView<Friend> friendLeaderboard;
@FXML
private TableColumn<Friend, Integer> friendPlace;
@FXML
private TableColumn<Friend, String> friendUser;
@FXML
private TableColumn<Friend, Float> friendScore;
@@ -154,21 +181,58 @@ public class DashBoardController {
@FXML
private Label snacks;
@FXML
private CheckBox localProduce;
@SuppressWarnings("CheckStyle")
private ImageView achieve1;
@FXML
private CheckBox loweringTemp;
@SuppressWarnings("CheckStyle")
private ImageView achieve2;
@FXML
private CheckBox bike;
@SuppressWarnings("CheckStyle")
private ImageView achieve3;
@FXML
private CheckBox solarPanels;
private ImageView achieve4;
@FXML
private ImageView achieve5;
@FXML
private ImageView achieve6;
@FXML
private Label hintText;
@FXML
private Label veganMeal;
@FXML
private Label localProduce;
@FXML
private Label bike;
@FXML
private Label publicTrans;
@FXML
private Label loweringTemp;
@FXML
private Label solarPanels;
@FXML
private Button achiev1Tip;
@FXML
private Button achiev2Tip;
@FXML
private Button achiev3Tip;
@FXML
private Button achiev4Tip;
@FXML
private Button achiev5Tip;
@FXML
private Button achiev6Tip;
/**
* Loads the the necessary things before anything else.
* @throws InterruptedException exception if interrupted
*/
public void initialize() throws InterruptedException {
hintText.setWrapText(true);
hintText.setText(hints.randomHint());
//set the dashboardPane to visible
dashboardPane.setVisible(true);
userPane.setVisible(false);
activitiesPane.setVisible(false);
friendsPane.setVisible(false);
//sets the text of the 'welcome back' text to include the username
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
//adds the slide transition to the menu bar
@@ -178,36 +242,81 @@ public class DashBoardController {
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
userButton.setSkin(new MyButtonSkin(userButton));
friendsButton.setSkin(new MyButtonSkin(friendsButton));
logOutButton.setSkin(new MyButtonSkin(logOutButton));
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
globalPlace.setCellValueFactory(new PropertyValueFactory<>("Place"));
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
globalScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
developmentUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
developmentPlace.setCellValueFactory(new PropertyValueFactory<>("Place"));
developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
friendPlace.setCellValueFactory(new PropertyValueFactory<>("Place"));
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
if (pieChart != null) {
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Vegan Meal", 100),
new PieChart.Data("Public Transport", 200),
new PieChart.Data("Home Temperature", 50),
new PieChart.Data("Bike", 75),
new PieChart.Data("Local Product", 110),
new PieChart.Data("Solar Panel", 300)
);
pieChart.setTitle("FOOTPRINT DISTRIBUTION");
pieChart.setMaxSize(1000, 1000);
pieChart.setData(pieChartData);
}
List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
for (int i = 0; i < friendList.size(); i++) {
Friend friend = new Friend(friendList.get(i),
Friend friend = new Friend(i, friendList.get(i),
userService.getFootprint(friendList.get(i)));
data.add(friend);
}
friendsTable.setItems(data);
updateLeaderboard();
updateAchievements();
updatePiechart();
calculateFootPrintButton.setSkin(new ClickButtonSkin(calculateFootPrintButton));
addFriendButton.setSkin(new ClickButtonSkin(addFriendButton));
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
addFriend.setSkin(new ClickButtonSkin(addFriend));
removeFriend.setSkin(new ClickButtonSkin(removeFriend));
addRandomHints();
Tooltip tooltip = new Tooltip("tip");
hackTooltipStartTiming(tooltip);
addToolTip(achiev1Tip, "Starting off \n You did your first green activity!");
addToolTip(achiev2Tip, "Social Butterfly \n You added three friends");
addToolTip(achiev3Tip, "Green Saver \n You saved 20 tonnes of CO2");
addToolTip(achiev4Tip, "Animal Friend \n You have eaten 10 vegetarian meals");
addToolTip(achiev5Tip, "Tom Dumoulin \n You have biked 15 km");
addToolTip(achiev6Tip, "Let it shine \n You installed solar panels");
}
/**
* adds a tooltip to the button.
* @param button the button to add the tooltip to.
* @param message the message to be displayed in the tooltip.
*/
private void addToolTip(Button button, String message) {
button.setTooltip(new Tooltip(message));
}
/**
* changes the delay time between hovering over something with a tooltip and when the
* tooltip is displayed.
* @param tooltip the tooltip to change the delay of
*/
private static void hackTooltipStartTiming(Tooltip tooltip) {
try {
Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");
fieldBehavior.setAccessible(true);
Object objBehavior = fieldBehavior.get(tooltip);
Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");
fieldTimer.setAccessible(true);
Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);
objTimer.getKeyFrames().clear();
objTimer.getKeyFrames().add(new KeyFrame(new Duration(150)));
} catch (NoSuchFieldException e) {
e.printStackTrace();
e.getMessage();
} catch (IllegalAccessException e) {
e.getMessage();
e.printStackTrace();
}
}
/**
@@ -217,14 +326,14 @@ public class DashBoardController {
public void sortScores(List<String> users) throws InterruptedException {
for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size(); j++) {
Float firstScore = userService.getFootprint(users.get(i));
Float secondScore = userService.getFootprint(users.get(j));
if (i > j && firstScore < secondScore) {
Double first = userService.getFootprint(users.get(i));
Double second = userService.getFootprint(users.get(j));
if (i < j && (first.compareTo(second) < 0)) {
String temp = users.get(i);
users.set(i, users.get(j));
users.set(j, temp);
}
if (i < j && firstScore > secondScore) {
if (i > j && (first.compareTo(second) > 0)) {
String temp = users.get(i);
users.set(i, users.get(j));
users.set(j, temp);
@@ -237,12 +346,12 @@ public class DashBoardController {
* Sorts the scores of users.
* @param users the list of users
*/
public void 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 j = 0; j < users.size(); j++) {
Float firstDiff = userService.getFirstFootprint(users.get(i)) - userService
Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService
.getFootprint(users.get(i));
Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService
Double secondDiff = userService.getFirstFootprint(users.get(j)) - userService
.getFootprint(users.get(j));
if (i < j && firstDiff < secondDiff) {
String temp = users.get(i);
@@ -256,6 +365,7 @@ public class DashBoardController {
}
}
}
return users;
}
/**
@@ -282,6 +392,7 @@ public class DashBoardController {
activitiesPane.setVisible(false);
friendsPane.setVisible(false);
updateLeaderboard();
updateAchievements();
}
/**
@@ -314,8 +425,8 @@ public class DashBoardController {
electricMiles.setText(inputMap.get("input_footprint_transportation_miles3"));
electricMpg.setText(inputMap.get("input_footprint_transportation_mpg3"));
publicTransportation.setText(inputMap.get("input_footprint_transportation_publictrans")
+ " mi/yr");
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " mi/yr");
+ " km/yr");
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " km/yr");
goodShopping.setText(inputMap.get("input_footprint_shopping_goods_total") + " €/mo");
serviceShopping.setText(inputMap.get("input_footprint_shopping_services_total") + " €/mo");
meat.setText(inputMap.get("input_footprint_shopping_food_meatfisheggs"));
@@ -323,33 +434,29 @@ public class DashBoardController {
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
if (userService.getExtraInputs(userService.currentUser.getName()).get("local_produce")) {
localProduce.setSelected(true);
}
if (userService.getExtraInputs(userService.currentUser.getName()).get("bike")) {
bike.setSelected(true);
}
if (userService.getExtraInputs(userService.currentUser.getName()).get("temperature")) {
loweringTemp.setSelected(true);
}
if (userService.getExtraInputs(userService.currentUser.getName()).get("solar_panels")) {
solarPanels.setSelected(true);
}
Map<String, String> extraMap = userService
.getExtraInputs(userService.currentUser.getName());
veganMeal.setText(extraMap.get("vegan"));
localProduce.setText(extraMap.get("local_produce"));
bike.setText(extraMap.get("bike"));
publicTrans.setText(extraMap.get("public_transport"));
loweringTemp.setText(extraMap.get("temperature"));
solarPanels.setText(extraMap.get("solar_panels"));
}
/**
* Displays the user profile pane.
* @param event the event (clicking the button)
*/
public void displayUser(ActionEvent event) {
public void displayUser(ActionEvent event) throws InterruptedException {
System.out.println(userService.currentUser.getName());
System.out.println(userService.getFootprint(userService.currentUser.getName()));
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
firstFootprintLabel.setText("" + userService
.getFirstFootprint(userService.currentUser.getName()));
Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
Double diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
.getFootprint(userService.currentUser.getName());
differenceLabel.setText( "" + diff);
differenceLabel.setText( "" + Math.round(diff * 10) / 10.0);
usernameLabel.setText("" + userService.currentUser.getName());
addFadeTransition(userPane);
System.out.println("display user");
@@ -357,7 +464,7 @@ public class DashBoardController {
userPane.setVisible(true);
activitiesPane.setVisible(false);
friendsPane.setVisible(false);
updatePiechart();
}
/**
@@ -374,6 +481,44 @@ public class DashBoardController {
updateFriends();
}
/**
* Logs out the user.
* @param event the event (clicking the button)
* @throws IOException if the Application doesn't load.
*/
public void logOut(ActionEvent event) throws IOException {
//get the current window
Window owner = logOutButton.getScene().getWindow();
Stage current = (Stage) owner;
//close current window (log out)
current.close();
System.out.println("User is logged out");
//global leaderboard
globalLeaderboard.getItems().clear();
globalLeaderData.removeAll();
//development leaderboard
developmentLeaderboard.getItems().clear();
developmentData.removeAll();
//friends leaderboard
friendLeaderboard.getItems().clear();
friendLeaderData.removeAll();
//load the fxml file
Parent dash = Application.load(this.getClass().getClassLoader()
.getResource("fxml/LoginWindow.fxml"));
Scene scene = new Scene(dash);
//add the stylesheet for the CSS
scene.getStylesheets().add(Objects.requireNonNull(getClass().getClassLoader()
.getResource("stylesheets/LoginWindowStyle.css")).toExternalForm());
Stage appStage = new Stage();
appStage.setScene(scene);
//set the title
appStage.setTitle("Greenify");
appStage.show();
}
//sets the slide in transition for startup
public void addSlideTransition(Node node, Line path1) {
PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node);
@@ -384,6 +529,7 @@ public class DashBoardController {
* Opens the calculator.
* @throws IOException if the Application doesn't load.
*/
@SuppressWarnings("Duplicates")
public void openCalculator() throws IOException, InterruptedException {
Parent calc = Application.load(this.getClass().getClassLoader()
.getResource("fxml/calculator.fxml"));
@@ -398,7 +544,39 @@ public class DashBoardController {
}
/**
* method opend addFriend scene.
* This method adds a random hint to the side bar.
*/
public void addRandomHints() {
FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText);
fadeOut.setFromValue(1.0);
fadeOut.setToValue(0.0);
fadeOut.play();
hintText.setWrapText(true);
hintText.setText(hints.randomHint());
FadeTransition fadeIn = new FadeTransition(Duration.millis(400), hintText);
fadeIn.setFromValue(0.0);
fadeIn.setToValue(1.0);
fadeIn.play();
}
/**
* Opens extra activities.
* @param event the event (clicking the button)
* @throws IOException if the Application doesn't load.
*/
public void openExtraActivities(ActionEvent event) throws IOException {
Parent extra = Application.load(this.getClass().getClassLoader()
.getResource("fxml/extraActivities.fxml"));
Scene scene = new Scene(extra);
Stage extraStage = new Stage();
extraStage.setScene(scene);
extraStage.setTitle("Add extra activity - " + userService.currentUser.getName());
extraStage.show();
}
/**
* method opens addFriend scene.
* @throws IOException when file is not found
*/
public void openAddFriend() throws IOException {
@@ -411,36 +589,81 @@ public class DashBoardController {
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.
* @throws InterruptedException throws exception
*/
@SuppressWarnings("Duplicates")
public void updateLeaderboard() throws InterruptedException {
List<String> userList = userService.getAllUsers();
//global leaderboard
globalLeaderboard.getItems().clear();
globalLeaderData.removeAll();
sortScores(userList);
//development leaderboard
developmentLeaderboard.getItems().clear();
developmentData.removeAll();
sortDiffScores(userList);
for (int j = 0; j < userList.size(); j++) {
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
Friend diffUser = new Friend(userList.get(j), userService
.getFirstFootprint(userList.get(j))
- userService.getFootprint(userList.get(j)));
List<String> userList = userService.getAllUsers();
sortScores(userList);
for (int i = userList.size() - 1; i >= 0; i--) {
Friend user = new Friend(userList.size() - i, userList.get(i),
userService.getFootprint(userList.get(i)));
globalLeaderData.add(user);
}
List<String> secondList = sortDiffScores(userList);
for (int j = 0; j < userList.size(); j++) {
double diff = Math.round((userService.getFirstFootprint(secondList.get(j))
- userService.getFootprint(secondList.get(j))) * 10) / 10.0;
Friend diffUser = new Friend(j + 1, secondList.get(j), diff);
developmentData.add(diffUser);
}
globalLeaderboard.setItems(globalLeaderData);
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.
* @throws InterruptedException throws exception
*/
@SuppressWarnings("Duplicates")
public void updateFriends() throws InterruptedException {
List<String> wholeList = userService.getFriendNames(userService.currentUser.getName());
wholeList.add(userService.currentUser.getName());
@@ -453,31 +676,75 @@ public class DashBoardController {
friendLeaderboard.getItems().clear();
friendLeaderData.removeAll();
sortDiffScores(wholeList);
for (int i = 0; i < friendList.size(); i++) {
Friend user = new Friend(friendList.get(i), userService
for (int i = friendList.size() - 1; i >= 0 ; i--) {
Friend user = new Friend(i, friendList.get(i), userService
.getFootprint(friendList.get(i)));
data.add(user);
}
for (int j = 0; j < wholeList.size(); j++) {
Friend diffUser = new Friend(wholeList.get(j),
userService.getFirstFootprint(wholeList.get(j))
- userService.getFootprint(wholeList.get(j)));
double diff = Math.round((userService.getFirstFootprint(wholeList.get(j))
- userService.getFootprint(wholeList.get(j))) * 10) / 10.0;
Friend diffUser = new Friend(j + 1, wholeList.get(j), diff);
friendLeaderData.add(diffUser);
}
friendsTable.setItems(data);
friendLeaderboard.setItems(friendLeaderData);
}
/**
* Updates the achievements.
*/
public void updateAchievements() {
Map achievements = userService.getAchievements(userService.currentUser.getName());
ColorAdjust desaturate = new ColorAdjust();
desaturate.setSaturation(-0.75);
if ((Boolean)achievements.get("Starting off")) {
achieve1.setOpacity(1);
} else {
achieve1.setEffect(desaturate);
achieve1.setOpacity(0.3);
}
if ((Boolean)achievements.get("Social butterfly")) {
achieve2.setOpacity(1);
} else {
achieve2.setEffect(desaturate);
achieve2.setOpacity(0.3);
}
if ((Boolean)achievements.get("Green saver")) {
achieve3.setOpacity(1);
} else {
achieve3.setEffect(desaturate);
achieve3.setOpacity(0.3);
}
if ((Boolean)achievements.get("Animal friend")) {
achieve4.setOpacity(1);
} else {
achieve4.setEffect(desaturate);
achieve4.setOpacity(0.3);
}
if ((Boolean)achievements.get("Tom Dumoulin")) {
achieve5.setOpacity(1);
} else {
achieve5.setEffect(desaturate);
achieve5.setOpacity(0.3);
}
if ((Boolean)achievements.get("Let it shine")) {
achieve6.setOpacity(1);
} else {
achieve6.setEffect(desaturate);
achieve6.setOpacity(0.3);
}
}
//class for the animations on the navigation buttons
public class MyButtonSkin extends ButtonSkin {
private class MyButtonSkin extends ButtonSkin {
/**
* adds a skin and scale animation to a button.
* the scale transition is for hovering over it so it then scales up
* and scales down when you stop hovering over it.
* @param button the button to add the animation to
*/
public MyButtonSkin(Button button) {
private MyButtonSkin(Button button) {
//inherit the button properties
super(button);
//transition to scale up on hover
@@ -493,6 +760,45 @@ public class DashBoardController {
scaleDown.setToX(1.0);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
}
@SuppressWarnings("Duplicates")
private class ClickButtonSkin extends ButtonSkin {
/**
* button skin for the 'add activity' buttons.
* adds scale animations on entering, clicking and exiting the button
* @param button the button to set the skin of
*/
private ClickButtonSkin(Button button) {
super(button);
//transition to scale up on hover
final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(100));
//add the node and the position to scale to
scaleUp.setNode(button);
scaleUp.setToX(1.1);
scaleUp.setToY(1.1);
//play the transition when hovered over the button
button.setOnMouseEntered(e -> scaleUp.playFromStart());
final ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
scaleMiddleDown.setNode(button);
scaleMiddleDown.setToX(1.05);
scaleMiddleDown.setToY(1.05);
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
final ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
scaleMiddleUp.setNode(button);
scaleMiddleUp.setToX(1.1);
scaleMiddleUp.setToY(1.1);
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(100));
scaleDown.setNode(button);
scaleDown.setToX(1.0);
scaleDown.setToY(1.0);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
}

View File

@@ -0,0 +1,372 @@
package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.TranslateTransition;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Controller
public class ExtraActivityController {
@Autowired
UserService userService;
@Autowired
CalculatorController calculatorController;
@Autowired
DashBoardController controller;
@FXML
private AnchorPane veganMealPane;
@FXML
private AnchorPane bikePane;
@FXML
private AnchorPane temperaturePane;
@FXML
private AnchorPane solarPanelPane;
@FXML
private AnchorPane localProducePane;
@FXML
private AnchorPane publicTransportPane;
@FXML
private Button displayVeganMealButton;
@FXML
private Button displayBikeButton;
@FXML
private Button displayTemperatureButton;
@FXML
private Button displaySolarPanelButton;
@FXML
private Button displayLocalProduceButton;
@FXML
private Button displayPublicTransportButton;
@FXML
private Button addVeganMealButton;
@FXML
private Button addBikeButton;
@FXML
private Button addTemperatureButton;
@FXML
private Button addSolarPanelsButton;
@FXML
private Button addLocalProduceButton;
@FXML
private Button addPublicTransportButton;
@FXML
private Slider bikeSlider;
@FXML
private Label bikeLabel;
@FXML
private Slider temperatureSlider;
@FXML
private Label temperatureLabel;
@FXML
private Slider solarPanelsSlider;
@FXML
private Label solarPanelsLabel;
@FXML
private Label publicTransportLabel;
@FXML
private Slider publicTransportSlider;
/**
* initializes the sliders and labels before loading.
* sets the labels to display the outputs of the designated sliders.
*/
public void initialize() {
coupleSliderToLabel(bikeSlider, bikeLabel, " km", false);
coupleSliderToLabel(temperatureSlider, temperatureLabel, " Degrees", true);
coupleSliderToLabel(solarPanelsSlider, solarPanelsLabel, "", true);
coupleSliderToLabel(publicTransportSlider, publicTransportLabel, " km", false);
addVeganMealButton.setSkin(new ActivityButtonSkin(addVeganMealButton));
addBikeButton.setSkin(new ActivityButtonSkin(addBikeButton));
addTemperatureButton.setSkin(new ActivityButtonSkin(addTemperatureButton));
addSolarPanelsButton.setSkin(new ActivityButtonSkin(addSolarPanelsButton));
addLocalProduceButton.setSkin(new ActivityButtonSkin(addLocalProduceButton));
addPublicTransportButton.setSkin(new ActivityButtonSkin(addPublicTransportButton));
displayVeganMealButton.setSkin(new TranslateButtonSkin(displayVeganMealButton));
displayBikeButton.setSkin(new TranslateButtonSkin(displayBikeButton));
displayTemperatureButton.setSkin(new TranslateButtonSkin(displayTemperatureButton));
displaySolarPanelButton.setSkin(new TranslateButtonSkin(displaySolarPanelButton));
displayLocalProduceButton.setSkin(new TranslateButtonSkin(displayLocalProduceButton));
displayPublicTransportButton.setSkin(new TranslateButtonSkin(displayPublicTransportButton));
}
/**
* Sets the label to display the value of the designated slider.
* sets the text to be displayed after the value of the slider.
* sets whether the slider should snap to ticks
* @param slider the slider to read the value from
* @param label the label to display the value of the slider
* @param string the string to be placed after the outputted value of the slider
* @param snapToTicks whether the slider should snap to ticks or not
*/
private void coupleSliderToLabel(Slider slider, Label label, String string,
boolean snapToTicks) {
slider.setSnapToTicks(snapToTicks);
slider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldValue, Number newValue) {
label.setText(newValue.intValue() + string);
}
});
}
/**
* 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.
* @param event the click of the designated button
*/
public void displayVeganMeal(ActionEvent event) {
// System.out.println("display vm");
addFadeTransAnimation(veganMealPane);
veganMealPane.setVisible(true);
bikePane.setVisible(false);
temperaturePane.setVisible(false);
solarPanelPane.setVisible(false);
localProducePane.setVisible(false);
publicTransportPane.setVisible(false);
}
/**
* displays the bike section.
* @param event the click of the designated button
*/
public void displayBike(ActionEvent event) {
// System.out.println("display b");
addFadeTransAnimation(bikePane);
veganMealPane.setVisible(false);
bikePane.setVisible(true);
temperaturePane.setVisible(false);
solarPanelPane.setVisible(false);
localProducePane.setVisible(false);
publicTransportPane.setVisible(false);
}
/**
* displays the temperature section.
* @param event the click of the designated button
*/
public void displayTemperature(ActionEvent event) {
// System.out.println("display t");
addFadeTransAnimation(temperaturePane);
veganMealPane.setVisible(false);
bikePane.setVisible(false);
temperaturePane.setVisible(true);
solarPanelPane.setVisible(false);
localProducePane.setVisible(false);
publicTransportPane.setVisible(false);
}
/**
* displays the solar panels section.
* @param event the click of the designated button
*/
public void displaySolarPanel(ActionEvent event) {
// System.out.println("display sp");
addFadeTransAnimation(solarPanelPane);
veganMealPane.setVisible(false);
bikePane.setVisible(false);
temperaturePane.setVisible(false);
solarPanelPane.setVisible(true);
localProducePane.setVisible(false);
publicTransportPane.setVisible(false);
}
/**
* displays the local produce section.
* @param event the click of the designated button
*/
public void displayLocalProduce(ActionEvent event) {
addFadeTransAnimation(localProducePane);
veganMealPane.setVisible(false);
bikePane.setVisible(false);
temperaturePane.setVisible(false);
solarPanelPane.setVisible(false);
localProducePane.setVisible(true);
publicTransportPane.setVisible(false);
}
/**
* displays the public transport section.
* @param event the click of the designated button
*/
public void displayPublicTransport(ActionEvent event) {
addFadeTransAnimation(publicTransportPane);
veganMealPane.setVisible(false);
bikePane.setVisible(false);
temperaturePane.setVisible(false);
solarPanelPane.setVisible(false);
localProducePane.setVisible(false);
publicTransportPane.setVisible(true);
}
/**
* The method updates the values.
*/
@SuppressWarnings("Duplicates")
public void save(ActionEvent event) {
try {
updateExtras();
Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateLeaderboard();
controller.updateAchievements();
} catch (InterruptedException ex) {
System.out.println("continue");
}
}
/**
* The method updates the values of extras.
*/
@SuppressWarnings("Duplicates")
public void updateExtras() throws InterruptedException {
if (!bikeLabel.getText().replace(" km", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"bike",
bikeLabel.getText().replace(" km", ""));
}
if (!solarPanelsLabel.getText().equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels",
solarPanelsLabel.getText());
}
if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"temperature",
temperatureLabel.getText().replace(" Degrees", ""));
}
if (!publicTransportLabel.getText().replace(" km", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"public_transport",
publicTransportLabel.getText().replace(" km", ""));
}
}
/**
* The method updates the values of extras.
*/
@SuppressWarnings("Duplicates")
public void updateExtraVegan() throws InterruptedException {
try {
userService.updateExtraInput(userService.currentUser.getName(), "vegan", "1");
Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements();
controller.updateLeaderboard();
} catch (NullPointerException ex) {
System.out.println("continue");
}
}
/**
* The method updates the values of extras.
*/
@SuppressWarnings("Duplicates")
public void updateExtraLocal() throws InterruptedException {
try {
userService.updateExtraInput(userService.currentUser.getName(), "local_produce", "1");
Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements();
controller.updateLeaderboard();
} catch (NullPointerException ex) {
System.out.println("continue");
}
}
public class TranslateButtonSkin extends ButtonSkin {
/**
* button skin that sets a translate animation on entering and exiting the button.
* @param button the button to set the animation for
*/
private TranslateButtonSkin(Button button) {
super(button);
TranslateTransition transEnter = new TranslateTransition(Duration.millis(50));
transEnter.setNode(button);
transEnter.setToX(10);
button.setOnMouseEntered(e -> transEnter.playFromStart());
TranslateTransition transExit = new TranslateTransition(Duration.millis(50));
transExit.setNode(button);
transExit.setToX(1.0);
button.setOnMouseExited(e -> transExit.playFromStart());
}
}
@SuppressWarnings("Duplicates")
private class ActivityButtonSkin extends ButtonSkin {
/**
* button skin for the 'add activity' buttons.
* adds scale animations on entering, clicking and exiting the button
* @param button the button to set the skin of
*/
private ActivityButtonSkin(Button button) {
super(button);
//transition to scale up on hover
final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(100));
//add the node and the position to scale to
scaleUp.setNode(button);
scaleUp.setToX(1.1);
scaleUp.setToY(1.1);
//play the transition when hovered over the button
button.setOnMouseEntered(e -> scaleUp.playFromStart());
final ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
scaleMiddleDown.setNode(button);
scaleMiddleDown.setToX(1.05);
scaleMiddleDown.setToY(1.05);
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
final ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
scaleMiddleUp.setNode(button);
scaleMiddleUp.setToX(1.1);
scaleMiddleUp.setToY(1.1);
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(100));
scaleDown.setNode(button);
scaleDown.setToX(1.0);
scaleDown.setToY(1.0);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
}

View File

@@ -16,13 +16,20 @@ public class FriendController {
@Autowired
UserService userService;
@Autowired
DashBoardController dashBoardController;
@FXML
private Button addButton;
@FXML
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
*/
@FXML
@@ -52,7 +59,51 @@ public class FriendController {
//add friend to the current user
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
//close the register window after the user has entered all the credentials
String friendName = userNameText.getText();
Stage current = (Stage) owner;
dashBoardController.updateAchievements();
dashBoardController.updateFriends();
current.close();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend added!",
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,12 +1,17 @@
package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
@@ -16,7 +21,6 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ScrollPane;
@@ -29,8 +33,10 @@ import javafx.stage.Window;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.client.HttpClientErrorException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;
@@ -39,13 +45,14 @@ import java.util.concurrent.TimeUnit;
*/
@Controller
public class RegisterWindowController {
@Autowired
UserService userService;
@Autowired
DashBoardController controller;
ExtraActivityController extraActivityController;
@FXML
private Text explainText;
//navigation panes
@FXML
private AnchorPane getStartedPane;
@@ -151,15 +158,6 @@ public class RegisterWindowController {
//extra pane
@FXML
private AnchorPane extraPane;
@FXML
private CheckBox localProduceCheckbox;
@FXML
private CheckBox bikeCheckbox;
@FXML
private CheckBox temperatureCheckbox;
@FXML
private CheckBox solarPanelsCheckbox;
@FXML
private TextField userNameText;
@FXML
@@ -168,6 +166,8 @@ public class RegisterWindowController {
private PasswordField passwordField2;
@FXML
private Button signUpButton;
//@FXML
//private Line uNamePathLine;
@@ -180,6 +180,8 @@ public class RegisterWindowController {
addSlideAnimation(1100, passwordField, 300);
TimeUnit.MILLISECONDS.sleep(300);
addSlideAnimation(1100, passwordField2, -420);
signUpButton.setSkin(new RegisterButtonSkin(signUpButton));
}
/**
@@ -195,12 +197,24 @@ public class RegisterWindowController {
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.
* @param event the click of the sign up button
*/
@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)
Window owner = signUpButton.getScene().getWindow();
//check if the username field is empty
@@ -228,11 +242,17 @@ public class RegisterWindowController {
}
//register the user with the provided username and password
userService.registerUser(userNameText.getText(), passwordField.getText());
try {
userService.registerUser(userNameText.getText(), passwordField.getText());
} catch (HttpClientErrorException ex) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
"This username has already been taken!");
return;
}
//close the register window after the user has entered all the credentials
Stage current = (Stage) owner;
current.close();
Parent calc = Application.load(this.getClass().getClassLoader()
.getResource("fxml/FirstCalculator.fxml"));
Scene scene = new Scene(calc);
@@ -263,9 +283,9 @@ public class RegisterWindowController {
}
});
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
@@ -308,6 +328,7 @@ public class RegisterWindowController {
});
}
@SuppressWarnings("Duplicates")
private void addSliderListenerDailyServing(Slider slider, Label label) {
DecimalFormat df = new DecimalFormat("0.0");
slider.valueProperty().addListener(new ChangeListener<Number>() {
@@ -329,6 +350,23 @@ public class RegisterWindowController {
});
}
/**
* adds a fade transition to the given node.
* @param node the node to add the transition to
*/
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.setFromY(800);
trans.setToY(0);
ParallelTransition par = new ParallelTransition();
par.setNode(travelPane);
par.getChildren().addAll(fade, trans);
par.play();
}
private void addSlideInAnimation(Node node) {
Timeline timeline = new Timeline();
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
@@ -344,6 +382,7 @@ public class RegisterWindowController {
*/
@SuppressWarnings("Duplicates")
public void displayGetStarted(ActionEvent event) {
addFadeTransAnimation(getStartedPane);
getStartedPane.setVisible(true);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -359,7 +398,7 @@ public class RegisterWindowController {
*/
@SuppressWarnings("Duplicates")
public void displayTravel(ActionEvent event) {
addSlideInAnimation(travelPane);
addFadeTransAnimation(travelPane);
getStartedPane.setVisible(false);
travelPane.setVisible(true);
homePane.setVisible(false);
@@ -376,6 +415,7 @@ public class RegisterWindowController {
*/
@SuppressWarnings("Duplicates")
public void displayHome(ActionEvent event) {
addFadeTransAnimation(homePane);
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(true);
@@ -391,6 +431,7 @@ public class RegisterWindowController {
*/
@SuppressWarnings("Duplicates")
public void displayFood(ActionEvent event) {
addFadeTransAnimation(foodPane);
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -406,6 +447,7 @@ public class RegisterWindowController {
*/
@SuppressWarnings("Duplicates")
public void displayShopping(ActionEvent event) {
addFadeTransAnimation(shoppingPane);
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -420,7 +462,10 @@ public class RegisterWindowController {
* @param event the click of the designated button
*/
@SuppressWarnings("Duplicates")
public void displayExtra(ActionEvent event) {
public void displayExtra(ActionEvent event) throws IOException {
addFadeTransAnimation(extraPane);
extraPane.getChildren().setAll((Node) Application.load(this.getClass()
.getClassLoader().getResource("fxml/extraActivities.fxml")));
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
@@ -449,46 +494,70 @@ public class RegisterWindowController {
userService.updateInput(userService.currentUser.getName(), "input_size",
peopleInHouseHoldLabel.getText());
}
if (!publicTransitField.getText().equals("0")) {
checkTransportLabels();
checkHousingLabels();
checkFoodLabels();
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_publictrans",
publicTransitField.getText());
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!airplaneTravelField.getText().equals("0")) {
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_airtotal",
airplaneTravelField.getText());
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
if (!carTravelGasolineField.getText().equals("0")) {
try {
extraActivityController.updateExtras();
} catch (NullPointerException ex) {
System.out.println("Continue");
}
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
owner, "Footprint saved!", "Your footprint is saved!");
}
/**
* Checks the food labels.
*/
public void checkFoodLabels() {
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles1",
carTravelGasolineField.getText());
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg1",
carTravelGasolineLabel.getText().replace(" mpg", ""));
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelDieselField.getText().equals("0")) {
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles2",
carTravelDieselField.getText());
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg2",
carTravelDieselLabel.getText().replace(" mpg", ""));
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!carTravelElectricField.getText().equals("0")) {
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles3",
carTravelElectricField.getText());
}
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg3",
carTravelElectricLabel.getText().replace(" mpge", ""));
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
}
/**
* Checks the housing labels.
*/
public void checkHousingLabels() {
if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars",
@@ -519,63 +588,88 @@ public class RegisterWindowController {
"input_footprint_housing_watersewage",
waterUsageLabel.getText().replace("% of similar households", ""));
}
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
if (localProduceCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"local_produce", true);
}
if (bikeCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"bike", true);
}
if (temperatureCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"temperature", true);
}
if (solarPanelsCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels", true);
}
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
}
}
/**
* Checks the transport labels.
*/
public void checkTransportLabels() {
if (!publicTransitField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_publictrans",
publicTransitField.getText());
}
if (!airplaneTravelField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_airtotal",
airplaneTravelField.getText());
}
if (!carTravelGasolineField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles1",
carTravelGasolineField.getText());
}
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg1",
carTravelGasolineLabel.getText().replace(" km/L", ""));
}
if (!carTravelDieselField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles2",
carTravelDieselField.getText());
}
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg2",
carTravelDieselLabel.getText().replace(" km/L", ""));
}
if (!carTravelElectricField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles3",
carTravelElectricField.getText());
}
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_mpg3",
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;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application;
import greenify.client.rest.UserService;
import javafx.animation.ScaleTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Parent;
@@ -12,10 +14,13 @@ import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.client.HttpClientErrorException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;
/**
@@ -35,6 +40,11 @@ public class UserController {
@FXML
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.
* 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
*/
@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
if (usernameField.getText().isEmpty()) {
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
@@ -65,7 +75,13 @@ public class UserController {
System.out.println("Password is " + passwordField.getText());
}
//log the user in with the userService method
userService.loginUser(usernameField.getText(), passwordField.getText());
try {
userService.loginUser(usernameField.getText(), passwordField.getText());
} catch (HttpClientErrorException ex) {
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
"Your username or password is incorrect!");
return;
}
Stage current = (Stage) owner;
//after logging in, close the login window
current.close();
@@ -129,10 +145,51 @@ public class UserController {
Parent registerWindow = Application.load(this.getClass().getClassLoader()
.getResource("fxml/RegisterWindow.fxml"));
Scene registerScene = new Scene(registerWindow);
registerScene.getStylesheets().add(this.getClass().getClassLoader()
.getResource("stylesheets/registerWindowStyle.css").toExternalForm());
Stage registerStage = new Stage();
registerStage.setScene(registerScene);
registerStage.setTitle("Enter register credentials");
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

@@ -0,0 +1,48 @@
package greenify.client.features;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class Friend {
private SimpleIntegerProperty place;
private SimpleStringProperty friend;
private SimpleDoubleProperty score;
/**
* 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.score = new SimpleDoubleProperty(friendScore);
}
public Integer getPlace() {
return place.get();
}
public void setPlace(Integer place) {
this.place = new SimpleIntegerProperty(place);
}
public String getFriend() {
return friend.get();
}
public void setFriend(String name) {
this.friend = new SimpleStringProperty(name);
}
public Double getScore() {
return score.get();
}
public void setScore(Double score) {
this.score = new SimpleDoubleProperty(score);
}
}

View File

@@ -0,0 +1,92 @@
package greenify.client.features;
import java.util.ArrayList;
import java.util.Random;
public class Hints {
public ArrayList<String> hints;
public Hints() {
this.hints = new ArrayList<String>();
initHints();
}
/**
* This method adds all the Strings to the array list.
*/
private void initHints() {
this.hints.add("Buying local produce will not only decrease your carbon "
+ "footprint, but it will also help your local economy: A win-win!");
this.hints.add("Did you know that a gas oven only uses 6% of its energy "
+ "to cook? And an electric oven is not much better at 12%!");
this.hints.add("70% of the deforestation of the Amazon rainforest is to provide land "
+ "for cattle ranches.");
this.hints.add("Research shows that reducing meat consumption can "
+ "increase your life span by 3,6 years");
this.hints.add("Vegetarians have a lower risk of getting: Heart disease, high blood "
+ "pressure, diabetes and cancer than meat eaters.");
this.hints.add("The carbon footprint of a vegetarian diet is about half "
+ "that of a meat-lovers diet!");
this.hints.add("Cycling is good for the environment and for your body, "
+ "so why not grab your bike instead of your car?");
this.hints.add("If we could capture all of the suns energy shining on the Earth for just "
+ "one hour, we could power the entire world for one whole year!");
this.hints.add("27,000 trees are cut down every day so we can have toilet paper.");
this.hints.add("Recycle glass bottles! A glass bottle made now will take "
+ "more than 4,000 years to decompose.");
this.hints.add("Don't forget to turn off the lights and heating in rooms"
+ " you're not using at the moment. Save some energy!");
this.hints.add("Did you know that about 4,5% of the Dutch population does not eat meat?");
this.hints.add("Reuse your bags when you go grocery shopping. You will save "
+ "plastic bags and won't have a lot of unused bags at home!");
this.hints.add("An estimated 250 million trees can be saved each year "
+ "if every published newspaper would be recycled!");
this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector. "
+ "That is a lot of jobs");
this.hints.add("You can use LED lights in your home to save energy! "
+ "They make light from about 85% of their energy");
this.hints.add("If you isolate your home well, it will be warmer, "
+ "and you'll save energy as well! No need to wear sweaters anymore");
this.hints.add("Do you have leftovers? Donate them to food kitchens."
+ " This way you won't waste"
+ " food, and you'll help a lot of people at the same time!");
this.hints.add("A lot of coffee places give you a discount if you bring your own cup. "
+ "Get rid of disposable cups!");
this.hints.add("When shopping, look for products with minimal to no packaging, "
+ "or packaging made from recycled items. ");
this.hints.add("If you order food, you can ask the restaurant to not include "
+ "utensils and napkins, it saves plastic and paper!");
this.hints.add("It takes about 66 days to form a new habit, keep going, you'll get there!");
this.hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for "
+ "the environment to refill than to buy one every time it's empty.");
this.hints.add("Only 1% of our planets water supply can be used a drinkwater."
+ " 97% is ocean water and 2% is frozen solid in the Arctic, for now.");
this.hints.add("For every two million tons of paper and glass, collected in "
+ "the Netherlands, close to 90% gets recycled and used to make new products");
this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household "
+ "equipment, you will automatically be charged a recycling tax on it. This is "
+ "also known as removal tax, or verwijderingsbijdrage in Dutch");
this.hints.add("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 seeks out a random hint from the list of strings.
* @return the random string hint.
*/
public String randomHint() {
Random rand = new Random();
int index = rand.nextInt(this.hints.size());
return this.hints.get(index);
}
}

View File

@@ -2,6 +2,7 @@ package greenify.client.rest;
import greenify.common.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
@@ -12,6 +13,9 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
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.Map;
@@ -19,6 +23,9 @@ import java.util.Map;
public class UserService {
public UserDto currentUser;
@Value( "${server.address:http://localhost:8080}" )
String serverAddress = "http://localhost:8080";
@Autowired
RestTemplate restTemplate;
@@ -36,16 +43,17 @@ public class UserService {
@SuppressWarnings("Duplicates")
//this suppressWarnings is to get rid of the errors of duplicate code
//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
HttpHeaders headers = new HttpHeaders();
//set the accept header in JSON value
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
//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)
//getting the name from the database
.queryParam("password", password);
.queryParam("password", hashPassword(password));
//getting the password from the database
//create a http entity to be sent
@@ -67,13 +75,14 @@ public class UserService {
* @return a userDTO
*/
@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
HttpHeaders headers = new HttpHeaders();
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("password", password);
.queryParam("password", hashPassword(password));
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
UserDto result = this.restTemplate.getForObject(builder.build()
@@ -92,7 +101,7 @@ public class UserService {
public void updateInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders();
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("inputName", inputName)
.queryParam("value",value);
@@ -109,13 +118,14 @@ public class UserService {
* @param value value of the input
*/
@SuppressWarnings("Duplicates")
public void updateExtraInput(String name, String inputName, Boolean value) {
public void updateExtraInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders();
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("inputName", inputName)
.queryParam("value",value);
.queryParam("value", value);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
@@ -128,15 +138,17 @@ public class UserService {
* @return returns the footprint score
*/
@SuppressWarnings("Duplicates")
public Float getFootprint(String name) {
public double getFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getFootprint")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Float result = this.restTemplate.getForObject(builder
Float footprint = this.restTemplate.getForObject(builder
.build().encode().toUri(), Float.class);
double result = Math.round(footprint * 10) / 10.0;
return result;
}
@@ -145,16 +157,17 @@ public class UserService {
* @param name name of the user
* @return returns the footprint score
*/
public Float getFirstFootprint(String name) {
public double getFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(serverAddress + "/getFirst")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Float footprint = this.restTemplate.getForObject(builder
.build().encode().toUri(), Float.class);
return footprint;
double result = Math.round(footprint * 10) / 10.0;
return result;
}
/**
@@ -166,7 +179,8 @@ public class UserService {
public Float saveFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFootprint")
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/saveFootprint")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
@@ -185,7 +199,8 @@ public class UserService {
public Float saveFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFirstFootprint")
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/saveFirstFootprint")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
@@ -203,7 +218,8 @@ public class UserService {
public List<String> getFriendNames(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFriends")
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getFriends")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
@@ -221,7 +237,27 @@ public class UserService {
public void addFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders();
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("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
}
/**
* Removes a friend from the friendslist of the user.
* @param name the username of the current user.
* @param friend the username of the friend you want to remove.
*/
@SuppressWarnings("Duplicates")
public void removeFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/removeFriend")
.queryParam("name", name)
.queryParam("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers);
@@ -238,7 +274,8 @@ public class UserService {
public Map<String, String> getInputs(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getInputs")
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getInputs")
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
@@ -252,18 +289,55 @@ public class UserService {
* @param name the username of the current user.
*/
@SuppressWarnings("Duplicates")
public Map<String, Boolean> getExtraInputs(String name) {
public Map<String, String> getExtraInputs(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl(serverAddress + "/getExtraInputs")
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build()
Map<String, String> result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class);
return result;
}
/**
* Gets the achievements of a user.
* @param name name of the user
* @return Map with all achievements
*/
@SuppressWarnings("Duplicates")
public Map getAchievements(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
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);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
return this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class);
}
/**
* Gets the list of all users.
*/
@@ -271,11 +345,50 @@ public class UserService {
public List<String> getAllUsers() {
HttpHeaders headers = new HttpHeaders();
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);
System.out.println(builder.build().encode().toUri());
List<String> result = this.restTemplate.getForObject(builder
.build().encode().toUri(), List.class);
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,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?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?>
@@ -17,6 +18,7 @@
<?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?>
@@ -159,6 +161,24 @@
</Label>
<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" />
<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>
<AnchorPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
<children>
@@ -178,7 +198,7 @@
</TextField>
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
<font>
<Font size="13.0" />
</font>
@@ -188,7 +208,7 @@
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
<children>
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
<font>
<Font size="13.0" />
</font>
@@ -197,7 +217,7 @@
</HBox>
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
<children>
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
<font>
<Font size="13.0" />
</font>
@@ -207,7 +227,7 @@
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
<font>
<Font size="13.0" />
</font>
@@ -236,7 +256,7 @@
</TextField>
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
<font>
<Font size="13.0" />
</font>
@@ -246,7 +266,7 @@
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
<children>
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpge">
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/Le">
<font>
<Font size="13.0" />
</font>
@@ -285,7 +305,7 @@
</font></TextField>
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
<font>
<Font size="16.0" />
</font>
@@ -294,7 +314,7 @@
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
<font>
<Font size="16.0" />
</font>

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="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" />
<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">
<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">
<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="Californian FB" size="20.0" />
</font>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
@@ -24,7 +25,7 @@
<Font size="13.0" />
</font>
</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 name="Corbel Bold" size="14.0" />
</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

@@ -178,7 +178,7 @@
</TextField>
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
<font>
<Font size="13.0" />
</font>
@@ -188,7 +188,7 @@
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
<children>
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
<font>
<Font size="13.0" />
</font>
@@ -197,7 +197,7 @@
</HBox>
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
<children>
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
<font>
<Font size="13.0" />
</font>
@@ -207,7 +207,7 @@
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
<font>
<Font size="13.0" />
</font>
@@ -236,7 +236,7 @@
</TextField>
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
<font>
<Font size="13.0" />
</font>
@@ -246,7 +246,7 @@
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
<children>
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpge">
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/Le">
<font>
<Font size="13.0" />
</font>
@@ -285,7 +285,7 @@
</font></TextField>
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
<font>
<Font size="16.0" />
</font>
@@ -294,7 +294,7 @@
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
<children>
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
<font>
<Font size="16.0" />
</font>

View File

@@ -2,14 +2,16 @@
<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
@@ -44,10 +46,36 @@
<Font size="21.0" />
</font>
</Button>
<Button fx:id="logOutButton" layoutX="33.0" layoutY="638.0" mnemonicParsing="false" onAction="#logOut" prefHeight="45.0" prefWidth="149.0" text="log out ">
<font>
<Font size="21.0" />
</font>
</Button>
<Line endX="104.0" layoutX="102.0" layoutY="133.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 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="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">
<font>
<Font size="15.0" />
</font>
</Label>
<Text fill="#002c0c" layoutX="14.0" layoutY="415.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Random hint!">
<font>
<Font size="20.0" />
</font>
</Text>
<Button fx:id="refreshHintsButton" layoutX="157.0" layoutY="390.0" mnemonicParsing="false" onAction="#addRandomHints" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="26.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/refresh2.png" />
</image>
</ImageView>
</graphic>
</Button>
<Line endX="104.0" layoutX="108.0" layoutY="88.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
</children></AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
@@ -129,32 +157,32 @@
</Label>
<Pane layoutX="290.0" layoutY="130.0" prefHeight="342.0" prefWidth="230.0" style="-fx-background-color: #f4fff4;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline miles">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline km">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline mpg">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline km/L">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="99.0" prefHeight="27.0" prefWidth="149.0" text="Diesel miles">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="99.0" prefHeight="27.0" prefWidth="149.0" text="Diesel km">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="143.0" prefHeight="27.0" prefWidth="149.0" text="Diesel mpg">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="143.0" prefHeight="27.0" prefWidth="149.0" text="Diesel km/L">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="187.0" prefHeight="27.0" prefWidth="149.0" text="Electric miles">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="187.0" prefHeight="27.0" prefWidth="149.0" text="Electric km">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="231.0" prefHeight="27.0" prefWidth="149.0" text="Electric mpg">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="231.0" prefHeight="27.0" prefWidth="149.0" text="Electric km/Le">
<font>
<Font size="14.0" />
</font>
@@ -205,74 +233,99 @@
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="545.0" layoutY="130.0" prefHeight="342.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<Pane layoutX="545.0" layoutY="130.0" prefHeight="255.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="26.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="14.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="90.0" prefHeight="46.0" prefWidth="115.0" text="Grains/baked &#10;foods" textAlignment="CENTER">
<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 size="14.0" />
</font>
</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 size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="218.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="152.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables">
<font>
<Font size="14.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="282.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="198.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="meat" layoutX="171.0" layoutY="41.0" styleClass="activityField" text="Label" />
<Label fx:id="grains" layoutX="171.0" layoutY="105.0" styleClass="activityField" text="Label" />
<Label fx:id="dairy" layoutX="171.0" layoutY="169.0" styleClass="activityField" text="Label" />
<Label fx:id="fruits" layoutX="171.0" layoutY="233.0" styleClass="activityField" text="Label" />
<Label fx:id="snacks" layoutX="171.0" layoutY="297.0" styleClass="activityField" text="Label" />
<Label fx:id="meat" layoutX="171.0" layoutY="29.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="121.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="213.0" styleClass="activityField" text="Label" />
</children>
</Pane>
<Label alignment="CENTER" layoutX="545.0" layoutY="488.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222">
<Label alignment="CENTER" layoutX="545.0" layoutY="385.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Label>
<Pane layoutX="545.0" layoutY="520.0" prefHeight="129.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<Pane layoutX="545.0" layoutY="412.0" prefHeight="238.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="7.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.0" layoutY="56.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
<Label fx:id="localProduce" layoutX="189.0" layoutY="56.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.0" layoutY="92.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
<Label fx:id="bike" layoutX="189.0" layoutY="92.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="164.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
<Label fx:id="loweringTemp" layoutX="188.0" layoutY="164.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="200.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
<font>
<Font size="14.0" />
</font>
</Label>
<CheckBox fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<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>
</Pane>
</children></AnchorPane>
<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">
<graphic>
<ImageView fitHeight="69.0" fitWidth="61.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold Italic" size="14.0" />
</font>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Text layoutX="94.0" layoutY="72.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Your Profile" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
@@ -398,16 +451,11 @@
</ImageView>
</graphic>
</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>
<TableColumn fx:id="globalPlace" prefWidth="30.0" text="#" />
<TableColumn fx:id="globalUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="globalScore" prefWidth="124.0" text="Score" />
</columns>
</TableView>
<TableView fx:id="developmentLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="developmentUser" prefWidth="75.0" text="User" />
<TableColumn fx:id="developmentScore" prefWidth="124.0" text="Score" />
<TableColumn fx:id="globalScore" prefWidth="100.0" text="Score" />
</columns>
</TableView>
<Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616">
@@ -420,6 +468,102 @@
<Font size="20.0" />
</font>
</Label>
<Button fx:id="addExtraActivityButton" contentDisplay="RIGHT" layoutX="568.0" layoutY="223.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity" textFill="#147219">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="80.0" fitWidth="79.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
<Label fx:id="achiev1text" alignment="CENTER" layoutX="555.0" layoutY="350.0" prefHeight="30.0" prefWidth="250.0" text="ACHIEVEMENTS" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<GridPane layoutX="539.0" layoutY="380.0" prefHeight="303.0" prefWidth="258.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="achiev1Tip" mnemonicParsing="false" styleClass="toolTipButton">
<graphic>
<ImageView fx:id="achieve1" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/Clover.png" />
<!-- image from pngall.com - 3548 -->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev4Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1">
<graphic>
<ImageView fx:id="achieve4" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/alternate_foods.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev2Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="1">
<graphic>
<ImageView fx:id="achieve2" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/Friendship.png" />
<!-- image from pngall.com - 24498 -->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev3Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="2">
<graphic>
<ImageView fx:id="achieve3" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/co2dev.png" />
<!-- image from exceldryer.com -->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev5Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic>
<ImageView fx:id="achieve5" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/achiev1pic.jpg" />
<!-- image from shutterstock.com - 1038138760 -->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev6Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1" GridPane.rowIndex="2">
<graphic>
<ImageView fx:id="achieve6" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/solar_panels.jpeg" />
<!-- image from moregreenenergy.com -->
</image>
</ImageView>
</graphic>
</Button>
</children>
</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>
</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">
@@ -434,7 +578,7 @@
<Font size="20.0" />
</font>
</Text>
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="170.0" prefHeight="426.0" prefWidth="214.0" style="-fx-background-color: #e1fcd9;">
<columns>
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
@@ -448,15 +592,40 @@
<Font size="20.0" />
</font>
</Text>
<TableView fx:id="friendLeaderboard" layoutX="300.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
<TableView fx:id="friendLeaderboard" layoutX="300.0" layoutY="170.0" prefHeight="426.0" prefWidth="232.0" style="-fx-background-color: #e1fcd9;">
<columns>
<TableColumn fx:id="friendUser" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="friendScore" prefWidth="108.0" text="Score" />
<TableColumn fx:id="friendPlace" prefWidth="30.0" resizable="false" text="#" />
<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>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</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>
</AnchorPane>
</children>

View File

@@ -0,0 +1,262 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<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>
<AnchorPane fx:id="veganMealPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0">
<children>
<Line fx:id="line1" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
<Text layoutX="248.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Eating a vegetarian meal">
<font>
<Font size="20.0" />
</font>
</Text>
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtraVegan" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="bikePane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
<children>
<Line fx:id="line2" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
<Text layoutX="203.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Using your bike instead of your car">
<font>
<Font size="20.0" />
</font>
</Text>
<Slider fx:id="bikeSlider" layoutX="144.0" layoutY="271.0" majorTickUnit="20.0" max="200.0" minorTickCount="0" prefHeight="24.0" prefWidth="427.0" showTickLabels="true" showTickMarks="true" />
<Text fill="#727272" layoutX="179.0" layoutY="144.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many km did you travel using your bike &#10;that you would have traveled with your car?" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Text>
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
<graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
<HBox alignment="CENTER" layoutX="305.0" layoutY="204.0" prefHeight="36.0" prefWidth="107.0" styleClass="textHolder">
<children>
<Label fx:id="bikeLabel" text="0 km">
<font>
<Font size="17.0" />
</font>
</Label>
</children>
</HBox>
</children>
</AnchorPane>
<AnchorPane fx:id="temperaturePane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
<children>
<Line fx:id="line3" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
<Text layoutX="179.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Lowering the temperature of your home">
<font>
<Font size="20.0" />
</font>
</Text>
<Text fill="#727272" layoutX="187.0" layoutY="133.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many degrees (Celcius) did you lower&#10;your home temperature?" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Text>
<Slider fx:id="temperatureSlider" blockIncrement="1.0" layoutX="176.0" layoutY="266.0" majorTickUnit="1.0" max="15.0" minorTickCount="0" prefHeight="24.0" prefWidth="360.0" showTickLabels="true" showTickMarks="true" />
<HBox alignment="CENTER" layoutX="316.0" layoutY="194.0" prefHeight="36.0" prefWidth="107.0" styleClass="textHolder">
<children>
<Label fx:id="temperatureLabel" text="0 Degrees">
<font>
<Font size="17.0" />
</font>
</Label>
</children>
</HBox>
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
<graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="solarPanelPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
<children>
<Line fx:id="line4" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
<Text layoutX="262.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Installing solar panels">
<font>
<Font size="20.0" />
</font>
</Text>
<Text fill="#727272" layoutX="202.0" layoutY="150.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many solar panels did you install?" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Text>
<HBox alignment="CENTER" layoutX="329.0" layoutY="201.0" prefHeight="36.0" prefWidth="56.0" styleClass="textHolder">
<children>
<Label fx:id="solarPanelsLabel" text="0">
<font>
<Font size="17.0" />
</font>
</Label>
</children>
</HBox>
<Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" />
<Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
<graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="localProducePane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
<children>
<Line fx:id="line11" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
<Text layoutX="264.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Buying local produce">
<font>
<Font size="20.0" />
</font>
</Text>
<Button fx:id="addLocalProduceButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtraLocal" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
<graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="publicTransportPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
<children>
<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 public transport instead of your car">
<font>
<Font size="20.0" />
</font>
</Text>
<Slider fx:id="publicTransportSlider" layoutX="144.0" layoutY="271.0" majorTickUnit="20.0" max="200.0" minorTickCount="0" prefHeight="24.0" prefWidth="427.0" showTickLabels="true" showTickMarks="true" />
<Text fill="#727272" layoutX="151.0" layoutY="145.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many km did you travel using public transport &#10;that you would have traveled with your car?" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Text>
<Button fx:id="addPublicTransportButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font>
<Font name="System Bold Italic" size="18.0" />
</font>
<graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/addActivity1.png" />
</image>
</ImageView>
</graphic>
</Button>
<HBox alignment="CENTER" layoutX="305.0" layoutY="204.0" prefHeight="36.0" prefWidth="107.0" styleClass="textHolder">
<children>
<Label fx:id="publicTransportLabel" text="0 km">
<font>
<Font size="17.0" />
</font>
</Label>
</children>
</HBox>
</children>
</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>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -2,4 +2,12 @@
-fx-background-color: #005e07;
-fx-text-fill: #c4eec9;
-fx-font-weight: bold;
}
.button:hover {
-fx-background-color: #027009;
}
.button:pressed {
-fx-background-color: #1ba023;
}

View File

@@ -29,7 +29,6 @@
.slider {
-show-value-on-interaction: true;
-fx-text-fill: red;
}
.km-yearBox {

View File

@@ -53,8 +53,15 @@
-fx-border-color: #497251;
}
#calculateFootPrintButton:pressed {
-fx-border-color: #497251;
#logOutButton {
-fx-background-color: #5a635c;
-fx-text-fill: #e3efe4;
}
#logOutButton:hover {
-fx-background-color: #e08f8f;
}
#logOutButton:pressed {
-fx-background-color: #ba3737;
}
/*friends table*/
@@ -85,5 +92,16 @@
-fx-font-size: 14px;
}
.toolTipButton {
-fx-background-color: transparent;
-fx-padding: 0 0 0 0;
}
.tooltip {
-fx-background-color: #d0f2d3;
-fx-text-fill: #364c38;
-fx-font-size: 14px;
}

View File

@@ -0,0 +1,26 @@
.navButton {
-fx-background-color: #6a7a6d;
}
.navButton:hover {
-fx-background-color: #728475;
}
.navButton:pressed {
-fx-background-color: #8cad91;
}
.slider .track {
-fx-background-color: #d3d3d3;
}
.slider .thumb {
-fx-background-color: transparent;
-fx-background-image: url('../icons/leaficon.png');
-fx-padding: 12;
}
.textHolder {
-fx-background-color: #89a888;
-fx-background-radius: 5px;
-fx-border-radius: 5px;
}

View File

@@ -0,0 +1,12 @@
#signUpButton {
-fx-background-color: #005e07;
-fx-text-fill: #c4eec9;
}
#signUpButton:hover {
-fx-background-color: #11911b;
}
#signUpButton:pressed {
-fx-background-color: #1a8c23;
}

View File

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

View File

@@ -0,0 +1,44 @@
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import greenify.client.features.Hints;
import org.junit.Test;
public class HintsTest {
@Test
public void initHintsTest() {
Hints test = new Hints();
assertFalse(test.hints.isEmpty());
}
@Test
public void hintsContainsTest() {
Hints test = new Hints();
assertTrue(test.hints.contains("27,000 trees are cut down "
+ "every day so we can have toilet paper."));
}
@Test
public void randomHintTest() {
Hints test = new Hints();
String random = test.randomHint();
assertTrue(test.hints.contains(random));
}
@Test
public void hintsContainsTestTwo() {
Hints test = new Hints();
assertTrue(test.hints.contains("Plastic bad, very bad."));
}
@Test
public void hintsNotNullTest() {
Hints test = new Hints();
assertNotNull(test.hints);
}
}

View File

@@ -1,6 +1,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import greenify.client.rest.UserService;
import greenify.common.UserDto;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -28,22 +30,22 @@ public class UserServiceTest {
@Test
public void userRegisterTest() throws Exception {
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))
.thenReturn(testUser);
UserDto user = userService.registerUser("Eric", "password");
Assert.assertEquals(testUser, user);
assertEquals(testUser, user);
}
@Test
public void userLoginTest() throws Exception {
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))
.thenReturn(testUser);
UserDto user = userService.loginUser("Eric", "password");
Assert.assertEquals(testUser, user);
assertEquals(testUser, user);
}
@Test
@@ -52,8 +54,8 @@ public class UserServiceTest {
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
Float.class))
.thenReturn(estimate);
Float result = userService.getFootprint("Eric");
Assert.assertEquals(estimate, result);
double result = (5 * 10) / 10.0;
assertTrue(result == userService.getFootprint("Eric"));
}
@Test
@@ -62,8 +64,8 @@ public class UserServiceTest {
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
Float.class))
.thenReturn(estimate);
Float result = userService.getFirstFootprint("Eric");
Assert.assertEquals(estimate, result);
double result = (5 * 10) / 10.0;
assertTrue(result == userService.getFirstFootprint("Eric"));
}
@Test
@@ -73,7 +75,7 @@ public class UserServiceTest {
Float.class))
.thenReturn(estimate);
Float result = userService.saveFootprint("Eric");
Assert.assertEquals(estimate, result);
assertEquals(estimate, result);
}
@Test
@@ -83,7 +85,7 @@ public class UserServiceTest {
Float.class))
.thenReturn(estimate);
Float result = userService.saveFirstFootprint("Eric");
Assert.assertEquals(estimate, result);
assertEquals(estimate, result);
}
@Test
@@ -94,7 +96,7 @@ public class UserServiceTest {
List.class))
.thenReturn(estimate);
List<String> result = userService.getFriendNames("Eric");
Assert.assertEquals(estimate, result);
assertEquals(estimate, result);
}
@Test
@@ -105,7 +107,7 @@ public class UserServiceTest {
List.class))
.thenReturn(estimate);
List<String> result = userService.getAllUsers();
Assert.assertEquals(estimate, result);
assertEquals(estimate, result);
}
@Test
@@ -116,18 +118,18 @@ public class UserServiceTest {
Map.class))
.thenReturn(estimate);
Map<String, String> result = userService.getInputs("Eric");
Assert.assertEquals(estimate, result);
assertEquals(estimate, result);
}
@Test
public void getExtraInputsTest() throws Exception {
Map<String, Boolean> estimate = new HashMap<>();
estimate.put("solar_panels", true);
Map<String, String> estimate = new HashMap<>();
estimate.put("solar_panels", "5");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
Map.class))
.thenReturn(estimate);
Map<String, Boolean> result = userService.getExtraInputs("Eric");
Assert.assertEquals(estimate, result);
Map<String, String> result = userService.getExtraInputs("Eric");
assertEquals(estimate, result);
}
@Test
@@ -138,8 +140,8 @@ public class UserServiceTest {
@Test
public void setExtraInputTest() throws Exception {
userService.updateExtraInput("Eric", "solar_panels", true);
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
userService.updateExtraInput("Eric", "solar_panels", "8");
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", "8");
}
@Test
@@ -147,6 +149,30 @@ public class UserServiceTest {
userService.addFriend("Eric", "Ceren");
Mockito.verify(userService).addFriend("Eric", "Ceren");
}
@Test
public void removeFriendTest() throws Exception {
userService.removeFriend("Eric", "Ceren");
Mockito.verify(userService).removeFriend("Eric", "Ceren");
}
@Test
public void getAchievementsTest() throws Exception {
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

@@ -0,0 +1,21 @@
import static org.junit.Assert.assertEquals;
import greenify.common.ApplicationException;
import org.junit.Test;
public class ApplicationExceptionTest {
@Test
public void setAndGetTest() {
ApplicationException ex = new ApplicationException("This is an exception");
assertEquals(ex.getMessage(), "This is an exception");
}
@Test
public void equalsTest() {
ApplicationException ex = new ApplicationException("This is an exception");
ApplicationException test = new ApplicationException("This is an exception");
assertEquals(ex.getMessage(), test.getMessage());
}
}

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: 'eclipse'
apply plugin: 'idea'
@@ -16,8 +29,8 @@ apply plugin: 'jacoco'
apply plugin: 'checkstyle'
bootJar {
baseName = 'gs-rest-service'
version = '0.1.0'
baseName = 'greenify-server'
version = '1.0.0'
}
test {

View File

@@ -0,0 +1,41 @@
package greenify.server;
import greenify.server.data.model.Achievement;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AllAchievements {
private static final List<Achievement> allAchievements = Arrays.asList(
new Achievement("Starting off", "You did your first green activity", false),
new Achievement("Social butterfly", "You added three friends", false),
new Achievement("Green saver", "You saved * of CO2", false),
new Achievement("Animal friend", "You have eaten 10 vegetarian meals", false),
new Achievement("Tom Dumoulin", "You have biked * km", false),
new Achievement("Let it shine", "You installed solar panels", false)
);
/**
* The method checks whether the achievement name is valid or not.
* @param achievementName the name of the achievement
* @return true or false
*/
public static Boolean isValidAchievement(String achievementName) {
return allAchievements.stream().anyMatch(i -> i.getName().equals(achievementName));
}
/**
* This method gets default achievements.
* @return the list of default achievements
*/
public static Map<String, Boolean> getDefaults() {
Map<String, Boolean> all = new HashMap<>();
for (Achievement achievement : allAchievements) {
all.put(achievement.getName(), achievement.isAchieved());
}
return all;
}
}

View File

@@ -185,12 +185,14 @@ public class InputValidator {
* This method gets extra values.
* @return the map of default values
*/
public static Map<String, Boolean> getExtraValues() {
Map<String, Boolean> map = new HashMap<String, Boolean>() { };
map.put("local_produce", false);
map.put("bike", false);
map.put("temperature", false);
map.put("solar_panels", false);
public static Map<String, String> getExtraValues() {
Map<String, String> map = new HashMap<String, String>() { };
map.put("vegan", "0");
map.put("local_produce", "0");
map.put("bike", "0");
map.put("public_transport", "0");
map.put("temperature", "0");
map.put("solar_panels", "0");
return map;
}
}

View File

@@ -0,0 +1,106 @@
package greenify.server.data.model;
import java.util.Objects;
public class Achievement {
private String name;
private String description;
private boolean achieved;
public Achievement() {}
/**
* Constructor for an achievement.
* @param name name of the achievement
* @param description description of the achievement
* @param achieved whether the achievement is achieved or not
*/
public Achievement(String name, String description, boolean achieved) {
this.name = name;
this.description = description;
this.achieved = achieved;
}
/**
* This method sets the name of an achievement.
* @return name of the achievement
*/
public String getName() {
return name;
}
/**
* This method sets the name of an achievement.
* @param name name of the achievement
*/
public void setName(String name) {
this.name = name;
}
/**
* This method gets the description of an achievement.
* @return the description of the achievement
*/
public String getDescription() {
return description;
}
/**
* This method sets the name of an achievement.
* @param description the description of an achievement
*/
public void setDescription(String description) {
this.description = description;
}
/**
* This method gets the state of an achievement.
* @return achievement is (not) achieved
*/
public boolean isAchieved() {
return achieved;
}
/**
* This method sets the state of an achievement.
* @param achieved achievement is (not) achieved
*/
public void setAchieved(boolean achieved) {
this.achieved = achieved;
}
/**
* This method gets a human readable (JSON) object.
* @return the JSON form of the object
*/
@Override
public String toString() {
return "Achievement(name=" + name + ", description=" + description
+ ", achieved=" + achieved + ")";
}
/**
* This method checks whether two users are equal or not.
* @param other another achievement
* @return achievements are (not) equal
*/
@Override
public boolean equals(Object other) {
if (other instanceof Achievement) {
Achievement that = (Achievement) other;
return achieved == that.achieved
&& name.equals(that.name)
&& description.equals(that.description);
}
return false;
}
/**
* This method gets the hashcode of an achievement.
* @return hashcode of an achievement
*/
@Override
public int hashCode() {
return Objects.hash(name, description, achieved);
}
}

View File

@@ -1,6 +1,7 @@
package greenify.server.data.model;
import greenify.common.ApplicationException;
import greenify.server.AllAchievements;
import greenify.server.InputValidator;
import lombok.Data;
@@ -45,11 +46,14 @@ public class User {
private Map<String, String> footPrintInputs = new HashMap<>();
@ElementCollection
private Map<String, Boolean> extraInputs = new HashMap<>();
private Map<String, String> extraInputs = new HashMap<>();
@ManyToMany
private List<User> friends;
@ElementCollection
private Map<String, Boolean> achievements;
public User() {}
/**
@@ -65,6 +69,7 @@ public class User {
this.setFootPrintInputs(InputValidator.getDefaultValues());
this.setExtraInputs(InputValidator.getExtraValues());
this.friends = new ArrayList<User>();
this.setAchievements(AllAchievements.getDefaults());
}
/**
@@ -167,7 +172,7 @@ public class User {
* This method gets the extra inputs of the user.
* @return extra inputs of the user
*/
public Map<String, Boolean> getExtraInputs() {
public Map<String, String> getExtraInputs() {
return extraInputs;
}
@@ -175,7 +180,7 @@ public class User {
* This method sets the extra inputs of the user.
* @param extraInputs footprint inputs of the user
*/
public void setExtraInputs(Map<String, Boolean> extraInputs) {
public void setExtraInputs(Map<String, String> extraInputs) {
this.extraInputs = extraInputs;
}
@@ -204,10 +209,37 @@ public class User {
throw new ApplicationException("Cannot add yourself as a friend");
} else {
friends.add(user);
System.out.print("Friend added!");
}
}
/**
* Removes a friend from the friendslist of the user.
* @param user the friend you want to remove.
*/
public void removeFriend(User user) {
if (!friends.contains(user)) {
throw new ApplicationException("This user is not your friend!");
} else {
friends.remove(user);
}
}
/**
* This method sets the achievements of the user.
* @param achievements achievements of the user
*/
public void setAchievements(Map<String, Boolean> achievements) {
this.achievements = achievements;
}
/**
* This method gets the achievements of the user.
* @return achievements of the user
*/
public Map<String, Boolean> getAchievements() {
return this.achievements;
}
/**
* This method gets a human readable (JSON) object.
* @return the JSON form of the object.

View File

@@ -63,7 +63,7 @@ public class UserController {
@RequestMapping("/setExtraInput")
public void setExtraInput(@RequestParam(value = "name") String name,
@RequestParam(value = "inputName") String inputName,
@RequestParam(value = "value") Boolean value) {
@RequestParam(value = "value") String value) {
userService.setExtraInput(name, inputName, value);
}
@@ -114,7 +114,6 @@ public class UserController {
*/
@RequestMapping("/getFirst")
public Float getFirstFootprint(@RequestParam(value = "name") String name) {
System.out.println("hello");
Float footprint = userService.getFirstFootprint(name);
return footprint;
}
@@ -150,18 +149,59 @@ public class UserController {
* This method gets the extra inputs map of the user.
*/
@RequestMapping("/getExtraInputs")
public Map<String, Boolean> getExtraInputs(@RequestParam(value = "name") String name) {
public Map<String, String> getExtraInputs(@RequestParam(value = "name") String name) {
return userService.getExtraInputMap(name);
}
/**
* This method adds friend for a user.
* This method adds a friend to a user.
* @param name name of the user
*
* @param friend the name of the user you want to add as a friend.
*/
@RequestMapping("/addFriend")
public void addFriend(@RequestParam(value = "name") String name,
@RequestParam(value = "friend") String friend) {
@RequestParam(value = "friend") String friend) {
userService.addFriend(name, friend);
}
/**
* This method removes a friend from a user.
* @param name name of the user
* @param friend name of the friend you want to remove
*/
@RequestMapping("/removeFriend")
public void removeFriend(@RequestParam(value = "name") String name,
@RequestParam(value = "friend") String friend) {
userService.removeFriend(name, friend);
}
/**
* This method gets all achievements of a user.
* @param name name of the user
* @return map of all achievements of the user
*/
@RequestMapping("/getAchievements")
public Map<String, Boolean> getAchievements(@RequestParam(value = "name") String name) {
return userService.getAchievements(name);
}
/**
* This method gets the result for schema.
* @param name name of the user
* @return map of all results of the user
*/
@RequestMapping("/getResults")
public Map<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

@@ -0,0 +1,97 @@
package greenify.server.service;
import greenify.server.data.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AchievementService {
@Autowired
UserService userService;
/**
* This method updates all achievements of a user.
* @param user the user for whom the achievements change
*/
public void updateAchievements(User user) {
achieveGettingStarted(user);
achieveSocialButterfly(user);
achieveGreenSaver(user);
achieveAnimalFriend(user);
achieveTomDumoulin(user);
achieveLetItShine(user);
}
/**
* This method makes sure the user gets an achievement
* upon calculating their footprint for the first time.
* @param user user for whom achiev1 changes
*/
public void achieveGettingStarted(User user) {
userService.setAchievement(user.getName(), "Starting off", true);
}
/**
* This method changes achiev2 when this is the case.
* @param user user for whom achiev2 changes
*/
public void achieveSocialButterfly(User user) {
if (user.getFriends().size() >= 3) {
userService.setAchievement(user.getName(), "Social butterfly", true);
} else {
userService.setAchievement(user.getName(), "Social butterfly", false);
}
}
/**
* This method changes achiev3 when this is the case.
* @param user user for whom achiev3 changes
*/
public void achieveGreenSaver(User user) {
if (20 > user.getFootPrint()) {
userService.setAchievement(user.getName(), "Green saver", true);
} else {
userService.setAchievement(user.getName(), "Green saver", false);
}
}
/**
* This method changes achiev4 when this is the case.
* @param user user for whom achiev4 changes
*/
public void achieveAnimalFriend(User user) {
int vegan = Integer.parseInt(user.getExtraInputs().get("vegan"));
if (vegan > 10) {
userService.setAchievement(user.getName(), "Animal friend", true);
} else {
userService.setAchievement(user.getName(), "Animal friend", false);
}
}
/**
* This method changes achiev5 when this is the case.
* @param user user for whom achiev5 changes
*/
public void achieveTomDumoulin(User user) {
int bike = Integer.parseInt(user.getExtraInputs().get("bike"));
if (bike > 15) {
userService.setAchievement(user.getName(), "Tom Dumoulin", true);
} else {
userService.setAchievement(user.getName(), "Tom Dumoulin", false);
}
}
/**
* This method changes achiev6 when this is the case.
* @param user user for whom achiev6 changes
*/
public void achieveLetItShine(User user) {
int solarPanels = Integer.parseInt(user.getExtraInputs().get("solar_panels"));
if (solarPanels >= 2) {
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.util.UriComponentsBuilder;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -62,7 +63,6 @@ public class CalculatorService {
.indexOf("<result_grand_total>")
+ 20, response.getBody().indexOf("</result_grand_total>"));
// to do: in not HTTP 200 or exception case throws exception
System.out.println(Float.parseFloat(result));
return Float.parseFloat(result);
}
@@ -72,21 +72,84 @@ public class CalculatorService {
* @return the footprint of the user
*/
public Float calculateFootprint(User user) {
Float footprint = invokeExternalService(user.getFootPrintInputs());
addExtras(user);
Float footprint = invokeExternalService(user.getFootPrintInputs());
footprint = footprint - (float) (Float.parseFloat(user
.getExtraInputs().get("solar_panels")) * 1.2);
footprint = footprint - Float.parseFloat(user
.getExtraInputs().get("temperature")) / 4;
footprint = footprint - (float) (Float.parseFloat(user
.getExtraInputs().get("local_produce")) * 0.1);
return footprint;
}
/**
* This method adds extra input to the user.
* @param user name of the user
*/
public void addExtras(User user) {
if (user.getExtraInputs().get("local_produce")) {
user.setFootPrint(user.getFootPrint() - 2);
} else if (user.getExtraInputs().get("bike")) {
user.setFootPrint(user.getFootPrint() - 2);
} else if (user.getExtraInputs().get("temperature")) {
user.setFootPrint(user.getFootPrint() - 2);
} else if (user.getExtraInputs().get("solar_panels")) {
user.setFootPrint(user.getFootPrint() - 2);
Map<String, String> inputs = user.getFootPrintInputs();
Float netPublic = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_transportation_publictrans"))
+ Float.parseFloat(user.getExtraInputs().get("public_transport"));
Float netCar = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_transportation_miles1"))
- Float.parseFloat(user.getExtraInputs().get("public_transport"))
- Float.parseFloat(user.getExtraInputs().get("bike"));
Float netVegan = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_shopping_food_fruitvegetables"))
+ Float.parseFloat(user.getExtraInputs().get("vegan"));
Float netShopping = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_shopping_goods_total"))
- Float.parseFloat(user.getExtraInputs().get("local_produce")) * 100;
inputs.put("input_footprint_transportation_publictrans", netPublic + "");
inputs.put("input_footprint_transportation_miles1", netCar + "");
inputs.put("input_footprint_shopping_food_fruitvegetables", netVegan + "");
inputs.put("input_footprint_shopping_goods_total", netShopping + "");
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

@@ -2,6 +2,7 @@ package greenify.server.service;
import greenify.common.ApplicationException;
import greenify.common.UserDto;
import greenify.server.AllAchievements;
import greenify.server.InputValidator;
import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository;
@@ -19,6 +20,9 @@ public class UserService {
@Autowired
CalculatorService calculatorService;
@Autowired
AchievementService achievementService;
@Autowired
UserRepository userRepository;
@@ -37,6 +41,7 @@ public class UserService {
user.setFootPrintInputs(InputValidator.getDefaultValues());
Float footprint = calculatorService.calculateFootprint(user);
user.setFootPrint(footprint);
user.setAchievements(AllAchievements.getDefaults());
userRepository.save(user);
} else {
throw new ApplicationException("User already exists");
@@ -64,21 +69,37 @@ public class UserService {
}
/**
<<<<<<< HEAD
* Adds a friend to the friendlist of the user.
* @param name the username of the user
* @param friend the name of the friend you want to add.
* @throws ApplicationException if the user is not in the database.
*/
public void addFriend(String name, String friend) {
User user = userRepository.findByName(name);
User add = userRepository.findByName(friend);
if (user == null || add == null ) {
if (add == null ) {
throw new ApplicationException("User does not exist");
}
user.addFriend(add);
userRepository.save(user);
}
/**
* Removes a friend from the friendlist of the user.
* @param name the username of the user
* @param friend the name of the friend you want to remove.
* @throws ApplicationException if the user is not in the database.
*/
public void removeFriend(String name, String friend) {
User user = userRepository.findByName(name);
User remove = userRepository.findByName(friend);
if (remove == null ) {
throw new ApplicationException("User does not exist");
}
user.removeFriend(remove);
userRepository.save(user);
}
/**
* This method sets input for a user.
* @param name name of the user
@@ -93,6 +114,7 @@ public class UserService {
if (InputValidator.isValidItem(inputName)
&& InputValidator.isValidItemValue(inputName, value)) {
user.getFootPrintInputs().put(inputName, value);
achievementService.updateAchievements(user);
userRepository.save(user);
} else {
throw new ApplicationException("Invalid input");
@@ -106,12 +128,14 @@ public class UserService {
* @param inputName name of the input of the user
* @param value value of the input
*/
public void setExtraInput(String name, String inputName, Boolean value) {
public void setExtraInput(String name, String inputName, String value) {
User user = userRepository.findByName(name);
if (user == null) {
throw new ApplicationException("User does not exist");
} else {
user.getExtraInputs().put(inputName, value);
String oldValue = user.getExtraInputs().get(inputName);
Integer total = Integer.parseInt(oldValue) + Integer.parseInt(value);
user.getExtraInputs().put(inputName, total + "");
userRepository.save(user);
}
}
@@ -146,7 +170,7 @@ public class UserService {
* @param name of the user
* @return extra input map
*/
public Map<String, Boolean> getExtraInputMap(String name) {
public Map<String, String> getExtraInputMap(String name) {
User user = userRepository.findByName(name);
return user.getExtraInputs();
}
@@ -210,6 +234,63 @@ public class UserService {
return result;
}
/**
* This methods sets a achievement.
* @param name name of the user
* @param achievement name of the achievement
* @param achieved (not) achieved
*/
public void setAchievement(String name, String achievement, Boolean achieved) {
User user = userRepository.findByName(name);
if (user == null) {
throw new ApplicationException("User does not exist");
}
if (!AllAchievements.isValidAchievement(achievement)) {
throw new ApplicationException("Invalid achievement");
}
Map<String, Boolean> temp = user.getAchievements();
temp.put(achievement, achieved);
user.setAchievements(temp);
userRepository.save(user);
}
/**
* This method gets whether the achievement is achieved.
* @param name of the user
* @param achievement name of the achievement
* @return (not) achieved
*/
public Boolean getAchievement(String name, String achievement) {
User user = userRepository.findByName(name);
if (AllAchievements.isValidAchievement(achievement)) {
return user.getAchievements().get(achievement);
} else {
throw new ApplicationException("Invalid achievement");
}
}
/**
* 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, Boolean> getAchievements(String name) {
User user = userRepository.findByName(name);
achievementService.updateAchievements(user);
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.
* @return list of all users
@@ -222,4 +303,15 @@ public class UserService {
}
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

@@ -0,0 +1,39 @@
import static org.junit.Assert.assertEquals;
import greenify.server.AllAchievements;
import greenify.server.data.model.Achievement;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
class AllAchievementsTest {
@Test
void isValidAchievementTest() {
new AllAchievements();
assertEquals(true, AllAchievements.isValidAchievement(
"Starting off"));
assertEquals(false, AllAchievements.isValidAchievement("test"));
}
@Test
void getDefaultsTest() {
List<Achievement> all = new ArrayList<Achievement>() {{
add(new Achievement(
"Starting off", "You did your first green activity", false));
add(new Achievement(
"Social butterfly", "You added three friends", false));
add(new Achievement(
"Green saver", "You saved * of CO2", false));
add(new Achievement(
"Animal friend", "You have eaten 10 vegetarian meals", false));
add(new Achievement(
"Tom Dumoulin", "You have biked * km", false));
add(new Achievement(
"Let it shine", "You installed solar panels", false));
}
};
assertEquals(all.size(), AllAchievements.getDefaults().size());
}
}

View File

@@ -151,7 +151,7 @@ public class InputValidatorTest {
put("input_footprint_shopping_services_charity", "146");
put("input_footprint_shopping_services_miscservices", "114");
put("internal_state_abbreviation", "US");
}
}
};
assertTrue(map.size() == InputValidator.getDefaultValues().size());
}

View File

@@ -0,0 +1,75 @@
package greenify.server.data.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Test;
class AchievementTest {
private Achievement achievement = new Achievement("SavedCO2",
"You saved 100 cow farts of CO2!", true);
private Achievement other = new Achievement("SavedCO2",
"You saved 100 cow farts of CO2!", true);
@Test
public void getAndSetTest() {
Achievement testAchievement = new Achievement();
testAchievement.setName("SavedCO2");
testAchievement.setDescription("You saved 100 cow farts of CO2!");
testAchievement.setAchieved(true);
assertEquals("SavedCO2", achievement.getName());
assertEquals("You saved 100 cow farts of CO2!", achievement.getDescription());
assertTrue(achievement.isAchieved());
assertEquals(achievement, testAchievement);
}
@Test
public void toStringTest() {
assertEquals("Achievement(name=SavedCO2, "
+ "description=You saved 100 cow farts of CO2!, achieved=true)",
achievement.toString());
}
@Test
public void equalsTest() {
assertEquals(achievement.getName(), other.getName());
assertEquals(achievement.getDescription(), other.getDescription());
assertEquals(achievement.isAchieved(), other.isAchieved());
assertEquals(achievement, other);
}
@Test
public void notEqualAchievedTest() {
Achievement first = new Achievement("greenify", "description", true);
Achievement second = new Achievement("greenify", "description", false);
assertNotEquals(first, second);
}
@Test
public void notEqualNameTest() {
Achievement first = new Achievement("greenify", "description", true);
Achievement second = new Achievement("ceren", "description", true);
assertNotEquals(first, second);
}
@Test
public void notEqualDescriptionTest() {
Achievement first = new Achievement("greenify", "hello", false);
Achievement second = new Achievement("greenify", "description", false);
assertNotEquals(first, second);
}
@Test
public void instanceOfTest() {
Achievement first = new Achievement();
Object second = new Object();
assertNotEquals(first, second);
}
@Test
public void hashCodeTest() {
assertEquals(achievement, other);
assertEquals(achievement.hashCode(), other.hashCode());
}
}

View File

@@ -2,9 +2,11 @@ package greenify.server.data.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import greenify.common.ApplicationException;
import greenify.server.AllAchievements;
import org.junit.Test;
@@ -125,6 +127,27 @@ public class UserTest {
});
}
@Test
public void removeFriendValidTest() {
User test = new User(1L, "greenify", "password");
List<User> friendList = new ArrayList<>();
friendList.add(test);
User user = new User(1L, "green", "pass");
user.setFriends(friendList);
assertEquals(user.getFriends(), friendList);
user.removeFriend(test);
assertEquals(user.getFriends(), new ArrayList<User>());
}
@Test
public void removeFriendInvalidTest() {
User user = new User(1L, "greenify", "password");
User test = new User(2L, "user", "pass");
assertThrows(ApplicationException.class, () -> {
user.removeFriend(test);
});
}
@Test
public void setFriendTest() {
List<User> friends = new ArrayList<User>();
@@ -134,4 +157,17 @@ public class UserTest {
first.setFriends(friends);
assertEquals(friends, first.getFriends());
}
@Test
public void getAchievementsTest() {
User user = new User(1L, "greenify", "password");
assertEquals(user.getAchievements(), AllAchievements.getDefaults());
}
@Test
public void setAchievementsTest() {
User user = new User(1L, "greenify", "password");
user.setAchievements(null);
assertNull(user.getAchievements());
}
}

View File

@@ -82,11 +82,11 @@ public class UserControllerTest {
public void setExtraInputTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Boolean> arg3Captor = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<String> arg3Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/setExtraInput")
.param("name", "ceren")
.param("inputName", "input_size")
.param("value", "true")
.param("value", "5")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
@@ -94,7 +94,7 @@ public class UserControllerTest {
.setExtraInput(arg1Captor.capture(), arg2Captor.capture(), arg3Captor.capture());
assertEquals("ceren", arg1Captor.getValue());
assertEquals("input_size", arg2Captor.getValue());
assertEquals(true, arg3Captor.getValue());
assertEquals("5", arg3Captor.getValue());
}
@Test
@@ -113,6 +113,22 @@ public class UserControllerTest {
assertEquals("merel", arg2Captor.getValue());
}
@Test
public void removeFriendTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/removeFriend")
.param("name", "ceren")
.param("friend", "merel")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
verify(userService, times(1))
.removeFriend(arg1Captor.capture(), arg2Captor.capture());
assertEquals("ceren", arg1Captor.getValue());
assertEquals("merel", arg2Captor.getValue());
}
@Test
public void getInputMapTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
@@ -221,4 +237,41 @@ public class UserControllerTest {
verify(userService, times(1)).saveFirstFootprint(arg1Captor.capture());
assertEquals("ceren", arg1Captor.getValue());
}
@Test
public void getAchievementsTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/getAchievements")
.param("name", "mika")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
verify(userService, times(1)).getAchievements(arg1Captor.capture());
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

@@ -0,0 +1,152 @@
package greenify.server.service;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
public class AchievementServiceTest {
@TestConfiguration
static class UserServiceConfiguration {
@Bean
public UserService userService() {
return new UserService();
}
}
@TestConfiguration
static class AchievementServiceConfiguration {
@Bean
public AchievementService achievementService() {
return new AchievementService();
}
}
@Autowired
private UserService userService;
@MockBean
private UserRepository userRepository;
@MockBean
private CalculatorService calculatorService;
@Autowired
private AchievementService achievementService;
/**
* setUp method for test.
*/
@Before
public void setUp() {
User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName()))
.thenReturn(alex);
userService.setExtraInput("alex", "vegan", "25");
userService.setExtraInput("alex", "solar_panels", "3");
}
@Test
public void updateAchievementsTest() {
User alex = userRepository.findByName("alex");
achievementService.updateAchievements(alex);
assertEquals(true, userService.getAchievement("alex", "Starting off"));
}
@Test
public void achieveGettingStartedTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveGettingStarted(alex);
assertEquals(true, userService.getAchievement("alex", "Starting off"));
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
}
@Test
public void achieveSocialButterflyTest() {
User alex = userRepository.findByName("alex");
alex.addFriend(new User(2L, "Bubbles", "Bubbles"));
alex.addFriend(new User(3L, "Cheese", "crackers"));
alex.addFriend(new User(4L, "Perry", "Doofenshmirtz"));
achievementService.achieveSocialButterfly(alex);
assertEquals(true, userService.getAchievement("alex", "Social butterfly"));
}
@Test
public void notAchieveSocialButterflyTest() {
User alex = userRepository.findByName("alex");
alex.addFriend(new User(2L, "Bubbles", "Bubbles"));
achievementService.achieveSocialButterfly(alex);
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
}
@Test
public void achieveGreenSaverTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveGreenSaver(alex);
assertEquals(true, userService.getAchievement("alex", "Green saver"));
}
@Test
public void notAchieveGreenSaverTest() {
User alex = userRepository.findByName("alex");
alex.setFootPrint(90f);
achievementService.achieveGreenSaver(alex);
assertEquals(false, userService.getAchievement("alex", "Green saver"));
}
@Test
public void achieveAnimalFriendTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveAnimalFriend(alex);
assertEquals(true, userService.getAchievement("alex", "Animal friend"));
}
@Test
public void notAchieveAnimalFriendTest() {
User alex = userRepository.findByName("alex");
alex.getExtraInputs().put("vegan", "0");
achievementService.achieveAnimalFriend(alex);
assertEquals(false, userService.getAchievement("alex", "Animal friend"));
}
@Test
public void achieveTomDumoulinTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveTomDumoulin(alex);
assertEquals(false, userService.getAchievement("alex", "Tom Dumoulin"));
}
@Test
public void successfulAchieveTomDumoulinTest() {
User alex = userRepository.findByName("alex");
alex.getExtraInputs().put("bike", "25");
achievementService.achieveTomDumoulin(alex);
assertEquals(true, userService.getAchievement("alex", "Tom Dumoulin"));
}
@Test
public void achieveLetItShineTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveLetItShine(alex);
assertEquals(true, userService.getAchievement("alex", "Let it shine"));
}
@Test
public void notAchieveLetItShineTest() {
User alex = userRepository.findByName("alex");
alex.getExtraInputs().put("solar_panels", "0");
achievementService.achieveLetItShine(alex);
assertEquals(false, userService.getAchievement("alex", "Let it shine"));
}
}

View File

@@ -1,12 +1,5 @@
package greenify.server.service;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import greenify.server.data.model.User;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -14,16 +7,10 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.ExpectedCount;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
@@ -59,62 +46,6 @@ public class CalculatorServiceTest {
mockServer = MockRestServiceServer.createServer(restTemplate);
}
@Test
public void calculateFootprintTest() throws URISyntaxException {
Map<String,String> map = new HashMap<String, String>() {{
put("input_location_mode", "1");
put("input_location", "48001");
put("input_income", "1");
}
};
User user = new User(1L,"greenify", "password");
user.setFootPrintInputs(map);
mockServer.expect(ExpectedCount.once(),
requestTo(new URI("https://apis.berkeley.edu/coolclimate/footprint?"
+ "input_location=48001&input_location_mode=1&input_income=1")))
.andExpect(method(HttpMethod.GET))
.andExpect(header("app_id", "a98272e3"))
.andExpect(header("app_key", "b9167c4918cb2b3143614b595065d83b"))
.andRespond(withStatus(HttpStatus.OK)
.contentType(MediaType.APPLICATION_JSON)
.body("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<response>\n"
+ " <result_motor_vehicles_direct>5.0765</result_motor_vehicles_direct>\n"
+ " <result_motor_vehicles_indirect>1.167595"
+ "</result_motor_vehicles_indirect>\n"
+ " <result_goods_total>2.481474</result_goods_total>\n"
+ " <result_services_total>2.478352</result_services_total>\n"
+ " <result_grand_total>19.259982</result_grand_total>\n"
+ "</response>")
);
Float footPrint = calculatorService.calculateFootprint(user);
mockServer.verify();
Assert.assertEquals(new Float(19.259982), footPrint);
}
@Test
public void addExtrasTest() throws URISyntaxException {
User user = new User(1L,"greenify", "password");
Map<String,Boolean> map = new HashMap<String, Boolean>() {{
put("local_produce", false);
put("bike", false);
put("temperature", false);
put("solar_panels", false);
}};
user.setExtraInputs(map);
user.setFootPrint(50f);
Map<String,Boolean> secondMap = new HashMap<String, Boolean>() {{
put("local_produce", true);
put("bike", true);
put("temperature", true);
put("solar_panels", true);
}};
user.setExtraInputs(secondMap);
calculatorService.addExtras(user);
mockServer.verify();
Assert.assertEquals(new Float(48f), user.getFootPrint());
}
@Test
public void invokeExternalServiceTest() {
CalculatorService service = new CalculatorService();
@@ -242,4 +173,138 @@ public class CalculatorServiceTest {
Float footPrint = service.invokeExternalService(map);
Assert.assertEquals(new Float(11421.537), footPrint);
}
@Test
public void getResultsTest() {
CalculatorService service = new CalculatorService();
service.restTemplate = new RestTemplate();
Map<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,10 +2,14 @@ package greenify.server.service;
import static org.junit.Assert.assertEquals;
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 greenify.common.ApplicationException;
import greenify.common.UserDto;
import greenify.server.AllAchievements;
import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository;
import org.junit.Assert;
@@ -43,6 +47,9 @@ public class UserServiceTest {
@MockBean
private CalculatorService calculatorService;
@MockBean
private AchievementService achievementService;
/**
* setUp method for test.
*/
@@ -97,8 +104,8 @@ public class UserServiceTest {
User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName()))
.thenReturn(alex);
userService.setExtraInput("alex", "solar_panels", true);
assertEquals(true, alex.getExtraInputs()
userService.setExtraInput("alex", "solar_panels", "5");
assertEquals("5", alex.getExtraInputs()
.get("solar_panels"));
}
@@ -109,7 +116,8 @@ public class UserServiceTest {
@Test
public void setExtraInputNullTest() {
assertThrows(ApplicationException.class, () -> userService.setExtraInput(null, "hello", true));
assertThrows(ApplicationException.class, () -> userService
.setExtraInput(null, "hello", "6"));
}
@Test
@@ -166,7 +174,7 @@ public class UserServiceTest {
@Test
public void getExtraInputMapTest() {
Map<String, Boolean> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName()))
.thenReturn(alex);
@@ -265,13 +273,73 @@ public class UserServiceTest {
assertEquals(alex.getFriends(), test);
}
@Test
public void removeFriendTest() {
User alex = userRepository.findByName("alex");
User lola = userRepository.findByName("lola");
assertEquals(lola.getFriends(), alex.getFriends());
userService.addFriend("alex", "lola");
ArrayList<User> test = new ArrayList<User>();
test.add(lola);
assertEquals(alex.getFriends(), test);
userService.removeFriend("alex", "lola");
assertEquals(lola.getFriends(), alex.getFriends());
}
@Test
public void removeFriendNullTest() {
assertThrows(ApplicationException.class, () -> userService.removeFriend("alex", null));
}
@Test
public void setAchievementNullUserTest() {
assertThrows(ApplicationException.class, () -> userService
.setAchievement("ceren", "Starting off", true));
}
@Test
public void invalidAchievementTest() {
assertThrows(ApplicationException.class, () -> userService
.setAchievement("alex", "greenify", true));
}
@Test
public void addFriendNullFriendTest() {
assertThrows(ApplicationException.class, () -> userService.addFriend("alex", null));
}
@Test
public void addFriendNullUserTest() {
assertThrows(ApplicationException.class, () -> userService.addFriend(null, "password"));
public void setAchievementTest() {
User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName()))
.thenReturn(alex);
userService.setAchievement("alex",
"Starting off", true);
assertEquals(true, userService
.getAchievement("alex", "Starting off"));
}
}
@Test
public void getAchievementTest() {
assertThrows(ApplicationException.class, () -> userService.getAchievement("alex", "hello"));
assertEquals(false, userService.getAchievement("alex", "Starting off"));
}
@Test
public void getAchievementsTest() {
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);
}
}