mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -36,21 +36,24 @@ import org.alfresco.service.namespace.QName;
|
||||
public class CalendarEntryImpl extends CalendarEntryDTO
|
||||
{
|
||||
private NodeRef nodeRef;
|
||||
private NodeRef containerNodeRef;
|
||||
private String systemName;
|
||||
|
||||
/**
|
||||
* Wraps an existing Calendar Entry node
|
||||
*/
|
||||
protected CalendarEntryImpl(NodeRef nodeRef, String systemName)
|
||||
protected CalendarEntryImpl(NodeRef nodeRef, NodeRef containerNodeRef, String systemName)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
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.systemName = systemName;
|
||||
this.containerNodeRef = containerNodeRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,6 +62,12 @@ public class CalendarEntryImpl extends CalendarEntryDTO
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeRef getContainerNodeRef()
|
||||
{
|
||||
return containerNodeRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemName()
|
||||
{
|
||||
|
@@ -20,6 +20,7 @@ package org.alfresco.repo.calendar;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -30,6 +31,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.CannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryResults;
|
||||
import org.alfresco.query.EmptyPagingResults;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQuery;
|
||||
@@ -58,7 +60,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
*/
|
||||
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
|
||||
@@ -284,7 +286,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
NodeRef event = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, entryName);
|
||||
if(event != null)
|
||||
{
|
||||
CalendarEntryImpl entry = new CalendarEntryImpl(event, entryName);
|
||||
CalendarEntryImpl entry = new CalendarEntryImpl(event, container, entryName);
|
||||
entry.populate(nodeService.getProperties(event));
|
||||
entry.setTags(taggingService.getTags(event));
|
||||
return entry;
|
||||
@@ -326,11 +328,11 @@ public class CalendarServiceImpl implements CalendarService
|
||||
if(entry instanceof CalendarEntryImpl)
|
||||
{
|
||||
entryImpl = (CalendarEntryImpl)entry;
|
||||
entryImpl.recordStorageDetails(nodeRef, name);
|
||||
entryImpl.recordStorageDetails(nodeRef, container, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
entryImpl = new CalendarEntryImpl(nodeRef, name);
|
||||
entryImpl = new CalendarEntryImpl(nodeRef, container, name);
|
||||
entryImpl.populate(properties);
|
||||
entryImpl.setTags(entry.getTags());
|
||||
}
|
||||
@@ -379,7 +381,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
if(container == null)
|
||||
{
|
||||
// No events
|
||||
return null;
|
||||
return new EmptyPagingResults<CalendarEntry>();
|
||||
}
|
||||
|
||||
// Build our sorting, by date
|
||||
@@ -398,7 +400,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
|
||||
// Execute the canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
return wrap(results);
|
||||
return wrap(results, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -432,6 +434,13 @@ public class CalendarServiceImpl implements CalendarService
|
||||
}
|
||||
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
|
||||
GetCalendarEntriesCannedQueryFactory cqFactory = (GetCalendarEntriesCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_ENTRIES);
|
||||
GetCalendarEntriesCannedQuery cq = (GetCalendarEntriesCannedQuery)cqFactory.getCannedQuery(
|
||||
@@ -446,7 +455,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
* Our class to wrap up paged results of NodeRefs as
|
||||
* 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>()
|
||||
{
|
||||
@@ -463,7 +472,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
{
|
||||
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.setTags(taggingService.getTags(nodeRef));
|
||||
entries.add(entry);
|
||||
|
@@ -536,7 +536,7 @@ public class CalendarServiceImplTest
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(2, results.getPage().size());
|
||||
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
|
||||
@@ -584,7 +584,7 @@ public class CalendarServiceImplTest
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(2, results.getPage().size());
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(null, results);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
|
||||
// Tidy
|
||||
|
@@ -169,7 +169,12 @@ public class GetCalendarEntriesCannedQuery extends AbstractCannedQueryPermission
|
||||
{
|
||||
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.setTags(taggingService.getTags(entity.getNodeRef()));
|
||||
}
|
||||
|
@@ -37,6 +37,11 @@ public interface CalendarEntry extends Serializable, PermissionCheckValue {
|
||||
*/
|
||||
NodeRef getNodeRef();
|
||||
|
||||
/**
|
||||
* @return the NodeRef of the site container this belongs to
|
||||
*/
|
||||
NodeRef getContainerNodeRef();
|
||||
|
||||
/**
|
||||
* @return the System generated name for the event
|
||||
*/
|
||||
|
@@ -33,7 +33,10 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CalendarEntryDTO implements CalendarEntry, Serializable {
|
||||
private static final long serialVersionUID = -7997650453677545845L;
|
||||
|
||||
private NodeRef nodeRef;
|
||||
private NodeRef containerNodeRef;
|
||||
private String systemName;
|
||||
|
||||
private String title;
|
||||
@@ -76,6 +79,14 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable {
|
||||
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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user