BrightSide Workbench Full Report + Source Code
FullCalendarUtil.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.elephant.calendar;
20 
21 import com.google.gson.GsonBuilder;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import javax.servlet.ServletContext;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import org.turro.string.Strings;
32 import org.turro.action.Events;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.direct.DirectContent;
35 import org.turro.elephant.direct.DirectContents;
36 import org.turro.elephant.direct.IDirectContent;
37 import org.turro.plugin.calendar.ICalendarEvent;
38 
43 @DirectContent(identifier="full-calendar")
44 public class FullCalendarUtil implements IDirectContent {
45 
46  public static String getIdentifier() {
47  return FullCalendarUtil.class.getAnnotation(DirectContent.class).identifier();
48  }
49 
50  @Override
51  public boolean itsMe(String id) {
52  return getIdentifier().equals(id);
53  }
54 
55  @Override
56  public boolean myTurn(HttpServletRequest request) {
57  return DirectContents.isYourTurn(request, getIdentifier());
58  }
59 
60  @Override
61  public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
62  try {
63  String pstart = request.getParameter("start"),
64  pend = request.getParameter("end");
65  if(!Strings.isBlank(pstart) && !Strings.isBlank(pend)) {
66  Date start = Iso8601DateFormat.getDate(pstart + "T00:00:00");
67  Date end = Iso8601DateFormat.getDate(pend + "T00:00:00");
68  HashMap<String, String> args = new HashMap<>();
69  if(!Strings.isBlank(request.getParameter("webInfo"))) {
70  args.put("webInfo", request.getParameter("webInfo"));
71  }
72  if(!Strings.isBlank(request.getParameter("pubCats"))) {
73  args.put("publicationCategories", request.getParameter("pubCats"));
74  }
75  if(!Strings.isBlank(request.getParameter("pubGroups"))) {
76  args.put("publicationGroups", request.getParameter("pubGroups"));
77  }
78  if(!Strings.isBlank(request.getParameter("dosCats"))) {
79  args.put("dossierCategories", request.getParameter("dosCats"));
80  }
81  if(!Strings.isBlank(request.getParameter("convPaths"))) {
82  args.put("convocationPaths", request.getParameter("convPaths"));
83  }
84  if(!Strings.isBlank(request.getParameter("servTypes"))) {
85  args.put("serviceTypes", request.getParameter("servTypes"));
86  }
87  if(!Strings.isBlank(request.getParameter("required"))) {
88  args.put("required", request.getParameter("required"));
89  }
90  if(!Strings.isBlank(request.getParameter("target"))) {
91  args.put("target", request.getParameter("target"));
92  }
93  response.setContentType("application/json");
94  response.getWriter().write(getPublicEvents(start, end, args));
95  }
96  } catch (IOException ex) {
97  Logger.getLogger(FullCalendarUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
98  }
99  }
100 
101  public static String getPublicEvents(Date start, Date end, HashMap<String, String> args) {
102  String url = args.get("webInfo");
103  ArrayList<FullCalendarEvent> fevents = new ArrayList<>();
104  for(ICalendarEvent evt : Events.getPublicEvents(start, end, args)) {
106  fce.start = evt.getBeginDate();
107  fce.end = evt.getEndDate();
108  fce.title = evt.getTitle();
109  fce.description = evt.getContent();
110  fce.motive = evt.getMotive();
111  fce.url = Strings.isBlank(url) ? evt.getPath() : url + "?webInfo=" + evt.getPath();
112  fevents.add(fce);
113  }
114  return new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssX").create().toJson(fevents);
115  }
116 
117 }
static Collection< ICalendarEvent > getPublicEvents(Date start, Date end, HashMap< String, String > args)
Definition: Events.java:40
static String getPublicEvents(Date start, Date end, HashMap< String, String > args)
boolean myTurn(HttpServletRequest request)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
static boolean isYourTurn(HttpServletRequest request, String path)