BrightSide Workbench Full Report + Source Code
ConvocationCalendar.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.contacts.command;
20 
21 import java.util.Date;
22 import java.util.List;
23 import org.amic.util.date.CheckDate;
24 import org.turro.string.Strings;
25 import org.turro.action.Contacts;
26 import org.turro.annotation.ElephantPlugin;
27 import org.turro.contacts.Attendee;
28 import org.turro.contacts.Convocation;
29 import org.turro.contacts.db.ContactsPU;
30 import org.turro.jpa.Dao;
31 import org.turro.plugin.calendar.CalendarColor;
32 import org.turro.plugin.calendar.DefaultCalendarEvent;
33 import org.turro.plugin.command.CalendarPlugin;
34 import org.turro.plugin.contacts.IContact;
35 import org.turro.util.Chars;
36 import org.turro.util.PhraseBuilder;
37 
42 @ElephantPlugin
43 public class ConvocationCalendar extends CalendarPlugin {
44 
45  @Override
46  protected void executePlugin() {
47  Dao dao = new ContactsPU();
48  Date newFrom = new CheckDate(getFrom()).addDays(-7).getDate(),
49  newTo = new CheckDate(getTo()).addDays(7).getDate();
50  List<Convocation> list = dao.getResultList(
51  "select c from Convocation c " +
52  "where c.callDate >= ? " +
53  "and c.callDate <= ? " +
54  "and (c.organizer = ? " +
55  "or c.publishable = TRUE " +
56  "or exists ( " +
57  " select a from Attendee a " +
58  " where a.convocation = c " +
59  " and a.contact = ? " +
60  "))",
61  new Object[] {
62  newFrom, newTo,
65  });
66  for(Convocation c : list) {
67  DefaultCalendarEvent calendarEvent = new DefaultCalendarEvent();
68  calendarEvent.setLocked(false);
69  calendarEvent.setHeaderColor(CalendarColor.PURPLE.getHeader());
70  calendarEvent.setContentColor(CalendarColor.PURPLE.getContent());
71  calendarEvent.setBeginDate(c.getCallDate());
72  calendarEvent.setEndDate(c.getEndDate());
73  calendarEvent.setPath(ContactsPU.getObjectPath(c));
74  calendarEvent.setOrganizer(Contacts.getContact(c.getOrganizer()));
75  calendarEvent.setTitle(c.getName());
76  PhraseBuilder pb = new PhraseBuilder();
77  pb.addPendingSeparator(Chars.nl().repeat(2).toString());
78  pb.addWord(c.getPlainText());
79  pb.addPendingSeparator(Chars.nl().repeat(2).toString());
80  for(Attendee attendee : c.getAttendees()) {
81  IContact ic = Contacts.getContact(attendee.getContact());
82  pb.addWord(ic.getName());
83  pb.addPendingSeparator(", ");
84  calendarEvent.addAttendee(ic);
85  }
86  calendarEvent.setContent(pb.toString());
87  calendarEvent.setEventId(Strings.identifier("conv" + c.getId()));
88  addResult(calendarEvent.getEventId(), calendarEvent);
89  }
90  }
91 
92 }
static IContact getContact(Object object)
Definition: Contacts.java:109
Object addResult(String key, Object value)
static String getObjectPath(Object object)
Definition: ContactsPU.java:68