1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.blog.web.portlet;
35
36 import fr.paris.lutece.plugins.blog.business.Blog;
37 import fr.paris.lutece.plugins.blog.business.BlogHome;
38 import fr.paris.lutece.plugins.blog.business.portlet.BlogListPortletHome;
39 import fr.paris.lutece.plugins.blog.business.portlet.BlogPortlet;
40 import fr.paris.lutece.plugins.blog.business.portlet.BlogPortletHome;
41 import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
42 import fr.paris.lutece.plugins.blog.business.portlet.BlogPublicationHome;
43 import fr.paris.lutece.plugins.blog.service.BlogParameterService;
44 import fr.paris.lutece.plugins.blog.service.BlogService;
45 import fr.paris.lutece.portal.business.portlet.PortletHome;
46 import fr.paris.lutece.portal.web.portlet.PortletJspBean;
47 import fr.paris.lutece.util.html.HtmlTemplate;
48 import fr.paris.lutece.portal.service.util.AppPathService;
49 import fr.paris.lutece.portal.service.admin.AdminUserService;
50 import fr.paris.lutece.portal.business.user.AdminUser;
51
52 import javax.servlet.http.HttpServletRequest;
53
54 import org.apache.commons.lang3.StringUtils;
55
56 import java.util.Date;
57 import java.util.HashMap;
58 import java.util.List;
59
60
61
62
63 public class BlogPortletJspBean extends PortletJspBean
64 {
65
66 private static final long serialVersionUID = 5744334133144418317L;
67 public static final String MARK_HTML_CONTENT = "htmlcontent";
68 public static final String MARK_EDIT_COMMENT = "editcomment";
69 public static final String MARK_WEBAPP_URL = "webapp_url";
70 public static final String MARK_LIST_HTMLDOC = "blog_list";
71 public static final String MARK_LIST_PAGES = "pages_list";
72 public static final String MARK_BLOG_ID = "blog_id";
73
74 public static final String PARAMETER_CONTENT_ID = "content_id";
75 public static final String PARAMETER_DESCRIPTION = "description";
76 public static final String PARAMETER_HTML_CONTENT = "html_content";
77 public static final String PARAMETER_EDIT_COMMENT = "edit_comment";
78 public static final String PARAMETER_PORTLET_NAME = "portlet_name";
79 public static final String PARAMETER_HTMLDOC_SELECTED = "blog_selected";
80 private static final String PARAMETER_PAGE_TEMPLATE_CODE = "page_template_code";
81
82 public static final String TEMPLATE_MODIFY_PORTLET = "admin/portlet/modify_portlet.html";
83
84
85
86
87
88
89
90
91 @Override
92 public String getCreate( HttpServletRequest request )
93 {
94 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
95 String strPortletTypeId = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
96 List<Blog> listBlog = BlogHome.selectByArchiveStatus(false);
97 HashMap<String, Object> model = new HashMap<>( );
98
99 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
100 model.put( MARK_LIST_HTMLDOC, listBlog );
101 model.put( MARK_LIST_PAGES, BlogListPortletHome.loadPages( BlogPortlet.RESOURCE_ID ) );
102
103 HtmlTemplate template = getCreateTemplate( strPageId, strPortletTypeId, model );
104
105 return template.getHtml( );
106 }
107
108
109
110
111
112
113
114
115 @Override
116 public String getModify( HttpServletRequest request )
117 {
118 String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
119 int nPortletId = Integer.parseInt( strPortletId );
120 BlogPortlet../../../../../fr/paris/lutece/plugins/blog/business/portlet/BlogPortlet.html#BlogPortlet">BlogPortlet portlet = (BlogPortlet) PortletHome.findByPrimaryKey( nPortletId );
121 Blog blog = BlogHome.findByPrimaryKey( portlet.getContentId( ) );
122 HashMap<String, Object> model = new HashMap<>( );
123
124 model.put( MARK_HTML_CONTENT, blog.getHtmlContent( ) );
125 model.put( MARK_EDIT_COMMENT, blog.getEditComment( ) );
126 model.put( MARK_LIST_PAGES, BlogListPortletHome.loadPages( BlogPortlet.RESOURCE_ID ) );
127 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
128 model.put( MARK_BLOG_ID, blog.getId( ) );
129
130 HtmlTemplate template = getModifyTemplate( portlet, model );
131
132 return template.getHtml( );
133 }
134
135
136
137
138
139
140
141
142 @Override
143 public String doCreate( HttpServletRequest request )
144 {
145 BlogPortletlog/business/portlet/BlogPortlet.html#BlogPortlet">BlogPortlet portlet = new BlogPortlet( );
146 AdminUser user = AdminUserService.getAdminUser( request );
147 String strSelectedBlog = request.getParameter( PARAMETER_HTMLDOC_SELECTED );
148 String strTemplateCode = request.getParameter( PARAMETER_PAGE_TEMPLATE_CODE );
149
150
151 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
152 int nPageId = Integer.parseInt( strPageId );
153 Blog/plugins/blog/business/Blog.html#Blog">Blog blog = new Blog( );
154 if ( strSelectedBlog == null || StringUtils.isEmpty( strSelectedBlog ) || !StringUtils.isNumeric( strSelectedBlog ) )
155 {
156 blog.setContentLabel( request.getParameter( PARAMETER_PORTLET_NAME ) );
157 blog.setVersion( 1 );
158 blog.setCreationDate( getSqlDate( ) );
159 blog.setUpdateDate( getSqlDate( ) );
160 blog.setDescription( request.getParameter( PARAMETER_DESCRIPTION ) );
161 blog.setHtmlContent( request.getParameter( PARAMETER_HTML_CONTENT ) );
162
163 blog.setEditComment( request.getParameter( PARAMETER_EDIT_COMMENT ) );
164 blog.setUser( user.getAccessCode( ) );
165 blog.setUserCreator( user.getAccessCode( ) );
166 BlogHome.addInitialVersion( blog );
167 }
168 else
169 {
170 blog = BlogHome.findByPrimaryKey( Integer.parseInt( strSelectedBlog ) );
171 }
172 int nContentId = blog.getId( );
173
174
175 String strErrorUrl = setPortletCommonData( request, portlet );
176
177 if ( strErrorUrl != null )
178 {
179 return strErrorUrl;
180 }
181
182 portlet.setPageTemplateDocument( Integer.parseInt( strTemplateCode ) );
183 portlet.setPageId( nPageId );
184 portlet.setContentId( nContentId );
185 portlet.setPortletName( request.getParameter( PARAMETER_PORTLET_NAME ) );
186
187 BlogPublicationlog/business/portlet/BlogPublication.html#BlogPublication">BlogPublication doc = new BlogPublication( );
188 doc.setDateEndPublishing(BlogParameterService.getInstance().getDefaultDateEndPublishing());
189 portlet.setBlogPublication(doc);
190
191
192 BlogPortletHome.getInstance( ).create( portlet );
193 blog.setAttachedPortletId( portlet.getId( ) );
194 BlogHome.update( blog );
195 int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( blog.getId( ), new Date( ) );
196
197 if ( nbPublication == 1 )
198 {
199 BlogService.getInstance( ).fireCreateBlogEvent( blog.getId( ) );
200 }
201
202
203 return getPageUrl( nPageId );
204 }
205
206
207
208
209
210
211
212
213 @Override
214 public String doModify( HttpServletRequest request )
215 {
216
217 String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
218
219 String strDocumentTypeCode = request.getParameter( PARAMETER_PAGE_TEMPLATE_CODE );
220 int nPortletId = Integer.parseInt( strPortletId );
221 BlogPortlet../../../../../fr/paris/lutece/plugins/blog/business/portlet/BlogPortlet.html#BlogPortlet">BlogPortlet portlet = (BlogPortlet) PortletHome.findByPrimaryKey( nPortletId );
222 Blog blog = BlogService.getInstance( ).loadBlog( portlet.getContentId() );
223
224 String strErrorUrl = setPortletCommonData( request, portlet );
225
226 if ( strErrorUrl != null )
227 {
228 return strErrorUrl;
229 }
230 portlet.setPageTemplateDocument( Integer.parseInt( strDocumentTypeCode ) );
231
232 blog.setHtmlContent( request.getParameter( PARAMETER_HTML_CONTENT ) );
233 blog.setEditComment( request.getParameter( PARAMETER_EDIT_COMMENT ) );
234 blog.setUpdateDate( getSqlDate( ) );
235 blog.setVersion( blog.getVersion( ) + 1 );
236
237 BlogHome.update( blog );
238 BlogService.getInstance( ).updateBlog( blog, blog.getDocContent( ) );
239
240 portlet.setBlogPublication( BlogPublicationHome.findDocPublicationByPimaryKey( nPortletId, portlet.getContentId( ) ) );
241
242 portlet.update( );
243
244
245 return getPageUrl( portlet.getPageId( ) );
246 }
247
248
249
250
251
252
253 protected java.sql.Timestamp getSqlDate( )
254 {
255 java.util.Date utilDate = new java.util.Date( );
256 java.sql.Timestamp sqlDate = new java.sql.Timestamp( utilDate.getTime( ) );
257
258 return ( sqlDate );
259 }
260 }