Alfresco · Entries list order in Blog module

Sometimes we need that blog entries do not appear ordered by date of publication. In our internal use of Alfresco, we are including entries as we receive information. However, in some cases it is necessary to insert an entry in the middle of two existent entries, either because the information was not available at the time desired or because we forgot to include it.

Alfresco uses to manage blog entries lists two classes: DraftsAndPublishedBlogPostsCannedQuery and GetBlogPostsCannedQuery. These classes have their own factories: DraftsAndPublishedBlogPostsCannedQueryFactory and GetBlogPostsCannedQueryFactory. The problem with both is just the same: sort criteria are set directly in the source code, so it can not be changed by configuration.

Both classes inherit from AbstractBlogPostsCannedQueryFactory, which set comparing criteria to: PUBLISHED, CREATED and POSTED.


public abstract class AbstractBlogPostsCannedQueryFactory extends AbstractQNameAwareCannedQueryFactory<BlogEntity>
    protected static class BlogEntityComparator extends PropertyBasedComparator<BlogEntity>
        public BlogEntityComparator(QName comparableProperty)

        protected Comparable getProperty(BlogEntity entity) {
           if (comparableProperty.equals(ContentModel.PROP_PUBLISHED))
               return entity.getPublishedDate();
           else if (comparableProperty.equals(ContentModel.PROP_CREATED))
               return entity.getCreatedDate();
           else if (comparableProperty.equals(BlogIntegrationModel.PROP_POSTED))
               return entity.getPostedDate();
               throw new IllegalArgumentException("Unsupported blog sort property: "+comparableProperty);

Moreover, in the factories, as in GetBlogPostsCannedQueryFactory, these criteria are explicitly included. The following is one method of this factory setting by code criteria to PUBLISHED.


public class GetBlogPostsCannedQueryFactory extends AbstractBlogPostsCannedQueryFactory

    public CannedQuery<BlogEntity> getGetPublishedCannedQuery(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq)
        ParameterCheck.mandatory("blogContainerNode", blogContainerNode);
        ParameterCheck.mandatory("pagingReq", pagingReq);

        int requestTotalCountMax = pagingReq.getRequestTotalCountMax();

        boolean isPublished = true;
        GetBlogPostsCannedQueryParams paramBean = new GetBlogPostsCannedQueryParams(getNodeId(blogContainerNode),
                                                                                    fromDate, toDate,
                                                                                    null, null);

        CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
        CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING);

        // create query params holder
        CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingReq.getQueryExecutionId());

        // return canned query instance
        return getCannedQuery(params);

For this reason, customizing this behaviour can be very hard, since these beans must be selectively overriden to get access to the criteria. In a few words, you just need to find the BlogService bean in blog-context.xml and overwrite beans needed in the context module customization spring context.

Final remarks
It is hard to estimate the time required for an extension on Alfresco when it comes to areas that have not been worked. In these cases is always wiser to study the components structure before setting any delivery date.


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s