View Javadoc
1   /*
2    * Copyright (C) 2003-2014 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  
18  package org.exoplatform.calendar.ws.bean;
19  
20  import static org.exoplatform.calendar.ws.CalendarRestApi.CALENDAR_URI;
21  import static org.exoplatform.calendar.ws.CalendarRestApi.CAL_BASE_URI;
22  import static org.exoplatform.calendar.ws.CalendarRestApi.FEED_URI;
23  import static org.exoplatform.calendar.ws.CalendarRestApi.RSS_URI;
24  
25  import java.io.Serializable;
26  import java.util.Collection;
27  import java.util.LinkedList;
28  
29  import org.exoplatform.calendar.service.FeedData;
30  import org.exoplatform.calendar.ws.common.Resource;
31  
32  public class FeedResource extends Resource {
33    private static final long serialVersionUID = 7911451293360539750L;
34  
35    private String            name;
36  
37    private String                    rss;
38  
39    private Collection<Serializable>                  calendars;
40  
41    /**
42     * This field is introduced for user can update calendars in Feed
43     * It's because calendars field must readonly,
44     * it's a workaround for the restriction of rest framework (it can not unmarshall from JSON string into generic field)
45     */
46    private String[] calendarIds = null;
47  
48    public FeedResource() {
49      super(null);
50    }
51    
52    public FeedResource(FeedData data, String[] calendarids, String basePath) {
53      super(data.getFeed());
54  
55      setHref(new StringBuilder(basePath).append(FEED_URI).append(data.getTitle()).toString());
56      name = data.getTitle();
57      rss = new StringBuilder(CAL_BASE_URI).append(FEED_URI)
58                                          .append(data.getTitle())
59                                          .append(RSS_URI)
60                                          .toString();
61      calendars = new LinkedList<Serializable>();
62      for (String id : calendarids) {
63        calendars.add(new StringBuilder(basePath).append(CALENDAR_URI).append(id).toString());      
64      }
65      this.calendarIds = calendarids;
66    }
67  
68    public String getName() {
69      return name;
70    }
71  
72    public void setName(String name) {
73      this.name = name;
74    }
75  
76    public String getRss() {
77      return rss;
78    }
79  
80    public void setRss(String rss) {
81      this.rss = rss;
82    }
83  
84    public Collection<Serializable> getCalendars() {
85      return calendars;
86    }
87  
88    /**
89     * Because rest framework can not unmarshall from JSON if object contain generic field
90     * So, we must make #calendars field is readonly with rest-framework by rename setter method to #setCals
91     * And we introduce field #calendarIds, that enable user can update calendars in Feed
92     * @param calendars
93     * @return this
94     */
95    public FeedResource setCals(Collection<Serializable> calendars) {
96      this.calendars = calendars;
97      return this;
98    }
99  
100   public String[] getCalendarIds() {
101     return calendarIds;
102   }
103 
104   public void setCalendarIds(String[] calendarIds) {
105     this.calendarIds = calendarIds;
106   }
107 }