diff --git a/src/.idea/workspace.xml b/src/.idea/workspace.xml index d7cd59b..b69fda1 100644 --- a/src/.idea/workspace.xml +++ b/src/.idea/workspace.xml @@ -1,30 +1,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - + @@ -81,6 +58,9 @@ + + + @@ -91,85 +71,28 @@ - + - + - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/src/.project b/src/src/.project new file mode 100644 index 0000000..d4fb5ff --- /dev/null +++ b/src/src/.project @@ -0,0 +1,17 @@ + + + OOPP + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/src/src/Client/.classpath b/src/src/Client/.classpath new file mode 100644 index 0000000..e5b885c --- /dev/null +++ b/src/src/Client/.classpath @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/src/Client/.idea/compiler.xml b/src/src/Client/.idea/compiler.xml new file mode 100644 index 0000000..3d94435 --- /dev/null +++ b/src/src/Client/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/src/Client/.idea/encodings.xml b/src/src/Client/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/src/src/Client/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/src/Client/.idea/gradle.xml b/src/src/Client/.idea/gradle.xml new file mode 100644 index 0000000..d1f1d89 --- /dev/null +++ b/src/src/Client/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/src/src/Client/.idea/misc.xml b/src/src/Client/.idea/misc.xml new file mode 100644 index 0000000..9870be1 --- /dev/null +++ b/src/src/Client/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/src/Client/.idea/modules.xml b/src/src/Client/.idea/modules.xml new file mode 100644 index 0000000..cde60df --- /dev/null +++ b/src/src/Client/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/src/Client/.idea/uiDesigner.xml b/src/src/Client/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/src/src/Client/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/src/Client/.idea/workspace.xml b/src/src/Client/.idea/workspace.xml new file mode 100644 index 0000000..06551d4 --- /dev/null +++ b/src/src/Client/.idea/workspace.xml @@ -0,0 +1,489 @@ + + + + + + + + + + + + + hello.* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + 1550791437583 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 10 + + + + + + + + main|com.bettercoding.jfx.Client + + + + + + + + 10 + + + + + + + + Gradle: ch.qos.logback:logback-classic:1.2.3 + + + + + + + + \ No newline at end of file diff --git a/src/src/Client/.project b/src/src/Client/.project new file mode 100644 index 0000000..2598613 --- /dev/null +++ b/src/src/Client/.project @@ -0,0 +1,17 @@ + + + Client + + + + org.eclipse.jdt.core.javanature + + + + org.eclipse.jdt.core.javabuilder + + + + + + diff --git a/src/src/Client/build.gradle b/src/src/Client/build.gradle new file mode 100644 index 0000000..9b01f2b --- /dev/null +++ b/src/src/Client/build.gradle @@ -0,0 +1,83 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE") + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' +apply plugin: 'jacoco' +//apply plugin: 'checkstyle' +// +//checkstyle { +// version = '7.8.1' +// config = 'checkstyle/checkstyle.xml' as File +//} +// +//checkstyleMain { +// source ='src/main/java' +//} +// +//checkstyleTest { +// source ='src/test/java' +//} +// +//tasks.withType(Checkstyle) { +// reports { +// xml.enabled false +// html.enabled true +// html.stylesheet resources.text.fromFile('config/xsl/checkstyle-custom.xsl') +// } +//} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +test { + useJUnitPlatform() +} + +bootJar { + baseName = 'gs-consuming-rest' + version = '0.1.0' +} + +repositories { + mavenCentral() +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter") + compile("org.springframework:spring-web") + compile("com.fasterxml.jackson.core:jackson-databind") + testCompile("junit:junit") + compile project(':src:Common') + testCompile('org.springframework.boot:spring-boot-starter-test') + testCompile( + 'junit:junit:4.12', + 'org.junit.jupiter:junit-jupiter-api:5.4.0' + ) + testRuntime( + 'org.junit.jupiter:junit-jupiter-engine:5.4.0', + 'org.junit.vintage:junit-vintage-engine:5.4.0' + ) +} + +jacoco { + toolVersion = "0.8.3" + reportsDir = file("$buildDir/customJacocoReportDir") +} + +jacocoTestReport { + reports { + xml.enabled false + csv.enabled false + html.destination file("${buildDir}/jacocoHtml") + } +} \ No newline at end of file diff --git a/src/src/Client/src/main/java/greenify/client/Application.java b/src/src/Client/src/main/java/greenify/client/Application.java new file mode 100644 index 0000000..ede019f --- /dev/null +++ b/src/src/Client/src/main/java/greenify/client/Application.java @@ -0,0 +1,45 @@ +package greenify.client; + +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; + +@SpringBootApplication +public class Application extends javafx.application.Application { + private ConfigurableApplicationContext springContext; + private Parent rootNode; + private FXMLLoader fxmlLoader; + private static final Logger log = LoggerFactory.getLogger(Application.class); + + public static void main(String[] args) { + launch(args); + } + + @Override + public void init() throws Exception { + springContext = SpringApplication.run(Application.class); + fxmlLoader = new FXMLLoader(); + fxmlLoader.setControllerFactory(springContext::getBean); + } + + @Override + public void start(Stage primaryStage) throws Exception { + fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); + rootNode = fxmlLoader.load(); + primaryStage.setTitle("Greenify"); + Scene scene = new Scene(rootNode); + primaryStage.setScene(scene); + primaryStage.show(); + } + + @Override + public void stop() { + springContext.stop(); + } +} \ No newline at end of file diff --git a/src/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/src/Client/src/main/java/greenify/client/controller/DashBoardController.java new file mode 100644 index 0000000..3e4b76e --- /dev/null +++ b/src/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -0,0 +1,73 @@ +package greenify.client.controller; + +import greenify.client.rest.UserService; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.AnchorPane; +import org.springframework.stereotype.Controller; + +@Controller +public class DashBoardController { + + private int count = 0; + + @FXML + public AnchorPane menuBar; + public AnchorPane dashboardPane; + public AnchorPane userPane; + public AnchorPane activitiesPane; + public Label welcomebacktext; + public Button dashboardButton; + public Button activitiesButton; + public Button userButton; + public Button veganMealButton; + public Label counter; + public Label scoreField; + + /** + * displays the dashboard pane. + * @param event the event (clicking the button) + */ + public void displayDashboard(ActionEvent event) { + System.out.println("display dashboard"); + dashboardPane.setVisible(true); + userPane.setVisible(false); + 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); + userPane.setVisible(false); + 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); + } + + /** + * adds a vegetarian meal. + * @param event the event (clicking the button) + */ + public void addVeganMeal(ActionEvent event) { + count++; + counter.setText("Count: " + count); + UserService service = new UserService(); + service.addVeganMeal(null, null); + System.out.println("Vegetarian meal is added"); + } +} diff --git a/src/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java new file mode 100644 index 0000000..a0e6a8b --- /dev/null +++ b/src/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -0,0 +1,68 @@ +package greenify.client.controller; + +import greenify.client.rest.UserService; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.PasswordField; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import javafx.stage.Window; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +@Controller +public class RegisterWindowController { + + @Autowired + UserService userService; + + @FXML + private TextField userNameText; + @FXML + private PasswordField passwordField; + @FXML + private PasswordField passwordField2; + @FXML + private Button signupButton; + + /** + * signs the user up. + * @param event the click of the signup button + */ + @FXML + public void handleSignUpButton(ActionEvent event) { + //set the window to the current window (for displaying the alerts) + Window owner = signupButton.getScene().getWindow(); + //check if the username field is empty + if (userNameText.getText().isEmpty()) { + //if so, display an alert + UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", + "Please enter a username!"); + return; + } + + //check if the password field is empty + if (passwordField.getText().isEmpty()) { + //if so, display an alert + UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Password Error!", + "Please enter a password!"); + return; + } + + //check if the two password fields are equal + if (!passwordField.getText().equals(passwordField2.getText())) { + //if not, display an alert + UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Password Error!", + "Please make sure the passwords entered are the same!"); + return; + } + + userService.registerUser(userNameText.getText(), passwordField.getText()); + + //close the register window after the user has entered all the credentials + Stage current = (Stage) owner; + current.close(); + } +} diff --git a/src/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/src/Client/src/main/java/greenify/client/controller/UserController.java new file mode 100644 index 0000000..abf29a5 --- /dev/null +++ b/src/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -0,0 +1,112 @@ +package greenify.client.controller; + +import greenify.client.rest.UserService; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.PasswordField; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import javafx.stage.Window; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +import java.io.IOException; + +@Controller +public class UserController { + @Autowired + UserService userService; + + @FXML + public TextField usernameField; + + @FXML + private PasswordField passwordField; + + @FXML + private Button loginButton; + + @FXML + private Button signupButton; + + @FXML + protected void handleLoginButtonAction(ActionEvent event) throws IOException { + Window owner = loginButton.getScene().getWindow(); + if (usernameField.getText().isEmpty()) { + AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", + "Please enter your username"); + return; + } else { + System.out.println("Username is " + usernameField.getText()); + } + if (passwordField.getText().isEmpty()) { + AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", + "Please enter a password"); + return; + } else { + System.out.println("Password is " + passwordField.getText()); + } + userService.loginUser(usernameField.getText(), passwordField.getText()); + Stage current = (Stage) owner; + current.close(); + 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") + ); + Scene scene = new Scene(dash); + scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/dashboardStyle.css").toExternalForm()); + Stage appStage = new Stage(); + appStage.setScene(scene); + appStage.show(); + } + + public static class AlertHelper { + /** + * 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); + alert.setContentText(message); + alert.initOwner(owner); + alert.show(); + } + } + + public void handleRegisterButtonAction(ActionEvent event) throws Exception{ + //load the fxml file + Parent registerWindow = FXMLLoader.load ( + this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml") + ); + //make the window use the scene + Scene registerscene = new Scene(registerWindow); + Stage registerStage = new Stage(); + //open the window + registerStage.setScene(registerscene); + registerStage.setTitle("Enter register credentials"); + registerStage.show(); + } + +} diff --git a/src/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/src/Client/src/main/java/greenify/client/rest/UserService.java new file mode 100644 index 0000000..9ede326 --- /dev/null +++ b/src/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -0,0 +1,62 @@ +package greenify.client.rest; + +import greenify.common.UserDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.http.*; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +@Service +public class UserService { + + @Autowired + RestTemplate restTemplate; + + @Bean + RestTemplate restTemplate(RestTemplateBuilder builder) { + 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); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser") + .queryParam("name", name) + .queryParam("password", password); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); + } + + public UserDTO loginUser(String name, String password) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser") + .queryParam("name", name) + .queryParam("password", password); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); + } + + public UserDTO addVeganMeal(Long id, String name) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addVeganMeal") + .queryParam("id", id) + .queryParam("name", name); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); + } +} diff --git a/src/src/Client/src/main/resources/addActivity1.png b/src/src/Client/src/main/resources/addActivity1.png new file mode 100644 index 0000000..85af03c Binary files /dev/null and b/src/src/Client/src/main/resources/addActivity1.png differ diff --git a/src/src/Client/src/main/resources/addActivity2.png b/src/src/Client/src/main/resources/addActivity2.png new file mode 100644 index 0000000..48d85d9 Binary files /dev/null and b/src/src/Client/src/main/resources/addActivity2.png differ diff --git a/src/src/Client/src/main/resources/application.properties b/src/src/Client/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/src/Client/src/main/resources/fxml/RegisterWindow.fxml b/src/src/Client/src/main/resources/fxml/RegisterWindow.fxml new file mode 100644 index 0000000..4b3a472 --- /dev/null +++ b/src/src/Client/src/main/resources/fxml/RegisterWindow.fxml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/src/Client/src/main/resources/fxml/dashboard.fxml b/src/src/Client/src/main/resources/fxml/dashboard.fxml new file mode 100644 index 0000000..1627774 --- /dev/null +++ b/src/src/Client/src/main/resources/fxml/dashboard.fxml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/src/Client/src/main/resources/fxml/sample.fxml b/src/src/Client/src/main/resources/fxml/sample.fxml new file mode 100644 index 0000000..ea80989 --- /dev/null +++ b/src/src/Client/src/main/resources/fxml/sample.fxml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + +