Skip to content
Snippets Groups Projects
Commit 56f99cd7 authored by Puissegur Alexis's avatar Puissegur Alexis
Browse files

merge

parents 6c41fa49 84c06afd
No related branches found
No related tags found
No related merge requests found
File added
...@@ -31,7 +31,11 @@ endorsed.classpath= ...@@ -31,7 +31,11 @@ endorsed.classpath=
excludes= excludes=
file.reference.bluecove-2.1.1-SNAPSHOT.jar=bluecove-2.1.1-SNAPSHOT.jar file.reference.bluecove-2.1.1-SNAPSHOT.jar=bluecove-2.1.1-SNAPSHOT.jar
file.reference.javax.mail-api-1.4.7.jar=javax.mail-api-1.4.7.jar file.reference.javax.mail-api-1.4.7.jar=javax.mail-api-1.4.7.jar
<<<<<<< HEAD
file.reference.sqlite-jdbc-3.23.1.jar=C:\\Users\\puiss\\Downloads\\sqlite-jdbc-3.23.1.jar file.reference.sqlite-jdbc-3.23.1.jar=C:\\Users\\puiss\\Downloads\\sqlite-jdbc-3.23.1.jar
=======
file.reference.javax.mail.jar-1=javax.mail.jar
>>>>>>> 84c06afd4e19e0ca4a71de80c0796fbf58b31b57
includes=** includes=**
# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects # Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects
jar.archive.disabled=true jar.archive.disabled=true
...@@ -40,7 +44,11 @@ javac.classpath=\ ...@@ -40,7 +44,11 @@ javac.classpath=\
${javafx.classpath.extension}:\ ${javafx.classpath.extension}:\
${file.reference.bluecove-2.1.1-SNAPSHOT.jar}:\ ${file.reference.bluecove-2.1.1-SNAPSHOT.jar}:\
${file.reference.javax.mail-api-1.4.7.jar}:\ ${file.reference.javax.mail-api-1.4.7.jar}:\
<<<<<<< HEAD
${file.reference.sqlite-jdbc-3.23.1.jar} ${file.reference.sqlite-jdbc-3.23.1.jar}
=======
${file.reference.javax.mail.jar-1}
>>>>>>> 84c06afd4e19e0ca4a71de80c0796fbf58b31b57
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package MailUtil;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
/**
*
* @author lmasson
*/
public class MailUtil {
private static String USER_NAME = "plantequipleure"; // GMail user name (just the part before "@gmail.com")
private static String PASSWORD = "cryingplant12"; // GMail password
private static String RECIPIENT = "theo.coulin@gmail.com";
public static void sendDistressMail() {
String from = USER_NAME;
String pass = PASSWORD;
String subject = "Votre plante pleure";
sendFromGMail(from, pass, RECIPIENT, subject, "Ta plante pleure arrose-la");
}
private static void sendFromGMail(String from, String pass, String to, String subject, String body) {
Properties props = System.getProperties();
String host = "smtp.gmail.com";
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
InternetAddress toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
catch (AddressException ae) {
ae.printStackTrace();
}
catch (MessagingException me) {
me.printStackTrace();
}
}
}
...@@ -9,17 +9,15 @@ import Bluetooth.BluetoothManager; ...@@ -9,17 +9,15 @@ import Bluetooth.BluetoothManager;
import Bluetooth.BluetoothThread; import Bluetooth.BluetoothThread;
import Interfaces.Observable; import Interfaces.Observable;
import Interfaces.Observer; import Interfaces.Observer;
import MailUtil.MailUtil;
import Util.CalendarUtil; import Util.CalendarUtil;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.text.NumberFormat; import java.time.LocalDate;
import java.time.Period;
import java.util.Calendar; import java.util.Calendar;
import java.util.Formatter;
import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
...@@ -35,17 +33,22 @@ import javafx.scene.control.ComboBox; ...@@ -35,17 +33,22 @@ import javafx.scene.control.ComboBox;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.RadioButton; import javafx.scene.control.RadioButton;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
/** /**
* FXML Controller class * FXML Controller class
* *
...@@ -118,6 +121,7 @@ public class FXMLVueController implements Initializable, Observer { ...@@ -118,6 +121,7 @@ public class FXMLVueController implements Initializable, Observer {
private boolean isConnected = false; private boolean isConnected = false;
private BluetoothManager bluetoothManager; private BluetoothManager bluetoothManager;
private BluetoothThread workingThread; private BluetoothThread workingThread;
LocalDate lastMailDay;
/** /**
...@@ -132,6 +136,9 @@ public class FXMLVueController implements Initializable, Observer { ...@@ -132,6 +136,9 @@ public class FXMLVueController implements Initializable, Observer {
currentGridPane = accueil; currentGridPane = accueil;
currentButton = buttonAccueil; currentButton = buttonAccueil;
openPage(accueil, buttonAccueil); openPage(accueil, buttonAccueil);
//TODO initialize lastMailDay with database
lastMailDay = LocalDate.of(2018, 12, 12);
seuil.valueProperty().addListener(new ChangeListener<Number>() { seuil.valueProperty().addListener(new ChangeListener<Number>() {
@Override @Override
...@@ -169,14 +176,13 @@ public class FXMLVueController implements Initializable, Observer { ...@@ -169,14 +176,13 @@ public class FXMLVueController implements Initializable, Observer {
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
System.out.println(oldValue); System.out.println(oldValue);
System.out.println(newValue); System.out.println(newValue);
if (oldValue != null && newValue != null && humiditySeuil.getText() != null && Integer.parseInt(newValue) < Integer.parseInt(humiditySeuil.getText())) { if (humiditySeuil.getText() != null && Integer.parseInt(newValue) < Integer.parseInt(humiditySeuil.getText())) {
changeImagePlante(true); changeImagePlante(true);
alert = true; alert = true;
if(Integer.parseInt(oldValue) > Integer.parseInt(humiditySeuil.getText()) || Integer.parseInt(oldValue) == -1){ // start or change if(Integer.parseInt(oldValue) > Integer.parseInt(humiditySeuil.getText()) || Integer.parseInt(oldValue) == -1){ // start or change
work(); work();
} }
} } else {
else {
if(alert){ if(alert){
changeImagePlante(false); changeImagePlante(false);
} }
...@@ -188,7 +194,7 @@ public class FXMLVueController implements Initializable, Observer { ...@@ -188,7 +194,7 @@ public class FXMLVueController implements Initializable, Observer {
tmp = false; tmp = false;
} catch(IOException e){ } catch(IOException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
...@@ -300,7 +306,7 @@ public class FXMLVueController implements Initializable, Observer { ...@@ -300,7 +306,7 @@ public class FXMLVueController implements Initializable, Observer {
@FXML @FXML
private void clickActivationBluetooth(ActionEvent event) { private void clickActivationBluetooth(ActionEvent event) {
if(!this.isConnected){ if(!this.isConnected){
isConnected = bluetoothManager.launch(); isConnected = bluetoothManager.launch();
} }
if(isConnected){ if(isConnected){
...@@ -389,14 +395,18 @@ public class FXMLVueController implements Initializable, Observer { ...@@ -389,14 +395,18 @@ public class FXMLVueController implements Initializable, Observer {
} }
private void work(){ private void work(){
computeGravity();
if(CalendarUtil.isBusinessDay(Calendar.getInstance())){ if(CalendarUtil.isBusinessDay(Calendar.getInstance())){
System.out.println("is business"); System.out.println("is business day");
// compute & send
computeGravity();
} else { } else {
System.out.println("is not"); System.out.println("is not business day");
// send mail, not this LocalDate today = LocalDate.now();
computeGravity(); Period difference = Period.between(lastMailDay, today);
if(difference.getDays() > 1){
// send mail
MailUtil.sendDistressMail();
lastMailDay = today;
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment