Skip to content
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

LUT-28237: Add possibility to archive blogs #103

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
20 changes: 20 additions & 0 deletions src/java/fr/paris/lutece/plugins/blog/business/Blog.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class Blog extends ReferenceItem implements Serializable, IExtendableReso
public static final String PERMISSION_MODIFY = "MODIFY";
public static final String PERMISSION_DELETE = "DELETE";
public static final String PERMISSION_PUBLISH = "PUBLISH";
public static final String PERMISSION_ARCHIVE = "ARCHIVE";

// Variables declarations
private int _nId;
Expand Down Expand Up @@ -108,6 +109,7 @@ public class Blog extends ReferenceItem implements Serializable, IExtendableReso
private List<Tag> _tag = new ArrayList<>( );

private List<BlogPublication> _blogPublication = new ArrayList<>( );
private boolean _bIsArchived;

/**
* Returns the Id
Expand Down Expand Up @@ -638,4 +640,22 @@ public AdminUser getUserCreatorInfos( )
return AdminUserHome.findUserByLogin( _strUserCreator );
}


/**
*@return the boolean value of the blog is archived
*/
public boolean isArchived( )
{

return _bIsArchived;
}

/**
*set the blog is archived
* @param bIsArchived
*/
public void setArchived( boolean bIsArchived )
{
_bIsArchived = bIsArchived;
}
}
96 changes: 83 additions & 13 deletions src/java/fr/paris/lutece/plugins/blog/business/BlogDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,34 @@ public final class BlogDAO implements IBlogDAO
// Constants
private static final String SQL_QUERY_NEW_PK = "SELECT max( id_blog ) FROM blog_blog";
private static final String SQL_QUERY_NEW_PK_VERSION = "SELECT max( id_version ) FROM blog_versions";
private static final String SQL_QUERY_SELECT = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_blog WHERE id_blog = ?";
private static final String SQL_QUERY_SELECT_LAST_DOCUMENTS = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_blog ORDER BY update_date DESC LIMIT ?";
private static final String SQL_QUERY_SELECT_BY_NAME = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_blog WHERE content_label = ?";
private static final String SQL_QUERY_SELECT = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url, is_archived FROM blog_blog WHERE id_blog = ?";
private static final String SQL_QUERY_SELECT_LAST_DOCUMENTS = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url, is_archived FROM blog_blog ORDER BY update_date DESC LIMIT ?";
private static final String SQL_QUERY_SELECT_BY_NAME = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url, is_archived FROM blog_blog WHERE content_label = ?";
private static final String SQL_QUERY_SELECT_VERSION = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_versions WHERE id_blog = ? AND version = ? ";
private static final String SQL_QUERY_INSERT = "INSERT INTO blog_blog ( id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
private static final String SQL_QUERY_INSERT = "INSERT INTO blog_blog ( id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url, is_archived ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String SQL_QUERY_DELETE = "DELETE FROM blog_blog WHERE id_blog = ?";
private static final String SQL_QUERY_DELETE_VERSIONS = "DELETE FROM blog_versions WHERE id_blog = ? ";
private static final String SQL_QUERY_DELETE_SPECIFIC_VERSION = "DELETE FROM blog_versions WHERE id_blog = ? AND version = ? ";
private static final String SQL_QUERY_UPDATE = "UPDATE blog_blog SET id_blog = ?, version = ?, content_label = ?, creation_date = ?, update_date = ?, html_content = ?, user_editor = ?, user_creator = ?, attached_portlet_id = ?, edit_comment = ?, description = ?, shareable = ?, url= ? WHERE id_blog = ?";
private static final String SQL_QUERY_SELECTALL = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_blog order by creation_date DESC";
private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_blog FROM blog_blog ORDER BY creation_date DESC";
private static final String SQL_QUERY_UPDATE = "UPDATE blog_blog SET id_blog = ?, version = ?, content_label = ?, creation_date = ?, update_date = ?, html_content = ?, user_editor = ?, user_creator = ?, attached_portlet_id = ?, edit_comment = ?, description = ?, shareable = ?, url= ?, is_archived=? WHERE id_blog = ?";
private static final String SQL_QUERY_SELECTALL = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url, is_archived FROM blog_blog order by creation_date DESC";
private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_blog FROM blog_blog WHERE !is_archived ORDER BY creation_date DESC";
private static final String SQL_QUERY_SELECTALL_VERSION = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_versions where id_blog = ?";
private static final String SQL_QUERY_SELECT_LAST_VERSIONS_BY_BLOG_ID = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url FROM blog_versions where id_blog = ? ORDER BY id_version DESC LIMIT ?";

private static final String SQL_QUERY_SELECT_BY_ARCHIVE_STATUS = "SELECT id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url, is_archived FROM blog_blog WHERE is_archived = ?";
private static final String SQL_QUERY_SELECTALL_USERS_EDITED_BLOG_VERSION = "SELECT distinct user_editor FROM blog_versions where id_blog = ?";

private static final String SQL_QUERY_INSERT_VERSION = "INSERT INTO blog_versions ( id_version, id_blog, version, content_label, creation_date, update_date, html_content, user_editor, user_creator, attached_portlet_id, edit_comment, description, shareable, url ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";

private static final String SQL_QUERY_SELECT_BY_FILTER = " SELECT DISTINCT a.id_blog, a.version, a.content_label, "
+ " a.creation_date, a.update_date, a.html_content, a.user_editor, a.user_creator , a.attached_portlet_id , "
+ " a.edit_comment , a.description, a.shareable, a.url, p.document_order FROM blog_blog a "
+ " a.edit_comment , a.description, a.shareable, a.url, a.is_archived, p.document_order FROM blog_blog a "
+ " LEFT OUTER JOIN blog_tag_document f ON a.id_blog = f.id_blog" + " LEFT OUTER JOIN blog_list_portlet_htmldocs p ON a.id_blog = p.id_blog";

private static final String SQL_QUERY_SELECT_BLOG_BY_ID_TAG = " SELECT b.id_blog, b.version, b.content_label, b.creation_date, b.update_date, b.html_content, b.user_editor, b.user_creator, b.attached_portlet_id, b.edit_comment, b.description, b.shareable, b.url, a.id_tag FROM blog_tag_document a Inner join blog_blog b on (b.id_blog = a.id_blog) WHERE a.id_tag = ? ORDER BY priority";
private static final String SQL_QUERY_SELECT_BLOG_BY_ID_TAG = " SELECT b.id_blog, b.version, b.content_label, b.creation_date, b.update_date, b.html_content, b.user_editor, b.user_creator, b.attached_portlet_id, b.edit_comment, b.description, b.shareable, b.url, b.is_archived a.id_tag FROM blog_tag_document a Inner join blog_blog b on (b.id_blog = a.id_blog) WHERE a.id_tag = ? ORDER BY priority";

private static final String SQL_QUERY_SELECT_ALL_BLOG = " SELECT DISTINCT a.id_blog, a.version, a.content_label, a.creation_date, a.update_date, a.html_content, a.user_editor, a.user_creator , a.attached_portlet_id, a.edit_comment , a.description, a.shareable, a.url FROM blog_blog a";
private static final String SQL_QUERY_SELECT_ALL_BLOG = " SELECT DISTINCT a.id_blog, a.version, a.content_label, a.creation_date, a.update_date, a.html_content, a.user_editor, a.user_creator , a.attached_portlet_id, a.edit_comment , a.description, a.shareable, a.url, a.is_archived FROM blog_blog a";
private static final String SQL_QUERY_SELECT_VERSION_NUMBER_BY_BLOG_ID_AND_CREATION_DATE = "SELECT version FROM blog_versions WHERE id_blog = ? ORDER BY ABS( update_date - ? );";

private static final String SQL_FILTER_WHERE_CLAUSE = " WHERE ";
private static final String SQL_FILTER_AND = " AND ";
private static final String SQL_FILTER_TAGS_BEGIN = " (";
Expand All @@ -93,7 +94,7 @@ public final class BlogDAO implements IBlogDAO
private static final String SQL_FILTER_ID_END = ") ";
private static final String SQL_ORDER_BY_LAST_MODIFICATION = " ORDER BY a.update_date DESC ";
private static final String SQL_ORDER_BY_ORDER_DOCUMENT = " ORDER by p.document_order ";

private static final String SQL_UPDATE_BLOG_ARCHIVE = "UPDATE blog_blog SET is_archived = ? WHERE id_blog = ? ";
/**
* Generates a new primary key
*
Expand Down Expand Up @@ -161,6 +162,7 @@ public void insert( Blog blog, Plugin plugin )
daoUtil.setString( nIndex++, blog.getDescription( ) );
daoUtil.setBoolean( nIndex++, blog.getShareable( ) );
daoUtil.setString( nIndex++, blog.getUrl( ) );
daoUtil.setBoolean( nIndex, false );

daoUtil.executeUpdate( );
}
Expand Down Expand Up @@ -226,6 +228,7 @@ public Blog load( int nKey, Plugin plugin )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

}

Expand Down Expand Up @@ -263,6 +266,7 @@ public Blog loadByName( String strName, Plugin plugin )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

}
}
Expand Down Expand Up @@ -369,6 +373,7 @@ public void store( Blog blog, Plugin plugin )
daoUtil.setString( nIndex++, blog.getDescription( ) );
daoUtil.setBoolean( nIndex++, blog.getShareable( ) );
daoUtil.setString( nIndex++, blog.getUrl( ) );
daoUtil.setInt( nIndex++, blog.isArchived( )?1:0 );

daoUtil.setInt( nIndex, blog.getId( ) );

Expand Down Expand Up @@ -405,13 +410,51 @@ public List<Blog> selectBlogsList( Plugin plugin )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

blogList.add( blog );
}

}
return blogList;
}
/**
* {@inheritDoc }
*/
@Override
public List<Blog> selectBlogsListByArchiveStatus(boolean isArchived, Plugin plugin )
{
List<Blog> blogList = new ArrayList<>( );
try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ARCHIVE_STATUS, plugin ) )
{
daoUtil.setBoolean( 1, isArchived );
daoUtil.executeQuery( );

while ( daoUtil.next( ) )
{
Blog blog = new Blog( );
int nIndex = 1;

blog.setId( daoUtil.getInt( nIndex++ ) );
blog.setVersion( daoUtil.getInt( nIndex++ ) );
blog.setContentLabel( daoUtil.getString( nIndex++ ) );
blog.setCreationDate( daoUtil.getTimestamp( nIndex++ ) );
blog.setUpdateDate( daoUtil.getTimestamp( nIndex++ ) );
blog.setHtmlContent( daoUtil.getString( nIndex++ ) );
blog.setUser( daoUtil.getString( nIndex++ ) );
blog.setUserCreator( daoUtil.getString( nIndex++ ) );
blog.setAttachedPortletId( daoUtil.getInt( nIndex++ ) );
blog.setEditComment( daoUtil.getString( nIndex++ ) );
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

blogList.add( blog );
}
}
return blogList;
}

/**
* {@inheritDoc }
Expand Down Expand Up @@ -443,6 +486,7 @@ public List<Blog> selectlastModifiedBlogsList( Plugin plugin, int nLimit )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

blogList.add( blog );
}
Expand Down Expand Up @@ -481,7 +525,6 @@ public List<Blog> selectBlogsVersionsList( int nId, Plugin plugin )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );

blogVersionsList.add( blog );
}
}
Expand Down Expand Up @@ -579,6 +622,7 @@ public List<Blog> selectByFilter( BlogFilter filter )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

if ( filter.getLoadBinaries( ) )
{
Expand Down Expand Up @@ -661,6 +705,14 @@ private DAOUtil getDaoFromFilter( String strQuerySelect, BlogFilter filter )
sbWhere.append( ( sbWhere.length( ) != 0 ) ? SQL_FILTER_AND : StringUtils.EMPTY )
.append( "a.id_blog NOT IN (SELECT DISTINCT id_blog FROM blogs_tag_document) " );
}
if ( filter.isArchived( ) )
{
sbWhere.append( ( sbWhere.length( ) != 0 ) ? SQL_FILTER_AND : StringUtils.EMPTY ).append( "a.is_archived = 1 " );
}
else
{
sbWhere.append( ( sbWhere.length( ) != 0 ) ? SQL_FILTER_AND : StringUtils.EMPTY ).append( "a.is_archived != 1 " );
}
if ( filter.getPortletId( ) != 0 )
{
sbWhere.append( ( sbWhere.length( ) != 0 ) ? SQL_FILTER_AND : StringUtils.EMPTY ).append( "p.id_portlet=" )
Expand Down Expand Up @@ -766,6 +818,7 @@ public List<Blog> loadBlogByIdTag( int nIdTag, Plugin plugin )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );
listBlog.add( blog );

}
Expand Down Expand Up @@ -804,6 +857,7 @@ public List<Blog> selectWithoutBinaries( Plugin plugin )
blog.setDescription( daoUtil.getString( nIndex++ ) );
blog.setShareable( daoUtil.getBoolean( nIndex++ ) );
blog.setUrl( daoUtil.getString( nIndex++ ) );
blog.setArchived( daoUtil.getBoolean( nIndex ) );

listDocuments.add( blog );
}
Expand Down Expand Up @@ -878,4 +932,20 @@ public int getActualVersionNumber( Timestamp strUpdateDate, int nId, Plugin plug
return nVersion;
}
}

/**
* Update the blog archive
* @param nIdBlog The blog id
*
**/
@Override
public void updateBlogArchiveId( int nIdBlog, boolean bArchive, Plugin plugin )
{
try ( DAOUtil daoUtil = new DAOUtil( SQL_UPDATE_BLOG_ARCHIVE, plugin ) )
{
daoUtil.setBoolean( 1, bArchive );
daoUtil.setInt( 2, nIdBlog );
daoUtil.executeUpdate( );
}
}
}
19 changes: 19 additions & 0 deletions src/java/fr/paris/lutece/plugins/blog/business/BlogFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class BlogFilter
private String _dateMax;
private int _nPortletId;
private boolean _bOrderInPortlet;
private boolean _bIsArchived;

/**
* @return the _arrayTagsId
Expand Down Expand Up @@ -218,4 +219,22 @@ public void setPortletId( int nPortletId )
{
_nPortletId = nPortletId;
}

/**
* @return the _bisArchived
*/
public boolean isArchived( )
{
return _bIsArchived;
}

/**
* @param bIsArchived
* the _bIsArchived to set
*/
public void setIsArchived( boolean bIsArchived )
{
this._bIsArchived = bIsArchived;
}

}
22 changes: 22 additions & 0 deletions src/java/fr/paris/lutece/plugins/blog/business/BlogHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,26 @@ public static int getActualVersionNumber( Timestamp strUpdateDate, int nId )
return _dao.getActualVersionNumber( strUpdateDate, nId, _plugin );
}

/**
* Archive a blog
*
* @param blogId
* The id of the blog to archive
*/
public static void updateBlogArchiveId( boolean isArchived, int blogId )
{
_dao.updateBlogArchiveId( blogId, isArchived, _plugin );
}

/**
* Select the list of blogs by archive status
*
* @param isArchived
* The archive status
* @return The list of blogs
*/
public static List<Blog> selectByArchiveStatus( boolean isArchived )
{
return _dao.selectBlogsListByArchiveStatus( isArchived, _plugin );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class BlogSearchFilter
private Date _dateUpdateDateAfter;
private Date _dateUpdateDateBefor;
private String _strUserEditedBlogVersion;
private Boolean _bIsArchived;

/**
* Get the id of the filter
Expand Down Expand Up @@ -214,4 +215,24 @@ public void setUpdateDateBefor( Date dateUpdateDateBefor )
_dateUpdateDateBefor = dateUpdateDateBefor;
}

/**
* Returns the isArchived
*
* @return The isArchived
*/
public Boolean getIsArchived( )
{
return _bIsArchived;
}

/**
* Sets the isArchived
*
* @param isArchived
* The isArchived
*/
public void setIsArchived( Boolean isArchived )
{
_bIsArchived = isArchived;
}
}
4 changes: 4 additions & 0 deletions src/java/fr/paris/lutece/plugins/blog/business/IBlogDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public interface IBlogDAO
*/
List<Blog> selectBlogsList( Plugin plugin );

List<Blog> selectBlogsListByArchiveStatus( boolean isArchived, Plugin plugin );

/**
* Load the data of nLimit last modified blog objects and returns them as a list
*
Expand Down Expand Up @@ -232,4 +234,6 @@ public interface IBlogDAO
List<Blog> selectWithoutBinaries( Plugin plugin );

int getActualVersionNumber( java.sql.Timestamp strUpdateDate, int nId, fr.paris.lutece.portal.service.plugin.Plugin plugin );

void updateBlogArchiveId( int nIdBlog, boolean bArchive, Plugin plugin );
}
Loading