diff --git a/.gitignore b/.gitignore
index f836b6b..689dcab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -119,3 +119,5 @@ local.properties
nbproject/private/
build/
+
+fichier.ics
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 240da1f..06f4769 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,13 +18,30 @@
11
+
+
+
+ org.junit
+ junit-bom
+ 5.5.2
+ pom
+ import
+
+
+
+
- junit
- junit
- 4.13.1
+ org.junit.jupiter
+ junit-jupiter
+ 5.4.0-M1
test
+
+ org.mnode.ical4j
+ ical4j
+ 1.0.2
+
diff --git a/src/main/java/edt/umontp/fr/Cours.java b/src/main/java/edt/umontp/fr/Cours.java
index d2d50d9..13d0c1a 100644
--- a/src/main/java/edt/umontp/fr/Cours.java
+++ b/src/main/java/edt/umontp/fr/Cours.java
@@ -1,21 +1,27 @@
package edt.umontp.fr;
+import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Objects;
+import net.fortuna.ical4j.data.ParserException;
+import net.fortuna.ical4j.model.Component;
+import net.fortuna.ical4j.model.DateTime;
+import net.fortuna.ical4j.model.Property;
+
public class Cours implements Comparable {
- private final LocalDate date;
- private final String prof;
- private final LocalTime heureDebut;
- private final LocalTime heureFin;
- private final String lieu;
- private final int duree;
- private final Groupe groupe;
- private final String intitule;
+ private LocalDate date;
+ private String prof;
+ private LocalTime heureDebut;
+ private LocalTime heureFin;
+ private String lieu;
+ private int duree;
+ private Groupe groupe;
+ private String intitule;
public Cours(LocalDate date, String prof, LocalTime heureDebut, LocalTime heureFin, String lieu, int duree,
- Groupe groupe, String intitule) {
+ Groupe groupe, String intitule) {
this.date = date;
this.prof = prof;
this.heureDebut = heureDebut;
@@ -26,12 +32,49 @@ public Cours(LocalDate date, String prof, LocalTime heureDebut, LocalTime heureF
this.intitule = intitule;
}
+ public Cours(Component vEvent) {
+ Property summary = vEvent.getProperty(Property.SUMMARY);
+ Property description = vEvent.getProperty(Property.DESCRIPTION);
+ Property dtStart = vEvent.getProperty(Property.DTSTART);
+ Property dtEnd = vEvent.getProperty(Property.DTEND);
+ Property location = vEvent.getProperty(Property.LOCATION);
+
+ DateTime dateDebut = null;
+ DateTime dateFin = null;
+ try {
+ dateDebut = new DateTime(dtStart.getValue());
+ dateFin = new DateTime(dtEnd.getValue());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ date = LocalDate.ofInstant(dateDebut.toInstant(), dateDebut.getTimeZone().toZoneId());
+ heureDebut = LocalTime.ofInstant(dateDebut.toInstant(), dateDebut.getTimeZone().toZoneId());
+ heureFin = LocalTime.ofInstant(dateFin.toInstant(), dateFin.getTimeZone().toZoneId());
+ lieu = location.getValue();
+ intitule = summary.getValue();
+ // TODO spliter la description pour initialiser les autres attributs
+ }
+
+ public static Groupe getGroupeFromDesc(String desc) {
+ Groupe res = null;
+ for (Groupe g : Groupe.values()) {
+ if (desc.contains(g.name())) {
+ res = g;
+ }
+ }
+ return res;
+ }
+
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
Cours cours = (Cours) o;
- return duree == cours.duree && date.equals(cours.date) && prof.equals(cours.prof) && heureDebut.equals(cours.heureDebut) && heureFin.equals(cours.heureFin) && lieu.equals(cours.lieu) && groupe == cours.groupe && intitule.equals(cours.intitule);
+ return duree == cours.duree && date.equals(cours.date) && prof.equals(cours.prof)
+ && heureDebut.equals(cours.heureDebut) && heureFin.equals(cours.heureFin) && lieu.equals(cours.lieu)
+ && groupe == cours.groupe && intitule.equals(cours.intitule);
}
@Override
diff --git a/src/main/java/edt/umontp/fr/EmploiDuTemps.java b/src/main/java/edt/umontp/fr/EmploiDuTemps.java
new file mode 100644
index 0000000..4a42cb9
--- /dev/null
+++ b/src/main/java/edt/umontp/fr/EmploiDuTemps.java
@@ -0,0 +1,73 @@
+package edt.umontp.fr;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.ParseException;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.ArrayList;
+
+import net.fortuna.ical4j.data.CalendarBuilder;
+import net.fortuna.ical4j.data.ParserException;
+import net.fortuna.ical4j.model.Calendar;
+import net.fortuna.ical4j.model.Component;
+import net.fortuna.ical4j.model.DateTime;
+import net.fortuna.ical4j.model.Property;
+
+public class EmploiDuTemps {
+ private final String LIEN_ICAL = "https://proseconsult.umontpellier.fr/jsp/custom/modules/plannings/direct_cal.jsp?data=58c99062bab31d256bee14356aca3f2423c0f022cb9660eba051b2653be722c431b66c493702208e664667048bc04373dc5c094f7d1a811b903031bde802c7f59b21846d3c6254443d7b6e956d3145c6e0d5bac87b70fdd185b8b86771d71211a02411e8351020815cfb0dcc54c667187353dbcfc377b44753a4f433d4e51f753c2b0fc0eafdcbc1cbb6ef4e715ebea9d495758b595b12cb294e70e715876fbaa3c654023c76f43cd51442775ff171e0a5f21b50c55a5b52d94df3e7977af823a1e78ee86c6497b1cf8732d52143eeffacc27449fc13ec1f0b04d23e09712df15579474e1aa0cd65f50f33a1dd766301,1";
+ private final EmploiDuTemps singleton = null;
+ private Planning planningEmploisDutemps;
+
+ private Calendar convertieFichierIcsEnCalendar(File fichierIcs) {
+ Calendar calendar = null;
+ try (FileInputStream fileICS = new FileInputStream(fichierIcs)) {
+ CalendarBuilder builder = new CalendarBuilder();
+ calendar = builder.build(fileICS);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserException e) {
+ e.printStackTrace();
+ }
+ return calendar;
+ }
+
+ private File getFichierIcsDepuisLienIcal() {
+ File fichierIcs = new File("fichier.ics");
+ if (fichierIcs.isFile()) {
+ fichierIcs.delete();
+ }
+ try {
+ URL url = new URL(LIEN_ICAL);
+ InputStream in = url.openStream();
+ Files.copy(in, Paths.get(fichierIcs.getName()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return fichierIcs;
+ }
+
+ public void actualiser() {
+ File fichierIcs = getFichierIcsDepuisLienIcal();
+ Calendar calendar = convertieFichierIcsEnCalendar(fichierIcs);
+ ArrayList coursList = new ArrayList<>();
+ // TODO en attente de finalisation du constructeur de Cours
+ // for (Object vEvent : calendar.getComponents(Component.VEVENT)) {
+ // coursList.add(new Cours((Component) vEvent));
+ // }
+ // planningEmploisDutemps = new Planning(coursList);
+ }
+
+}
diff --git a/src/main/java/edt/umontp/fr/Planning.java b/src/main/java/edt/umontp/fr/Planning.java
index 443c483..eaaab09 100644
--- a/src/main/java/edt/umontp/fr/Planning.java
+++ b/src/main/java/edt/umontp/fr/Planning.java
@@ -19,10 +19,9 @@ public Iterator iterator() {
return null;
}
- //TODO a coder
@Override
public void forEach(Consumer action) {
-
+ //TODO a coder
}
//TODO a coder
diff --git a/src/main/java/edt/umontp/fr/Test.java b/src/main/java/edt/umontp/fr/Test.java
new file mode 100644
index 0000000..b0f3087
--- /dev/null
+++ b/src/main/java/edt/umontp/fr/Test.java
@@ -0,0 +1,8 @@
+package edt.umontp.fr;
+
+public class Test {
+ public static void main(String[] args) {
+ System.out.println(Cours.getGroupeFromDesc("\n\n-Semestre-1\nGOUAICH ABDELKADER\nLAGUILLAUMIE FABIE " +
+ "N\nPOUPET VICTOR\nROSENFELD MATTHIEU\nA1valider\n(Exporté le:18 / 01 / 2 021 10:51)\n "));
+ }
+}
diff --git a/src/test/java/edt/umontp/fr/AppTest.java b/src/test/java/edt/umontp/fr/AppTest.java
index 1712b1a..497a762 100644
--- a/src/test/java/edt/umontp/fr/AppTest.java
+++ b/src/test/java/edt/umontp/fr/AppTest.java
@@ -1,8 +1,8 @@
package edt.umontp.fr;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test for simple App.
diff --git a/src/test/java/edt/umontp/fr/CoursTest.java b/src/test/java/edt/umontp/fr/CoursTest.java
new file mode 100644
index 0000000..a52659c
--- /dev/null
+++ b/src/test/java/edt/umontp/fr/CoursTest.java
@@ -0,0 +1,22 @@
+package edt.umontp.fr;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CoursTest {
+
+ @Test
+ void Test_getGroupeFromDesc_A1Seul_A1() {
+ String desc = "\n\nA1\nGOUAICH ABDELKADER\nLAGUILLAUMIE FABIE " + "N\nPOUPET VICTOR\nROSENFELD " +
+ "MATTHIEU\nA valider\n(Exporté le:18 / 01 / 2 021 10:51)\n";
+ assertEquals(Groupe.A1, Cours.getGroupeFromDesc(desc));
+ }
+
+ @Test
+ void Test_getGroupeFromDesc_A1NonSeul_A1() {
+ String desc = "\n\nA1-Semestre-1\nGOUAICH ABDELKADER\nLAGUILLAUMIE FABIE N\nPOUPET " +
+ "VICTOR\nROSENFELD MATTHIEU\nA valider\n(Exporté le:18/01/2 021 10:51)\n";
+ assertEquals(Groupe.A1, Cours.getGroupeFromDesc(desc));
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/edt/umontp/fr/EmploiDuTempsTest.java b/src/test/java/edt/umontp/fr/EmploiDuTempsTest.java
new file mode 100644
index 0000000..e0cc095
--- /dev/null
+++ b/src/test/java/edt/umontp/fr/EmploiDuTempsTest.java
@@ -0,0 +1,15 @@
+package edt.umontp.fr;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import org.junit.jupiter.api.Test;
+
+public class EmploiDuTempsTest {
+
+
+ @Test
+ void test_actualiser_verifierRetourneAucuneErreur(){
+ EmploiDuTemps emploiDuTemps = new EmploiDuTemps();
+ assertAll(() -> emploiDuTemps.actualiser());
+ }
+}