Skip to content

LUT-26182 #13

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
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
57 changes: 24 additions & 33 deletions src/java/fr/paris/lutece/plugins/wiki/business/TopicDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ 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 ) 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 = ?";

/**
* Generates a new primary key
*
Expand All @@ -64,7 +63,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 +80,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 @@ -104,21 +103,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 +123,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 +136,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 +157,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 +180,30 @@ 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;
}
/**
* 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 ) );
return topic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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 +133,5 @@ public static Collection<Topic> getTopicsList( )
{
return _dao.selectTopicsList( _plugin );
}

}
Loading