apparently the changes that were supposed to be made weren't committed in my previous commit, so here is the right one

REMOVE:: removed the .gradle and build folders from the Client, Server and Common folders, also moved the contents that was in the src folders of these folders, to the folders themselves and deleted the src folders

EDIT:: edited the build.gradle file, build should now work

combined the build.gradle files in the Client, Server and Common folders into the build.gradle file in the root
This commit is contained in:
Sem van der Hoeven
2019-03-06 21:22:29 +01:00
parent 7a60ecb60f
commit aa79365784
115 changed files with 47 additions and 5373 deletions

View File

@@ -0,0 +1,68 @@
package Client.main.java.gogreen.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.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import static org.springframework.boot.SpringApplication.*;
@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);
}
// @Bean
// public RestTemplate restTemplate(RestTemplateBuilder builder) {
// return builder.build();
// }
@Override
public void init() throws Exception {
springContext = 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();
// rootNode = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/sample.fxml"));
primaryStage.setTitle("GoGreen");
Scene scene = new Scene(rootNode);
primaryStage.setScene(scene);
primaryStage.show();
}
// @Override
// public void stop() {
// 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());
//
// };
// }
}

View File

@@ -0,0 +1,89 @@
package gogreen.client.controller;
import gogreen.client.rest.UserService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
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
private TextField usernameField;
@FXML
private PasswordField passwordField;
@FXML
private Button loginButton;
@FXML
private Button signupButton;
// @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
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 {
// newUser.setUsername(usernameField.getText());
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 {
// newUser.setPassword(passwordField.getText());
System.out.println("Password is " + passwordField.getText());
}
userService.registerUser(usernameField.getText(), passwordField.getText());
// 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.show();
}
public static class AlertHelper {
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();
}
}
}

View File

@@ -0,0 +1,32 @@
package gogreen.client.rest;
import gogreen.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.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
@Component
public class UserService {
@Autowired
RestTemplate restTemplate;
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
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);
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" />

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.PasswordField?>
<?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 fx:controller="gogreen.client.controller.UserController" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ImageView fitHeight="574.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
<image>
<Image url="@../pinkleaf.jpg" />
</image></ImageView>
<Text fill="#23773d" layoutX="283.0" layoutY="100.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Go Green" textAlignment="CENTER" wrappingWidth="374.936767578125">
<font>
<Font name="Californian FB" size="72.0" />
</font>
</Text>
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" onAction="#handleLoginButtonAction"/>
<Button fx:id="signupButton" layoutX="49.0" layoutY="52.0" mnemonicParsing="false" prefHeight="6.0" prefWidth="61.0" text="Sign UP"/>
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
<Hyperlink layoutX="392.0" layoutY="308.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="WHITE" textOverrun="LEADING_WORD_ELLIPSIS">
<font>
<Font name="Bodoni MT Bold" size="18.0" />
</font>
</Hyperlink>
<Text fill="#23773d" layoutX="7.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
<font>
<Font name="Californian FB" size="14.0" />
</font>
</Text>
<TextField fx:id="usernameField" layoutX="319.0" layoutY="154.0" prefHeight="42.0" prefWidth="303.0" promptText="Username" />
</children>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

View File

@@ -0,0 +1,41 @@
//import gogreen.client.rest.UserService;
//import gogreen.common.UserDTO;
//import org.junit.Assert;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.mockito.InjectMocks;
//import org.mockito.Mock;
//import org.mockito.Mockito;
//import org.mockito.Spy;
//import org.mockito.junit.MockitoJUnitRunner;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.client.RestTemplate;
//
//import static org.junit.Assert.assertEquals;
//
//@RunWith(MockitoJUnitRunner.class)
//public class UserServiceTest {
// private static Logger logger = LoggerFactory.getLogger(UserServiceTest.class);
//
// @Mock
// RestTemplate restTemplate;
//
// @InjectMocks
// @Spy
// UserService userService;
//
// @Test
// public void mocking() {
// UserDTO testUser = new UserDTO(1L, "Eric Simmons");
// Mockito.when(restTemplate.getForObject("http://localhost:8080/registerUser?name=Eric%20Simmons&password=password", UserDTO.class))
// .thenReturn(testUser);
//
// UserDTO user = userService.registerUser("Eric Simmons", "password");
// Assert.assertEquals(testUser, user);
// }
//}