Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2016, CauseCode Technologies Pvt Ltd, India.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are not permitted.
*/
package com.causecode.content.blog
import com.causecode.annotation.shorthand.ControllerShorthand
import com.causecode.content.ContentService
import com.causecode.content.blog.comment.BlogComment
import com.causecode.content.blog.comment.Comment
import com.causecode.content.meta.Meta
import com.causecode.fileuploader.FileUploaderService
import com.causecode.fileuploader.ProviderNotFoundException
import com.causecode.fileuploader.StorageConfigurationException
import com.causecode.fileuploader.UFile
import com.causecode.fileuploader.UploadFailureException
import com.naleid.grails.MarkdownService
import grails.converters.JSON
import grails.core.GrailsApplication
import grails.databinding.SimpleMapDataBindingSource
import grails.plugin.springsecurity.SpringSecurityService
import grails.plugin.springsecurity.annotation.Secured
import grails.transaction.Transactional
import grails.web.databinding.GrailsWebDataBinder
import org.springframework.dao.DataIntegrityViolationException
import org.springframework.http.HttpStatus
import java.util.regex.Pattern
/**
* Provides default CRUD end point for Content Manager.
*
* @author Vishesh Duggar
* @author Shashank Agrawal
* @author Laxmi Salunkhe
*/
@Secured(['ROLE_CONTENT_MANAGER'])
@Transactional(readOnly = true)
@ControllerShorthand(value = 'blog')
class BlogController {
static allowedMethods = [save: 'POST', update: 'PUT']
static responseFormats = ['json']
ContentService contentService
SpringSecurityService springSecurityService
def simpleCaptchaService
BlogService blogService
GrailsWebDataBinder grailsWebDataBinder
FileUploaderService fileUploaderService
MarkdownService markdownService
GrailsApplication grailsApplication
/**
* Action list filters blog list with tags and returns Blog list and total matched result count.
* If current user has role content manager then all Blog list will be returned otherwise blog with publish field
* set to true will be returned.
*
* Note: Action refactored for implementing modularity and improvement of code. New variables and methods added.
* Kindly refer previous commits for reference.
*
* New methods added: 1. blogService.queryModifierBasedOnFilter(...)
* 2. blogService.getBlogSummaries(...)
* 3. blogService.updatedMonthFilterListBasedOnPublishedDate(...)
* 4. renderGSPContentAndBlogCustomURLRedirect(...)
*
* @param max Pagination parameters used to specify maximum number of list items to be returned.
* @param offset Pagination parameter
* @param tag String Used to filter Blogs with tag.
* @return Map containing blog list and total count.
*/
@Secured(['permitAll'])
def index(Integer max, Integer offset, String tag, String monthFilter, String queryFilter) {
// To avoid Parameter Reassignment
def (updateTag, updateMonthFilter, updateQueryFilter) = [tag, monthFilter, queryFilter]
updateTag = (tag == 'undefined') ? '' : tag
updateMonthFilter = (monthFilter == 'undefined') ? '' : monthFilter
updateQueryFilter = (queryFilter == 'undefined') ? '' : queryFilter
log.info "Parameters received to filter blogs : $params"
long blogInstanceTotal
int defaultMax = grailsApplication.config.cc.plugins.content.blog.list.max ?: 10
List monthFilterList = []
Map monthYearFilterMapInstance = updateMonthFilter ? getMonthYearFilterMapInstance(updateMonthFilter) :
[month: '', year: '']
params.offset = offset ?: 0
params.max = Math.min(max ?: defaultMax, 100)
// TODO Improve blog string query to support GORM/Hibernate criteria query
StringBuilder query = new StringBuilder('SELECT distinct new Map(b.id as id, b.body as body,' +
' b.title as title, b.subTitle as subTitle, b.author as author,' +
' b.lastUpdated as lastUpdated, b.publishedDate as publishedDate) FROM Blog b')
// Modifying query based on filters
query = blogService.queryModifierBasedOnFilter(query, updateTag, monthYearFilterMapInstance, updateQueryFilter,
updateMonthFilter)
// Modifying query and blogInstance Total based on Role @here : ROLE_CONTENT_MANAGER
if (contentService.contentManager) {
blogInstanceTotal = updateTag ? Blog.countByTag(updateTag) : Blog.count()
} else if (updateTag) {
query.append('AND b.publish = true')
blogInstanceTotal = Blog.findAllByTagWithCriteria(updateTag) {
eq('publish', true)
}.size()
} else if (updateMonthFilter) {
query.append('AND b.publish = true')
blogInstanceTotal = Blog.countByPublish(true)
} else {
(updateQueryFilter) ? query.append(' AND ') : query.append(' where ')
query.append(' b.publish = true')
blogInstanceTotal = Blog.countByPublish(true)
}
query.append(' order by b.dateCreated desc')
List