View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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.blog.business;
35  
36  import java.io.Serializable;
37  import java.sql.Timestamp;
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  import javax.validation.constraints.NotEmpty;
42  import javax.validation.constraints.Size;
43  
44  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
45  import fr.paris.lutece.portal.business.user.AdminUser;
46  import fr.paris.lutece.portal.business.user.AdminUserHome;
47  import fr.paris.lutece.portal.service.rbac.RBACResource;
48  import fr.paris.lutece.portal.service.resource.IExtendableResource;
49  import fr.paris.lutece.util.ReferenceItem;
50  
51  /**
52   * This is the business class for the object Blog
53   */
54  public class Blog extends ReferenceItem implements Serializable, IExtendableResource, RBACResource
55  {
56      public static final String PROPERTY_RESOURCE_TYPE = "BLOG";
57  
58      private static final long serialVersionUID = 1L;
59  
60      // Perimissions
61      public static final String PERMISSION_VIEW = "VIEW";
62      public static final String PERMISSION_CREATE = "CREATE";
63      public static final String PERMISSION_MODIFY = "MODIFY";
64      public static final String PERMISSION_DELETE = "DELETE";
65      public static final String PERMISSION_PUBLISH = "PUBLISH";
66      public static final String PERMISSION_ARCHIVE = "ARCHIVE";
67  
68      // Variables declarations
69      private int _nId;
70  
71      private int _nAttachedPortletId;
72  
73      private int _nVersion;
74  
75      @NotEmpty( message = "#i18n{blog.validation.blog.ContentLabel.notEmpty}" )
76      @Size( max = 255, message = "#i18n{blog.validation.blog.ContentLabel.size}" )
77      private String _strContentLabel;
78  
79      private Timestamp _dateCreationDate;
80  
81      private Timestamp _dateUpdateDate;
82  
83      @NotEmpty( message = "#i18n{blog.validation.blog.HtmlContent.notEmpty}" )
84      @Size( message = "#i18n{blog.validation.blog.HtmlContent.size}" )
85      private String _strHtmlContent;
86  
87      @NotEmpty( message = "#i18n{blog.validation.blog.User.notEmpty}" )
88      @Size( max = 255, message = "#i18n{blog.validation.blog.User.size}" )
89      private String _strUser;
90  
91      @NotEmpty( message = "#i18n{blog.validation.blog.UserCreator.notEmpty}" )
92      @Size( max = 255, message = "#i18n{blog.validation.blog.UserCreator.size}" )
93      private String _strUserCreator;
94  
95      @Size( max = 255, message = "#i18n{blog.validation.blog.EditComment.size}" )
96      private String _strEditComment;
97  
98      @Size( message = "#i18n{blog.validation.description.size}" )
99      private String _strDescription;
100 
101     private List<DocContent> _docContent = new ArrayList<>( );
102 
103     private String _strUrl;
104 
105     private boolean _bShareable;
106 
107     private boolean _bLocked;
108 
109     private List<Tag> _tag = new ArrayList<>( );
110 
111     private List<BlogPublication> _blogPublication = new ArrayList<>( );
112     private boolean _bIsArchived;
113 
114     /**
115      * Returns the Id
116      * 
117      * @return The Id
118      */
119     public int getId( )
120     {
121         return _nId;
122     }
123 
124     /**
125      * {@inheritDoc }
126      */
127     @Override
128     public String getName( )
129     {
130         return getContentLabel( );
131     }
132 
133     /**
134      * Sets the Id
135      * 
136      * @param nId
137      *            The Id
138      */
139     public void setId( int nId )
140     {
141         _nId = nId;
142     }
143 
144     /**
145      * Returns the Version
146      * 
147      * @return The Version
148      */
149     public int getVersion( )
150     {
151         return _nVersion;
152     }
153 
154     /**
155      * Sets the Version
156      * 
157      * @param nVersion
158      *            The Version
159      */
160     public void setVersion( int nVersion )
161     {
162         _nVersion = nVersion;
163     }
164 
165     /**
166      * Returns the ContentLabel
167      * 
168      * @return The ContentLabel
169      */
170     public String getContentLabel( )
171     {
172         return _strContentLabel;
173     }
174 
175     /**
176      * Sets the ContentLabel
177      * 
178      * @param strContentLabel
179      *            The ContentLabel
180      */
181     public void setContentLabel( String strContentLabel )
182     {
183         _strContentLabel = strContentLabel;
184     }
185 
186     /**
187      * Returns the CreationDate
188      * 
189      * @return The CreationDate
190      */
191     public Timestamp getCreationDate( )
192     {
193         return _dateCreationDate;
194     }
195 
196     /**
197      * Sets the CreationDate
198      * 
199      * @param dateCreationDate
200      *            The CreationDate
201      */
202     public void setCreationDate( Timestamp dateCreationDate )
203     {
204         _dateCreationDate = dateCreationDate;
205     }
206 
207     /**
208      * Returns the UpdateDate
209      * 
210      * @return The UpdateDate
211      */
212     public Timestamp getUpdateDate( )
213     {
214         return _dateUpdateDate;
215     }
216 
217     /**
218      * Sets the UpdateDate
219      * 
220      * @param dateUpdateDate
221      *            The UpdateDate
222      */
223     public void setUpdateDate( Timestamp dateUpdateDate )
224     {
225         _dateUpdateDate = dateUpdateDate;
226     }
227 
228     /**
229      * Returns the HtmlContent
230      * 
231      * @return The HtmlContent
232      */
233     public String getHtmlContent( )
234     {
235         return _strHtmlContent;
236     }
237 
238     /**
239      * Sets the HtmlContent
240      * 
241      * @param strHtmlContent
242      *            The HtmlContent
243      */
244     public void setHtmlContent( String strHtmlContent )
245     {
246         _strHtmlContent = strHtmlContent;
247     }
248 
249     /**
250      * Returns the User
251      * 
252      * @return The User
253      */
254     public String getUser( )
255     {
256         return _strUser;
257     }
258 
259     /**
260      * Sets the User
261      * 
262      * @param strUser
263      *            The User
264      */
265     public void setUser( String strUser )
266     {
267         _strUser = strUser;
268     }
269 
270     /**
271      * Returns the UserCreator
272      * 
273      * @return The UserCreator
274      */
275     public String getUserCreator( )
276     {
277         return _strUserCreator;
278     }
279 
280     /**
281      * Sets the UserCreator
282      * 
283      * @param strUserCreator
284      *            The UserCreator
285      */
286     public void setUserCreator( String strUserCreator )
287     {
288         _strUserCreator = strUserCreator;
289     }
290 
291     public void setAttachedPortletId( int nAttachedPortletId )
292     {
293         _nAttachedPortletId = nAttachedPortletId;
294     }
295 
296     public int getAttachedPortletId( )
297     {
298         return _nAttachedPortletId;
299     }
300 
301     /**
302      * Returns the EditComment
303      *
304      * @return The EditComment
305      */
306     public String getEditComment( )
307     {
308         return _strEditComment;
309     }
310 
311     /**
312      * Sets the EditComment
313      *
314      * @param strEditComment
315      *            The EditComment
316      */
317     public void setEditComment( String strEditComment )
318     {
319         _strEditComment = strEditComment;
320     }
321 
322     /**
323      * Returns the Description
324      *
325      * @return The Description
326      */
327     public String getDescription( )
328     {
329         return _strDescription;
330     }
331 
332     /**
333      * Sets the Description
334      *
335      * @param strDescription
336      *            The Description
337      */
338     public void setDescription( String strDescription )
339     {
340         _strDescription = strDescription;
341     }
342 
343     /**
344      * Returns the list of DocContent
345      *
346      * @return The DocContent
347      */
348     public List<DocContent> getDocContent( )
349     {
350         return _docContent;
351     }
352 
353     /**
354      * Sets the list DocContent
355      *
356      * @param docContent
357      *            the list DocContent
358      */
359     public void setDocContent( List<DocContent> docContent )
360     {
361         _docContent = docContent;
362     }
363 
364     /**
365      * Sets the docConetnt list
366      *
367      * @param docContent
368      *            list The docContent list
369      */
370     public void addContent( DocContent docContent )
371     {
372         _docContent.add( docContent );
373     }
374 
375     /**
376      * delet the docContent
377      *
378      * @param nIdDoc
379      *            The docContent Id
380      */
381     public void deleteDocContent( int nIdDoc )
382     {
383         _docContent.removeIf( dc -> dc.getId( ) == nIdDoc );
384 
385     }
386 
387     /**
388      * Returns the Url
389      *
390      * @return The Url
391      */
392     public String getUrl( )
393     {
394         return _strUrl;
395     }
396 
397     /**
398      * Sets the Url
399      *
400      * @param strUrl
401      *            The Url
402      */
403     public void setUrl( String strUrl )
404     {
405         _strUrl = strUrl;
406     }
407 
408     /**
409      * Returns the Shareable
410      * 
411      * @return The Shareable
412      */
413     public boolean getShareable( )
414     {
415         return _bShareable;
416     }
417 
418     /**
419      * shareable
420      * 
421      * @param bShareable
422      */
423     public void setShareable( boolean bShareable )
424     {
425         _bShareable = bShareable;
426     }
427 
428     /**
429      * Returns the Locked
430      * 
431      * @return The Locked
432      */
433     public boolean getLocked( )
434     {
435         return _bLocked;
436     }
437 
438     /**
439      * Locked
440      * 
441      * @param bLocked
442      */
443     public void setLocked( boolean bLocked )
444     {
445         _bLocked = bLocked;
446     }
447 
448     /**
449      * Returns the tag list
450      *
451      * @return The tag list
452      */
453     public List<Tag> getTag( )
454     {
455         return _tag;
456     }
457 
458     /**
459      * Sets the tag list
460      *
461      * @param tag
462      *            list The tag list
463      */
464     public void setTag( List<Tag> tag )
465     {
466         _tag = tag;
467     }
468 
469     /**
470      * Sets the tag list
471      *
472      * @param tag
473      *            list The tag list
474      */
475     public void addTag( Tag tag )
476     {
477         boolean bContain = _tag.stream( ).anyMatch( tg -> tg.getIdTag( ) == tag.getIdTag( ) );
478         if ( !bContain )
479         {
480             _tag.add( tag );
481         }
482     }
483 
484     /**
485      * delet the tag
486      *
487      * @param tag
488      *            The tag
489      */
490     public void deleteTag( Tag tag )
491     {
492         _tag.removeIf( tg -> tg.getIdTag( ) == tag.getIdTag( ) );
493 
494     }
495 
496     /**
497      * Returns the blogc list
498      *
499      * @return The BlogPublication list
500      */
501     public List<BlogPublication> getBlogPublication( )
502     {
503         return _blogPublication;
504     }
505 
506     /**
507      * Sets the BlogPublication list
508      *
509      * @param blogPublication
510      *            list The blogPublication list
511      */
512     public void setBlogPublication( List<BlogPublication> blogPublication )
513     {
514         _blogPublication = blogPublication;
515     }
516 
517     /**
518      * Sets the BlogPublication list
519      *
520      * @param blogPublication
521      *            list The BlogPublication list
522      */
523     public void addBlogPublication( BlogPublication blogPublication )
524     {
525 
526         boolean bContain = _blogPublication.stream( )
527                 .anyMatch( blogPub -> ( blogPub.getIdBlog( ) == blogPublication.getIdBlog( ) && blogPub.getIdPortlet( ) == blogPublication.getIdPortlet( ) ) );
528 
529         if ( !bContain )
530         {
531             _blogPublication.add( blogPublication );
532         }
533     }
534 
535     /**
536      * delet the BlogPublication
537      *
538      * @param blogPublication
539      *            The BlogPublication
540      */
541     public void deleteBlogPublication( BlogPublication blogPublication )
542     {
543 
544         _blogPublication
545                 .removeIf( blogPub -> ( blogPub.getIdBlog( ) == blogPublication.getIdBlog( ) && blogPub.getIdPortlet( ) == blogPublication.getIdPortlet( ) ) );
546     }
547 
548     /**
549      * {@inheritDoc}
550      */
551     @Override
552     public String getExtendableResourceDescription( )
553     {
554 
555         return getDescription( );
556     }
557 
558     /**
559      * {@inheritDoc}
560      */
561     @Override
562     public String getExtendableResourceImageUrl( )
563     {
564 
565         return null;
566     }
567 
568     /**
569      * {@inheritDoc}
570      */
571     @Override
572     public String getExtendableResourceName( )
573     {
574 
575         return getContentLabel( );
576     }
577 
578     /**
579      * {@inheritDoc}
580      */
581     @Override
582     public String getExtendableResourceType( )
583     {
584 
585         return PROPERTY_RESOURCE_TYPE;
586     }
587 
588     /**
589      * {@inheritDoc}
590      */
591     @Override
592     public String getIdExtendableResource( )
593     {
594         return Integer.toString( _nId );
595     }
596 
597     /**
598      * {@inheritDoc}
599      */
600     @Override
601     public String getResourceId( )
602     {
603 
604         return String.valueOf( _nId );
605     }
606 
607     /**
608      * {@inheritDoc}
609      */
610     @Override
611     public String getResourceTypeCode( )
612     {
613 
614         return PROPERTY_RESOURCE_TYPE;
615     }
616 
617     /**
618      * Return the user informations
619      * 
620      * @return AdminUser
621      */
622     public AdminUser getUserInfos( )
623     {
624         return AdminUserHome.findUserByLogin( _strUser );
625     }
626 
627     /**
628      * Return the user creator informations
629      * 
630      * @return AdminUser
631      */
632     public AdminUser getUserCreatorInfos( )
633     {
634         return AdminUserHome.findUserByLogin( _strUserCreator );
635     }
636 
637 
638     /**
639      *@return the boolean value of the blog is archived
640      */
641     public boolean isArchived( )
642     {
643 
644         return _bIsArchived;
645     }
646 
647     /**
648      *set the blog is archived
649      * @param bIsArchived
650      */
651     public void setArchived( boolean bIsArchived )
652     {
653         _bIsArchived = bIsArchived;
654     }
655 }