Skip to content

Commit

Permalink
Development of collect info module.
Browse files Browse the repository at this point in the history
  • Loading branch information
eltonnuness committed Oct 3, 2016
1 parent a7c5dfc commit b0abba3
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 77 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/jasmine/StartJasmine.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.jasmine;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.jasmine.conf.JasmineFactory;
Expand All @@ -9,23 +10,24 @@
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class StartJasmine extends Application{
public class StartJasmine extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JasmineFactory.class);

SpringFxmlLoader loader = new SpringFxmlLoader(context);
Pane root = (Pane) loader.loadLogin("/fxml/login.fxml",primaryStage);

Pane root = (Pane) loader.loadLogin("/fxml/login.fxml", primaryStage);
Scene stackScene = new Scene(root);
primaryStage.setScene(stackScene);
primaryStage.setTitle("Jasmine IPA - Login");
primaryStage.show();

}

}
16 changes: 1 addition & 15 deletions src/main/java/com/jasmine/conf/JasmineFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@

import com.jasmine.controller.HomeController;
import com.jasmine.controller.LoginController;
import com.jasmine.integrations.TwitterConnector;
import com.jasmine.model.User;

@ComponentScan(basePackages = "com.jasmine")
@Configuration
@ComponentScan(basePackages = "com.jasmine")
public class JasmineFactory {

@Bean
public User user() {
User u = new User();
return u;
}

@Bean
public LoginController loginController() {
LoginController lc = new LoginController();
Expand All @@ -30,10 +22,4 @@ public HomeController homeController() {
HomeController hc = new HomeController();
return hc;
}

@Bean(name = "twitterConnector")
public TwitterConnector twitterConnector() {
return new TwitterConnector();
}

}
53 changes: 23 additions & 30 deletions src/main/java/com/jasmine/conf/SpringFxmlLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,51 @@
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.stage.Stage;
import javafx.util.Callback;

public class SpringFxmlLoader {

private ApplicationContext context;
public SpringFxmlLoader(ApplicationContext context){

public SpringFxmlLoader(ApplicationContext context) {
this.context = context;
}
public Parent loadLogin(String url, Stage stage) throws IOException{

public Parent loadLogin(String url, Stage stage) throws IOException {

InputStream fxmlStream = null;
try{

try {
fxmlStream = LoginController.class.getResourceAsStream(url);
LoginController instance = (LoginController)context.getBean(LoginController.class);
LoginController instance = context.getBean(LoginController.class);
instance.setPrimaryStage(stage);
FXMLLoader loader = new FXMLLoader();
//loader.getNamespace().put("controller", instance);
loader.setControllerFactory(new Callback<Class<?>, Object>() {
public Object call(Class<?> clazz) {
return context.getBean(clazz);
}
});
loader.setControllerFactory(clazz -> context.getBean(clazz));
return loader.load(fxmlStream);
}finally {
if (fxmlStream != null){
} finally {
if (fxmlStream != null) {
fxmlStream.close();
}
}

}
public Parent loadHome(String url, Stage stage) throws IOException{

public Parent loadHome(String url, Stage stage) throws IOException {

InputStream fxmlStream = null;
try{

try {
fxmlStream = HomeController.class.getResourceAsStream(url);
HomeController instance = (HomeController)context.getBean(HomeController.class);
HomeController instance = context.getBean(HomeController.class);
instance.setPrimaryStage(stage);
FXMLLoader loader = new FXMLLoader();
loader.getNamespace().put("controller", instance);
loader.setControllerFactory(clazz -> context.getBean(clazz));
return loader.load(fxmlStream);
}finally {
if (fxmlStream != null){
} finally {
if (fxmlStream != null) {
fxmlStream.close();
}
}

}



}
2 changes: 2 additions & 0 deletions src/main/java/com/jasmine/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.TimerTask;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.jasmine.integrations.TwitterConnector;
import com.jasmine.model.User;
Expand All @@ -17,6 +18,7 @@
import javafx.stage.Stage;
import twitter4j.TwitterException;

@Controller
public class HomeController {

@FXML
Expand Down
63 changes: 37 additions & 26 deletions src/main/java/com/jasmine/controller/LoginController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.jasmine.controller;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Controller;

import com.jasmine.conf.JasmineFactory;
import com.jasmine.conf.SpringFxmlLoader;
import com.jasmine.model.User;
import com.jasmine.service.UserService;
import com.jasmine.service.collector.InfoCollector;

import javafx.fxml.FXML;
import javafx.scene.Scene;
Expand All @@ -22,24 +21,31 @@

/**
* Controller of the main login window
*
* @author enunes
* @since 29/09/2016
*
*/
@Controller
public class LoginController {

@Autowired private UserService userService;
@FXML private TextField txtLogin;
@FXML private PasswordField txtPassword;

@Autowired
private UserService userService;
@Autowired
private InfoCollector infoCollector;
@FXML
private TextField txtLogin;
@FXML
private PasswordField txtPassword;
private Stage primaryStage;

private User user;

@FXML
private void login(){
User user = userService.login(txtLogin.getText(), txtPassword.getText());
if (user != null){
private void login() {
this.user = this.userService.login(this.txtLogin.getText(), this.txtPassword.getText());
if (this.user != null) {
openHome();
}else {
} else {
Alert alert = new Alert(AlertType.ERROR);
alert.setHeaderText("Error");
alert.setContentText("User not found.");
Expand All @@ -50,35 +56,40 @@ private void login(){
/**
* Open the home.
*/
private void openHome(){
private void openHome() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JasmineFactory.class);
SpringFxmlLoader loader = new SpringFxmlLoader(context);
try{
Stage newStage = new Stage(); //Create a new Window(Stage)
StackPane root = (StackPane) loader.loadHome("/fxml/home.fxml",newStage);

try {
Stage newStage = new Stage(); //Create a new Window(Stage)
StackPane root = (StackPane) loader.loadHome("/fxml/home.fxml", newStage);
Scene stackScene = new Scene(root);
newStage.setScene(stackScene);
newStage.setTitle("Jasmine IPA - Core");
newStage.show();
primaryStage.close(); //Close the previous window
this.primaryStage = newStage; //Set the new stage on primaryStage variable.
}catch (Exception e){
this.primaryStage.close(); //Close the previous window
this.primaryStage = newStage; //Set the new stage on primaryStage variable.

this.infoCollector.startTwitterCollectService(this.user);

} catch (Exception e) {
e.printStackTrace();
}
}

@FXML
private void exit(){
private void exit() {
System.exit(1);
}

/**
* Method helper to set the primary stage.
* @param stage new stage.
*
* @param stage
* new stage.
*/
public void setPrimaryStage(Stage stage){
public void setPrimaryStage(Stage stage) {
this.primaryStage = stage;
}

}
30 changes: 30 additions & 0 deletions src/main/java/com/jasmine/exceptions/DataSourceException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.jasmine.exceptions;

public class DataSourceException extends Exception {

/**
*
*/
private static final long serialVersionUID = -6842384730824942123L;

public DataSourceException() {
super();
}

public DataSourceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public DataSourceException(String message, Throwable cause) {
super(message, cause);
}

public DataSourceException(String message) {
super(message);
}

public DataSourceException(Throwable cause) {
super(cause);
}

}
55 changes: 55 additions & 0 deletions src/main/java/com/jasmine/model/UserTwitterData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.jasmine.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import twitter4j.Status;

@Document(collection = "usertwitterdata")
public class UserTwitterData {

@Id
private String id;
private User user;
private Status status;

public UserTwitterData() {
super();
}

public UserTwitterData(User user, Status status) {
super();
this.user = user;
this.status = status;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public Status getStatus() {
return status;
}

public void setStatus(Status status) {
this.status = status;
}

@Override
public String toString() {
return String.format("UserTwitterData [id=%s, user=%s, status=%s]", id, user, status);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jasmine.repository;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import com.jasmine.model.UserTwitterData;

@Repository
public interface UserTwitterDataRepository extends MongoRepository<UserTwitterData, String> {

}
Loading

0 comments on commit b0abba3

Please sign in to comment.