Skip to content

Commit d8c174d

Browse files
committed
LUT-25169: create an option draft to save the work in progress
1 parent 5bd1f8a commit d8c174d

File tree

17 files changed

+595
-38
lines changed

17 files changed

+595
-38
lines changed

src/java/fr/paris/lutece/plugins/wiki/business/ITopicVersionDAO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public interface ITopicVersionDAO
7676
TopicVersion load( int nKey, Plugin plugin );
7777

7878
void deleteByTopicVersion(int nTopicId, Plugin plugin);
79+
80+
void updateIsPublished(int nIdTopicVersion, String comment, boolean bIsPublished, Plugin plugin);
81+
7982
/**
8083
* Load the data of all the topicVersion objects and returns them as a collection
8184
*
@@ -95,6 +98,8 @@ public interface ITopicVersionDAO
9598
*/
9699
void addTopicVersion( TopicVersion topicVersion, Plugin plugin );
97100

101+
void updateTopicVersion(TopicVersion topicVersion, Plugin plugin);
102+
98103
/**
99104
* Load last version
100105
*
@@ -106,6 +111,8 @@ public interface ITopicVersionDAO
106111
*/
107112
TopicVersion loadLastVersion( int idTopic, Plugin plugin );
108113

114+
TopicVersion getPublishedVersion(int nTopicId, Plugin plugin);
115+
109116
/**
110117
* Load all versions
111118
*

src/java/fr/paris/lutece/plugins/wiki/business/TopicVersion.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class TopicVersion
5252
private String _strUserPseudo;
5353
private String _strUserAvatarUrl;
5454
private String _strUserName;
55+
private Boolean _bIsPublished;
5556
private Map<String, WikiContent> _mapWikiContent = new HashMap<>( );
5657

5758
/**
@@ -277,4 +278,25 @@ public void setUserAvatarUrl( String strUserAvatarUrl )
277278
{
278279
_strUserAvatarUrl = strUserAvatarUrl;
279280
}
281+
282+
/**
283+
* Returns the IsPublished
284+
*
285+
* @return The IsPublished
286+
*/
287+
public Boolean getIsPublished( )
288+
{
289+
return _bIsPublished;
290+
}
291+
292+
/**
293+
* Sets the IsPublished
294+
*
295+
* @param bIsPublished
296+
* The IsPublished
297+
*/
298+
public void setIsPublished( Boolean bIsPublished )
299+
{
300+
_bIsPublished = bIsPublished;
301+
}
280302
}

src/java/fr/paris/lutece/plugins/wiki/business/TopicVersionDAO.java

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@
4545
public final class TopicVersionDAO implements ITopicVersionDAO {
4646
// Constants
4747
private static final String SQL_QUERY_NEW_PK = "SELECT max( id_topic_version ) FROM wiki_topic_version";
48-
private static final String SQL_QUERY_SELECT = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous FROM wiki_topic_version WHERE id_topic_version = ?";
49-
private static final String SQL_QUERY_INSERT = "INSERT INTO wiki_topic_version ( id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous ) VALUES ( ?, ?, ?, ?, ?, ? ) ";
48+
private static final String SQL_QUERY_SELECT = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published FROM wiki_topic_version WHERE id_topic_version = ?";
49+
private static final String SQL_QUERY_INSERT = "INSERT INTO wiki_topic_version ( id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) ";
5050
private static final String SQL_QUERY_DELETE = "DELETE FROM wiki_topic_version WHERE id_topic_version = ? ";
51-
private static final String SQL_QUERY_SELECTALL = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous FROM wiki_topic_version";
52-
private static final String SQL_QUERY_INSERT_MODIFICATION = "INSERT INTO wiki_topic_version ( id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous ) VALUES ( ?, ?, ?, ?, ?, ?) ";
53-
private static final String SQL_QUERY_SELECT_LAST_BY_TOPIC_ID = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous FROM wiki_topic_version WHERE id_topic = ? ORDER BY date_edition DESC LIMIT 1";
54-
private static final String SQL_QUERY_SELECT_BY_TOPIC_ID = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous FROM wiki_topic_version WHERE id_topic = ? ORDER BY date_edition DESC ";
51+
private static final String SQL_QUERY_SELECTALL = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published FROM wiki_topic_version";
52+
private static final String SQL_QUERY_INSERT_MODIFICATION = "INSERT INTO wiki_topic_version ( id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) ";
53+
private static final String SQL_QUERY_SELECT_LAST_BY_TOPIC_ID = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published FROM wiki_topic_version WHERE id_topic = ? ORDER BY date_edition DESC LIMIT 1";
54+
private static final String SQL_QUERY_SELECT_BY_TOPIC_ID = "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published FROM wiki_topic_version WHERE id_topic = ? ORDER BY date_edition DESC ";
5555
private static final String SQL_QUERY_DELETE_BY_TOPIC_ID = "DELETE FROM wiki_topic_version WHERE id_topic = ? ";
5656
private static final String SQL_QUERY_SELECT_CONTENT = "SELECT locale, page_title, wiki_content, html_wiki_content FROM wiki_topic_version_content WHERE id_topic_version = ?";
5757
private static final String SQL_QUERY_INSERT_CONTENT = "INSERT INTO wiki_topic_version_content ( id_topic_version, locale, page_title, wiki_content, html_wiki_content ) VALUES ( ?, ?, ?, ?, ?) ";
5858
private static final String SQL_QUERY_DELETE_CONTENT = "DELETE FROM wiki_topic_version_content WHERE id_topic_version = ? ";
5959
private static final String SQL_QUERY_DELETE_CONTENT_BY_TOPIC_ID = "DELETE a.* FROM wiki_topic_version_content a, wiki_topic_version b WHERE a.id_topic_version = b.id_topic_version AND b.id_topic = ? ";
60+
private static final String SQL_QUERY_SELECT_PUBLISHED_BY_TOPIC_ID= "SELECT id_topic_version, edit_comment, id_topic, lutece_user_id, date_edition, id_topic_version_previous, is_published FROM wiki_topic_version WHERE id_topic = ? AND is_published = 1 ORDER BY date_edition DESC ";
61+
private static final String SQL_QUERY_UPDATE_IS_PUBLISHED = "UPDATE wiki_topic_version SET is_published=?,edit_comment=? WHERE id_topic_version = ? ";
6062
private static final String SQL_QUERY_DELETE_CONTENT_BY_TOPIC_VERSION_ID = "DELETE FROM wiki_topic_version_content WHERE id_topic_version = ? ";
6163
private static final String SQL_QUERY_DELETE_BY_TOPIC_VERSION_ID = "DELETE FROM wiki_topic_version WHERE id_topic_version = ? ";
6264

@@ -93,6 +95,7 @@ public void insert(TopicVersion topicVersion, Plugin plugin) {
9395
daoUtil.setString(4, topicVersion.getLuteceUserId());
9496
daoUtil.setTimestamp(5, topicVersion.getDateEdition());
9597
daoUtil.setInt(6, topicVersion.getIdTopicVersionPrevious());
98+
daoUtil.setBoolean(7, topicVersion.getIsPublished());
9699

97100
daoUtil.executeUpdate();
98101
}
@@ -202,6 +205,21 @@ public void deleteByTopicVersion(int nTopicVersionId, Plugin plugin) {
202205
}
203206
}
204207

208+
/**
209+
* {@inheritDoc }
210+
*/
211+
@Override
212+
public void updateIsPublished(int nIdTopicVersion, String comment, boolean bIsPublished, Plugin plugin) {
213+
try (DAOUtil daoUtil = new DAOUtil(SQL_QUERY_UPDATE_IS_PUBLISHED, plugin)) {
214+
daoUtil.setBoolean(1, bIsPublished);
215+
daoUtil.setString(2, comment);
216+
daoUtil.setInt(3, nIdTopicVersion);
217+
daoUtil.executeUpdate();
218+
}
219+
220+
}
221+
222+
205223
/**
206224
* {@inheritDoc }
207225
*/
@@ -237,6 +255,28 @@ public void addTopicVersion(TopicVersion topicVersion, Plugin plugin) {
237255
daoUtil.setString(4, topicVersion.getUserName());
238256
daoUtil.setTimestamp(5, new java.sql.Timestamp(new java.util.Date().getTime()));
239257
daoUtil.setInt(6, topicVersion.getIdTopicVersionPrevious());
258+
daoUtil.setBoolean(7, topicVersion.getIsPublished());
259+
260+
daoUtil.executeUpdate();
261+
}
262+
263+
storeContent(topicVersion);
264+
}
265+
/**
266+
* {@inheritDoc }
267+
*/
268+
@Override
269+
public void updateTopicVersion(TopicVersion topicVersion, Plugin plugin) {
270+
deleteByTopicVersion(topicVersion.getIdTopicVersion(), plugin);
271+
try (DAOUtil daoUtil = new DAOUtil(SQL_QUERY_INSERT_MODIFICATION, plugin)) {
272+
topicVersion.setIdTopicVersion(newPrimaryKey(plugin));
273+
daoUtil.setInt(1, topicVersion.getIdTopicVersion());
274+
daoUtil.setString(2, topicVersion.getEditComment());
275+
daoUtil.setInt(3, topicVersion.getIdTopic());
276+
daoUtil.setString(4, topicVersion.getUserName());
277+
daoUtil.setTimestamp(5, new java.sql.Timestamp(new java.util.Date().getTime()));
278+
daoUtil.setInt(6, topicVersion.getIdTopicVersionPrevious());
279+
daoUtil.setBoolean(7, topicVersion.getIsPublished());
240280

241281
daoUtil.executeUpdate();
242282
}
@@ -286,6 +326,25 @@ public TopicVersion loadLastVersion(int nIdTopic, Plugin plugin) {
286326
return topicVersion;
287327
}
288328

329+
@Override
330+
public TopicVersion getPublishedVersion(int nTopicId, Plugin plugin) {
331+
TopicVersion topicVersion = null;
332+
333+
try (DAOUtil daoUtil = new DAOUtil(SQL_QUERY_SELECT_PUBLISHED_BY_TOPIC_ID, plugin)) {
334+
daoUtil.setInt(1, nTopicId);
335+
daoUtil.executeQuery();
336+
337+
if (daoUtil.next()) {
338+
topicVersion = setTopicVersionWithDaoUtil(daoUtil);
339+
}
340+
}
341+
342+
if (topicVersion != null) {
343+
fillContent(topicVersion);
344+
}
345+
346+
return topicVersion;
347+
}
289348
/**
290349
* {@inheritDoc }
291350
*/
@@ -315,6 +374,7 @@ public TopicVersion setTopicVersionWithDaoUtil(DAOUtil daoUtil) {
315374
topicVersion.setLuteceUserId(daoUtil.getString(4));
316375
topicVersion.setDateEdition(daoUtil.getTimestamp(5));
317376
topicVersion.setIdTopicVersionPrevious(daoUtil.getInt(6));
377+
topicVersion.setIsPublished(daoUtil.getBoolean(7));
318378

319379
return topicVersion;
320380
}

src/java/fr/paris/lutece/plugins/wiki/business/TopicVersionHome.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,43 @@ public static Collection<TopicVersion> findAllVersions( int idTopic )
151151
{
152152
return _dao.loadAllVersions( idTopic, _plugin );
153153
}
154+
155+
/**
156+
* Overwrite the topic's version
157+
*
158+
* @param topicVersion
159+
* The topicVersion id
160+
* @return void
161+
*/
162+
public static void updateTopicVersion(TopicVersion topicVersion)
163+
{
164+
_dao.updateTopicVersion( topicVersion, _plugin );
165+
}
166+
167+
/**
168+
* Cancel the publication of a topicVersion
169+
*
170+
* @param topicId
171+
* The topic id
172+
* @return void
173+
*/
174+
public static void cancelPublication(int topicId, String comment)
175+
{
176+
TopicVersion topicVersionPublished = _dao.getPublishedVersion(topicId, _plugin);
177+
if(topicVersionPublished != null ) {
178+
_dao.updateIsPublished( topicVersionPublished.getIdTopicVersion(), comment, false, _plugin );
179+
}
180+
}
181+
/**
182+
* Get the published version of a topic
183+
*
184+
* @param topicId
185+
* The topic id
186+
* @return void
187+
*/
188+
public static TopicVersion getPublishedVersion(int topicId)
189+
{
190+
return _dao.getPublishedVersion(topicId, _plugin);
191+
}
192+
154193
}

src/java/fr/paris/lutece/plugins/wiki/search/WikiIndexer.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,29 @@ public static Document getDocument( Topic topic, String strUrl, String strLangua
241241
// tokenized prior to indexing.
242242
String strIdSubject = String.valueOf( topic.getPageName( ) );
243243
doc.add( new Field( SearchItem.FIELD_UID, strIdSubject + "_" + SHORT_NAME_TOPIC, ftNotStored ) );
244-
TopicVersion latestTopicVersion = TopicVersionHome.findLastVersion( topic.getIdTopic( ) );
245-
String strWikiContent = latestTopicVersion.getWikiContent( strLanguage ).getWikiContent( );
244+
246245
String strWikiResult = "";
247-
if ( latestTopicVersion.getWikiContent( strLanguage ).getHtmlWikiContent() != null ) {
248-
strWikiResult = latestTopicVersion.getWikiContent( strLanguage ).getHtmlWikiContent( );
246+
TopicVersion topicVersion = null;
247+
248+
TopicVersion publishedTopicVersion = TopicVersionHome.getPublishedVersion( topic.getIdTopic( ) );
249+
if ( publishedTopicVersion.getWikiContent( strLanguage ).getHtmlWikiContent() != null ) {
250+
topicVersion = publishedTopicVersion;
251+
strWikiResult = publishedTopicVersion.getWikiContent( strLanguage ).getHtmlWikiContent( );
249252
} else
250253
{
254+
TopicVersion latestTopicVersion = TopicVersionHome.findLastVersion( topic.getIdTopic( ) );
255+
topicVersion = latestTopicVersion;
256+
String strWikiContent = latestTopicVersion.getWikiContent( strLanguage ).getWikiContent( );
251257
strWikiResult = new LuteceWikiParser( strWikiContent, topic.getPageName( ), null, strLanguage ).toString( );
252258
}
253-
254259
doc.add( new Field( SearchItem.FIELD_CONTENTS, strWikiResult, TextField.TYPE_NOT_STORED ) );
255260

256-
String strDate = DateTools.dateToString( latestTopicVersion.getDateEdition( ), DateTools.Resolution.DAY );
261+
String strDate = DateTools.dateToString( topicVersion.getDateEdition( ), DateTools.Resolution.DAY );
257262
doc.add( new Field( SearchItem.FIELD_DATE, strDate, fieldType ) );
258263

259264
// Add the subject name as a separate Text field, so that it can be
260265
// searched separately.
261-
doc.add( new Field( SearchItem.FIELD_TITLE, latestTopicVersion.getWikiContent( strLanguage ).getPageTitle( ), fieldType ) );
266+
doc.add( new Field( SearchItem.FIELD_TITLE, publishedTopicVersion.getWikiContent( strLanguage ).getPageTitle( ), fieldType ) );
262267

263268
doc.add( new Field( SearchItem.FIELD_TYPE, getDocumentType( ), fieldType ) );
264269

src/java/fr/paris/lutece/plugins/wiki/service/ContentDeserializer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class ContentDeserializer {
1919
public String wikiHtmlContent;
2020

2121
public String wikiPageUrl;
22+
23+
public String createVersion;
24+
25+
public String publishVersion;
26+
2227
public String editComment;
2328

2429
public String viewRole;
@@ -63,6 +68,13 @@ public String getWikiHtmlContent() {
6368
}
6469

6570
public String getWikiPageUrl() {return wikiPageUrl;}
71+
72+
public Boolean getIsCreateVersion() {
73+
return Boolean.parseBoolean(createVersion);
74+
}
75+
public Boolean getIsPublishVersion() {
76+
return Boolean.parseBoolean(publishVersion);
77+
}
6678
public String getEditComment() {
6779
return editComment;
6880
}

0 commit comments

Comments
 (0)