1 /*
2 * Copyright (c) 2002-2014, Mairie de Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.plugins.calendar.business.portlet;
35
36 import fr.paris.lutece.plugins.calendar.service.AgendaResource;
37 import fr.paris.lutece.portal.business.portlet.IPortletInterfaceDAO;
38 import fr.paris.lutece.portal.business.portlet.PortletHome;
39 import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
40 import fr.paris.lutece.portal.service.spring.SpringContextService;
41
42 import java.util.Date;
43 import java.util.List;
44
45
46 /**
47 * This class provides instances management methods for CalendarPortlet objects
48 */
49 public class CalendarPortletHome extends PortletHome
50 {
51 // This class implements the Singleton design pattern.
52 private static CalendarPortletHome _singleton;
53
54 // Static variable pointed at the DAO instance
55 private static ICalendarPortletDAO _dao = SpringContextService.getBean( "calendar.calendarPortletDAO" );
56
57 /**
58 * Constructor
59 */
60 public CalendarPortletHome( )
61 {
62 if ( _singleton == null )
63 {
64 _singleton = this;
65 }
66 }
67
68 /**
69 * Returns the identifier of the portlet type
70 *
71 * @return the portlet type identifier
72 */
73 public String getPortletTypeId( )
74 {
75 String strCurrentClassName = this.getClass( ).getName( );
76 String strPortletTypeId = PortletTypeHome.getPortletTypeId( strCurrentClassName );
77
78 return strPortletTypeId;
79 }
80
81 /**
82 * Returns the instance of NewsLetterArchive Portlet
83 *
84 * @return the Archive Portlet instance
85 */
86 public static PortletHome getInstance( )
87 {
88 if ( _singleton == null )
89 {
90 _singleton = new CalendarPortletHome( );
91 }
92
93 return _singleton;
94 }
95
96 /**
97 * Returns the instance of the portlet DAO singleton
98 *
99 * @return the instance of the DAO singleton
100 */
101 public IPortletInterfaceDAO getDAO( )
102 {
103 return _dao;
104 }
105
106 /**
107 * Associates a new agenda to a given portlet.
108 * @param strAgendaId The identifier of the agenda
109 * @param strDateBegin The beginning date
110 * @param strDateEnd The end date
111 * @param nPortletId The identifier of the portlet.
112 */
113 public static void insertAgendaInterval( int nPortletId, String strAgendaId, String strDateBegin, String strDateEnd )
114 {
115 _dao.insertAgendaInterval( nPortletId, strAgendaId, strDateBegin, strDateEnd );
116 }
117
118 /**
119 * De-associate an agenda from a given portlet.
120 * @param nPortletId the identifier of the portlet.
121 * @param strAgenda the identifier of the agenda
122 */
123 public static void removeAgenda( int nPortletId, String strAgenda )
124 {
125 _dao.removeAgenda( nPortletId, strAgenda );
126 }
127
128 /**
129 * De-associate an agenda from a given portlet.
130 * @param nPortletId the identifier of the portlet.
131 */
132 public static void removeAllAgendas( int nPortletId )
133 {
134 _dao.delete( nPortletId );
135 }
136
137 /**
138 * Returns all the agenda associated with a given portlet.
139 * @param nPortletId the identifier of the portlet.
140 * @return a list of agenda resources unfiltered
141 */
142 public static List<AgendaResource> findAgendasInPortlet( int nPortletId )
143 {
144 return _dao.findAgendasInPortlet( nPortletId );
145 }
146
147 /**
148 * Returns all the agenda associated with a given portlet.
149 * @return a list of agenda resources unfiltered
150 * @param dateBegin The start date
151 * @param dateEnd The end date
152 * @param nPortletId the identifier of the portlet.
153 */
154 public static List<AgendaResource> findAgendaBetween( int nPortletId, Date dateBegin, Date dateEnd )
155 {
156 return _dao.findAgendaBetween( nPortletId, dateBegin, dateEnd );
157 }
158
159 /**
160 * Associates a new calendar to a given portlet.
161 * @param strAgendaId The id of the agenda
162 * @param nDays The number of days
163 * @param nPortletId the identifier of the portlet.
164 */
165 public static void insertCalendar( int nPortletId, String strAgendaId, int nDays )
166 {
167 _dao.insertCalendar( nPortletId, strAgendaId, nDays );
168 }
169
170 /**
171 * Returns the beginning date of the display of corresponding events
172 * @param nPortletId The id portlet
173 * @return Returns the start date
174 */
175 public static Date getBeginDate( int nPortletId )
176 {
177 return _dao.getBeginDate( nPortletId );
178 }
179
180 /**
181 * Returns the last date of the display
182 * @param nPortletId The id of the portlet
183 * @return The End date of the portlet display
184 */
185 public static Date getEndDate( int nPortletId )
186 {
187 return _dao.getEndDate( nPortletId );
188 }
189
190 /**
191 * Returns the number of days within which the events will occur
192 * @param nPortletId The id of the portlet
193 * @return Returns the number of days
194 */
195 public static int getRepetitionDays( int nPortletId )
196 {
197 return _dao.getRepetitionDays( nPortletId );
198 }
199 }