ALF-9156 Tweaks to the calendar listing, to return better empty results where needed, and to include the container noderef too

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29038 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-07-14 14:24:16 +00:00
parent 812398be66
commit bfa8a8c4ff
6 changed files with 52 additions and 13 deletions

View File

@@ -36,21 +36,24 @@ import org.alfresco.service.namespace.QName;
public class CalendarEntryImpl extends CalendarEntryDTO public class CalendarEntryImpl extends CalendarEntryDTO
{ {
private NodeRef nodeRef; private NodeRef nodeRef;
private NodeRef containerNodeRef;
private String systemName; private String systemName;
/** /**
* Wraps an existing Calendar Entry node * Wraps an existing Calendar Entry node
*/ */
protected CalendarEntryImpl(NodeRef nodeRef, String systemName) protected CalendarEntryImpl(NodeRef nodeRef, NodeRef containerNodeRef, String systemName)
{ {
this.nodeRef = nodeRef; this.nodeRef = nodeRef;
this.systemName = systemName; this.systemName = systemName;
this.containerNodeRef = containerNodeRef;
} }
protected void recordStorageDetails(NodeRef nodeRef, String systemName) protected void recordStorageDetails(NodeRef nodeRef, NodeRef containerNodeRef, String systemName)
{ {
this.nodeRef = nodeRef; this.nodeRef = nodeRef;
this.systemName = systemName; this.systemName = systemName;
this.containerNodeRef = containerNodeRef;
} }
@Override @Override
@@ -59,6 +62,12 @@ public class CalendarEntryImpl extends CalendarEntryDTO
return nodeRef; return nodeRef;
} }
@Override
public NodeRef getContainerNodeRef()
{
return containerNodeRef;
}
@Override @Override
public String getSystemName() public String getSystemName()
{ {

View File

@@ -20,6 +20,7 @@ package org.alfresco.repo.calendar;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -30,6 +31,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQueryFactory; import org.alfresco.query.CannedQueryFactory;
import org.alfresco.query.CannedQueryResults; import org.alfresco.query.CannedQueryResults;
import org.alfresco.query.EmptyPagingResults;
import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults; import org.alfresco.query.PagingResults;
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQuery; import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQuery;
@@ -58,7 +60,7 @@ import org.apache.commons.logging.LogFactory;
*/ */
public class CalendarServiceImpl implements CalendarService public class CalendarServiceImpl implements CalendarService
{ {
protected static final String CALENDAR_COMPONENT = "calendar"; public static final String CALENDAR_COMPONENT = "calendar";
/** /**
* For backwards compatibility with pre-Swift, we are asking the query to give us an accurate total count of how many * For backwards compatibility with pre-Swift, we are asking the query to give us an accurate total count of how many
@@ -284,7 +286,7 @@ public class CalendarServiceImpl implements CalendarService
NodeRef event = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, entryName); NodeRef event = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, entryName);
if(event != null) if(event != null)
{ {
CalendarEntryImpl entry = new CalendarEntryImpl(event, entryName); CalendarEntryImpl entry = new CalendarEntryImpl(event, container, entryName);
entry.populate(nodeService.getProperties(event)); entry.populate(nodeService.getProperties(event));
entry.setTags(taggingService.getTags(event)); entry.setTags(taggingService.getTags(event));
return entry; return entry;
@@ -326,11 +328,11 @@ public class CalendarServiceImpl implements CalendarService
if(entry instanceof CalendarEntryImpl) if(entry instanceof CalendarEntryImpl)
{ {
entryImpl = (CalendarEntryImpl)entry; entryImpl = (CalendarEntryImpl)entry;
entryImpl.recordStorageDetails(nodeRef, name); entryImpl.recordStorageDetails(nodeRef, container, name);
} }
else else
{ {
entryImpl = new CalendarEntryImpl(nodeRef, name); entryImpl = new CalendarEntryImpl(nodeRef, container, name);
entryImpl.populate(properties); entryImpl.populate(properties);
entryImpl.setTags(entry.getTags()); entryImpl.setTags(entry.getTags());
} }
@@ -379,7 +381,7 @@ public class CalendarServiceImpl implements CalendarService
if(container == null) if(container == null)
{ {
// No events // No events
return null; return new EmptyPagingResults<CalendarEntry>();
} }
// Build our sorting, by date // Build our sorting, by date
@@ -398,7 +400,7 @@ public class CalendarServiceImpl implements CalendarService
// Execute the canned query // Execute the canned query
CannedQueryResults<NodeRef> results = cq.execute(); CannedQueryResults<NodeRef> results = cq.execute();
return wrap(results); return wrap(results, container);
} }
@Override @Override
@@ -432,6 +434,13 @@ public class CalendarServiceImpl implements CalendarService
} }
NodeRef[] containers = containersL.toArray(new NodeRef[containersL.size()]); NodeRef[] containers = containersL.toArray(new NodeRef[containersL.size()]);
// Check we have some sites to look for
if(containers.length == 0)
{
// No sites, so no events
return new EmptyPagingResults<CalendarEntry>();
}
// Run the canned query // Run the canned query
GetCalendarEntriesCannedQueryFactory cqFactory = (GetCalendarEntriesCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_ENTRIES); GetCalendarEntriesCannedQueryFactory cqFactory = (GetCalendarEntriesCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_ENTRIES);
GetCalendarEntriesCannedQuery cq = (GetCalendarEntriesCannedQuery)cqFactory.getCannedQuery( GetCalendarEntriesCannedQuery cq = (GetCalendarEntriesCannedQuery)cqFactory.getCannedQuery(
@@ -446,7 +455,7 @@ public class CalendarServiceImpl implements CalendarService
* Our class to wrap up paged results of NodeRefs as * Our class to wrap up paged results of NodeRefs as
* CalendarEntry instances * CalendarEntry instances
*/ */
private PagingResults<CalendarEntry> wrap(final PagingResults<NodeRef> results) private PagingResults<CalendarEntry> wrap(final PagingResults<NodeRef> results, final NodeRef container)
{ {
return new PagingResults<CalendarEntry>() return new PagingResults<CalendarEntry>()
{ {
@@ -463,7 +472,7 @@ public class CalendarServiceImpl implements CalendarService
{ {
String entryName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); String entryName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
CalendarEntryImpl entry = new CalendarEntryImpl(nodeRef, entryName); CalendarEntryImpl entry = new CalendarEntryImpl(nodeRef, container, entryName);
entry.populate(nodeService.getProperties(nodeRef)); entry.populate(nodeService.getProperties(nodeRef));
entry.setTags(taggingService.getTags(nodeRef)); entry.setTags(taggingService.getTags(nodeRef));
entries.add(entry); entries.add(entry);

View File

@@ -536,7 +536,7 @@ public class CalendarServiceImplTest
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size()); assertEquals(2, results.getPage().size());
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
assertEquals(null, results); // TODO is this the right answer? assertEquals(0, results.getPage().size());
// Join the site, now we can see both // Join the site, now we can see both
@@ -584,7 +584,7 @@ public class CalendarServiceImplTest
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size()); assertEquals(2, results.getPage().size());
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
assertEquals(null, results); assertEquals(0, results.getPage().size());
// Tidy // Tidy

View File

@@ -169,7 +169,12 @@ public class GetCalendarEntriesCannedQuery extends AbstractCannedQueryPermission
{ {
private CalendarEntryImpl(CalendarEntity entity) private CalendarEntryImpl(CalendarEntity entity)
{ {
super(entity.getNodeRef(), entity.getName()); super(
entity.getNodeRef(),
// TODO Fetch this from the database layer when querying
nodeService.getPrimaryParent(entity.getNodeRef()).getParentRef(),
entity.getName()
);
super.populate(nodeService.getProperties(entity.getNodeRef())); super.populate(nodeService.getProperties(entity.getNodeRef()));
super.setTags(taggingService.getTags(entity.getNodeRef())); super.setTags(taggingService.getTags(entity.getNodeRef()));
} }

View File

@@ -37,6 +37,11 @@ public interface CalendarEntry extends Serializable, PermissionCheckValue {
*/ */
NodeRef getNodeRef(); NodeRef getNodeRef();
/**
* @return the NodeRef of the site container this belongs to
*/
NodeRef getContainerNodeRef();
/** /**
* @return the System generated name for the event * @return the System generated name for the event
*/ */

View File

@@ -33,7 +33,10 @@ import org.alfresco.service.cmr.repository.NodeRef;
* @since 4.0 * @since 4.0
*/ */
public class CalendarEntryDTO implements CalendarEntry, Serializable { public class CalendarEntryDTO implements CalendarEntry, Serializable {
private static final long serialVersionUID = -7997650453677545845L;
private NodeRef nodeRef; private NodeRef nodeRef;
private NodeRef containerNodeRef;
private String systemName; private String systemName;
private String title; private String title;
@@ -76,6 +79,14 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable {
return nodeRef; return nodeRef;
} }
/**
* @return the NodeRef of the calendar's container in the site
*/
public NodeRef getContainerNodeRef()
{
return containerNodeRef;
}
/** /**
* @return the System generated name for the event * @return the System generated name for the event
*/ */