/*
 * myLazyClock
 *
 * Copyright (C) 2014
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.myLazyClock.calendarApi;

import java.util.Calendar;

/**
* Send request to get schedule and returns the first
* event of the given day
*  
* @author Jeremy
* 
* @warning Caution with offsets and calendar and see getEdt warning
* 
* External library iCal4j (http://build.mnode.org/projects/ical4j/apidocs/): 
*   - put in eclipse projet (add jar) for local use
*   - in war/WEB-INF/lib to deploy
*   
*/
public class CalendarSmartEdtStrategy implements CalendarStrategy {

    public static final int ID = 2;

    @Override
    public Integer getId() {
        return ID;
    }

    @Override
    public String getName() {
        return "Calendar edt univ-nantes";
    }

    @Override
    public CalendarEvent getFirstEvent(String url, Calendar day) throws EventNotFoundException {
        if (day == null) {
            throw new EventNotFoundException();
        }

        CalendarEvent returnEvent = new CalendarEvent();

        returnEvent.setBeginDate(day.getTime());

        return returnEvent;
    }
}

@@ -765,28 +765,238 @@
 ava.
-util.Calenda
+io.IOException;%0Aimport java.util.Calendar;%0Aimport java.util.HashMap;%0A%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonArray;%0Aimport org.myLazyClock.calendarApi.JsonConverte
 r;%0A%0A/**%0A
 * Se
@@ -991,16 +991,17 @@
 r;%0A%0A/**%0A
+ 
 * Send r
@@ -1045,16 +1045,17 @@
 e first%0A
+ 
 * event 
@@ -1075,12 +1075,12 @@
 day%0A
-*  %0A
+ *%0A 
 * @a
@@ -1092,19 +1092,20 @@
  Jeremy%0A
-* %0A
+ *%0A 
 * @warni
@@ -1168,11 +1168,12 @@
 ing%0A
-* %0A
+ *%0A 
 * Ex
@@ -1244,18 +1244,18 @@
 idocs/):
- 
 %0A
+ 
 *   - pu
@@ -1298,16 +1298,17 @@
 cal use%0A
+ 
 *   - in
@@ -1338,13 +1338,12 @@
 loy%0A
-*   %0A
+ *%0A 
 */%0Ap
@@ -1721,24 +1721,25 @@
 ption %7B%0A
+%0A
         
 if (day 
@@ -1734,27 +1734,960 @@
     
-if (day == null) %7B%0A
+HashMap%3CString, String%3E urlParameters = new HashMap%3CString, String%3E();%0A        urlParameters.put(%22getWeek%22, url);%0A        urlParameters.put(%22year%22, String.valueOf(day.get(Calendar.YEAR)));%0A        urlParameters.put(%22week%22, String.valueOf(day.get(Calendar.WEEK_OF_YEAR) - 1));%0A%0A        CalendarEvent returnEvent = new CalendarEvent();%0A%0A        try %7B%0A            // Calendar days begin from sunday 1 to saturday 7%0A            // Smart edt array begin from monday 0 to sunday 6%0A            int dayIndex = day.get(Calendar.DAY_OF_WEEK);%0A            dayIndex = (dayIndex == 1) ? 6 : dayIndex - 2;%0A%0A            JsonElement root = JsonConverter.getJson(urlParameters).getAsJsonArray().get(0);%0A            JsonArray daysArray = root.getAsJsonObject().get(%22days%22).getAsJsonArray();%0A            JsonArray modulesArray = daysArray.get(dayIndex).getAsJsonObject().get(%22modules%22).getAsJsonArray();%0A%0A            if(modulesArray.size() %3C= 0 )%7B // No events today%0A    
     
@@ -2734,24 +2734,28 @@
 ();%0A        
+    
 %7D%0A%0A        C
@@ -2757,58 +2757,481 @@
     
-CalendarEvent returnEvent = new CalendarEvent();%0A%0A
+    JsonObject firstModule = modulesArray.get(0).getAsJsonObject();%0A            returnEvent.setName(%22%5BSmartEdt%5D%22 + firstModule.get(%22name%22).getAsString());%0A%0A            // StartTime is number of minutes from midnight%0A            int startHour = firstModule.get(%22startTime%22).getAsInt();%0A%0A            Calendar beginDate = (Calendar) day.clone();%0A            beginDate.set(Calendar.HOUR_OF_DAY, startHour / 60);%0A            beginDate.set(Calendar.MINUTE, startHour %25 60);%0A%0A    
     
@@ -3259,19 +3259,25 @@
 ginDate(
-day
+beginDate
 .getTime
@@ -3276,24 +3276,123 @@
 .getTime());
+%0A        %7D%0A        catch(IOException ex)%7B%0A            throw new EventNotFoundException();%0A        %7D
 %0A%0A        re

Implement SmartEDT calendar without course name