From 5877e307d55744ac05fb5c0264799bb8f366b7d5 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 11 Mar 2019 16:44:55 +0100 Subject: [PATCH] ADD:: added javadoc comments where needed for the checkstyle EDIT:: edited some lines to fit the checkstyle fixed some indentation warnings and line length warnings --- .../main/java/gogreen/client/Application.java | 40 ++++++---- .../controller/DashBoardController.java | 49 ++++++------ .../client/controller/UserController.java | 79 +++++++++++-------- .../java/gogreen/client/rest/UserService.java | 6 ++ .../src/main/java/gogreen/common/UserDTO.java | 5 +- .../java/gogreen/server/data/model/User.java | 18 +++++ .../server/rest/RestExceptionHandler.java | 2 +- .../gogreen/server/rest/UserController.java | 8 +- .../gogreen/server/service/UserService.java | 12 +++ 9 files changed, 136 insertions(+), 83 deletions(-) diff --git a/src/Client/src/main/java/gogreen/client/Application.java b/src/Client/src/main/java/gogreen/client/Application.java index 574a1a8..645f59f 100644 --- a/src/Client/src/main/java/gogreen/client/Application.java +++ b/src/Client/src/main/java/gogreen/client/Application.java @@ -21,10 +21,10 @@ public class Application extends javafx.application.Application { launch(args); } -// @Bean -// public RestTemplate restTemplate(RestTemplateBuilder builder) { -// return builder.build(); -// } + // @Bean + // public RestTemplate restTemplate(RestTemplateBuilder builder) { + // return builder.build(); + // } @Override public void init() throws Exception { @@ -34,20 +34,26 @@ public class Application extends javafx.application.Application { } @Override - public void start(Stage primaryStage) throws Exception{ + public void start(Stage primaryStage) throws Exception { fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); -// fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")); + // fxmlLoader.setLocation( + // this.getClass().getClassLoader().getResource("fxml/dashboard.fxml") + // ); rootNode = fxmlLoader.load(); -// rootNode = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); + // rootNode = FXMLLoader.load( + // this.getClass().getClassLoader().getResource("fxml/sample.fxml") + // ); primaryStage.setTitle("GoGreen"); Scene scene = new Scene(rootNode); - // scene.getStylesheets().add(getClass().getResource("stylesheets/dashboardStyle.css").toExternalForm()); + // scene.getStylesheets().add( + // getClass().getResource("stylesheets/dashboardStyle.css").toExternalForm() + // ); primaryStage.setScene(scene); primaryStage.show(); @@ -58,13 +64,13 @@ public class Application extends javafx.application.Application { springContext.stop(); } -// @Bean -// public CommandLineRunner run(RestTemplate restTemplate) throws Exception { -// return args -> { -// User user = restTemplate.getForObject( -// "http://localhost:8080/user", User.class); -// log.info(user.toString()); -// -// }; -// } + // @Bean + // public CommandLineRunner run(RestTemplate restTemplate) throws Exception { + // return args -> { + // User user = restTemplate.getForObject( + // "http://localhost:8080/user", User.class); + // log.info(user.toString()); + // + // }; + // } } \ No newline at end of file diff --git a/src/Client/src/main/java/gogreen/client/controller/DashBoardController.java b/src/Client/src/main/java/gogreen/client/controller/DashBoardController.java index 7e8a37e..247b265 100644 --- a/src/Client/src/main/java/gogreen/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/gogreen/client/controller/DashBoardController.java @@ -6,7 +6,6 @@ import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.effect.DropShadow; -import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import org.springframework.beans.factory.annotation.Autowired; @@ -20,8 +19,8 @@ public class DashBoardController { public AnchorPane userPane; public AnchorPane activitiesPane; public Label welcomebacktext; -// public Button addActivityButton; -// public ComboBox addActivity; + // public Button addActivityButton; + // public ComboBox addActivity; @FXML public Label dashboardText; @@ -33,22 +32,10 @@ public class DashBoardController { DropShadow shadow = new DropShadow(); - public void handleClickAction(MouseEvent event) { - if (event.getTarget() == dashboardButton) { - dashboardPane.setVisible(true); - userPane.setVisible(false); - activitiesPane.setVisible(false); - } else if (event.getTarget() == activitiesButton){ - dashboardPane.setVisible(false); - userPane.setVisible(false); - activitiesPane.setVisible(true); - } else if (event.getTarget() == userButton) { - dashboardPane.setVisible(false); - userPane.setVisible(true); - activitiesPane.setVisible(false); - } - } - + /** + * displays the dashboard pane. + * @param event the event (clicking the button) + */ public void displayDashboard(ActionEvent event) { System.out.println("display dashboard"); dashboardPane.setVisible(true); @@ -56,6 +43,10 @@ public class DashBoardController { activitiesPane.setVisible(false); } + /** + * displays the activities pane. + * @param event the event (clicking the button) + */ public void displayActivities(ActionEvent event) { System.out.println("display activities"); dashboardPane.setVisible(false); @@ -63,19 +54,23 @@ public class DashBoardController { activitiesPane.setVisible(true); } + /** + * displays the user profile pane. + * @param event the event (clicking the button) + */ public void displayUser(ActionEvent event) { System.out.println("display user"); dashboardPane.setVisible(false); userPane.setVisible(true); activitiesPane.setVisible(false); } - public void addShadow(MouseEvent event) { - userButton.setEffect(shadow); - } - - public void removeShadow(MouseEvent event) { - userButton.setEffect(null); - - } + // public void addShadow(MouseEvent event) { + // userButton.setEffect(shadow); + // } + // + // public void removeShadow(MouseEvent event) { + // userButton.setEffect(null); + // + // } } diff --git a/src/Client/src/main/java/gogreen/client/controller/UserController.java b/src/Client/src/main/java/gogreen/client/controller/UserController.java index 036a02f..cac42ca 100644 --- a/src/Client/src/main/java/gogreen/client/controller/UserController.java +++ b/src/Client/src/main/java/gogreen/client/controller/UserController.java @@ -35,66 +35,83 @@ public class UserController { private Button signupButton; + // @Value("${my.url}") + // private String myUrl; -// @Value("${my.url}") -// private String myUrl; - -// @FXML -// private void initialize(ActionEvent event) throws IOException { -// Parent parent = FXMLLoader.load(getClass().getResource("sample.fxml")); -// Scene scene = new Scene(parent); -// Stage app_stage = (Stage)((Node) event.getSource()).getScene().getWindow(); -// app_stage.setScene(scene); -// app_stage.show(); -// } + // @FXML + // private void initialize(ActionEvent event) throws IOException { + // Parent parent = FXMLLoader.load(getClass().getResource("sample.fxml")); + // Scene scene = new Scene(parent); + // Stage app_stage = (Stage)((Node) event.getSource()).getScene().getWindow(); + // app_stage.setScene(scene); + // app_stage.show(); + // } @FXML protected void handleLoginButtonAction(ActionEvent event) throws IOException { Window owner = loginButton.getScene().getWindow(); - if(usernameField.getText().isEmpty()) { + if (usernameField.getText().isEmpty()) { AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", "Please enter your username"); return; } else { -// newUser.setUsername(usernameField.getText()); + // newUser.setUsername(usernameField.getText()); System.out.println("Username is " + usernameField.getText()); } - if(passwordField.getText().isEmpty()) { + if (passwordField.getText().isEmpty()) { AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", "Please enter a password"); return; } else { -// newUser.setPassword(passwordField.getText()); + // newUser.setPassword(passwordField.getText()); System.out.println("Password is " + passwordField.getText()); } userService.registerUser(usernameField.getText(), passwordField.getText()); - // load the dashboard stage -// Parent parent = FXMLLoader.load(this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml")); -// -// Scene scene = new Scene(parent); -// Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); -// app_stage.setScene(scene); -// app_stage.setFullScreen(true); -// app_stage.show(); - - //on,y works once, when already logged in once, need to restart client for it to work again + // load the dashboard stage + // Parent parent = FXMLLoader.load( + // this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml") + // ); + // + // Scene scene = new Scene(parent); + // Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + // app_stage.setScene(scene); + // app_stage.setFullScreen(true); + // app_stage.show(); openDashboard(); } + /** + * opens the dashboard stage. + * @throws IOException exception if fxml file can't be found + * @author sem + */ public void openDashboard() throws IOException { - Parent dash = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/Dashboard.fxml")); + Parent dash = FXMLLoader.load( + this.getClass().getClassLoader().getResource("fxml/Dashboard.fxml") + ); Scene scene = new Scene(dash); - Stage app_stage = new Stage(); - app_stage.setScene(scene); -// app_stage.setFullScreen(true); - app_stage.show(); + Stage appStage = new Stage(); + appStage.setScene(scene); + // app_stage.setFullScreen(true); + appStage.show(); } + public static class AlertHelper { - public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) { + /** + * alerts for the login screen. + * @param alertType the type of alert + * @param owner the owner (window) of the alert + * @param title the title given to the displayed alert + * @param message the message displayed in the alert + */ + public static void showAlert(Alert.AlertType alertType, + Window owner, + String title, + String message) { Alert alert = new Alert(alertType); alert.setTitle(title); alert.setHeaderText(null); diff --git a/src/Client/src/main/java/gogreen/client/rest/UserService.java b/src/Client/src/main/java/gogreen/client/rest/UserService.java index b88a610..06d5d02 100644 --- a/src/Client/src/main/java/gogreen/client/rest/UserService.java +++ b/src/Client/src/main/java/gogreen/client/rest/UserService.java @@ -19,6 +19,12 @@ public class UserService { return builder.build(); } + /** + * registers the user. + * @param name the username of the user + * @param password the password of the user + * @return a userDTO + */ public UserDTO registerUser(String name, String password) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); diff --git a/src/Common/src/main/java/gogreen/common/UserDTO.java b/src/Common/src/main/java/gogreen/common/UserDTO.java index 9cd969d..7556406 100644 --- a/src/Common/src/main/java/gogreen/common/UserDTO.java +++ b/src/Common/src/main/java/gogreen/common/UserDTO.java @@ -1,12 +1,11 @@ package gogreen.common; public class UserDTO { - - private Long id; + private Long id; private String name; public UserDTO() { - } + } public UserDTO(Long id, String name) { this.id = id; diff --git a/src/Server/src/main/java/gogreen/server/data/model/User.java b/src/Server/src/main/java/gogreen/server/data/model/User.java index 11bb0fb..9be58ba 100644 --- a/src/Server/src/main/java/gogreen/server/data/model/User.java +++ b/src/Server/src/main/java/gogreen/server/data/model/User.java @@ -20,20 +20,38 @@ public class User { String name; String password; + /** + * makes a user object. + * @param id the id of the user. + * @param name the supplied username + * @param password the supplied password + */ public User(Long id, String name, String password) { this.id = id; this.name = name; this.password = password; } + /** + * gets the id. + * @return the id + */ public Long getId() { return id; } + /** + * gets the name. + * @return the name + */ public String getName() { return name; } + /** + * gets the password. + * @return the password + */ public String getPassword() { return password; } diff --git a/src/Server/src/main/java/gogreen/server/rest/RestExceptionHandler.java b/src/Server/src/main/java/gogreen/server/rest/RestExceptionHandler.java index 18d2a04..bffb8cb 100644 --- a/src/Server/src/main/java/gogreen/server/rest/RestExceptionHandler.java +++ b/src/Server/src/main/java/gogreen/server/rest/RestExceptionHandler.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; public class RestExceptionHandler { @ExceptionHandler(ApplicationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) - public ErrorResponse applicationException (ApplicationException ex) { + public ErrorResponse applicationException(ApplicationException ex) { return new ErrorResponse(ex.getMessage()); } } diff --git a/src/Server/src/main/java/gogreen/server/rest/UserController.java b/src/Server/src/main/java/gogreen/server/rest/UserController.java index b6f9655..caf8850 100644 --- a/src/Server/src/main/java/gogreen/server/rest/UserController.java +++ b/src/Server/src/main/java/gogreen/server/rest/UserController.java @@ -13,14 +13,14 @@ public class UserController { UserService userService; @RequestMapping("/registerUser") - public UserDTO registerUser(@RequestParam(value="name") String name, - @RequestParam(value="password") String password) { + public UserDTO registerUser(@RequestParam(value = "name") String name, + @RequestParam(value = "password") String password) { return userService.registerUser(name, password); } @RequestMapping("/login") - public UserDTO login(@RequestParam(value="name") String name, - @RequestParam(value="password") String password) { + public UserDTO login(@RequestParam(value = "name") String name, + @RequestParam(value = "password") String password) { return userService.login(name, password); } } \ No newline at end of file diff --git a/src/Server/src/main/java/gogreen/server/service/UserService.java b/src/Server/src/main/java/gogreen/server/service/UserService.java index dbd40d6..59bc7ce 100644 --- a/src/Server/src/main/java/gogreen/server/service/UserService.java +++ b/src/Server/src/main/java/gogreen/server/service/UserService.java @@ -15,6 +15,12 @@ public class UserService { @Autowired UserRepository userRepository; + /** + * registers the user. + * @param name the username of the user + * @param password the password of the user + * @return a userDTO of the registered user + */ public UserDTO registerUser(String name, String password) { User user = userRepository.findByName(name); if (user != null) { @@ -26,6 +32,12 @@ public class UserService { return new UserDTO(user.getId(), user.getName()); } + /** + * logs the user in. + * @param name the username of the user + * @param password the password of the user + * @return a userDTO of the logged in user + */ public UserDTO login(String name, String password) { User user = userRepository.findByName(name); if (user == null) {