mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9156 Start on the calendar entry canned query, with date filtering, based on the Blog one
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28998 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -52,11 +52,20 @@
|
||||
<property name="methodSecurity" ref="CalendarService_security_listCalendarEntries"/>
|
||||
</bean>
|
||||
|
||||
<!-- The multiple site, Date filtering GetChildren Canned Query Factory -->
|
||||
<bean name="calendarGetCalendarEntriesCannedQueryFactory" class="org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQueryFactory">
|
||||
<property name="registry" ref="calendarCannedQueryRegistry"/>
|
||||
<property name="tenantService" ref="tenantService"/>
|
||||
<property name="nodeDAO" ref="nodeDAO"/>
|
||||
<property name="qnameDAO" ref="qnameDAO"/>
|
||||
<property name="cannedQueryDAO" ref="cannedQueryDAO"/>
|
||||
<property name="methodSecurity" ref="CalendarService_security_listCalendarEntries"/>
|
||||
</bean>
|
||||
|
||||
<!-- Calendar Service base bean -->
|
||||
<bean id="calendarService" class="org.alfresco.repo.calendar.CalendarServiceImpl">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
<property name="siteService" ref="SiteService"/>
|
||||
<property name="searchService" ref="SearchService" /> <!-- TODO Temp -->
|
||||
<property name="taggingService" ref="TaggingService"/>
|
||||
<property name="permissionService" ref="PermissionService"/>
|
||||
<property name="transactionService" ref="transactionService" />
|
||||
|
@@ -32,6 +32,8 @@ import org.alfresco.query.CannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryResults;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQuery;
|
||||
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQueryFactory;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -67,6 +69,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
private static final int MAX_QUERY_ENTRY_COUNT = 10000;
|
||||
|
||||
private static final String CANNED_QUERY_GET_CHILDREN = "calendarGetChildrenCannedQueryFactory";
|
||||
private static final String CANNED_QUERY_GET_ENTRIES = "calendarGetCalendarEntriesCannedQueryFactory";
|
||||
|
||||
/**
|
||||
* The logger
|
||||
@@ -75,11 +78,10 @@ public class CalendarServiceImpl implements CalendarService
|
||||
|
||||
private NodeService nodeService;
|
||||
private SiteService siteService;
|
||||
private SearchService searchService; // TODO Temp only
|
||||
private TaggingService taggingService;
|
||||
private PermissionService permissionService;
|
||||
private TransactionService transactionService;
|
||||
private NamedObjectRegistry<CannedQueryFactory<NodeRef>> cannedQueryRegistry;
|
||||
private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
@@ -91,14 +93,6 @@ public class CalendarServiceImpl implements CalendarService
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Temp only
|
||||
*/
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
@@ -117,7 +111,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
/**
|
||||
* Set the registry of {@link CannedQueryFactory canned queries}
|
||||
*/
|
||||
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<NodeRef>> cannedQueryRegistry)
|
||||
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry)
|
||||
{
|
||||
this.cannedQueryRegistry = cannedQueryRegistry;
|
||||
}
|
||||
@@ -360,9 +354,6 @@ public class CalendarServiceImpl implements CalendarService
|
||||
nodeService.deleteNode(entry.getNodeRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Switch to delegating
|
||||
*/
|
||||
@Override
|
||||
public PagingResults<CalendarEntry> listCalendarEntries(
|
||||
String siteShortName, PagingRequest paging)
|
||||
@@ -403,16 +394,34 @@ public class CalendarServiceImpl implements CalendarService
|
||||
return listCalendarEntries(siteShortNames[0], paging);
|
||||
}
|
||||
|
||||
// TODO Use search for now
|
||||
return null;
|
||||
// Use the date one with no dates
|
||||
return listCalendarEntries(siteShortNames, null, null, paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<CalendarEntry> listCalendarEntries(
|
||||
String[] siteShortNames, Date from, Date to, PagingRequest paging)
|
||||
{
|
||||
// TODO Use search for now
|
||||
return null;
|
||||
// Get the containers
|
||||
List<NodeRef> containersL = new ArrayList<NodeRef>();
|
||||
for(String siteShortName : siteShortNames)
|
||||
{
|
||||
NodeRef container = getSiteCalendarContainer(siteShortName, false);
|
||||
if(container != null)
|
||||
{
|
||||
containersL.add(container);
|
||||
}
|
||||
}
|
||||
NodeRef[] containers = containersL.toArray(new NodeRef[containersL.size()]);
|
||||
|
||||
// Run the canned query
|
||||
GetCalendarEntriesCannedQueryFactory cqFactory = (GetCalendarEntriesCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_ENTRIES);
|
||||
GetCalendarEntriesCannedQuery cq = (GetCalendarEntriesCannedQuery)cqFactory.getCannedQuery(
|
||||
containers, from, to, paging
|
||||
);
|
||||
|
||||
// Execute the canned query
|
||||
return cq.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.calendar.cannedqueries;
|
||||
|
||||
import org.alfresco.repo.domain.node.NodeEntity;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Calendar Entity - low level representation of parts of a
|
||||
* {@link CalendarEntry} - used by GetCalendarEntries Canned Query
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CalendarEntity
|
||||
{
|
||||
private Long id; // node id
|
||||
|
||||
private NodeEntity node;
|
||||
|
||||
private String name;
|
||||
|
||||
private String fromDate;
|
||||
private String toDate;
|
||||
|
||||
// Supplemental query-related parameters
|
||||
private Long parentNodeId;
|
||||
private Long nameQNameId;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public CalendarEntity()
|
||||
{
|
||||
}
|
||||
|
||||
public CalendarEntity(Long parentNodeId, Long nameQNameId)
|
||||
{
|
||||
this.parentNodeId = parentNodeId;
|
||||
this.nameQNameId = nameQNameId;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// helper
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return (node != null ? node.getNodeRef() : null);
|
||||
}
|
||||
|
||||
// helper (ISO 8061)
|
||||
public String getCreatedDate()
|
||||
{
|
||||
return ((node != null && node.getAuditableProperties() != null) ? node.getAuditableProperties().getAuditCreated() : null);
|
||||
}
|
||||
|
||||
// helper
|
||||
public String getCreator()
|
||||
{
|
||||
return ((node != null && node.getAuditableProperties() != null) ? node.getAuditableProperties().getAuditCreator() : null);
|
||||
}
|
||||
|
||||
public NodeEntity getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(NodeEntity childNode)
|
||||
{
|
||||
this.node = childNode;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// (ISO-8061)
|
||||
public String getFromDate()
|
||||
{
|
||||
return fromDate;
|
||||
}
|
||||
|
||||
public void setFromDate(String fromISO8601)
|
||||
{
|
||||
this.fromDate = fromISO8601;
|
||||
}
|
||||
|
||||
// (ISO-8061)
|
||||
public String getToDate()
|
||||
{
|
||||
return toDate;
|
||||
}
|
||||
|
||||
public void setToDate(String toISO8061)
|
||||
{
|
||||
this.toDate = toISO8061;
|
||||
}
|
||||
|
||||
// Supplemental query-related parameters
|
||||
|
||||
public Long getParentNodeId()
|
||||
{
|
||||
return parentNodeId;
|
||||
}
|
||||
|
||||
public Long getNameQNameId()
|
||||
{
|
||||
return nameQNameId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* 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.calendar.cannedqueries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.CannedQuery;
|
||||
import org.alfresco.query.CannedQueryParameters;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.repo.calendar.CalendarModel;
|
||||
import org.alfresco.repo.domain.query.CannedQueryDAO;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.calendar.CalendarService;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* This class provides support for {@link CannedQuery canned queries} used by the
|
||||
* {@link CalendarService}.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GetCalendarEntriesCannedQuery extends AbstractCannedQueryPermissions<CalendarEntry>
|
||||
{
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private static final String QUERY_NAMESPACE = "alfresco.query.calendar";
|
||||
private static final String QUERY_SELECT_GET_BLOGS = "select_GetCalendarEntriesCannedQuery";
|
||||
|
||||
private final CannedQueryDAO cannedQueryDAO;
|
||||
|
||||
public GetCalendarEntriesCannedQuery(
|
||||
CannedQueryDAO cannedQueryDAO,
|
||||
MethodSecurityBean<CalendarEntry> methodSecurity,
|
||||
CannedQueryParameters params)
|
||||
{
|
||||
super(params, methodSecurity);
|
||||
this.cannedQueryDAO = cannedQueryDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CalendarEntry> queryAndFilter(CannedQueryParameters parameters)
|
||||
{
|
||||
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
|
||||
|
||||
Object paramBeanObj = parameters.getParameterBean();
|
||||
if (paramBeanObj == null)
|
||||
throw new NullPointerException("Null GetCalendarEntries query params");
|
||||
|
||||
GetCalendarEntriesCannedQueryParams paramBean = (GetCalendarEntriesCannedQueryParams) paramBeanObj;
|
||||
Date entriesFromDate = paramBean.getEntriesFromDate();
|
||||
Date entriesToDate = paramBean.getEntriesToDate();
|
||||
|
||||
// note: refer to SQL for specific DB filtering (eg.parent nodes etc)
|
||||
List<CalendarEntity> results = cannedQueryDAO.executeQuery(QUERY_NAMESPACE, QUERY_SELECT_GET_BLOGS, paramBean, 0, Integer.MAX_VALUE);
|
||||
|
||||
List<CalendarEntity> filtered = new ArrayList<CalendarEntity>(results.size());
|
||||
for (CalendarEntity result : results)
|
||||
{
|
||||
boolean nextNodeIsAcceptable = true;
|
||||
|
||||
Date fromDate = DefaultTypeConverter.INSTANCE.convert(Date.class, result.getFromDate());
|
||||
Date toDate = DefaultTypeConverter.INSTANCE.convert(Date.class, result.getToDate());
|
||||
if(toDate == null)
|
||||
{
|
||||
toDate = fromDate;
|
||||
}
|
||||
|
||||
// Only return entries in the right period
|
||||
if(entriesFromDate != null)
|
||||
{
|
||||
// Needs to end on or after the Filter From date
|
||||
if(toDate == null || toDate.before(entriesFromDate))
|
||||
{
|
||||
nextNodeIsAcceptable = false;
|
||||
}
|
||||
}
|
||||
if(entriesToDate != null)
|
||||
{
|
||||
// Needs to start on or after the Filter End date
|
||||
if(fromDate == null || fromDate.after(entriesToDate))
|
||||
{
|
||||
nextNodeIsAcceptable = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextNodeIsAcceptable)
|
||||
{
|
||||
filtered.add(result);
|
||||
}
|
||||
}
|
||||
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = parameters.getSortDetails().getSortPairs();
|
||||
|
||||
// For now, the BlogService only sorts by a single property.
|
||||
if (sortPairs != null && !sortPairs.isEmpty())
|
||||
{
|
||||
List<Pair<Comparator<CalendarEntity>, SortOrder>> comparators =
|
||||
new ArrayList<Pair<Comparator<CalendarEntity>,SortOrder>>();
|
||||
for(Pair<? extends Object, SortOrder> sortPair : sortPairs)
|
||||
{
|
||||
QName sortProperty = (QName) sortPair.getFirst();
|
||||
final PropertyBasedComparator comparator = new PropertyBasedComparator(sortProperty);
|
||||
comparators.add(new Pair<Comparator<CalendarEntity>, SortOrder>(comparator, sortPair.getSecond()));
|
||||
}
|
||||
NestedComparator comparator = new NestedComparator(comparators);
|
||||
|
||||
// Sort
|
||||
Collections.sort(filtered, comparator);
|
||||
}
|
||||
|
||||
List<CalendarEntry> calendarEntries = new ArrayList<CalendarEntry>(filtered.size());
|
||||
for (CalendarEntity result : filtered)
|
||||
{
|
||||
calendarEntries.add(new CalendarEntryImpl(result));
|
||||
}
|
||||
|
||||
if (start != null)
|
||||
{
|
||||
logger.debug("Base query: "+calendarEntries.size()+" in "+(System.currentTimeMillis()-start)+" msecs");
|
||||
}
|
||||
|
||||
return calendarEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isApplyPostQuerySorting()
|
||||
{
|
||||
// No post-query sorting. It's done within the queryAndFilter() method above.
|
||||
return false;
|
||||
}
|
||||
|
||||
private class CalendarEntryImpl extends org.alfresco.repo.calendar.CalendarEntryImpl
|
||||
{
|
||||
private CalendarEntryImpl(CalendarEntity entity)
|
||||
{
|
||||
super(entity.getNodeRef(), entity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility class to sort {@link CalendarEntry}s on the basis of a Comparable property.
|
||||
* Comparisons of two null properties are considered 'equal' by this comparator.
|
||||
* Comparisons involving one null and one non-null property will return the null property as
|
||||
* being 'before' the non-null property.
|
||||
*
|
||||
* Note that it is the responsibility of the calling code to ensure that the specified
|
||||
* property values actually implement Comparable themselves.
|
||||
*/
|
||||
protected static class PropertyBasedComparator implements Comparator<CalendarEntity>
|
||||
{
|
||||
private QName comparableProperty;
|
||||
|
||||
public PropertyBasedComparator(QName comparableProperty)
|
||||
{
|
||||
this.comparableProperty = comparableProperty;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int compare(CalendarEntity nr1, CalendarEntity nr2)
|
||||
{
|
||||
Comparable prop1 = null;
|
||||
Comparable prop2 = null;
|
||||
if (comparableProperty.equals(CalendarModel.PROP_FROM_DATE))
|
||||
{
|
||||
prop1 = nr1.getFromDate();
|
||||
prop2 = nr2.getFromDate();
|
||||
}
|
||||
else if (comparableProperty.equals(CalendarModel.PROP_TO_DATE))
|
||||
{
|
||||
prop1 = nr1.getToDate();
|
||||
prop2 = nr2.getToDate();
|
||||
}
|
||||
else if (comparableProperty.equals(ContentModel.PROP_CREATED))
|
||||
{
|
||||
prop1 = nr1.getCreatedDate();
|
||||
prop2 = nr2.getCreatedDate();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Unsupported calendar sort property: "+comparableProperty);
|
||||
}
|
||||
|
||||
if (prop1 == null && prop2 == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (prop1 == null && prop2 != null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (prop1 != null && prop2 == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return prop1.compareTo(prop2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static class NestedComparator implements Comparator<CalendarEntity>
|
||||
{
|
||||
private List<Pair<Comparator<CalendarEntity>, SortOrder>> comparators;
|
||||
|
||||
private NestedComparator(List<Pair<Comparator<CalendarEntity>, SortOrder>> comparators)
|
||||
{
|
||||
this.comparators = comparators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(CalendarEntity entry1, CalendarEntity entry2) {
|
||||
for(Pair<Comparator<CalendarEntity>, SortOrder> pc : comparators)
|
||||
{
|
||||
int result = pc.getFirst().compare(entry1, entry2);
|
||||
if(result != 0)
|
||||
{
|
||||
// Sorts differ, return
|
||||
if(pc.getSecond() == SortOrder.ASCENDING)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0 - result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sorts are the same, try the next along
|
||||
}
|
||||
}
|
||||
// No difference on any
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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.calendar.cannedqueries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.AbstractCannedQueryFactory;
|
||||
import org.alfresco.query.CannedQuery;
|
||||
import org.alfresco.query.CannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryPageDetails;
|
||||
import org.alfresco.query.CannedQueryParameters;
|
||||
import org.alfresco.query.CannedQuerySortDetails;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.repo.calendar.CalendarModel;
|
||||
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.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.calendar.CalendarService;
|
||||
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.ParameterCheck;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* A {@link CannedQueryFactory} for various queries relating to {@link CalendarEntry calendar entries}.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*
|
||||
* @see CalendarService#listCalendarEntries(String, PagingRequest)
|
||||
* @see CalendarService#listCalendarEntries(String[], PagingRequest)
|
||||
* @see CalendarService#listCalendarEntries(String[], Date, Date, PagingRequest)
|
||||
*/
|
||||
public class GetCalendarEntriesCannedQueryFactory extends AbstractCannedQueryFactory<CalendarEntry>
|
||||
{
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
protected MethodSecurityBean<CalendarEntry> methodSecurity;
|
||||
protected NodeDAO nodeDAO;
|
||||
protected QNameDAO qnameDAO;
|
||||
protected CannedQueryDAO cannedQueryDAO;
|
||||
protected TenantService tenantService;
|
||||
|
||||
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<CalendarEntry> 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CannedQuery<CalendarEntry> getCannedQuery(CannedQueryParameters parameters)
|
||||
{
|
||||
final GetCalendarEntriesCannedQuery cq = new GetCalendarEntriesCannedQuery(cannedQueryDAO, methodSecurity, parameters);
|
||||
|
||||
return (CannedQuery<CalendarEntry>) cq;
|
||||
}
|
||||
|
||||
public CannedQuery<CalendarEntry> getCannedQuery(NodeRef[] containerNodes, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
ParameterCheck.mandatory("containerNodes", containerNodes);
|
||||
ParameterCheck.mandatory("pagingReq", pagingReq);
|
||||
|
||||
int requestTotalCountMax = pagingReq.getRequestTotalCountMax();
|
||||
|
||||
Long[] containerIds = new Long[containerNodes.length];
|
||||
for(int i=0; i<containerIds.length; i++)
|
||||
{
|
||||
containerIds[i] = getNodeId(containerNodes[i]);
|
||||
}
|
||||
|
||||
//FIXME Need tenant service like for GetChildren?
|
||||
GetCalendarEntriesCannedQueryParams paramBean = new GetCalendarEntriesCannedQueryParams(
|
||||
containerIds, getQNameId(ContentModel.PROP_NAME), fromDate, toDate
|
||||
);
|
||||
|
||||
CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
|
||||
CannedQuerySortDetails cqsd = createCQSortDetails();
|
||||
|
||||
// create query params holder
|
||||
CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingReq.getQueryExecutionId());
|
||||
|
||||
// return canned query instance
|
||||
return getCannedQuery(params);
|
||||
}
|
||||
|
||||
protected CannedQuerySortDetails createCQSortDetails()
|
||||
{
|
||||
List<Pair<? extends Object,SortOrder>> sort = new ArrayList<Pair<? extends Object, SortOrder>>();
|
||||
sort.add(new Pair<QName, SortOrder>(CalendarModel.PROP_FROM_DATE, SortOrder.DESCENDING));
|
||||
sort.add(new Pair<QName, SortOrder>(CalendarModel.PROP_TO_DATE, SortOrder.DESCENDING));
|
||||
|
||||
return new CannedQuerySortDetails(sort);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.calendar.cannedqueries;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Parameter objects for {@link GetCalendarEntriesCannedQuery}.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GetCalendarEntriesCannedQueryParams extends CalendarEntity
|
||||
{
|
||||
private final Long[] siteContainerNodeIds;
|
||||
private final Date entriesFromDate;
|
||||
private final Date entriesToDate;
|
||||
|
||||
public GetCalendarEntriesCannedQueryParams(Long[] siteContainerNodeIds,
|
||||
Long nameQNameId,
|
||||
Date entriesFromDate,
|
||||
Date entriesToDate)
|
||||
{
|
||||
super(null, nameQNameId);
|
||||
|
||||
this.siteContainerNodeIds = siteContainerNodeIds;
|
||||
this.entriesFromDate = entriesFromDate;
|
||||
this.entriesToDate = entriesToDate;
|
||||
}
|
||||
|
||||
public Long[] getSiteContainerNodeIds()
|
||||
{
|
||||
return siteContainerNodeIds;
|
||||
}
|
||||
|
||||
public Date getEntriesFromDate()
|
||||
{
|
||||
return entriesFromDate;
|
||||
}
|
||||
|
||||
public Date getEntriesToDate()
|
||||
{
|
||||
return entriesToDate;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user