FIX:: fixed Client application class
The class was not seeing some imports from the same package, and some getters and setters for User.java were not written, so I wrote those and fixed the imports FIX:: fixed packages Everything now isn't in several subpackages in the Client, Common and Server package anymore, but straight in their respectable packages. Also fixed the package names BUG FIX: fixed Client Application class not being able to see GetBean method Don't really know how it got fixed, but resolving the import issues also fixed this bug. EDIT::changed main class in build.gradle file to Client.Application --------------- I now only get a bug where the fxmlloader can't see the fxml files, and thus I can't start the application. I get the error message "location not set" although I used fxmlloader.setLocation.
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
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());
|
||||
//
|
||||
// };
|
||||
// }
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?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" />
|
||||
@@ -1,39 +0,0 @@
|
||||
<?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.
|
Before Width: | Height: | Size: 247 KiB |
@@ -1,41 +0,0 @@
|
||||
//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);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user