Skip to content

LUT-25199 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!-- Used to convert html to markdown -->
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>0.62.2</version>
</dependency>
</dependencies>

<properties>
Expand Down
10 changes: 10 additions & 0 deletions src/java/fr/paris/lutece/plugins/wiki/business/ITopicDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import fr.paris.lutece.portal.service.plugin.Plugin;

import java.sql.Timestamp;
import java.util.Collection;

/**
Expand Down Expand Up @@ -105,4 +106,13 @@ public interface ITopicDAO
* @return The topic
*/
Topic load( String strTopicName, Plugin plugin );

/**
* Update the name and the time of a user visiting modify page of a topic
* @param nTopicId
* @param strUserLogin
* @param date
* @param plugin
*/
void updateLastOpenModifyPage(int nTopicId, String strUserLogin, Timestamp date, Plugin plugin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public interface ITopicVersionDAO
*/
TopicVersion load( int nKey, Plugin plugin );

void deleteByTopicVersion(int nTopicId, Plugin plugin);
/**
* Load the data of all the topicVersion objects and returns them as a collection
*
Expand Down
45 changes: 45 additions & 0 deletions src/java/fr/paris/lutece/plugins/wiki/business/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import fr.paris.lutece.portal.business.page.Page;
import fr.paris.lutece.portal.service.resource.IExtendableResource;
import java.sql.Timestamp;

/**
* This is the business class for the object Topic
Expand All @@ -50,6 +51,8 @@ public class Topic implements IExtendableResource
private String _strViewRole = Page.ROLE_NONE;
private String _strEditRole = Page.ROLE_NONE;
private String _strParentPageName;
private String _strLastUserEditing;
private Timestamp _dateLastEditAttempt;

/**
* Returns the IdTopic
Expand Down Expand Up @@ -221,4 +224,46 @@ public void setParentPageName( String strParentPageName )
{
_strParentPageName = strParentPageName;
}

/**
* Returns the last user editing
*
* @return The last user editing
*/
public String getLastUserEditing ( )
{
return _strLastUserEditing;
}
/**
* Sets the last user editing
*
* @param strLastUserEditing
* The last user editing
*/
public void setLastUserEditing ( String strLastUserEditing )
{
_strLastUserEditing = strLastUserEditing;
}


/**
* Returns the date of the last user editing
*
* @return The date of the last user editing
*/
public Timestamp getDateLastEditAttempt ( )
{
return _dateLastEditAttempt;
}

/**
* Sets the date of the last user editing
*
* @param dateLastEditAttempt
* The date of the last user editing
*/
public void setDateLastEditAttempt ( Timestamp dateLastEditAttempt )
{
_dateLastEditAttempt = dateLastEditAttempt;
}
}
83 changes: 48 additions & 35 deletions src/java/fr/paris/lutece/plugins/wiki/business/TopicDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import fr.paris.lutece.portal.service.plugin.Plugin;
import fr.paris.lutece.util.sql.DAOUtil;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;

Expand All @@ -47,12 +48,13 @@ public final class TopicDAO implements ITopicDAO
// Constants
private static final String SQL_QUERY_NEW_PK = "SELECT max( id_topic ) FROM wiki_topic";
private static final String SQL_QUERY_SELECT = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name FROM wiki_topic WHERE id_topic = ?";
private static final String SQL_QUERY_INSERT = "INSERT INTO wiki_topic ( id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name ) VALUES ( ?, ?, ?, ?, ?, ? ) ";
private static final String SQL_QUERY_INSERT = "INSERT INTO wiki_topic ( id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name, last_user_editing, last_edit_attempt_date ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? ) ";
private static final String SQL_QUERY_DELETE = "DELETE FROM wiki_topic WHERE id_topic = ? ";
private static final String SQL_QUERY_UPDATE = "UPDATE wiki_topic SET id_topic = ?, namespace = ?, page_name = ?, page_view_role = ?, page_edit_role = ?, parent_page_name = ? WHERE id_topic = ?";
private static final String SQL_QUERY_SELECTALL = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name FROM wiki_topic";
private static final String SQL_QUERY_SELECT_BY_NAME = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name FROM wiki_topic WHERE page_name = ?";

private static final String SQL_QUERY_SELECTALL = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name, last_user_editing, last_edit_attempt_date FROM wiki_topic";
private static final String SQL_QUERY_SELECT_BY_NAME = "SELECT id_topic, namespace, page_name, page_view_role, page_edit_role, parent_page_name, last_user_editing, last_edit_attempt_date FROM wiki_topic WHERE page_name = ?";
private static final String SQL_QUERY_UPDATE_LAST_OPEN_MODIFY_PAGE = "UPDATE wiki_topic SET last_user_editing = ?, last_edit_attempt_date=? WHERE id_topic = ?";
/**
/**
* Generates a new primary key
*
Expand All @@ -64,7 +66,7 @@ public int newPrimaryKey( Plugin plugin )
{
int nKey;

try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ) )
{
daoUtil.executeQuery( );

Expand All @@ -81,7 +83,7 @@ public int newPrimaryKey( Plugin plugin )
@Override
public void insert( Topic topic, Plugin plugin )
{
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
{
topic.setIdTopic( newPrimaryKey( plugin ) );

Expand All @@ -91,6 +93,8 @@ public void insert( Topic topic, Plugin plugin )
daoUtil.setString( 4, topic.getViewRole( ) );
daoUtil.setString( 5, topic.getEditRole( ) );
daoUtil.setString( 6, topic.getParentPageName( ) );
daoUtil.setString( 7, topic.getLastUserEditing( ) );
daoUtil.setTimestamp( 8, topic.getDateLastEditAttempt( ) );

daoUtil.executeUpdate( );
}
Expand All @@ -104,21 +108,14 @@ public Topic load( int nId, Plugin plugin )
{
Topic topic = null;

try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
{
daoUtil.setInt( 1, nId );
daoUtil.executeQuery( );

if ( daoUtil.next( ) )
{
topic = new Topic( );

topic.setIdTopic( daoUtil.getInt( 1 ) );
topic.setNamespace( daoUtil.getInt( 2 ) );
topic.setPageName( daoUtil.getString( 3 ) );
topic.setViewRole( daoUtil.getString( 4 ) );
topic.setEditRole( daoUtil.getString( 5 ) );
topic.setParentPageName( daoUtil.getString( 6 ) );
topic = setTopicWithDaoUtil(daoUtil);
}
}

Expand All @@ -131,7 +128,7 @@ public Topic load( int nId, Plugin plugin )
@Override
public void delete( int nTopicId, Plugin plugin )
{
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
{
daoUtil.setInt( 1, nTopicId );
daoUtil.executeUpdate( );
Expand All @@ -144,7 +141,7 @@ public void delete( int nTopicId, Plugin plugin )
@Override
public void store( Topic topic, Plugin plugin )
{
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
{
daoUtil.setInt( 1, topic.getIdTopic( ) );
daoUtil.setInt( 2, topic.getNamespace( ) );
Expand All @@ -165,20 +162,13 @@ public void store( Topic topic, Plugin plugin )
public Collection<Topic> selectTopicsList( Plugin plugin )
{
Collection<Topic> topicList = new ArrayList<>( );
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
{
daoUtil.executeQuery( );

while ( daoUtil.next( ) )
{
Topic topic = new Topic( );

topic.setIdTopic( daoUtil.getInt( 1 ) );
topic.setNamespace( daoUtil.getInt( 2 ) );
topic.setPageName( daoUtil.getString( 3 ) );
topic.setViewRole( daoUtil.getString( 4 ) );
topic.setEditRole( daoUtil.getString( 5 ) );
topic.setParentPageName( daoUtil.getString( 6 ) );
Topic topic = setTopicWithDaoUtil(daoUtil);

topicList.add( topic );
}
Expand All @@ -195,24 +185,47 @@ public Topic load( String strTopicName, Plugin plugin )
{
Topic topic = null;

try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_NAME, plugin ) )
try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_NAME, plugin ) )
{
daoUtil.setString( 1, strTopicName );
daoUtil.executeQuery( );

if ( daoUtil.next( ) )
{
topic = new Topic( );

topic.setIdTopic( daoUtil.getInt( 1 ) );
topic.setNamespace( daoUtil.getInt( 2 ) );
topic.setPageName( daoUtil.getString( 3 ) );
topic.setViewRole( daoUtil.getString( 4 ) );
topic.setEditRole( daoUtil.getString( 5 ) );
topic.setParentPageName( daoUtil.getString( 6 ) );
topic = setTopicWithDaoUtil(daoUtil);
}
}

return topic;
}

/**
* {@inheritDoc }
*/
@Override
public void updateLastOpenModifyPage(int nTopicId, String strUserLogin, Timestamp date, Plugin plugin ) {
try (DAOUtil daoUtil = new DAOUtil(SQL_QUERY_UPDATE_LAST_OPEN_MODIFY_PAGE, plugin)) {
daoUtil.setString(1, strUserLogin);
daoUtil.setTimestamp(2, date);
daoUtil.setInt(3, nTopicId);

daoUtil.executeUpdate();
}
}

/**
* set the content of a topic version with doaUtil
*/
public Topic setTopicWithDaoUtil(DAOUtil daoUtil) {
Topic topic = new Topic( );
topic.setIdTopic( daoUtil.getInt( 1 ) );
topic.setNamespace( daoUtil.getInt( 2 ) );
topic.setPageName( daoUtil.getString( 3 ) );
topic.setViewRole( daoUtil.getString( 4 ) );
topic.setEditRole( daoUtil.getString( 5 ) );
topic.setParentPageName( daoUtil.getString( 6 ) );
topic.setLastUserEditing( daoUtil.getString( 7 ) );
topic.setDateLastEditAttempt( daoUtil.getTimestamp( 8 ) );
return topic;
}
}
17 changes: 16 additions & 1 deletion src/java/fr/paris/lutece/plugins/wiki/business/TopicHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
*/
package fr.paris.lutece.plugins.wiki.business;

import fr.paris.lutece.api.user.User;
import fr.paris.lutece.plugins.wiki.web.Constants;
import fr.paris.lutece.portal.service.plugin.Plugin;
import fr.paris.lutece.portal.service.plugin.PluginService;
import fr.paris.lutece.portal.service.spring.SpringContextService;

import java.sql.Timestamp;
import java.util.Collection;

/**
Expand Down Expand Up @@ -119,7 +121,7 @@ public static Topic findByPrimaryKey( int nKey )
* The topic name
* @return The topic
*/
public static Topic findByPrimaryKey( String strTopicName )
public static Topic findByPageName( String strTopicName )
{
return _dao.load( strTopicName, _plugin );
}
Expand All @@ -133,4 +135,17 @@ public static Collection<Topic> getTopicsList( )
{
return _dao.selectTopicsList( _plugin );
}

/**
* Update the name and the time of a user visiting modify page of a topic
* @param topicId
* @param user
*/
public static void updateLastOpenModifyPage(int topicId, User user)
{
Timestamp date = new Timestamp(System.currentTimeMillis());
String userName = user.getFirstName() + "_" + user.getLastName();
_dao.updateLastOpenModifyPage(topicId, userName, date, _plugin);
}

}
Loading