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.digglike.service;
35
36 import fr.paris.lutece.plugins.digglike.business.CommentSubmit;
37 import fr.paris.lutece.plugins.digglike.business.CommentSubmitHome;
38 import fr.paris.lutece.plugins.digglike.business.SubmitFilter;
39 import fr.paris.lutece.plugins.digglike.utils.DiggUtils;
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41 import fr.paris.lutece.portal.service.spring.SpringContextService;
42
43 import java.util.List;
44
45
46 public class CommentSubmitService implements ICommentSubmitService
47 {
48 public static final String BEAN_SERVICE = "digglike.commentSubmitService";
49 private static ICommentSubmitService _singleton;
50
51
52
53
54 @Override
55 public void create( CommentSubmit commentSubmit, Plugin plugin )
56 {
57 commentSubmit.setDateModify( commentSubmit.getDateComment( ) );
58 CommentSubmitHome.create( commentSubmit, plugin );
59
60 if ( commentSubmit.getIdParent( ) != DiggUtils.CONSTANT_ID_NULL )
61 {
62
63 CommentSubmitHome.updateDateModify( commentSubmit.getDateComment( ), commentSubmit.getIdParent( ), plugin );
64 }
65 }
66
67
68
69
70 @Override
71 public void update( CommentSubmit commentSubmit, Plugin plugin )
72 {
73 CommentSubmitHome.update( commentSubmit, plugin );
74 }
75
76
77
78
79 @Override
80 public void remove( int nIdCommentSubmit, Plugin plugin )
81 {
82
83
84
85
86
87
88
89
90 CommentSubmitHome.removeByIdParent( nIdCommentSubmit, plugin );
91 CommentSubmitHome.remove( nIdCommentSubmit, plugin );
92 }
93
94
95
96
97
98
99
100 @Override
101 public CommentSubmit findByPrimaryKey( int nKey, Plugin plugin )
102 {
103 return CommentSubmitHome.findByPrimaryKey( nKey, plugin );
104 }
105
106
107
108
109 @Override
110 public List<CommentSubmit> getCommentSubmitList( SubmitFilter filter, Plugin plugin )
111 {
112 if ( !filter.containsSortBy( ) )
113 {
114
115 DiggUtils.initCommentFilterBySort( filter, DiggUtils.CONSTANT_ID_NULL );
116 }
117
118
119 filter.setIdParent( SubmitFilter.ID_PARENT_NULL );
120
121 List<CommentSubmit> commentSubmitList = CommentSubmitHome.getCommentSubmitList( filter, null, plugin );
122
123 if ( commentSubmitList != null )
124 {
125 SubmitFilter subCommentFilter;
126
127 for ( CommentSubmit c : commentSubmitList )
128 {
129 subCommentFilter = new SubmitFilter( );
130
131 subCommentFilter.setIdParent( c.getIdCommentSubmit( ) );
132 subCommentFilter.setIdCommentSubmitState( filter.getIdCommentSubmitState( ) );
133 subCommentFilter.getSortBy( ).add( SubmitFilter.SORT_BY_DATE_RESPONSE_DESC );
134 c.setComments( CommentSubmitHome.getCommentSubmitList( subCommentFilter, null, plugin ) );
135 }
136 }
137
138 filter.setIdParent( DiggUtils.CONSTANT_ID_NULL );
139
140 return commentSubmitList;
141 }
142
143
144
145
146 @Override
147 public List<CommentSubmit> getCommentSubmitList( SubmitFilter filter, Integer nLimitParentNumber, Plugin plugin )
148 {
149 if ( ( nLimitParentNumber == null ) || ( nLimitParentNumber == DiggUtils.CONSTANT_ID_NULL ) )
150 {
151
152 return getCommentSubmitList( filter, plugin );
153 }
154
155 if ( !filter.containsSortBy( ) )
156 {
157
158 DiggUtils.initCommentFilterBySort( filter, DiggUtils.CONSTANT_ID_NULL );
159 }
160
161
162 filter.setIdParent( SubmitFilter.ID_PARENT_NULL );
163
164 List<CommentSubmit> commentSubmitList = CommentSubmitHome.getCommentSubmitList( filter, nLimitParentNumber,
165 plugin );
166
167 return commentSubmitList;
168 }
169
170
171
172
173 @Override
174 public int getCountCommentSubmit( SubmitFilter filter, Plugin plugin )
175 {
176 return CommentSubmitHome.getCountCommentSubmit( filter, plugin );
177 }
178
179
180
181
182
183
184 public static ICommentSubmitService getService( )
185 {
186 if ( _singleton == null )
187 {
188 _singleton = SpringContextService.getBean( BEAN_SERVICE );
189 }
190
191 return _singleton;
192 }
193 }