mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Refactor out the common entity and factory parts of the Calendar and Blog canned queries
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29436 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.query.AbstractCannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryPageDetails;
|
||||
import org.alfresco.query.CannedQuerySortDetails;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.domain.query.CannedQueryDAO;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* An intermediate {@link AbstractCannedQueryFactory} layer, for various
|
||||
* implementations that need to know about QName IDs and similar
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractQNameAwareCannedQueryFactory<R> extends AbstractCannedQueryFactory<R>
|
||||
{
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
protected MethodSecurityBean<R> methodSecurity;
|
||||
protected NodeDAO nodeDAO;
|
||||
protected QNameDAO qnameDAO;
|
||||
protected TenantService tenantService;
|
||||
protected CannedQueryDAO cannedQueryDAO;
|
||||
|
||||
public void setNodeDAO(NodeDAO nodeDAO)
|
||||
{
|
||||
this.nodeDAO = nodeDAO;
|
||||
}
|
||||
|
||||
public void setQnameDAO(QNameDAO qnameDAO)
|
||||
{
|
||||
this.qnameDAO = qnameDAO;
|
||||
}
|
||||
|
||||
public void setCannedQueryDAO(CannedQueryDAO cannedQueryDAO)
|
||||
{
|
||||
this.cannedQueryDAO = cannedQueryDAO;
|
||||
}
|
||||
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
public void setMethodSecurity(MethodSecurityBean<R> methodSecurity)
|
||||
{
|
||||
this.methodSecurity = methodSecurity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
super.afterPropertiesSet();
|
||||
|
||||
PropertyCheck.mandatory(this, "methodSecurity", methodSecurity);
|
||||
PropertyCheck.mandatory(this, "nodeDAO", nodeDAO);
|
||||
PropertyCheck.mandatory(this, "qnameDAO", qnameDAO);
|
||||
PropertyCheck.mandatory(this, "cannedQueryDAO", cannedQueryDAO);
|
||||
PropertyCheck.mandatory(this, "tenantService", tenantService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Canned Query sort details, for the given list of properties
|
||||
* and if they should be Ascending or Descending
|
||||
*/
|
||||
protected CannedQuerySortDetails createCQSortDetails(List<Pair<QName,Boolean>> sort)
|
||||
{
|
||||
List<Pair<? extends Object,SortOrder>> details = new ArrayList<Pair<? extends Object, SortOrder>>();
|
||||
for(Pair<QName,Boolean> sortProp : sort)
|
||||
{
|
||||
details.add(new Pair<QName, SortOrder>(
|
||||
sortProp.getFirst(),
|
||||
(sortProp.getSecond() ? SortOrder.ASCENDING : SortOrder.DESCENDING)
|
||||
));
|
||||
}
|
||||
return new CannedQuerySortDetails(details);
|
||||
}
|
||||
|
||||
protected CannedQueryPageDetails createCQPageDetails(PagingRequest pagingReq)
|
||||
{
|
||||
int skipCount = pagingReq.getSkipCount();
|
||||
if (skipCount == -1)
|
||||
{
|
||||
skipCount = CannedQueryPageDetails.DEFAULT_SKIP_RESULTS;
|
||||
}
|
||||
|
||||
int maxItems = pagingReq.getMaxItems();
|
||||
if (maxItems == -1)
|
||||
{
|
||||
maxItems = CannedQueryPageDetails.DEFAULT_PAGE_SIZE;
|
||||
}
|
||||
|
||||
// page details
|
||||
CannedQueryPageDetails cqpd = new CannedQueryPageDetails(skipCount, maxItems);
|
||||
return cqpd;
|
||||
}
|
||||
|
||||
protected Long getQNameId(QName qname)
|
||||
{
|
||||
Pair<Long, QName> qnamePair = qnameDAO.getQName(qname);
|
||||
if (qnamePair == null)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("QName does not exist: " + qname); // possible ... eg. blg:blogPost if a blog has never been posted externally
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return qnamePair.getFirst();
|
||||
}
|
||||
|
||||
protected Long getNodeId(NodeRef nodeRef)
|
||||
{
|
||||
Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(tenantService.getName(nodeRef));
|
||||
if (nodePair == null)
|
||||
{
|
||||
throw new InvalidNodeRefException("Node ref does not exist: " + nodeRef, nodeRef);
|
||||
}
|
||||
return nodePair.getFirst();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user