private void sendToGoogleCalendar(Utilisateur utilisateur, DemandeAbsence absence, boolean update) throws Exception { Date dateDebutEvent = absence.getDateDebut(); if (absence.getDebutPM()) { dateDebutEvent = DateUtils.setHours(dateDebutEvent, 14); } Date dateFinEvent = absence.getDateFin(); if (absence.getFinAM()) { dateFinEvent = DateUtils.setHours(dateFinEvent, 14); } else { dateFinEvent = DateUtils.addDays(dateFinEvent, 1); } if (update) { String oldTitre = absence.getLibelleType().toString() + "?"; String titre = absence.getLibelleType().toString(); calendarService.updateEvent( utilisateur.getEmail(), dateDebutEvent, dateFinEvent, oldTitre, titre, ""); } else { String titre = absence.getLibelleType().toString(); titre += (absence.getStatut().equals(StatutAbsence.VALIDE)) ? "" : "?"; calendarService.createEvent(utilisateur.getEmail(), dateDebutEvent, dateFinEvent, titre, ""); } }
private void removeFromGoogleCalendar(Utilisateur utilisateur, DemandeAbsence absence) throws Exception { Date dateDebutEvent = absence.getDateDebut(); if (absence.getDebutPM()) { dateDebutEvent = DateUtils.setHours(dateDebutEvent, 14); } Date dateFinEvent = absence.getDateFin(); if (absence.getFinAM()) { dateFinEvent = DateUtils.setHours(dateFinEvent, 14); } else { dateFinEvent = DateUtils.addDays(dateFinEvent, 1); } String titre = absence.getLibelleType().toString(); calendarService.deleteEvent(utilisateur.getEmail(), dateDebutEvent, dateFinEvent, titre); }
private float getNbJoursForAbsence(DemandeAbsence absence) throws Exception { // nombre de jours d'écart entre datedeb et dateFin float nbJours = Days.daysBetween(new DateTime(absence.getDateDebut()), new DateTime(absence.getDateFin())) .getDays(); nbJours += 1; if (absence.getDebutPM()) { nbJours -= 0.5; } if (absence.getFinAM()) { nbJours -= 0.5; } // recup des jours feries List<Date> joursFeries = null; try { joursFeries = calendarService.getJourFeries(); } catch (Exception e) { throw new Exception(e.getMessage()); } // les samedis et dimanche ne sont pas pris en compte // supprimer les jours feries GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(absence.getDateDebut()); // gestion des dates différentes dans le cloud while (!DateUtils.isSameDay(calendar.getTime(), absence.getDateFin())) { // System.out.println("!!!! " + calendar.getTime() + ">" + // calendar.get(Calendar.DAY_OF_WEEK)); if (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7) { nbJours -= 1; } if (joursFeries.contains(calendar.getTime())) { nbJours -= 1; } calendar.add(Calendar.DATE, 1); } return nbJours; }